test_class.declarator: LOGGER = LoggerFactory.getLogger(MinExternalConnectionsTest.class)
test_class.modifier: private static final
test_class.original_string: private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(MinExternalConnectionsTest.class);
test_class.type: org.slf4j.Logger
test_class.var_name: LOGGER
test_class.file: org.eclipse.winery.repository/src/test/java/org/eclipse/winery/repository/targetallocation/criteria/minexternalconnections/MinExternalConnectionsTest.java
test_class.identifier: MinExternalConnectionsTest
test_class.superclass: extends TestWithGitBackedRepository
test_case.body: @Test
      public void filter() throws Exception {
          ServiceTemplateId id = new ServiceTemplateId("http://www.winery.opentosca.org/test/targetallocation/servicetemplates",
              "MinExternalConnectionsTest1", false);
          TTopologyTemplate twoExternal = repository.getElement(id).getTopologyTemplate();
          ModelUtilities.setTargetLabel(twoExternal.getNodeTemplate("shetland_pony_2"), "PastureProvider");
          ModelUtilities.setTargetLabel(twoExternal.getNodeTemplate("shetland_pony_3"), "PastureProvider");
          TTopologyTemplate oneExternal = AllocationUtils.deepcopy(twoExternal);
  
          ModelUtilities.setTargetLabel(oneExternal.getNodeTemplate("shetland_pony_2"), "FieldProvider");
          ModelUtilities.setTargetLabel(oneExternal.getNodeTemplate("shetland_pony_3"), "FieldProvider");
  
          List<TopologyWrapper> topologies = new ArrayList<>();
          topologies.add(new TopologyWrapper(twoExternal));
          topologies.add(new TopologyWrapper(oneExternal));
          Criteria minExternalConnections = new MinExternalConnections(null, Integer.MAX_VALUE);
          List<TopologyWrapper> filtered = minExternalConnections.filter(topologies);
  
          assertEquals(1, filtered.size());
          TTopologyTemplate result = filtered.get(0).getTopology();
          assertEquals("PastureProvider".toLowerCase(), ModelUtilities.getTargetLabel(result.getNodeTemplate("shetland_pony")).get());
          assertEquals("FieldProvider".toLowerCase(), ModelUtilities.getTargetLabel(result.getNodeTemplate("shetland_pony_2")).get());
          assertEquals("FieldProvider".toLowerCase(), ModelUtilities.getTargetLabel(result.getNodeTemplate("shetland_pony_3")).get());
          assertEquals("FieldProvider".toLowerCase(), ModelUtilities.getTargetLabel(result.getNodeTemplate("shetland_pony_4")).get());
      }
test_case.class_method_signature: MinExternalConnectionsTest.filter()
test_case.full_signature: @Test public void filter()
test_case.identifier: filter
test_case.invocations: getTopologyTemplate getElement setTargetLabel getNodeTemplate setTargetLabel getNodeTemplate deepcopy setTargetLabel getNodeTemplate setTargetLabel getNodeTemplate add add filter assertEquals size getTopology get assertEquals toLowerCase get getTargetLabel getNodeTemplate assertEquals toLowerCase get getTargetLabel getNodeTemplate assertEquals toLowerCase get getTargetLabel getNodeTemplate assertEquals toLowerCase get getTargetLabel getNodeTemplate
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void filter()
focal_class.file: org.eclipse.winery.repository/src/main/java/org/eclipse/winery/repository/targetallocation/criteria/minexternalconnections/MinExternalConnections.java
focal_class.identifier: MinExternalConnections
focal_class.class_method_signature: MinExternalConnections.MinExternalConnections(JsonNode params, int outputCap)
focal_class.full_signature: public  MinExternalConnections(JsonNode params, int outputCap)
focal_class.identifier: MinExternalConnections
focal_class.modifiers: public
focal_class.parameters: (JsonNode params, int outputCap)
focal_class.signature:  MinExternalConnections(JsonNode params, int outputCap)
focal_class.class_method_signature: MinExternalConnections.filter(List<TopologyWrapper> topologies)
focal_class.full_signature: @Override public List<TopologyWrapper> filter(List<TopologyWrapper> topologies)
focal_class.identifier: filter
focal_class.modifiers: @Override public
focal_class.parameters: (List<TopologyWrapper> topologies)
focal_class.return: List<TopologyWrapper>
focal_class.signature: List<TopologyWrapper> filter(List<TopologyWrapper> topologies)
focal_class.class_method_signature: MinExternalConnections.generateTargetLabelTopologies(TopologyWrapper topology)
focal_class.full_signature: @Override public List<TopologyWrapper> generateTargetLabelTopologies(TopologyWrapper topology)
focal_class.identifier: generateTargetLabelTopologies
focal_class.modifiers: @Override public
focal_class.parameters: (TopologyWrapper topology)
focal_class.return: List<TopologyWrapper>
focal_class.signature: List<TopologyWrapper> generateTargetLabelTopologies(TopologyWrapper topology)
focal_class.class_method_signature: MinExternalConnections.getPossibleMatches(TopologyWrapper topology)
focal_class.full_signature: @Override protected List<List<PermutationHelper>> getPossibleMatches(TopologyWrapper topology)
focal_class.identifier: getPossibleMatches
focal_class.modifiers: @Override protected
focal_class.parameters: (TopologyWrapper topology)
focal_class.return: List<List<PermutationHelper>>
focal_class.signature: List<List<PermutationHelper>> getPossibleMatches(TopologyWrapper topology)
focal_class.superclass: extends CriteriaCached
focal_method.body: @Override
      public List<TopologyWrapper> filter(List<TopologyWrapper> topologies) {
          List<TopologyWrapper> minExternalRTs = new ArrayList<>();
          int minExternalRTsCount = Integer.MAX_VALUE;
  
          for (TopologyWrapper topology : topologies) {
              int externalRTsCount = 0;
  
              for (TRelationshipTemplate relationshipTemplate : topology.getConnectsTos(topology.getRelationshipTemplates())) {
                  TNodeTemplate source = topology.getSourceNT(relationshipTemplate);
                  TNodeTemplate target = topology.getTargetNT(relationshipTemplate);
                  // only consider connectsTos between top level nts
                  if (!topology.isTopLevelNT(source) || !topology.isTopLevelNT(target)) {
                      continue;
                  }
  
                  // external edge?
                  String sourceTargetLabel = ModelUtilities.getTargetLabel(source).get();
                  String targetTargetLabel = ModelUtilities.getTargetLabel(target).get();
                  if (!sourceTargetLabel.equals(targetTargetLabel)) {
                      externalRTsCount++;
                  }
              }
              if (externalRTsCount < minExternalRTsCount) {
                  minExternalRTs.clear();
                  minExternalRTs.add(topology);
                  minExternalRTsCount = externalRTsCount;
              } else if (externalRTsCount == minExternalRTsCount) {
                  minExternalRTs.add(topology);
              }
          }
          return minExternalRTs;
      }
focal_method.class_method_signature: MinExternalConnections.filter(List<TopologyWrapper> topologies)
focal_method.full_signature: @Override public List<TopologyWrapper> filter(List<TopologyWrapper> topologies)
focal_method.identifier: filter
focal_method.invocations: getConnectsTos getRelationshipTemplates getSourceNT getTargetNT isTopLevelNT isTopLevelNT get getTargetLabel get getTargetLabel equals clear add add
focal_method.modifiers: @Override public
focal_method.parameters: (List<TopologyWrapper> topologies)
focal_method.return: List<TopologyWrapper>
focal_method.signature: List<TopologyWrapper> filter(List<TopologyWrapper> topologies)