use of org.alien4cloud.tosca.model.types.CapabilityType in project alien4cloud by alien4cloud.
the class ToscaParserSimpleProfileAlien130Test method testNodeTypeWithCutomInterface.
@SuppressWarnings("unchecked")
@Test
public void testNodeTypeWithCutomInterface() throws FileNotFoundException, ParsingException {
NodeType mockedResult = Mockito.mock(NodeType.class);
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.SoftwareComponent"), Mockito.any(Set.class))).thenReturn(mockedResult);
Mockito.when(mockedResult.getDerivedFrom()).thenReturn(Lists.newArrayList("tosca.nodes.Root"));
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.Root"), Mockito.any(Set.class))).thenReturn(mockedResult);
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.Compute"), Mockito.any(Set.class))).thenReturn(mockedResult);
CapabilityType mockedCapabilityResult = Mockito.mock(CapabilityType.class);
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(CapabilityType.class), Mockito.eq("mytypes.mycapabilities.MyCapabilityTypeName"), Mockito.any(Set.class))).thenReturn(mockedCapabilityResult);
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(CapabilityType.class), Mockito.eq("tosca.capabilities.Container"), Mockito.any(Set.class))).thenReturn(mockedCapabilityResult);
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(CapabilityType.class), Mockito.eq("tosca.capabilities.Endpoint"), Mockito.any(Set.class))).thenReturn(mockedCapabilityResult);
RelationshipType hostedOn = new RelationshipType();
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(RelationshipType.class), Mockito.eq("tosca.relationships.HostedOn"), Mockito.any(Set.class))).thenReturn(hostedOn);
ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-node-type-interface-operations.yml"));
assertNoBlocker(parsingResult);
ArchiveRoot archiveRoot = parsingResult.getResult();
assertNotNull(archiveRoot.getArchive());
Assert.assertEquals(getToscaVersion(), archiveRoot.getArchive().getToscaDefinitionsVersion());
Assert.assertEquals(1, archiveRoot.getNodeTypes().size());
// check node type.
Entry<String, NodeType> entry = archiveRoot.getNodeTypes().entrySet().iterator().next();
Assert.assertEquals("my_company.my_types.MyAppNodeType", entry.getKey());
NodeType nodeType = entry.getValue();
assertNotNull(nodeType.getInterfaces());
Assert.assertEquals(2, nodeType.getInterfaces().size());
assertNotNull(nodeType.getInterfaces().get(ToscaNodeLifecycleConstants.STANDARD));
Interface customInterface = nodeType.getInterfaces().get("custom");
assertNotNull(customInterface);
Assert.assertEquals("this is a sample interface used to execute custom operations.", customInterface.getDescription());
Assert.assertEquals(1, customInterface.getOperations().size());
Operation operation = customInterface.getOperations().get("do_something");
assertNotNull(operation);
Assert.assertEquals(3, operation.getInputParameters().size());
Assert.assertEquals(ScalarPropertyValue.class, operation.getInputParameters().get("value_input").getClass());
Assert.assertEquals(PropertyDefinition.class, operation.getInputParameters().get("definition_input").getClass());
Assert.assertEquals(FunctionPropertyValue.class, operation.getInputParameters().get("function_input").getClass());
}
use of org.alien4cloud.tosca.model.types.CapabilityType in project alien4cloud by alien4cloud.
the class ToscaParserSimpleProfileAlien130Test method testGetOperationOutputFunction.
@Test
@SuppressWarnings("unchecked")
public void testGetOperationOutputFunction() throws Throwable {
Csar csar = new Csar("tosca-normative-types", "1.0.0-SNAPSHOT-wd03");
// Mockito.when(csarRepositorySearchService.getArchive(csar.getId())).thenReturn(csar);
NodeType mockedResult = Mockito.mock(NodeType.class);
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.SoftwareComponent"), Mockito.any(Set.class))).thenReturn(mockedResult);
Mockito.when(mockedResult.getDerivedFrom()).thenReturn(Lists.newArrayList("tosca.nodes.Root"));
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.Root"), Mockito.any(Set.class))).thenReturn(mockedResult);
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.Compute"), Mockito.any(Set.class))).thenReturn(mockedResult);
CapabilityType mockedCapabilityResult = Mockito.mock(CapabilityType.class);
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(CapabilityType.class), Mockito.eq("mytypes.mycapabilities.MyCapabilityTypeName"), Mockito.any(Set.class))).thenReturn(mockedCapabilityResult);
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(CapabilityType.class), Mockito.eq("tosca.capabilities.Container"), Mockito.any(Set.class))).thenReturn(mockedCapabilityResult);
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(CapabilityType.class), Mockito.eq("tosca.capabilities.Endpoint"), Mockito.any(Set.class))).thenReturn(mockedCapabilityResult);
RelationshipType hostedOn = new RelationshipType();
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(RelationshipType.class), Mockito.eq("tosca.relationships.HostedOn"), Mockito.any(Set.class))).thenReturn(hostedOn);
ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-functions.yml"));
Mockito.verify(csarRepositorySearchService).getArchive(csar.getName(), csar.getVersion());
assertNoBlocker(parsingResult);
ArchiveRoot archiveRoot = parsingResult.getResult();
assertNotNull(archiveRoot.getArchive());
Assert.assertEquals(getToscaVersion(), archiveRoot.getArchive().getToscaDefinitionsVersion());
// check nodetype elements
Entry<String, NodeType> entry = archiveRoot.getNodeTypes().entrySet().iterator().next();
Assert.assertEquals("my_company.my_types.MyAppNodeType", entry.getKey());
NodeType nodeType = entry.getValue();
// on input level
Map<String, Interface> interfaces = nodeType.getInterfaces();
Interface customInterface = interfaces.get("custom");
Map<String, IValue> doSomethingInputs = customInterface.getOperations().get("do_something").getInputParameters();
assertNotNull(doSomethingInputs);
Assert.assertFalse(doSomethingInputs.isEmpty());
IValue operationOutput_input = doSomethingInputs.get("operationOutput_input");
assertTrue(operationOutput_input instanceof FunctionPropertyValue);
FunctionPropertyValue function = (FunctionPropertyValue) operationOutput_input;
Assert.assertEquals("get_operation_output", function.getFunction());
Assert.assertEquals(4, function.getParameters().size());
Map<String, IValue> attributes = nodeType.getAttributes();
IValue operationOutputAttr = attributes.get("url");
// check attributes types
assertTrue(operationOutputAttr instanceof FunctionPropertyValue);
function = (FunctionPropertyValue) operationOutputAttr;
Assert.assertEquals("get_operation_output", function.getFunction());
Assert.assertEquals(4, function.getParameters().size());
}
use of org.alien4cloud.tosca.model.types.CapabilityType in project alien4cloud by alien4cloud.
the class ToscaParserSimpleProfileAlien130Test method testNodeType.
@SuppressWarnings("unchecked")
@Test
public void testNodeType() throws FileNotFoundException, ParsingException {
NodeType mockedResult = Mockito.mock(NodeType.class);
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.SoftwareComponent"), Mockito.any(Set.class))).thenReturn(mockedResult);
Mockito.when(mockedResult.getDerivedFrom()).thenReturn(Lists.newArrayList("tosca.nodes.Root"));
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.Root"), Mockito.any(Set.class))).thenReturn(mockedResult);
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.Compute"), Mockito.any(Set.class))).thenReturn(mockedResult);
CapabilityType mockedCapabilityResult = Mockito.mock(CapabilityType.class);
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(CapabilityType.class), Mockito.eq("mytypes.mycapabilities.MyCapabilityTypeName"), Mockito.any(Set.class))).thenReturn(mockedCapabilityResult);
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(CapabilityType.class), Mockito.eq("mytypes.mycapabilities.MyCapabilityTypeName"), Mockito.any(Set.class))).thenReturn(mockedCapabilityResult);
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(CapabilityType.class), Mockito.eq("tosca.capabilities.Endpoint"), Mockito.any(Set.class))).thenReturn(mockedCapabilityResult);
RelationshipType hostedOn = new RelationshipType();
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(RelationshipType.class), Mockito.eq("tosca.relationships.HostedOn"), Mockito.any(Set.class))).thenReturn(hostedOn);
ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-node-type.yml"));
ParserTestUtil.displayErrors(parsingResult);
assertNoBlocker(parsingResult);
ArchiveRoot archiveRoot = parsingResult.getResult();
assertNotNull(archiveRoot.getArchive());
Assert.assertEquals(getToscaVersion(), archiveRoot.getArchive().getToscaDefinitionsVersion());
Assert.assertEquals(1, archiveRoot.getNodeTypes().size());
// check node type.
Entry<String, NodeType> entry = archiveRoot.getNodeTypes().entrySet().iterator().next();
Assert.assertEquals("my_company.my_types.MyAppNodeType", entry.getKey());
NodeType nodeType = entry.getValue();
Assert.assertEquals(Lists.newArrayList("tosca.nodes.SoftwareComponent", "tosca.nodes.Root"), nodeType.getDerivedFrom());
Assert.assertEquals("My company’s custom applicaton", nodeType.getDescription());
// validate properties parsing
Assert.assertEquals(4, nodeType.getProperties().size());
PropertyDefinition def1 = new PropertyDefinition();
def1.setType("string");
def1.setDefault(new ScalarPropertyValue("default"));
def1.setDescription("application password");
List<PropertyConstraint> constraints = Lists.newArrayList();
constraints.add(new MinLengthConstraint(6));
constraints.add(new MaxLengthConstraint(10));
def1.setConstraints(constraints);
PropertyDefinition def2 = new PropertyDefinition();
def2.setType("integer");
def2.setDescription("application port number");
PropertyDefinition def3 = new PropertyDefinition();
def3.setType("scalar-unit.size");
def3.setDefault(new ScalarPropertyValue("1 GB"));
LessThanConstraint ltConstraint = new LessThanConstraint();
ltConstraint.setLessThan("1 TB");
constraints = Lists.<PropertyConstraint>newArrayList(ltConstraint);
def3.setConstraints(constraints);
PropertyDefinition def4 = new PropertyDefinition();
def4.setType("scalar-unit.time");
def4.setDefault(new ScalarPropertyValue("1 d"));
GreaterThanConstraint gtConstraint = new GreaterThanConstraint();
gtConstraint.setGreaterThan("1 h");
constraints = Lists.<PropertyConstraint>newArrayList(gtConstraint);
def4.setConstraints(constraints);
Assert.assertEquals(MapUtil.newHashMap(new String[] { "my_app_password", "my_app_duration", "my_app_size", "my_app_port" }, new PropertyDefinition[] { def1, def4, def3, def2 }), nodeType.getProperties());
}
use of org.alien4cloud.tosca.model.types.CapabilityType 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.types.CapabilityType in project alien4cloud by alien4cloud.
the class ParserTestUtil method mockNormativeTypes.
/**
* Utility method to mock the acess to some normative types nodes and capabilities.
*
* @param repositorySearchService The repositorySearchService to mock.
*/
public static void mockNormativeTypes(ICSARRepositorySearchService repositorySearchService) {
Csar csar = new Csar("tosca-normative-types", "1.0.0-ALIEN12");
Mockito.when(repositorySearchService.getArchive(csar.getName(), csar.getVersion())).thenReturn(csar);
NodeType mockedNodeRoot = new NodeType();
Mockito.when(repositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq(NormativeTypesConstant.ROOT_NODE_TYPE), Mockito.any(Set.class))).thenReturn(mockedNodeRoot);
RelationshipType mockedRelationshipRoot = new RelationshipType();
Mockito.when(repositorySearchService.getElementInDependencies(Mockito.eq(RelationshipType.class), Mockito.eq(NormativeTypesConstant.ROOT_RELATIONSHIP_TYPE), Mockito.any(Set.class))).thenReturn(mockedRelationshipRoot);
CapabilityType mockedCapabilityType = new CapabilityType();
Mockito.when(repositorySearchService.getElementInDependencies(Mockito.eq(CapabilityType.class), Mockito.eq(NormativeCapabilityTypes.ROOT), Mockito.any(Set.class))).thenReturn(mockedCapabilityType);
DataType mockedDataType = new DataType();
Mockito.when(repositorySearchService.getElementInDependencies(Mockito.eq(DataType.class), Mockito.eq(NormativeTypesConstant.ROOT_DATA_TYPE), Mockito.any(Set.class))).thenReturn(mockedDataType);
ArtifactType mockedArtifactType = new ArtifactType();
Mockito.when(repositorySearchService.getElementInDependencies(Mockito.eq(ArtifactType.class), Mockito.eq(NormativeTypesConstant.ROOT_ARTIFACT_TYPE), Mockito.any(Set.class))).thenReturn(mockedArtifactType);
}
Aggregations