use of org.alien4cloud.tosca.model.templates.Capability in project alien4cloud by alien4cloud.
the class DefaultNodeMatcherTest method location_resource_should_be_matched_only_if_capabilities_are_satisfied.
@Test
public void location_resource_should_be_matched_only_if_capabilities_are_satisfied() throws Exception {
// Given
CapabilityDefinition capabilityArchitecture = new CapabilityDefinition("tosca.capabilities.OperatingSystem");
computeNodeType.setCapabilities(Arrays.asList(capabilityArchitecture));
Capability capability = new Capability();
capability.setType("tosca.capabilities.OperatingSystem");
capability.setProperties(ImmutableMap.of("architecture", new ScalarPropertyValue("x86")));
computeNodeTemplate.setCapabilities(ImmutableMap.of("os", capability));
CapabilityType capabilityType = new CapabilityType();
PropertyDefinition propertyDefinition = new PropertyDefinition();
propertyDefinition.setType("string");
capabilityType.setElementId("tosca.capabilities.OperatingSystem");
capabilityType.setProperties(ImmutableMap.of("architecture", propertyDefinition));
locationResources.setCapabilityTypes(ImmutableMap.of("tosca.capabilities.OperatingSystem", capabilityType));
// Matching configuration
Map<String, MatchingConfiguration> capabilityFilterConfiguration = new HashMap<>();
MatchingConfiguration matchingConfiguration = new MatchingConfiguration();
MatchingFilterDefinition matchingFilterDefinition = new MatchingConfiguration();
matchingFilterDefinition.setProperties(ImmutableMap.of("architecture", Arrays.asList(new EqualConstraint())));
matchingConfiguration.setCapabilities(ImmutableMap.of("os", matchingFilterDefinition));
capabilityFilterConfiguration.put("org.alien4cloud.nodes.mock.aws.Compute", matchingConfiguration);
// When
NodeTemplate wantedNodeTemplate = new NodeTemplate();
wantedNodeTemplate.setType("tosca.nodes.Compute");
Capability wantedCapability = new Capability();
wantedCapability.setType("tosca.capabilities.OperatingSystem");
wantedCapability.setProperties(ImmutableMap.of("architecture", new ScalarPropertyValue("power_pc")));
wantedNodeTemplate.setCapabilities(ImmutableMap.of("os", wantedCapability));
NodeType nodeType = new NodeType();
List<LocationResourceTemplate> proposition = nodeMatcher.matchNode(wantedNodeTemplate, nodeType, locationResources, capabilityFilterConfiguration);
// Then
assertThat(proposition).hasSize(0);
}
use of org.alien4cloud.tosca.model.templates.Capability in project alien4cloud by alien4cloud.
the class ToscaSerializerUtilsTest method testHasCapabilitiesContainingNotNullProperties.
@Test
public void testHasCapabilitiesContainingNotNullProperties() {
NodeTemplate nt = new NodeTemplate();
Assert.assertFalse(utils.hasCapabilitiesContainingNotNullProperties(nt));
Map<String, Capability> capabilities = Maps.newHashMap();
nt.setCapabilities(capabilities);
Assert.assertFalse(utils.hasCapabilitiesContainingNotNullProperties(nt));
Capability capability1 = new Capability();
capabilities.put("capa1", capability1);
Assert.assertFalse(utils.hasCapabilitiesContainingNotNullProperties(nt));
Capability capability2 = new Capability();
Map<String, AbstractPropertyValue> properties = new HashMap<String, AbstractPropertyValue>();
capability2.setProperties(properties);
capabilities.put("capa2", capability2);
Assert.assertFalse(utils.hasCapabilitiesContainingNotNullProperties(nt));
properties.put("prop1", null);
Assert.assertFalse(utils.hasCapabilitiesContainingNotNullProperties(nt));
properties.put("prop2", new ScalarPropertyValue("value"));
Assert.assertTrue(utils.hasCapabilitiesContainingNotNullProperties(nt));
}
use of org.alien4cloud.tosca.model.templates.Capability in project alien4cloud by alien4cloud.
the class PaaSUtilsTest method buildFakeCapability.
private Capability buildFakeCapability() {
Map<String, AbstractPropertyValue> props = Maps.newHashMap();
props.put(fake1, new ScalarPropertyValue("1_capa"));
props.put(fake2, null);
props.put(fake3, new ComplexPropertyValue(MapUtil.newHashMap(new String[] { "toto" }, new String[] { "tata" })));
props.put(fake5, new ScalarPropertyValue("5_capa"));
Capability fakeCapability = Mockito.mock(Capability.class);
Mockito.when(fakeCapability.getProperties()).thenReturn(props);
return fakeCapability;
}
use of org.alien4cloud.tosca.model.templates.Capability in project alien4cloud by alien4cloud.
the class CapabilityMatcherServiceTest method addCapabilityToNodeTemplateAndToscaContext.
private void addCapabilityToNodeTemplateAndToscaContext(String name, String type, String... derivedFrom) {
CapabilityType capabilityType = new CapabilityType();
capabilityType.setDerivedFrom(Arrays.asList(derivedFrom));
capabilityType.setElementId(type);
capabilityTypeByTypeName.put(type, capabilityType);
Capability capability = new Capability();
capability.setType(type);
nodeTemplate.getCapabilities().put(name, capability);
}
use of org.alien4cloud.tosca.model.templates.Capability in project alien4cloud by alien4cloud.
the class CapabilityMatcherServiceTest method should_not_crash_even_if_node_template_capacities_is_incorrect.
@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);
}
Aggregations