From d1206d22932711035373c3fb0a6b7d3ee86bffc2 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Fri, 13 Jun 2014 18:15:48 +0200 Subject: [PATCH] [Minor] fixed brittle test due to unordered sets --- .../li/strolch/rest/endpoint/Inspector.java | 36 ++++++++++++------- .../rest/model/ElementMapOverview.java | 8 +++++ .../li/strolch/rest/model/TypeOverview.java | 7 ++++ .../rest/inspector/test/InspectorTest.java | 1 + 4 files changed, 40 insertions(+), 12 deletions(-) diff --git a/src/main/java/li/strolch/rest/endpoint/Inspector.java b/src/main/java/li/strolch/rest/endpoint/Inspector.java index c41821795..ea754b143 100644 --- a/src/main/java/li/strolch/rest/endpoint/Inspector.java +++ b/src/main/java/li/strolch/rest/endpoint/Inspector.java @@ -15,7 +15,9 @@ */ package li.strolch.rest.endpoint; +import java.text.MessageFormat; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Set; @@ -92,6 +94,7 @@ public class Inspector { AgentOverview agentOverview = new AgentOverview(realmOverviews); GenericEntity entity = new GenericEntity(agentOverview, AgentOverview.class) { + // }; return Response.ok().entity(entity).build(); } catch (Exception e) { @@ -120,7 +123,7 @@ public class Inspector { @Produces(MediaType.APPLICATION_JSON) @Path("{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); List elementMapOverviews = new ArrayList<>(2); @@ -141,6 +144,7 @@ public class Inspector { RealmDetail modelOverview = new RealmDetail(elementMapOverviews); GenericEntity entity = new GenericEntity(modelOverview, RealmDetail.class) { + // }; return Response.ok().entity(entity).build(); } @@ -164,13 +168,14 @@ public class Inspector { @Produces(MediaType.APPLICATION_JSON) @Path("{realm}/resource") 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); ElementMapOverview resourcesOverview; try (StrolchTransaction tx = strolchRealm.openTx()) { ResourceMap resourceMap = tx.getResourceMap(); - Set types = resourceMap.getTypes(tx); + List types = new ArrayList<>(resourceMap.getTypes(tx)); + Collections.sort(types); List typeOverviews = new ArrayList<>(types.size()); for (String type : types) { long size = resourceMap.querySize(tx, type); @@ -183,6 +188,7 @@ public class Inspector { GenericEntity entity = new GenericEntity(resourcesOverview, ElementMapOverview.class) { + // }; return Response.ok().entity(entity).build(); } @@ -206,13 +212,14 @@ public class Inspector { @Produces(MediaType.APPLICATION_JSON) @Path("{realm}/order") 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); ElementMapOverview ordersOverview; try (StrolchTransaction tx = strolchRealm.openTx()) { OrderMap orderMap = tx.getOrderMap(); - Set types = orderMap.getTypes(tx); + List types = new ArrayList<>(orderMap.getTypes(tx)); + Collections.sort(types); List typeOverviews = new ArrayList<>(types.size()); for (String type : types) { long size = orderMap.querySize(tx, type); @@ -225,6 +232,7 @@ public class Inspector { GenericEntity entity = new GenericEntity(ordersOverview, ElementMapOverview.class) { + // }; return Response.ok().entity(entity).build(); } @@ -254,7 +262,7 @@ public class Inspector { @Produces(MediaType.APPLICATION_JSON) @Path("{realm}/resource/{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); TypeDetail typeDetail; @@ -269,6 +277,7 @@ public class Inspector { } GenericEntity entity = new GenericEntity(typeDetail, TypeDetail.class) { + // }; return Response.ok().entity(entity).build(); } @@ -294,7 +303,7 @@ public class Inspector { @Produces(MediaType.APPLICATION_JSON) @Path("{realm}/order/{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); TypeDetail typeDetail; @@ -309,6 +318,7 @@ public class Inspector { } GenericEntity entity = new GenericEntity(typeDetail, TypeDetail.class) { + // }; return Response.ok().entity(entity).build(); } @@ -331,14 +341,14 @@ public class Inspector { * * @return the resource with the given id * - * @see Res + * @see ResourceDetail */ @GET @Produces(MediaType.APPLICATION_JSON) @Path("{realm}/resource/{type}/{id}") public Response getResource(@PathParam("realm") String realm, @PathParam("type") String type, @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); Resource resource; @@ -346,11 +356,12 @@ public class Inspector { resource = tx.getResourceMap().getBy(tx, type, id); } 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); GenericEntity entity = new GenericEntity(resourceDetail, ResourceDetail.class) { + // }; return Response.ok().entity(entity).build(); } @@ -360,7 +371,7 @@ public class Inspector { @Path("{realm}/order/{type}/{id}") public Response getOrder(@PathParam("realm") String realm, @PathParam("type") String type, @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); Order order; @@ -368,11 +379,12 @@ public class Inspector { order = tx.getOrderMap().getBy(tx, type, id); } 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); GenericEntity entity = new GenericEntity(orderDetail, OrderDetail.class) { + // }; return Response.ok().entity(entity).build(); } diff --git a/src/main/java/li/strolch/rest/model/ElementMapOverview.java b/src/main/java/li/strolch/rest/model/ElementMapOverview.java index 4e8d9a817..9fb83e490 100644 --- a/src/main/java/li/strolch/rest/model/ElementMapOverview.java +++ b/src/main/java/li/strolch/rest/model/ElementMapOverview.java @@ -15,6 +15,7 @@ */ package li.strolch.rest.model; +import java.text.MessageFormat; import java.util.List; import javax.xml.bind.annotation.XmlAccessType; @@ -129,4 +130,11 @@ public class ElementMapOverview { return false; 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); + } } diff --git a/src/main/java/li/strolch/rest/model/TypeOverview.java b/src/main/java/li/strolch/rest/model/TypeOverview.java index 3d265b2f2..1e51bccd7 100644 --- a/src/main/java/li/strolch/rest/model/TypeOverview.java +++ b/src/main/java/li/strolch/rest/model/TypeOverview.java @@ -15,6 +15,8 @@ */ package li.strolch.rest.model; +import java.text.MessageFormat; + import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; @@ -103,4 +105,9 @@ public class TypeOverview { return false; return true; } + + @Override + public String toString() { + return MessageFormat.format("TypeOverview [type={0}, size={1}]", this.type, this.size); //$NON-NLS-1$ + } } diff --git a/src/test/java/li/strolch/rest/inspector/test/InspectorTest.java b/src/test/java/li/strolch/rest/inspector/test/InspectorTest.java index fe0df0a98..3200da7a3 100644 --- a/src/test/java/li/strolch/rest/inspector/test/InspectorTest.java +++ b/src/test/java/li/strolch/rest/inspector/test/InspectorTest.java @@ -40,6 +40,7 @@ import org.junit.Test; /** * @author Robert von Burg */ +@SuppressWarnings("nls") public class InspectorTest extends AbstractRestfulTest { private static final String ROOT_PATH = "strolch/inspector/";