CapabilityMatcherService implements ICapabilityMatcherService { @Override public Map<String, Capability> getCompatibleCapabilityByType(NodeTemplate nodeTemplate, String type) { Map<String, Capability> capabilities = nodeTemplate.getCapabilities(); if (capabilities == null) { return Collections.emptyMap(); } Map<String, Capability> targetCapabilitiesMatch = Maps.newHashMap(); for (Map.Entry<String, Capability> capabilityEntry : capabilities.entrySet()) { String capabilityTypeName = capabilityEntry.getValue().getType(); CapabilityType capabilityType = toscaContextFinder.find(CapabilityType.class, capabilityTypeName); if (ToscaTypeUtils.isOfType(capabilityType, type)) { targetCapabilitiesMatch.put(capabilityEntry.getKey(), capabilityEntry.getValue()); } } return targetCapabilitiesMatch; } CapabilityMatcherService(); @Override Map<String, Capability> getCompatibleCapabilityByType(NodeTemplate nodeTemplate, String type); @Override List<CapabilityDefinition> getCompatibleCapabilityByType(NodeType nodeType, String type);  }
@Test public void capability_should_not_match_when_type_is_unknown() throws Exception { Map<String, Capability> compatibleCapabilities = service.getCompatibleCapabilityByType(nodeTemplate, "alien.capability.test.Unknown"); assertThat(compatibleCapabilities).hasSize(0); }
@Test public void should_not_crash_even_if_node_template_capacities_is_incorrect() throws Exception { nodeTemplate.getCapabilities().clear(); Capability unknownCapacity = new Capability(); unknownCapacity.setType("alien.typo.in.capa"); nodeTemplate.getCapabilities().put("incorrect", unknownCapacity); Map<String, Capability> compatibleCapabilities = service.getCompatibleCapabilityByType(nodeTemplate, "alien.capability.test.Unknown"); assertThat(compatibleCapabilities).hasSize(0); }
@Test public void capability_should_match_when_type_equals_element_id() throws Exception { Map<String, Capability> compatibleCapabilities = service.getCompatibleCapabilityByType(nodeTemplate, "alien.capability.test.MongoEndpoint"); assertThat(compatibleCapabilities).hasSize(1); assertThat(compatibleCapabilities).containsKeys("db_endpoint"); }
@Test public void capability_should_match_when_type_is_present_in_derived_from() throws Exception { Map<String, Capability> compatibleCapabilities = service.getCompatibleCapabilityByType(nodeTemplate, "alien.capability.test.Database"); assertThat(compatibleCapabilities).hasSize(1); assertThat(compatibleCapabilities).containsKeys("db_endpoint"); }