use of alien4cloud.component.ICSARRepositorySearchService in project alien4cloud by alien4cloud.
the class ConstraintPropertyServiceTest method testInvalidMapPropertyInComplex.
@Test(expected = ConstraintValueDoNotMatchPropertyTypeException.class)
public void testInvalidMapPropertyInComplex() 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 propertyValue = ImmutableMap.builder().put("myMap", "aa").build();
// then -> ConstraintViolationException
ConstraintPropertyService.checkPropertyConstraint("test", propertyValue, propertyDefinition);
} finally {
ToscaContext.setCsarRepositorySearchService(originalCsarRepositorySearchService);
ToscaContext.destroy();
}
}
use of alien4cloud.component.ICSARRepositorySearchService in project alien4cloud by alien4cloud.
the class ConstraintPropertyServiceTest method testInvalidListProperty.
@Test(expected = ConstraintViolationException.class)
public void testInvalidListProperty() throws Exception {
PropertyDefinition propertyDefinition = new PropertyDefinition();
propertyDefinition.setType(ToscaTypes.LIST);
PropertyDefinition entrySchema = new PropertyDefinition();
entrySchema.setType(ToscaTypes.STRING);
propertyDefinition.setEntrySchema(entrySchema);
Object propertyValue = ImmutableMap.builder().put("aa", "bb").build();
ToscaContext.init(new HashSet<>());
ICSARRepositorySearchService originalCsarRepositorySearchService = ToscaContext.getCsarRepositorySearchService();
ICSARRepositorySearchService mockSearchService = Mockito.mock(ICSARRepositorySearchService.class);
try {
ToscaContext.setCsarRepositorySearchService(mockSearchService);
ConstraintPropertyService.checkPropertyConstraint("test", propertyValue, propertyDefinition);
} finally {
ToscaContext.setCsarRepositorySearchService(originalCsarRepositorySearchService);
ToscaContext.destroy();
}
}
use of alien4cloud.component.ICSARRepositorySearchService 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