XmlMementoSerializerTest tidy
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/50c0f691 Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/50c0f691 Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/50c0f691 Branch: refs/heads/master Commit: 50c0f691212c5b2cbd5ebe58cf649118722d6b75 Parents: 80b05c1 Author: Aled Sage <aled.s...@gmail.com> Authored: Tue May 27 10:51:01 2014 +0100 Committer: Aled Sage <aled.s...@gmail.com> Committed: Fri May 30 10:24:38 2014 +0100 ---------------------------------------------------------------------- .../persister/XmlMementoSerializerTest.java | 38 +++++++++++++------- 1 file changed, 25 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/50c0f691/core/src/test/java/brooklyn/entity/rebind/persister/XmlMementoSerializerTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/brooklyn/entity/rebind/persister/XmlMementoSerializerTest.java b/core/src/test/java/brooklyn/entity/rebind/persister/XmlMementoSerializerTest.java index 47d525b..903fe4e 100644 --- a/core/src/test/java/brooklyn/entity/rebind/persister/XmlMementoSerializerTest.java +++ b/core/src/test/java/brooklyn/entity/rebind/persister/XmlMementoSerializerTest.java @@ -33,6 +33,7 @@ import com.google.common.base.Objects; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Maps; public class XmlMementoSerializerTest { @@ -108,7 +109,7 @@ public class XmlMementoSerializerTest { final TestApplication app = ApplicationBuilder.newManagedApp(TestApplication.class); ManagementContext managementContext = app.getManagementContext(); try { - serializer.setLookupContext(new LookupContextImpl(ImmutableMap.of(app.getId(), app), ImmutableMap.<String,Location>of(), ImmutableMap.<String,Policy>of(), ImmutableMap.<String,Enricher>of())); + serializer.setLookupContext(new LookupContextImpl(ImmutableList.of(app), ImmutableList.<Location>of(), ImmutableList.<Policy>of(), ImmutableList.<Enricher>of())); assertSerializeAndDeserialize(app); } finally { Entities.destroyAll(managementContext); @@ -122,7 +123,7 @@ public class XmlMementoSerializerTest { try { @SuppressWarnings("deprecation") final Location loc = managementContext.getLocationManager().createLocation(LocationSpec.create(brooklyn.location.basic.SimulatedLocation.class)); - serializer.setLookupContext(new LookupContextImpl(ImmutableMap.<String,Entity>of(), ImmutableMap.of(loc.getId(), loc), ImmutableMap.<String,Policy>of(), ImmutableMap.<String,Enricher>of())); + serializer.setLookupContext(new LookupContextImpl(ImmutableList.<Entity>of(), ImmutableList.of(loc), ImmutableList.<Policy>of(), ImmutableList.<Enricher>of())); assertSerializeAndDeserialize(loc); } finally { Entities.destroyAll(managementContext); @@ -135,7 +136,7 @@ public class XmlMementoSerializerTest { ReffingEntity reffer = new ReffingEntity(app); ManagementContext managementContext = app.getManagementContext(); try { - serializer.setLookupContext(new LookupContextImpl(ImmutableMap.of(app.getId(), app), ImmutableMap.<String,Location>of(), ImmutableMap.<String,Policy>of(), ImmutableMap.<String,Enricher>of())); + serializer.setLookupContext(new LookupContextImpl(ImmutableList.of(app), ImmutableList.<Location>of(), ImmutableList.<Policy>of(), ImmutableList.<Enricher>of())); ReffingEntity reffer2 = assertSerializeAndDeserialize(reffer); assertEquals(reffer2.entity, app); } finally { @@ -149,7 +150,7 @@ public class XmlMementoSerializerTest { ReffingEntity reffer = new ReffingEntity((Object)app); ManagementContext managementContext = app.getManagementContext(); try { - serializer.setLookupContext(new LookupContextImpl(ImmutableMap.of(app.getId(), app), ImmutableMap.<String,Location>of(), ImmutableMap.<String,Policy>of(), ImmutableMap.<String,Enricher>of())); + serializer.setLookupContext(new LookupContextImpl(ImmutableList.of(app), ImmutableList.<Location>of(), ImmutableList.<Policy>of(), ImmutableList.<Enricher>of())); ReffingEntity reffer2 = assertSerializeAndDeserialize(reffer); assertEquals(reffer2.obj, app); } finally { @@ -186,17 +187,28 @@ public class XmlMementoSerializerTest { } static class LookupContextImpl implements LookupContext { - private final Map<String, ? extends Entity> entities; - private final Map<String, ? extends Location> locations; - private final Map<String, ? extends Policy> policies; - private final Map<String, ? extends Enricher> enrichers; - + private final Map<String, Entity> entities; + private final Map<String, Location> locations; + private final Map<String, Policy> policies; + private final Map<String, Enricher> enrichers; + + LookupContextImpl(Iterable<? extends Entity> entities, Iterable<? extends Location> locations, + Iterable<? extends Policy> policies, Iterable<? extends Enricher> enrichers) { + this.entities = Maps.newLinkedHashMap(); + this.locations = Maps.newLinkedHashMap(); + this.policies = Maps.newLinkedHashMap(); + this.enrichers = Maps.newLinkedHashMap(); + for (Entity entity : entities) this.entities.put(entity.getId(), entity); + for (Location location : locations) this.locations.put(location.getId(), location); + for (Policy policy : policies) this.policies.put(policy.getId(), policy); + for (Enricher enricher : enrichers) this.enrichers.put(enricher.getId(), enricher); + } LookupContextImpl(Map<String,? extends Entity> entities, Map<String,? extends Location> locations, Map<String,? extends Policy> policies, Map<String,? extends Enricher> enrichers) { - this.entities = entities; - this.locations = locations; - this.policies = policies; - this.enrichers = enrichers; + this.entities = ImmutableMap.copyOf(entities); + this.locations = ImmutableMap.copyOf(locations); + this.policies = ImmutableMap.copyOf(policies); + this.enrichers = ImmutableMap.copyOf(enrichers); } @Override public Entity lookupEntity(Class<?> type, String id) { if (entities.containsKey(id)) {