public Aggregate(String name, AggregateType type) { super(getId(name)); _name = name; _type = type; _contents = new HashSet<>(); }
public Aggregate getOrCreateAggregate(String name, AggregateType aggType) { String aggId = Aggregate.getId(name); for (Aggregate aggregate : _aggregates) { if (aggregate.getId().equals(aggId)) { return aggregate; } } Aggregate aggregate = new Aggregate(name, aggType); getAggregates().add(aggregate); return aggregate; }
@Test public void serialization() { Aggregate aggregate = new Aggregate("test", AggregateType.REGION); Map<String, String> properties = new HashMap<>(); properties.put("key", "value"); aggregate.setProperties(properties); JsonNode jsonNode = BatfishObjectMapper.mapper().valueToTree(aggregate); assertThat(jsonNode.get("id").asText(), equalTo(Aggregate.getId("test"))); assertThat(jsonNode.get("name").asText(), equalTo("test")); assertThat(jsonNode.get("type").asText(), equalTo("REGION")); assertThat(jsonNode.get("properties").get("key").asText(), equalTo("value")); } }
@Test public void constructorBasic() throws IOException { String aggStr = "{\"name\" : \"test\"}"; Aggregate aggregate = BatfishObjectMapper.mapper().readValue(aggStr, Aggregate.class); assertThat(aggregate.getId(), equalTo(Aggregate.getId("test"))); assertThat(aggregate.getName(), equalTo("test")); }
@Test public void constructorProperties() throws IOException { String aggStr = "{\"name\" : \"aggName\", \"properties\" : { \"key\": \"value\"}}"; Aggregate node = BatfishObjectMapper.mapper().readValue(aggStr, Aggregate.class); assertThat(node.getId(), equalTo(Aggregate.getId("aggName"))); assertThat(node.getName(), equalTo("aggName")); assertThat(node.getProperties().size(), equalTo(1)); assertThat(node.getProperties().get("key"), equalTo("value")); }
vpcAggregate.getContents().add(subnetAggregate.getId()); } else if (configuration.getVendorFamily().getAws().getVpcId() != null) { String vpcId = configuration.getVendorFamily().getAws().getVpcId(); Aggregate regionAggregate = pojoTopology.getOrCreateAggregate(region, AggregateType.REGION); regionAggregate.getContents().add(vpcAggregate.getId()); } else if (configuration.getVendorFamily().getAws().getRegion() != null) { String region = configuration.getVendorFamily().getAws().getRegion(); awsAggregate.getContents().add(regionAggregate.getId()); } else { Aggregate awsAggregate = pojoTopology.getOrCreateAggregate("aws", AggregateType.CLOUD);