use of org.alien4cloud.tosca.model.definitions.PropertyDefinition 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.definitions.PropertyDefinition in project alien4cloud by alien4cloud.
the class ConstraintPropertyServiceTest method testValidMapProperty.
@Test
public void testValidMapProperty() throws Exception {
PropertyDefinition propertyDefinition = new PropertyDefinition();
propertyDefinition.setType(ToscaTypes.MAP);
PropertyDefinition entrySchema = new PropertyDefinition();
entrySchema.setType(ToscaTypes.STRING);
propertyDefinition.setEntrySchema(entrySchema);
Object propertyValue = ImmutableMap.builder().put("aa", "bb").build();
ConstraintPropertyService.checkPropertyConstraint("test", propertyValue, propertyDefinition);
// test length constraint
LengthConstraint lengthConstraint = new LengthConstraint();
lengthConstraint.setLength(1);
List<PropertyConstraint> constraints = Lists.newArrayList();
constraints.add(lengthConstraint);
propertyDefinition.setConstraints(constraints);
ConstraintPropertyService.checkPropertyConstraint("test", propertyValue, propertyDefinition);
}
use of org.alien4cloud.tosca.model.definitions.PropertyDefinition in project alien4cloud by alien4cloud.
the class ConstraintPropertyServiceTest method testValidFloatProperty.
@Test
public void testValidFloatProperty() throws Exception {
PropertyDefinition propertyDefinition = new PropertyDefinition();
propertyDefinition.setType(ToscaTypes.FLOAT);
ConstraintPropertyService.checkPropertyConstraint("test", "128", propertyDefinition);
ConstraintPropertyService.checkPropertyConstraint("test", "128.34", propertyDefinition);
}
use of org.alien4cloud.tosca.model.definitions.PropertyDefinition in project alien4cloud by alien4cloud.
the class ConstraintPropertyServiceTest method testInvalidVersionProperty.
@Test(expected = ConstraintValueDoNotMatchPropertyTypeException.class)
public void testInvalidVersionProperty() throws Exception {
PropertyDefinition propertyDefinition = new PropertyDefinition();
propertyDefinition.setType(ToscaTypes.VERSION);
ConstraintPropertyService.checkPropertyConstraint("test", "anything", propertyDefinition);
}
use of org.alien4cloud.tosca.model.definitions.PropertyDefinition in project alien4cloud by alien4cloud.
the class ConstraintPropertyServiceTest method testMapPropertyInComplex.
// ///////////////////////////////////////////////////////////////
// Tests on complex properties validation
// ///////////////////////////////////////////////////////////////
@Test
public void testMapPropertyInComplex() throws ConstraintValueDoNotMatchPropertyTypeException, ConstraintViolationException {
// given
PropertyDefinition propertyDefinition = new PropertyDefinition();
propertyDefinition.setType("alien.test.ComplexStruct");
PropertyDefinition subPropertyDefinition = new PropertyDefinition();
subPropertyDefinition.setType(ToscaTypes.MAP);
PropertyDefinition entrySchema = new PropertyDefinition();
entrySchema.setType(ToscaTypes.STRING);
subPropertyDefinition.setEntrySchema(entrySchema);
DataType dataType = new DataType();
dataType.setProperties(Maps.newHashMap());
dataType.getProperties().put("myMap", subPropertyDefinition);
dataType.setElementId("alien.test.ComplexStruct");
ICSARRepositorySearchService originalCsarRepositorySearchService = ToscaContext.getCsarRepositorySearchService();
ToscaContext.init(new HashSet<>());
ICSARRepositorySearchService mockSearchService = Mockito.mock(ICSARRepositorySearchService.class);
Mockito.when(mockSearchService.getRequiredElementInDependencies(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(dataType);
Mockito.when(mockSearchService.getElementInDependencies(Mockito.any(), Mockito.any(), Mockito.anySet())).thenReturn(dataType);
try {
ToscaContext.setCsarRepositorySearchService(mockSearchService);
// when
Object subPropertyValue = ImmutableMap.builder().put("aa", "bb").build();
Object propertyValue = ImmutableMap.builder().put("myMap", subPropertyValue).build();
// then
ConstraintPropertyService.checkPropertyConstraint("test", propertyValue, propertyDefinition);
} finally {
ToscaContext.setCsarRepositorySearchService(originalCsarRepositorySearchService);
ToscaContext.destroy();
}
}
Aggregations