[Minor] fixed brittle test due to unordered sets

This commit is contained in:
Robert von Burg 2014-06-13 18:15:48 +02:00
parent a7bae4b9f5
commit d1206d2293
4 changed files with 40 additions and 12 deletions

View File

@ -15,7 +15,9 @@
*/ */
package li.strolch.rest.endpoint; package li.strolch.rest.endpoint;
import java.text.MessageFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
@ -92,6 +94,7 @@ public class Inspector {
AgentOverview agentOverview = new AgentOverview(realmOverviews); AgentOverview agentOverview = new AgentOverview(realmOverviews);
GenericEntity<AgentOverview> entity = new GenericEntity<AgentOverview>(agentOverview, AgentOverview.class) { GenericEntity<AgentOverview> entity = new GenericEntity<AgentOverview>(agentOverview, AgentOverview.class) {
//
}; };
return Response.ok().entity(entity).build(); return Response.ok().entity(entity).build();
} catch (Exception e) { } catch (Exception e) {
@ -120,7 +123,7 @@ public class Inspector {
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Path("{realm}") @Path("{realm}")
public Response getRealm(@PathParam("realm") String realm) { public Response getRealm(@PathParam("realm") String realm) {
DBC.PRE.assertNotEmpty("Realm must be set!", realm); DBC.PRE.assertNotEmpty("Realm must be set!", realm); //$NON-NLS-1$
StrolchRealm strolchRealm = RestfulStrolchComponent.getInstance().getContainer().getRealm(realm); StrolchRealm strolchRealm = RestfulStrolchComponent.getInstance().getContainer().getRealm(realm);
List<ElementMapsOverview> elementMapOverviews = new ArrayList<>(2); List<ElementMapsOverview> elementMapOverviews = new ArrayList<>(2);
@ -141,6 +144,7 @@ public class Inspector {
RealmDetail modelOverview = new RealmDetail(elementMapOverviews); RealmDetail modelOverview = new RealmDetail(elementMapOverviews);
GenericEntity<RealmDetail> entity = new GenericEntity<RealmDetail>(modelOverview, RealmDetail.class) { GenericEntity<RealmDetail> entity = new GenericEntity<RealmDetail>(modelOverview, RealmDetail.class) {
//
}; };
return Response.ok().entity(entity).build(); return Response.ok().entity(entity).build();
} }
@ -164,13 +168,14 @@ public class Inspector {
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Path("{realm}/resource") @Path("{realm}/resource")
public Response getResourcesOverview(@PathParam("realm") String realm) { public Response getResourcesOverview(@PathParam("realm") String realm) {
DBC.PRE.assertNotEmpty("Realm must be set!", realm); DBC.PRE.assertNotEmpty("Realm must be set!", realm); //$NON-NLS-1$
StrolchRealm strolchRealm = RestfulStrolchComponent.getInstance().getContainer().getRealm(realm); StrolchRealm strolchRealm = RestfulStrolchComponent.getInstance().getContainer().getRealm(realm);
ElementMapOverview resourcesOverview; ElementMapOverview resourcesOverview;
try (StrolchTransaction tx = strolchRealm.openTx()) { try (StrolchTransaction tx = strolchRealm.openTx()) {
ResourceMap resourceMap = tx.getResourceMap(); ResourceMap resourceMap = tx.getResourceMap();
Set<String> types = resourceMap.getTypes(tx); List<String> types = new ArrayList<>(resourceMap.getTypes(tx));
Collections.sort(types);
List<TypeOverview> typeOverviews = new ArrayList<>(types.size()); List<TypeOverview> typeOverviews = new ArrayList<>(types.size());
for (String type : types) { for (String type : types) {
long size = resourceMap.querySize(tx, type); long size = resourceMap.querySize(tx, type);
@ -183,6 +188,7 @@ public class Inspector {
GenericEntity<ElementMapOverview> entity = new GenericEntity<ElementMapOverview>(resourcesOverview, GenericEntity<ElementMapOverview> entity = new GenericEntity<ElementMapOverview>(resourcesOverview,
ElementMapOverview.class) { ElementMapOverview.class) {
//
}; };
return Response.ok().entity(entity).build(); return Response.ok().entity(entity).build();
} }
@ -206,13 +212,14 @@ public class Inspector {
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Path("{realm}/order") @Path("{realm}/order")
public Response getOrdersOverview(@PathParam("realm") String realm) { public Response getOrdersOverview(@PathParam("realm") String realm) {
DBC.PRE.assertNotEmpty("Realm must be set!", realm); DBC.PRE.assertNotEmpty("Realm must be set!", realm); //$NON-NLS-1$
StrolchRealm strolchRealm = RestfulStrolchComponent.getInstance().getContainer().getRealm(realm); StrolchRealm strolchRealm = RestfulStrolchComponent.getInstance().getContainer().getRealm(realm);
ElementMapOverview ordersOverview; ElementMapOverview ordersOverview;
try (StrolchTransaction tx = strolchRealm.openTx()) { try (StrolchTransaction tx = strolchRealm.openTx()) {
OrderMap orderMap = tx.getOrderMap(); OrderMap orderMap = tx.getOrderMap();
Set<String> types = orderMap.getTypes(tx); List<String> types = new ArrayList<>(orderMap.getTypes(tx));
Collections.sort(types);
List<TypeOverview> typeOverviews = new ArrayList<>(types.size()); List<TypeOverview> typeOverviews = new ArrayList<>(types.size());
for (String type : types) { for (String type : types) {
long size = orderMap.querySize(tx, type); long size = orderMap.querySize(tx, type);
@ -225,6 +232,7 @@ public class Inspector {
GenericEntity<ElementMapOverview> entity = new GenericEntity<ElementMapOverview>(ordersOverview, GenericEntity<ElementMapOverview> entity = new GenericEntity<ElementMapOverview>(ordersOverview,
ElementMapOverview.class) { ElementMapOverview.class) {
//
}; };
return Response.ok().entity(entity).build(); return Response.ok().entity(entity).build();
} }
@ -254,7 +262,7 @@ public class Inspector {
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Path("{realm}/resource/{type}") @Path("{realm}/resource/{type}")
public Response getResourceTypeDetails(@PathParam("realm") String realm, @PathParam("type") String type) { public Response getResourceTypeDetails(@PathParam("realm") String realm, @PathParam("type") String type) {
DBC.PRE.assertNotEmpty("Realm must be set!", realm); DBC.PRE.assertNotEmpty("Realm must be set!", realm); //$NON-NLS-1$
StrolchRealm strolchRealm = RestfulStrolchComponent.getInstance().getContainer().getRealm(realm); StrolchRealm strolchRealm = RestfulStrolchComponent.getInstance().getContainer().getRealm(realm);
TypeDetail typeDetail; TypeDetail typeDetail;
@ -269,6 +277,7 @@ public class Inspector {
} }
GenericEntity<TypeDetail> entity = new GenericEntity<TypeDetail>(typeDetail, TypeDetail.class) { GenericEntity<TypeDetail> entity = new GenericEntity<TypeDetail>(typeDetail, TypeDetail.class) {
//
}; };
return Response.ok().entity(entity).build(); return Response.ok().entity(entity).build();
} }
@ -294,7 +303,7 @@ public class Inspector {
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Path("{realm}/order/{type}") @Path("{realm}/order/{type}")
public Response getOrderTypeDetails(@PathParam("realm") String realm, @PathParam("type") String type) { public Response getOrderTypeDetails(@PathParam("realm") String realm, @PathParam("type") String type) {
DBC.PRE.assertNotEmpty("Realm must be set!", realm); DBC.PRE.assertNotEmpty("Realm must be set!", realm); //$NON-NLS-1$
StrolchRealm strolchRealm = RestfulStrolchComponent.getInstance().getContainer().getRealm(realm); StrolchRealm strolchRealm = RestfulStrolchComponent.getInstance().getContainer().getRealm(realm);
TypeDetail typeDetail; TypeDetail typeDetail;
@ -309,6 +318,7 @@ public class Inspector {
} }
GenericEntity<TypeDetail> entity = new GenericEntity<TypeDetail>(typeDetail, TypeDetail.class) { GenericEntity<TypeDetail> entity = new GenericEntity<TypeDetail>(typeDetail, TypeDetail.class) {
//
}; };
return Response.ok().entity(entity).build(); return Response.ok().entity(entity).build();
} }
@ -331,14 +341,14 @@ public class Inspector {
* *
* @return the resource with the given id * @return the resource with the given id
* *
* @see Res * @see ResourceDetail
*/ */
@GET @GET
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Path("{realm}/resource/{type}/{id}") @Path("{realm}/resource/{type}/{id}")
public Response getResource(@PathParam("realm") String realm, @PathParam("type") String type, public Response getResource(@PathParam("realm") String realm, @PathParam("type") String type,
@PathParam("id") String id) { @PathParam("id") String id) {
DBC.PRE.assertNotEmpty("Realm must be set!", realm); DBC.PRE.assertNotEmpty("Realm must be set!", realm); //$NON-NLS-1$
StrolchRealm strolchRealm = RestfulStrolchComponent.getInstance().getContainer().getRealm(realm); StrolchRealm strolchRealm = RestfulStrolchComponent.getInstance().getContainer().getRealm(realm);
Resource resource; Resource resource;
@ -346,11 +356,12 @@ public class Inspector {
resource = tx.getResourceMap().getBy(tx, type, id); resource = tx.getResourceMap().getBy(tx, type, id);
} }
if (resource == null) { if (resource == null) {
throw new StrolchException("No Resource exists for " + type + "/" + id); throw new StrolchException(MessageFormat.format("No Resource exists for {0}/{1}", type, id)); //$NON-NLS-1$
} }
ResourceDetail resourceDetail = new ResourceDetail(resource); ResourceDetail resourceDetail = new ResourceDetail(resource);
GenericEntity<ResourceDetail> entity = new GenericEntity<ResourceDetail>(resourceDetail, ResourceDetail.class) { GenericEntity<ResourceDetail> entity = new GenericEntity<ResourceDetail>(resourceDetail, ResourceDetail.class) {
//
}; };
return Response.ok().entity(entity).build(); return Response.ok().entity(entity).build();
} }
@ -360,7 +371,7 @@ public class Inspector {
@Path("{realm}/order/{type}/{id}") @Path("{realm}/order/{type}/{id}")
public Response getOrder(@PathParam("realm") String realm, @PathParam("type") String type, public Response getOrder(@PathParam("realm") String realm, @PathParam("type") String type,
@PathParam("id") String id) { @PathParam("id") String id) {
DBC.PRE.assertNotEmpty("Realm must be set!", realm); DBC.PRE.assertNotEmpty("Realm must be set!", realm); //$NON-NLS-1$
StrolchRealm strolchRealm = RestfulStrolchComponent.getInstance().getContainer().getRealm(realm); StrolchRealm strolchRealm = RestfulStrolchComponent.getInstance().getContainer().getRealm(realm);
Order order; Order order;
@ -368,11 +379,12 @@ public class Inspector {
order = tx.getOrderMap().getBy(tx, type, id); order = tx.getOrderMap().getBy(tx, type, id);
} }
if (order == null) { if (order == null) {
throw new StrolchException("No Order exists for " + type + "/" + id); throw new StrolchException(MessageFormat.format("No Order exists for {0}/{1}", type, id)); //$NON-NLS-1$
} }
OrderDetail orderDetail = new OrderDetail(order); OrderDetail orderDetail = new OrderDetail(order);
GenericEntity<OrderDetail> entity = new GenericEntity<OrderDetail>(orderDetail, OrderDetail.class) { GenericEntity<OrderDetail> entity = new GenericEntity<OrderDetail>(orderDetail, OrderDetail.class) {
//
}; };
return Response.ok().entity(entity).build(); return Response.ok().entity(entity).build();
} }

View File

@ -15,6 +15,7 @@
*/ */
package li.strolch.rest.model; package li.strolch.rest.model;
import java.text.MessageFormat;
import java.util.List; import java.util.List;
import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessType;
@ -129,4 +130,11 @@ public class ElementMapOverview {
return false; return false;
return true; return true;
} }
@Override
public String toString() {
return MessageFormat.format(
"ElementMapOverview [elementMapName={0}, size={1}, typeOverviews={2}]", this.elementMapName, //$NON-NLS-1$
this.size, this.typeOverviews);
}
} }

View File

@ -15,6 +15,8 @@
*/ */
package li.strolch.rest.model; package li.strolch.rest.model;
import java.text.MessageFormat;
import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlAttribute;
@ -103,4 +105,9 @@ public class TypeOverview {
return false; return false;
return true; return true;
} }
@Override
public String toString() {
return MessageFormat.format("TypeOverview [type={0}, size={1}]", this.type, this.size); //$NON-NLS-1$
}
} }

View File

@ -40,6 +40,7 @@ import org.junit.Test;
/** /**
* @author Robert von Burg <eitch@eitchnet.ch> * @author Robert von Burg <eitch@eitchnet.ch>
*/ */
@SuppressWarnings("nls")
public class InspectorTest extends AbstractRestfulTest { public class InspectorTest extends AbstractRestfulTest {
private static final String ROOT_PATH = "strolch/inspector/"; private static final String ROOT_PATH = "strolch/inspector/";