use of org.eclipse.winery.repository.targetallocation.criteria.fulfillpolicies.FulfillPolicies in project winery by eclipse.
the class FulfillPoliciesTest method testFilter.
@Test
public void testFilter() throws Exception {
Criteria minConnections = new MinExternalConnections(null, Integer.MAX_VALUE);
List<TopologyWrapper> topologies = minConnections.allocate(topology);
if (topologies.size() != 4) {
LOGGER.debug("Min cut algorithm didn't find all results");
return;
}
boolean rightResultPresent = false;
for (TopologyWrapper topology : topologies) {
TTopologyTemplate topologyTemplate = topology.getTopology();
TNodeTemplate pony3 = topologyTemplate.getNodeTemplate("shetland_pony_3");
TNodeTemplate pony4 = topologyTemplate.getNodeTemplate("shetland_pony_4");
if (ModelUtilities.getTargetLabel(pony3).get().equals("PastureProvider") && ModelUtilities.getTargetLabel(pony4).get().equals("FieldProvider")) {
LOGGER.debug("Right result present");
rightResultPresent = true;
break;
}
}
if (!rightResultPresent) {
LOGGER.debug("Min cut algorithm didn't find needed result");
return;
}
JsonNode params = JacksonProvider.mapper.readTree("{\"policySelection\":[" + "{\"policy\":\"floorwarmth10\",\"property\":\"warmth\",\"operator\":\"min\"}," + "{\"policy\":\"floorwarmth30\",\"property\":\"warmth\",\"operator\":\"max\"}]}");
Criteria fulfillPolicies = new FulfillPolicies(params, Integer.MAX_VALUE);
topologies = fulfillPolicies.filter(topologies);
assertEquals(1, topologies.size());
TTopologyTemplate allocated = topologies.get(0).getTopology();
assertEquals(6, allocated.getNodeTemplates().size());
// set by criteria
assertEquals("PastureProvider", ModelUtilities.getTargetLabel(allocated.getNodeTemplate("shetland_pony_3")).get());
assertEquals("FieldProvider", ModelUtilities.getTargetLabel(allocated.getNodeTemplate("shetland_pony_4")).get());
// set by user
assertEquals("PastureProvider", ModelUtilities.getTargetLabel(allocated.getNodeTemplate("shetland_pony")).get());
assertEquals("FieldProvider", ModelUtilities.getTargetLabel(allocated.getNodeTemplate("shetland_pony_2")).get());
}
Aggregations