[New] Added tests for inspector with HTTP request test

This commit is contained in:
Robert von Burg 2014-01-22 20:18:22 +01:00
parent 4a0a0d5001
commit 495c925094
20 changed files with 1197 additions and 46 deletions

View File

@ -39,9 +39,11 @@ import li.strolch.rest.inspector.model.AgentOverview;
import li.strolch.rest.inspector.model.ElementMapOverview;
import li.strolch.rest.inspector.model.ElementMapType;
import li.strolch.rest.inspector.model.ElementMapsOverview;
import li.strolch.rest.inspector.model.OrderDetail;
import li.strolch.rest.inspector.model.OrderOverview;
import li.strolch.rest.inspector.model.RealmDetail;
import li.strolch.rest.inspector.model.RealmOverview;
import li.strolch.rest.inspector.model.ResourceDetail;
import li.strolch.rest.inspector.model.ResourceOverview;
import li.strolch.rest.inspector.model.StrolchElementOverview;
import li.strolch.rest.inspector.model.TypeDetail;
@ -189,7 +191,7 @@ public class Inspector {
* Order inspector
* </p>
* <p>
* Returns an overview of the {@link Order Orderss}. This is a list of all the types and the size each type has
* Returns an overview of the {@link Order Orders}. This is a list of all the types and the size each type has
* </p>
*
* @param realm
@ -228,6 +230,25 @@ public class Inspector {
// TODO for the get element type details, we should not simply query all objects, but rather find a solution to query only the id, name, type and date, state for the order
/**
* <p>
* Resource type inspector
* </p>
* <p>
* Returns an overview of the {@link Resource Resources} with the given type. This is a list of overviews of the
* resources
* </p>
*
* @param realm
* the realm for which the resource type overview is to be returned
* @param type
*
* @return an overview of the {@link Resource Resources} with the given type. This is a list of overviews of the
* resources
*
* @see TypeDetail
* @see StrolchElementOverview
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{realm}/resource/{type}")
@ -240,8 +261,7 @@ public class Inspector {
List<Resource> byType = tx.getResourceMap().getElementsBy(tx, type);
List<StrolchElementOverview> elementOverviews = new ArrayList<>(byType.size());
for (Resource resource : byType) {
ResourceOverview resourceOverview = new ResourceOverview(resource.getId(), resource.getName(),
resource.getType());
ResourceOverview resourceOverview = new ResourceOverview(resource);
elementOverviews.add(resourceOverview);
}
typeDetail = new TypeDetail(type, elementOverviews);
@ -252,6 +272,23 @@ public class Inspector {
return Response.ok().entity(entity).build();
}
/**
* <p>
* Order type inspector
* </p>
* <p>
* Returns an overview of the {@link Order Orders} with the given type. This is a list of overviews of the orders
* </p>
*
* @param realm
* the realm for which the order type overview is to be returned
* @param type
*
* @return an overview of the {@link Order Orders} with the given type. This is a list of overviews of the orders
*
* @see TypeDetail
* @see StrolchElementOverview
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{realm}/order/{type}")
@ -264,8 +301,7 @@ public class Inspector {
List<Order> byType = tx.getOrderMap().getElementsBy(tx, type);
List<StrolchElementOverview> elementOverviews = new ArrayList<>(byType.size());
for (Order order : byType) {
OrderOverview orderOverview = new OrderOverview(order.getId(), order.getName(), order.getType(),
order.getDate(), order.getState());
OrderOverview orderOverview = new OrderOverview(order);
elementOverviews.add(orderOverview);
}
typeDetail = new TypeDetail(type, elementOverviews);
@ -276,6 +312,26 @@ public class Inspector {
return Response.ok().entity(entity).build();
}
/**
* <p>
* Resource inspector
* </p>
*
* <p>
* Returns the resource with the given id
* </p>
*
* @param realm
* the realm for which the resource is to be returned
* @param type
* the type of the resource
* @param id
* the id of the resource
*
* @return the resource with the given id
*
* @see Res
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{realm}/resource/{type}/{id}")
@ -292,10 +348,8 @@ public class Inspector {
throw new StrolchException("No Resource exists for " + type + "/" + id);
}
ResourceOverview resourceOverview = new ResourceOverview(resource.getId(), resource.getName(),
resource.getType());
GenericEntity<ResourceOverview> entity = new GenericEntity<ResourceOverview>(resourceOverview,
ResourceOverview.class) {
ResourceDetail resourceDetail = new ResourceDetail(resource);
GenericEntity<ResourceDetail> entity = new GenericEntity<ResourceDetail>(resourceDetail, ResourceDetail.class) {
};
return Response.ok().entity(entity).build();
}
@ -316,9 +370,8 @@ public class Inspector {
throw new StrolchException("No Order exists for " + type + "/" + id);
}
OrderOverview orderOverview = new OrderOverview(order.getId(), order.getName(), order.getType(),
order.getDate(), order.getState());
GenericEntity<OrderOverview> entity = new GenericEntity<OrderOverview>(orderOverview, OrderOverview.class) {
OrderDetail orderDetail = new OrderDetail(order);
GenericEntity<OrderDetail> entity = new GenericEntity<OrderDetail>(orderDetail, OrderDetail.class) {
};
return Response.ok().entity(entity).build();
}

View File

@ -4,10 +4,11 @@ import javax.ws.rs.core.Response;
import javax.ws.rs.ext.ExceptionMapper;
import javax.ws.rs.ext.Provider;
import org.glassfish.grizzly.utils.Exceptions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ch.eitchnet.utils.helper.StringHelper;
@Provider
public class StrolchRestfulExceptionMapper implements ExceptionMapper<Exception> {
@ -16,6 +17,6 @@ public class StrolchRestfulExceptionMapper implements ExceptionMapper<Exception>
@Override
public Response toResponse(Exception ex) {
logger.error("Handling exception " + ex.getClass(), ex);
return Response.status(500).entity(Exceptions.getStackTraceAsString(ex)).type("text/plain").build();
return Response.status(500).entity(StringHelper.formatException(ex)).type("text/plain").build();
}
}

View File

@ -95,4 +95,38 @@ public class ElementMapOverview {
public void setTypeOverviews(List<TypeOverview> typeOverviews) {
this.typeOverviews = typeOverviews;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.elementMapName == null) ? 0 : this.elementMapName.hashCode());
result = prime * result + (int) (this.size ^ (this.size >>> 32));
result = prime * result + ((this.typeOverviews == null) ? 0 : this.typeOverviews.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ElementMapOverview other = (ElementMapOverview) obj;
if (this.elementMapName == null) {
if (other.elementMapName != null)
return false;
} else if (!this.elementMapName.equals(other.elementMapName))
return false;
if (this.size != other.size)
return false;
if (this.typeOverviews == null) {
if (other.typeOverviews != null)
return false;
} else if (!this.typeOverviews.equals(other.typeOverviews))
return false;
return true;
}
}

View File

@ -50,11 +50,22 @@ public class ElementMapsOverview {
* @param elementMapType
*/
public ElementMapsOverview(ElementMapType elementMapType) {
super();
this.elementMapType = elementMapType;
this.name = elementMapType.getName();
}
/**
*
* @param elementMapType
* @param nrOfElements
* @param types
*/
public ElementMapsOverview(ElementMapType elementMapType, long nrOfElements, Set<String> types) {
this(elementMapType);
this.nrOfElements = nrOfElements;
this.types = types;
}
/**
* @return the name
*/
@ -114,4 +125,41 @@ public class ElementMapsOverview {
public void setNrOfElements(long nrOfElements) {
this.nrOfElements = nrOfElements;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.elementMapType == null) ? 0 : this.elementMapType.hashCode());
result = prime * result + ((this.name == null) ? 0 : this.name.hashCode());
result = prime * result + (int) (this.nrOfElements ^ (this.nrOfElements >>> 32));
result = prime * result + ((this.types == null) ? 0 : this.types.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ElementMapsOverview other = (ElementMapsOverview) obj;
if (this.elementMapType != other.elementMapType)
return false;
if (this.name == null) {
if (other.name != null)
return false;
} else if (!this.name.equals(other.name))
return false;
if (this.nrOfElements != other.nrOfElements)
return false;
if (this.types == null) {
if (other.types != null)
return false;
} else if (!this.types.equals(other.types))
return false;
return true;
}
}

View File

@ -0,0 +1,111 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.rest.inspector.model;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSeeAlso;
import li.strolch.model.GroupedParameterizedElement;
import li.strolch.model.ParameterBag;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement(name = "GroupedParameterizedElement")
@XmlSeeAlso({ ResourceDetail.class, OrderDetail.class })
public class GroupedParameterizedElementDetail extends StrolchElementDetail {
@XmlElement(name = "parameterBags", type = ParameterizedElementDetail.class)
private List<ParameterizedElementDetail> parameterizedElements;
public GroupedParameterizedElementDetail() {
// no-arg constructor for JAXB
}
/**
* @param id
* @param name
* @param type
* @param parameterizedElements
*/
public GroupedParameterizedElementDetail(String id, String name, String type,
List<ParameterizedElementDetail> parameterizedElements) {
super(id, name, type);
this.parameterizedElements = parameterizedElements;
}
/**
* @param strolchElement
*/
public GroupedParameterizedElementDetail(GroupedParameterizedElement groupedParameterizedElement) {
super(groupedParameterizedElement);
Set<String> bagKeySet = groupedParameterizedElement.getParameterBagKeySet();
this.parameterizedElements = new ArrayList<>(bagKeySet.size());
for (String bagId : bagKeySet) {
ParameterBag parameterBag = groupedParameterizedElement.getParameterBag(bagId);
this.parameterizedElements.add(new ParameterizedElementDetail(parameterBag));
}
}
/**
* @return the parameterizedElements
*/
public List<ParameterizedElementDetail> getParameterizedElements() {
return this.parameterizedElements;
}
/**
* @param parameterizedElements
* the parameterizedElements to set
*/
public void setParameterizedElements(List<ParameterizedElementDetail> parameterizedElements) {
this.parameterizedElements = parameterizedElements;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((this.parameterizedElements == null) ? 0 : this.parameterizedElements.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
GroupedParameterizedElementDetail other = (GroupedParameterizedElementDetail) obj;
if (this.parameterizedElements == null) {
if (other.parameterizedElements != null)
return false;
} else if (!this.parameterizedElements.equals(other.parameterizedElements))
return false;
return true;
}
}

View File

@ -0,0 +1,129 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.rest.inspector.model;
import java.util.Date;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import li.strolch.model.Order;
import li.strolch.model.State;
import ch.eitchnet.utils.iso8601.ISO8601FormatFactory;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement(name = "Order")
@XmlType(name = "")
public class OrderDetail extends GroupedParameterizedElementDetail {
@XmlAttribute(name = "date")
private String date;
@XmlAttribute(name = "state")
private State state;
public OrderDetail() {
// no-arg constructor for JAXB
}
/**
* @param id
* @param name
* @param type
* @param date
* @param state
* @param parameterizedElementDetails
*/
public OrderDetail(String id, String name, String type, Date date, State state,
List<ParameterizedElementDetail> parameterizedElementDetails) {
super(id, name, type, parameterizedElementDetails);
this.state = state;
this.date = ISO8601FormatFactory.getInstance().formatDate(date);
}
/**
* @param order
*/
public OrderDetail(Order order) {
super(order);
this.state = order.getState();
this.date = ISO8601FormatFactory.getInstance().formatDate(order.getDate());
}
/**
* @return the date
*/
public String getDate() {
return this.date;
}
/**
* @param date
* the date to set
*/
public void setDate(String date) {
this.date = date;
}
/**
* @return the state
*/
public State getState() {
return this.state;
}
/**
* @param state
* the state to set
*/
public void setState(State state) {
this.state = state;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((this.date == null) ? 0 : this.date.hashCode());
result = prime * result + ((this.state == null) ? 0 : this.state.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
OrderDetail other = (OrderDetail) obj;
if (this.date == null) {
if (other.date != null)
return false;
} else if (!this.date.equals(other.date))
return false;
if (this.state != other.state)
return false;
return true;
}
}

View File

@ -22,6 +22,7 @@ import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import li.strolch.model.Order;
import li.strolch.model.State;
import ch.eitchnet.utils.iso8601.ISO8601FormatFactory;
@ -52,6 +53,15 @@ public class OrderOverview extends StrolchElementOverview {
this.date = ISO8601FormatFactory.getInstance().formatDate(date);
}
/**
* @param order
*/
public OrderOverview(Order order) {
super(order);
this.state = order.getState();
this.date = ISO8601FormatFactory.getInstance().formatDate(order.getDate());
}
/**
* @return the date
*/
@ -81,4 +91,32 @@ public class OrderOverview extends StrolchElementOverview {
public void setState(State state) {
this.state = state;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((this.date == null) ? 0 : this.date.hashCode());
result = prime * result + ((this.state == null) ? 0 : this.state.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
OrderOverview other = (OrderOverview) obj;
if (this.date == null) {
if (other.date != null)
return false;
} else if (!this.date.equals(other.date))
return false;
if (this.state != other.state)
return false;
return true;
}
}

View File

@ -0,0 +1,174 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.rest.inspector.model;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import li.strolch.model.parameter.Parameter;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement(name = "Parameter")
public class ParameterDetail extends StrolchElementDetail {
@XmlAttribute(name = "hidden")
private boolean hidden;
@XmlAttribute(name = "interpretation")
private String interpretation;
@XmlAttribute(name = "uom")
private String uom;
@XmlAttribute(name = "value")
private String value;
public ParameterDetail() {
// no-arg constructor for JAXB
}
/**
*
* @param id
* @param name
* @param type
* @param hidden
* @param interpretation
* @param uom
* @param value
*/
public ParameterDetail(String id, String name, String type, boolean hidden, String interpretation, String uom,
String value) {
super(id, name, type);
this.hidden = hidden;
this.interpretation = interpretation;
this.uom = uom;
this.value = value;
}
/**
* @param parameter
*/
public ParameterDetail(Parameter<?> parameter) {
super(parameter);
this.hidden = parameter.isHidden();
this.interpretation = parameter.getInterpretation();
this.uom = parameter.getUom();
this.value = parameter.getValueAsString();
}
/**
* @return the hidden
*/
public boolean isHidden() {
return this.hidden;
}
/**
* @param hidden
* the hidden to set
*/
public void setHidden(boolean hidden) {
this.hidden = hidden;
}
/**
* @return the interpretation
*/
public String getInterpretation() {
return this.interpretation;
}
/**
* @param interpretation
* the interpretation to set
*/
public void setInterpretation(String interpretation) {
this.interpretation = interpretation;
}
/**
* @return the uom
*/
public String getUom() {
return this.uom;
}
/**
* @param uom
* the uom to set
*/
public void setUom(String uom) {
this.uom = uom;
}
/**
* @return the value
*/
public String getValue() {
return this.value;
}
/**
* @param value
* the value to set
*/
public void setValue(String value) {
this.value = value;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + (this.hidden ? 1231 : 1237);
result = prime * result + ((this.interpretation == null) ? 0 : this.interpretation.hashCode());
result = prime * result + ((this.uom == null) ? 0 : this.uom.hashCode());
result = prime * result + ((this.value == null) ? 0 : this.value.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
ParameterDetail other = (ParameterDetail) obj;
if (this.hidden != other.hidden)
return false;
if (this.interpretation == null) {
if (other.interpretation != null)
return false;
} else if (!this.interpretation.equals(other.interpretation))
return false;
if (this.uom == null) {
if (other.uom != null)
return false;
} else if (!this.uom.equals(other.uom))
return false;
if (this.value == null) {
if (other.value != null)
return false;
} else if (!this.value.equals(other.value))
return false;
return true;
}
}

View File

@ -0,0 +1,106 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.rest.inspector.model;
import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import li.strolch.model.ParameterizedElement;
import li.strolch.model.parameter.Parameter;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement(name = "ParameterBag")
public class ParameterizedElementDetail extends StrolchElementDetail {
@XmlElement(name = "parameters", type = ParameterDetail.class)
private List<ParameterDetail> parameters;
public ParameterizedElementDetail() {
// no-arg constructor for JAXB
}
/**
* @param id
* @param name
* @param type
* @param parameters
*/
public ParameterizedElementDetail(String id, String name, String type, List<ParameterDetail> parameters) {
super(id, name, type);
this.parameters = parameters;
}
/**
* @param strolchElement
*/
public ParameterizedElementDetail(ParameterizedElement parameterizedElement) {
super(parameterizedElement);
List<Parameter<?>> parameters = parameterizedElement.getParameters();
this.parameters = new ArrayList<>(parameters.size());
for (Parameter<?> parameter : parameters) {
this.parameters.add(new ParameterDetail(parameter));
}
}
/**
* @return the parameters
*/
public List<ParameterDetail> getParameters() {
return this.parameters;
}
/**
* @param parameters
* the parameters to set
*/
public void setParameters(List<ParameterDetail> parameters) {
this.parameters = parameters;
}
@Override
public int hashCode() {
final int prime = 31;
int result = super.hashCode();
result = prime * result + ((this.parameters == null) ? 0 : this.parameters.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (!super.equals(obj))
return false;
if (getClass() != obj.getClass())
return false;
ParameterizedElementDetail other = (ParameterizedElementDetail) obj;
if (this.parameters == null) {
if (other.parameters != null)
return false;
} else if (!this.parameters.equals(other.parameters))
return false;
return true;
}
}

View File

@ -29,7 +29,7 @@ import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name = "Realm")
public class RealmDetail {
@XmlElement(name = "ElementMaps")
@XmlElement(name = "elementMaps")
private List<ElementMapsOverview> elementMapOverviews;
public RealmDetail() {
@ -54,4 +54,29 @@ public class RealmDetail {
public void setElementMapOverviews(List<ElementMapsOverview> elementMapOverviews) {
this.elementMapOverviews = elementMapOverviews;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.elementMapOverviews == null) ? 0 : this.elementMapOverviews.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
RealmDetail other = (RealmDetail) obj;
if (this.elementMapOverviews == null) {
if (other.elementMapOverviews != null)
return false;
} else if (!this.elementMapOverviews.equals(other.elementMapOverviews))
return false;
return true;
}
}

View File

@ -36,10 +36,13 @@ public class RealmOverview {
// no-arg constructor for JAXB
}
/**
* @param realmName
* @param size
*/
public RealmOverview(String realmName, long size) {
this.realmName = realmName;
this.size = size;
}
/**

View File

@ -0,0 +1,55 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.rest.inspector.model;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import li.strolch.model.Resource;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement(name = "Resource")
@XmlType(name = "")
public class ResourceDetail extends GroupedParameterizedElementDetail {
public ResourceDetail() {
// no-arg constructor for JAXB
}
/**
* @param id
* @param name
* @param type
* @param parameterizedElements
*/
public ResourceDetail(String id, String name, String type, List<ParameterizedElementDetail> parameterizedElements) {
super(id, name, type, parameterizedElements);
}
/**
* @param resource
*/
public ResourceDetail(Resource resource) {
super(resource);
}
}

View File

@ -15,11 +15,16 @@
*/
package li.strolch.rest.inspector.model;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import li.strolch.model.Resource;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement(name = "Resource")
public class ResourceOverview extends StrolchElementOverview {
@ -35,4 +40,11 @@ public class ResourceOverview extends StrolchElementOverview {
public ResourceOverview(String id, String name, String type) {
super(id, name, type);
}
/**
* @param resource
*/
public ResourceOverview(Resource resource) {
super(resource);
}
}

View File

@ -0,0 +1,144 @@
/*
* Copyright 2013 Robert von Burg <eitch@eitchnet.ch>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package li.strolch.rest.inspector.model;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlSeeAlso;
import li.strolch.model.StrolchElement;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
@XmlAccessorType(XmlAccessType.NONE)
@XmlSeeAlso({ GroupedParameterizedElementDetail.class, ParameterizedElementDetail.class, ParameterDetail.class })
public abstract class StrolchElementDetail {
@XmlAttribute(name = "id", required = true)
private String id;
@XmlAttribute(name = "name", required = true)
private String name;
@XmlAttribute(name = "type", required = true)
private String type;
public StrolchElementDetail() {
// no-arg constructor for JAXB
}
/**
* @param id
* @param name
* @param type
*/
public StrolchElementDetail(String id, String name, String type) {
this.id = id;
this.name = name;
this.type = type;
}
/**
* @param strolchElement
*/
public StrolchElementDetail(StrolchElement strolchElement) {
this.id = strolchElement.getId();
this.name = strolchElement.getName();
this.type = strolchElement.getType();
}
/**
* @return the id
*/
public String getId() {
return this.id;
}
/**
* @param id
* the id to set
*/
public void setId(String id) {
this.id = id;
}
/**
* @return the name
*/
public String getName() {
return this.name;
}
/**
* @param name
* the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the type
*/
public String getType() {
return this.type;
}
/**
* @param type
* the type to set
*/
public void setType(String type) {
this.type = type;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.id == null) ? 0 : this.id.hashCode());
result = prime * result + ((this.name == null) ? 0 : this.name.hashCode());
result = prime * result + ((this.type == null) ? 0 : this.type.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
StrolchElementDetail other = (StrolchElementDetail) obj;
if (this.id == null) {
if (other.id != null)
return false;
} else if (!this.id.equals(other.id))
return false;
if (this.name == null) {
if (other.name != null)
return false;
} else if (!this.name.equals(other.name))
return false;
if (this.type == null) {
if (other.type != null)
return false;
} else if (!this.type.equals(other.type))
return false;
return true;
}
}

View File

@ -20,6 +20,8 @@ import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlSeeAlso;
import li.strolch.model.StrolchElement;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
@ -44,12 +46,20 @@ public abstract class StrolchElementOverview {
* @param type
*/
public StrolchElementOverview(String id, String name, String type) {
super();
this.id = id;
this.name = name;
this.type = type;
}
/**
* @param strolchElement
*/
public StrolchElementOverview(StrolchElement strolchElement) {
this.id = strolchElement.getId();
this.name = strolchElement.getName();
this.type = strolchElement.getType();
}
/**
* @return the id
*/
@ -94,4 +104,41 @@ public abstract class StrolchElementOverview {
public void setType(String type) {
this.type = type;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.id == null) ? 0 : this.id.hashCode());
result = prime * result + ((this.name == null) ? 0 : this.name.hashCode());
result = prime * result + ((this.type == null) ? 0 : this.type.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
StrolchElementOverview other = (StrolchElementOverview) obj;
if (this.id == null) {
if (other.id != null)
return false;
} else if (!this.id.equals(other.id))
return false;
if (this.name == null) {
if (other.name != null)
return false;
} else if (!this.name.equals(other.name))
return false;
if (this.type == null) {
if (other.type != null)
return false;
} else if (!this.type.equals(other.type))
return false;
return true;
}
}

View File

@ -34,8 +34,8 @@ public class TypeDetail {
@XmlAttribute(name = "type")
private String type;
@XmlElements(value = { @XmlElement(name = "Orders", type = OrderOverview.class),
@XmlElement(name = "Resources", type = ResourceOverview.class) })
@XmlElements({ @XmlElement(name = "orders", type = OrderOverview.class),
@XmlElement(name = "resources", type = ResourceOverview.class) })
private List<StrolchElementOverview> elementOverviews;
public TypeDetail() {
@ -47,7 +47,6 @@ public class TypeDetail {
* @param elementOverviews
*/
public TypeDetail(String type, List<StrolchElementOverview> elementOverviews) {
super();
this.type = type;
this.elementOverviews = elementOverviews;
}
@ -81,4 +80,35 @@ public class TypeDetail {
public void setElementOverviews(List<StrolchElementOverview> elementOverviews) {
this.elementOverviews = elementOverviews;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.elementOverviews == null) ? 0 : this.elementOverviews.hashCode());
result = prime * result + ((this.type == null) ? 0 : this.type.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
TypeDetail other = (TypeDetail) obj;
if (this.elementOverviews == null) {
if (other.elementOverviews != null)
return false;
} else if (!this.elementOverviews.equals(other.elementOverviews))
return false;
if (this.type == null) {
if (other.type != null)
return false;
} else if (!this.type.equals(other.type))
return false;
return true;
}
}

View File

@ -75,4 +75,32 @@ public class TypeOverview {
public void setSize(long size) {
this.size = size;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + (int) (this.size ^ (this.size >>> 32));
result = prime * result + ((this.type == null) ? 0 : this.type.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
TypeOverview other = (TypeOverview) obj;
if (this.size != other.size)
return false;
if (this.type == null) {
if (other.type != null)
return false;
} else if (!this.type.equals(other.type))
return false;
return true;
}
}

View File

@ -18,12 +18,14 @@ package li.strolch.rest.inspector.test;
import java.io.File;
import java.net.URI;
import javax.ws.rs.core.MediaType;
import li.strolch.rest.inspector.AgentRef;
import li.strolch.rest.inspector.StrolchRestfulClasses;
import li.strolch.rest.inspector.StrolchRestfulExceptionMapper;
import li.strolch.service.api.ServiceHandler;
import li.strolch.testbase.runtime.RuntimeMock;
import org.eclipse.persistence.jaxb.rs.MOXyJsonProvider;
import org.glassfish.grizzly.http.server.HttpServer;
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
import org.glassfish.jersey.server.ResourceConfig;
@ -32,6 +34,12 @@ import org.junit.BeforeClass;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.config.ClientConfig;
import com.sun.jersey.api.client.config.DefaultClientConfig;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
@ -73,7 +81,20 @@ public abstract class AbstractRestfulTest {
runtimeMock.destroyRuntime();
}
public static ServiceHandler getServiceHandler() {
return runtimeMock.getContainer().getComponent(ServiceHandler.class);
protected WebResource getResource() {
ClientConfig cc = new DefaultClientConfig();
cc.getClasses().add(MOXyJsonProvider.class);
Client client = Client.create(cc);
WebResource resource = client.resource(BASE_URI);
return resource;
}
protected ClientResponse getClientResponse(String path) {
WebResource resource = getResource();
ClientResponse response = resource.path(path).accept(MediaType.APPLICATION_JSON_TYPE).get(ClientResponse.class);
if (response.getStatus() != ClientResponse.Status.OK.getStatusCode())
throw new RuntimeException("Failed to get path " + path + " due to " + response.getEntity(String.class));
return response;
}
}

View File

@ -16,44 +16,33 @@
package li.strolch.rest.inspector.test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import javax.ws.rs.core.MediaType;
import java.util.Set;
import li.strolch.rest.inspector.model.AgentOverview;
import li.strolch.rest.inspector.model.ElementMapOverview;
import li.strolch.rest.inspector.model.ElementMapType;
import li.strolch.rest.inspector.model.ElementMapsOverview;
import li.strolch.rest.inspector.model.OrderDetail;
import li.strolch.rest.inspector.model.RealmDetail;
import li.strolch.rest.inspector.model.RealmOverview;
import li.strolch.rest.inspector.model.ResourceDetail;
import li.strolch.rest.inspector.model.TypeOverview;
import org.eclipse.persistence.jaxb.rs.MOXyJsonProvider;
import org.junit.Test;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.GenericType;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.config.ClientConfig;
import com.sun.jersey.api.client.config.DefaultClientConfig;
/**
* @author Robert von Burg <eitch@eitchnet.ch>
*/
public class InspectorTest extends AbstractRestfulTest {
protected WebResource getResource() {
ClientConfig cc = new DefaultClientConfig();
cc.getClasses().add(MOXyJsonProvider.class);
Client client = Client.create(cc);
WebResource resource = client.resource(BASE_URI);
return resource;
}
protected ClientResponse getClientResponse(String path) {
WebResource resource = getResource();
ClientResponse response = resource.path(path).accept(MediaType.APPLICATION_JSON_TYPE).get(ClientResponse.class);
return response;
}
@Test
public void shouldGetAgent() {
@ -70,4 +59,107 @@ public class InspectorTest extends AbstractRestfulTest {
// assertions
assertEquals(expectedAgentOverview, agentOverview);
}
@Test
public void shouldGetRealm() {
// expected result
List<ElementMapsOverview> elementMapOverviews = new ArrayList<>(2);
Set<String> resourceTypes = new HashSet<>();
resourceTypes.add("Template");
resourceTypes.add("TestType");
elementMapOverviews.add(new ElementMapsOverview(ElementMapType.RESOURCE, 2, resourceTypes));
Set<String> orderTypes = new HashSet<>();
orderTypes.add("Template");
orderTypes.add("TestType");
elementMapOverviews.add(new ElementMapsOverview(ElementMapType.ORDER, 2, orderTypes));
RealmDetail expectedRealmDetail = new RealmDetail(elementMapOverviews);
// query
ClientResponse response = getClientResponse("/strolch/inspector/defaultRealm");
RealmDetail realmDetail = response.getEntity(new GenericType<RealmDetail>() {
});
// assertions
assertEquals(expectedRealmDetail, realmDetail);
}
@Test
public void shouldGetResourcesOverview() {
// expected result
String elementMapName = "Resource";
List<TypeOverview> typeOverviews = new ArrayList<>(2);
typeOverviews.add(new TypeOverview("Template", 1));
typeOverviews.add(new TypeOverview("TestType", 1));
ElementMapOverview expectedElementMapOverview = new ElementMapOverview(elementMapName, typeOverviews);
// query
ClientResponse response = getClientResponse("/strolch/inspector/defaultRealm/resource");
ElementMapOverview elementMapOverview = response.getEntity(new GenericType<ElementMapOverview>() {
});
// assertions
assertEquals(expectedElementMapOverview, elementMapOverview);
}
@Test
public void shouldGetOrdersOverview() {
// expected result
String elementMapName = "Order";
List<TypeOverview> typeOverviews = new ArrayList<>(2);
typeOverviews.add(new TypeOverview("Template", 1));
typeOverviews.add(new TypeOverview("TestType", 1));
ElementMapOverview expectedElementMapOverview = new ElementMapOverview(elementMapName, typeOverviews);
// query
ClientResponse response = getClientResponse("/strolch/inspector/defaultRealm/order");
ElementMapOverview elementMapOverview = response.getEntity(new GenericType<ElementMapOverview>() {
});
// assertions
assertEquals(expectedElementMapOverview, elementMapOverview);
}
// TODO modify object model to include discriminator values, so that we can parse the objects
@Test
public void shouldGetResourceTypeDetails() {
// query
ClientResponse response = getClientResponse("/strolch/inspector/defaultRealm/resource/Template");
String entity = response.getEntity(String.class);
String expected = "{\"type\":\"Template\",\"resources\":[{\"id\":\"TestType\",\"name\":\"TestType Template\",\"type\":\"Template\"}]}";
assertEquals(expected, entity);
}
@Test
public void shouldGetOrderTypeDetails() {
// query
ClientResponse response = getClientResponse("/strolch/inspector/defaultRealm/order/Template");
String entity = response.getEntity(String.class);
String expected = "{\"type\":\"Template\",\"orders\":[{\"id\":\"TestType\",\"name\":\"MyTestOrder Template\",\"type\":\"Template\",\"date\":\"2012-11-30T18:12:05.628+01:00\",\"state\":\"CREATED\"}]}";
assertEquals(expected, entity);
}
@Test
public void shouldGetResource() {
// query
ClientResponse response = getClientResponse("/strolch/inspector/defaultRealm/resource/Template/TestType");
String entity = response.getEntity(String.class);
assertTrue(entity.contains("name\":\"TestType Template\",\"type\":\"Template\",\"parameterBags\":"));
}
@Test
public void shouldGetOrder() {
// query
ClientResponse response = getClientResponse("/strolch/inspector/defaultRealm/order/Template/TestType");
String entity = response.getEntity(String.class);
assertTrue(entity
.contains("\"date\":\"2012-11-30T18:12:05.628+01:00\",\"state\":\"CREATED\",\"parameterBags\""));
}
}

View File

@ -11,7 +11,7 @@
<Parameter Id="@param1" Name="Boolean Param" Type="Boolean" Value="true" />
</ParameterBag>
</Resource>
<Order Id="Template" Name="MyTestOrder Template" Type="MyTestOrder">
<Order Id="TestType" Name="MyTestOrder Template" Type="Template" Date="2012-11-30T18:12:05.628+01:00">
<ParameterBag Id="@bag01" Name="Test Bag" Type="TestBag">
<Parameter Id="@param7" Name="StringList Param" Type="StringList" Value="Hello;World" />
<Parameter Id="@param6" Name="Date Param" Type="Date" Value="2012-11-30T18:12:05.628+01:00" />