use of alien4cloud.tosca.model.ArchiveRoot in project alien4cloud by alien4cloud.
the class ToscaParserSimpleProfileAlien120Test method testDataTypesComplexWithDefault.
@Test
public void testDataTypesComplexWithDefault() throws ParsingException {
ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-data-types-complex-default.yml"));
ParserTestUtil.displayErrors(parsingResult);
Assert.assertEquals(2, parsingResult.getResult().getDataTypes().size());
Assert.assertEquals(2, parsingResult.getResult().getNodeTypes().size());
Assert.assertEquals(0, parsingResult.getContext().getParsingErrors().size());
NodeType commandType = parsingResult.getResult().getNodeTypes().get("alien.test.Command");
Assert.assertNotNull(commandType);
PropertyDefinition pd = commandType.getProperties().get("customer");
Assert.assertNotNull(pd);
// check the default value
Object defaultValue = pd.getDefault();
Assert.assertNotNull(defaultValue);
Assert.assertTrue(defaultValue instanceof ComplexPropertyValue);
ComplexPropertyValue cpv = (ComplexPropertyValue) defaultValue;
Map<String, Object> valueAsMap = cpv.getValue();
Assert.assertNotNull(valueAsMap);
Assert.assertTrue(valueAsMap.containsKey("first_name"));
Assert.assertEquals("Foo", valueAsMap.get("first_name"));
Assert.assertTrue(valueAsMap.containsKey("last_name"));
Assert.assertEquals("Bar", valueAsMap.get("last_name"));
Assert.assertEquals(1, parsingResult.getResult().getTopology().getNodeTemplates().size());
NodeTemplate nodeTemplate = parsingResult.getResult().getTopology().getNodeTemplates().values().iterator().next();
// on the node, the default value should be set
Assert.assertNotNull(nodeTemplate.getProperties());
Assert.assertTrue(nodeTemplate.getProperties().containsKey("customer"));
AbstractPropertyValue apv = nodeTemplate.getProperties().get("customer");
Assert.assertNotNull(apv);
Assert.assertTrue(apv instanceof ComplexPropertyValue);
cpv = (ComplexPropertyValue) apv;
valueAsMap = cpv.getValue();
Assert.assertNotNull(valueAsMap);
Assert.assertTrue(valueAsMap.containsKey("first_name"));
Assert.assertEquals("Foo", valueAsMap.get("first_name"));
Assert.assertTrue(valueAsMap.containsKey("last_name"));
Assert.assertEquals("Bar", valueAsMap.get("last_name"));
}
use of alien4cloud.tosca.model.ArchiveRoot in project alien4cloud by alien4cloud.
the class ToscaParserSimpleProfileAlien120Test method testDataTypesVeryComplexWithDefault.
@Test
public void testDataTypesVeryComplexWithDefault() throws ParsingException {
ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-data-types-very-complex-default.yml"));
ParserTestUtil.displayErrors(parsingResult);
Assert.assertEquals(3, parsingResult.getResult().getDataTypes().size());
Assert.assertEquals(2, parsingResult.getResult().getNodeTypes().size());
Assert.assertEquals(0, parsingResult.getContext().getParsingErrors().size());
NodeType commandType = parsingResult.getResult().getNodeTypes().get("alien.test.Command");
Assert.assertNotNull(commandType);
PropertyDefinition pd = commandType.getProperties().get("customer");
Assert.assertNotNull(pd);
// check the default value
Object defaultValue = pd.getDefault();
Assert.assertNotNull(defaultValue);
Assert.assertTrue(defaultValue instanceof ComplexPropertyValue);
ComplexPropertyValue cpv = (ComplexPropertyValue) defaultValue;
Map<String, Object> valueAsMap = cpv.getValue();
Assert.assertNotNull(valueAsMap);
Assert.assertTrue(valueAsMap.containsKey("first_name"));
Assert.assertEquals("Foo", valueAsMap.get("first_name"));
Assert.assertTrue(valueAsMap.containsKey("last_name"));
Assert.assertEquals("Bar", valueAsMap.get("last_name"));
Assert.assertTrue(valueAsMap.containsKey("address"));
Object addressObj = valueAsMap.get("address");
Assert.assertNotNull(addressObj);
Assert.assertTrue(addressObj instanceof Map);
Map<String, Object> addressMap = (Map<String, Object>) addressObj;
Assert.assertTrue(addressMap.containsKey("street_name"));
Assert.assertEquals("rue des peupliers", addressMap.get("street_name"));
Assert.assertTrue(addressMap.containsKey("zipcode"));
Assert.assertEquals("92130", addressMap.get("zipcode"));
Assert.assertTrue(addressMap.containsKey("city_name"));
Assert.assertEquals("ISSY LES MOULES", addressMap.get("city_name"));
Assert.assertTrue(valueAsMap.containsKey("emails"));
Object emailsObj = valueAsMap.get("emails");
Assert.assertNotNull(emailsObj);
Assert.assertTrue(emailsObj instanceof List);
List<Object> emailsList = (List<Object>) emailsObj;
Assert.assertEquals(2, emailsList.size());
Assert.assertEquals("contact@fastconnect.fr", emailsList.get(0));
Assert.assertEquals("info@fastconnect.fr", emailsList.get(1));
Object accountsObj = valueAsMap.get("accounts");
Assert.assertNotNull(accountsObj);
Assert.assertTrue(accountsObj instanceof Map);
Map<String, Object> accountsMap = (Map<String, Object>) accountsObj;
Assert.assertEquals(2, accountsMap.size());
Assert.assertTrue(accountsMap.containsKey("main"));
Assert.assertEquals("root", accountsMap.get("main"));
Assert.assertTrue(accountsMap.containsKey("secondary"));
Assert.assertEquals("user", accountsMap.get("secondary"));
Assert.assertEquals(1, parsingResult.getResult().getTopology().getNodeTemplates().size());
NodeTemplate nodeTemplate = parsingResult.getResult().getTopology().getNodeTemplates().values().iterator().next();
// on the node, the default value should be set
Assert.assertNotNull(nodeTemplate.getProperties());
Assert.assertTrue(nodeTemplate.getProperties().containsKey("customer"));
AbstractPropertyValue apv = nodeTemplate.getProperties().get("customer");
Assert.assertNotNull(apv);
Assert.assertTrue(apv instanceof ComplexPropertyValue);
cpv = (ComplexPropertyValue) apv;
valueAsMap = cpv.getValue();
Assert.assertNotNull(valueAsMap);
Assert.assertTrue(valueAsMap.containsKey("first_name"));
Assert.assertEquals("Foo", valueAsMap.get("first_name"));
Assert.assertTrue(valueAsMap.containsKey("last_name"));
Assert.assertEquals("Bar", valueAsMap.get("last_name"));
Assert.assertTrue(valueAsMap.containsKey("address"));
addressObj = valueAsMap.get("address");
Assert.assertNotNull(addressObj);
Assert.assertTrue(addressObj instanceof Map);
addressMap = (Map<String, Object>) addressObj;
Assert.assertTrue(addressMap.containsKey("street_name"));
Assert.assertEquals("rue des peupliers", addressMap.get("street_name"));
Assert.assertTrue(addressMap.containsKey("zipcode"));
Assert.assertEquals("92130", addressMap.get("zipcode"));
Assert.assertTrue(addressMap.containsKey("city_name"));
Assert.assertEquals("ISSY LES MOULES", addressMap.get("city_name"));
Assert.assertTrue(valueAsMap.containsKey("emails"));
emailsObj = valueAsMap.get("emails");
Assert.assertNotNull(emailsObj);
Assert.assertTrue(emailsObj instanceof List);
emailsList = (List<Object>) emailsObj;
Assert.assertEquals(2, emailsList.size());
Assert.assertEquals("contact@fastconnect.fr", emailsList.get(0));
Assert.assertEquals("info@fastconnect.fr", emailsList.get(1));
accountsObj = valueAsMap.get("accounts");
Assert.assertNotNull(accountsObj);
Assert.assertTrue(accountsObj instanceof Map);
accountsMap = (Map<String, Object>) accountsObj;
Assert.assertEquals(2, accountsMap.size());
Assert.assertTrue(accountsMap.containsKey("main"));
Assert.assertEquals("root", accountsMap.get("main"));
Assert.assertTrue(accountsMap.containsKey("secondary"));
Assert.assertEquals("user", accountsMap.get("secondary"));
}
use of alien4cloud.tosca.model.ArchiveRoot in project alien4cloud by alien4cloud.
the class ToscaParserSimpleProfileAlien130Test method testParseImplementationArtifactWithRepository.
@Test
public void testParseImplementationArtifactWithRepository() throws ParsingException {
ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "implementation_artifact.yml"));
ParserTestUtil.displayErrors(parsingResult);
assertTrue(parsingResult.getContext().getParsingErrors().isEmpty());
ArchiveRoot archiveRoot = parsingResult.getResult();
assertNotNull(archiveRoot.getArchive());
Assert.assertEquals(getToscaVersion(), archiveRoot.getArchive().getToscaDefinitionsVersion());
Assert.assertEquals(2, archiveRoot.getArtifactTypes().size());
Assert.assertEquals(4, archiveRoot.getNodeTypes().size());
Assert.assertEquals(3, archiveRoot.getRepositories().size());
Assert.assertEquals(3, archiveRoot.getRelationshipTypes().size());
NodeType httpComponent = archiveRoot.getNodeTypes().get("my.http.component");
validateHttpArtifact(httpComponent);
NodeType httpComponentExtended = archiveRoot.getNodeTypes().get("my.http.component.extended");
validateHttpArtifact(httpComponentExtended);
NodeType gitComponent = archiveRoot.getNodeTypes().get("my.git.component");
ImplementationArtifact gitComponentCreateArtifact = getImplementationArtifact(gitComponent, "create");
Assert.assertEquals("master:myGitScript.xyz", gitComponentCreateArtifact.getArtifactRef());
Assert.assertEquals("tosca.artifacts.Implementation.Bash", gitComponentCreateArtifact.getArtifactType());
assertNull(gitComponentCreateArtifact.getRepositoryCredential());
Assert.assertEquals("git_repo", gitComponentCreateArtifact.getRepositoryName());
Assert.assertEquals("git", gitComponentCreateArtifact.getArtifactRepository());
Assert.assertEquals("https://github.com/myId/myRepo.git", gitComponentCreateArtifact.getRepositoryURL());
RelationshipType httpRelationship = archiveRoot.getRelationshipTypes().get("my.http.relationship");
ImplementationArtifact httpRelationshipCreateArtifact = getImplementationArtifact(httpRelationship, "create");
Assert.assertEquals("https://otherCompany/script/short_notation.sh", httpRelationshipCreateArtifact.getArtifactRef());
Assert.assertEquals("tosca.artifacts.Implementation.Bash", httpRelationshipCreateArtifact.getArtifactType());
assertNull(httpRelationshipCreateArtifact.getRepositoryCredential());
assertNull(httpRelationshipCreateArtifact.getRepositoryName());
assertNull(httpRelationshipCreateArtifact.getArtifactRepository());
assertNull(httpRelationshipCreateArtifact.getRepositoryURL());
ImplementationArtifact httpRelationshipStartArtifact = getImplementationArtifact(httpRelationship, "start");
Assert.assertEquals("myScript.abc", httpRelationshipStartArtifact.getArtifactRef());
Assert.assertEquals("tosca.artifacts.Implementation.Bash", httpRelationshipStartArtifact.getArtifactType());
Assert.assertEquals(ImmutableMap.<String, Object>builder().put(NormativeCredentialConstant.USER_KEY, "good_user").put(NormativeCredentialConstant.TOKEN_KEY, "real_secured_password").put(NormativeCredentialConstant.TOKEN_TYPE, "password").build(), httpRelationshipStartArtifact.getRepositoryCredential());
Assert.assertEquals("script_repo", httpRelationshipStartArtifact.getRepositoryName());
assertNull(httpRelationshipStartArtifact.getArtifactRepository());
Assert.assertEquals("https://myCompany/script", httpRelationshipStartArtifact.getRepositoryURL());
}
use of alien4cloud.tosca.model.ArchiveRoot in project alien4cloud by alien4cloud.
the class ToscaParserSimpleProfileAlien130Test method testImportDependencyMissing.
@Test
public void testImportDependencyMissing() throws FileNotFoundException, ParsingException {
Csar csar = new Csar("tosca-normative-types", "1.0.0-SNAPSHOT-wd03");
Mockito.when(csarRepositorySearchService.getArchive(csar.getName(), csar.getVersion())).thenReturn(null);
ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-import-dependency.yml"));
Mockito.verify(csarRepositorySearchService).getArchive(csar.getName(), csar.getVersion());
assertNoBlocker(parsingResult);
ArchiveRoot archiveRoot = parsingResult.getResult();
assertNotNull(archiveRoot.getArchive());
assertNotNull(archiveRoot.getArchive().getDependencies());
Assert.assertEquals(0, archiveRoot.getArchive().getDependencies().size());
}
use of alien4cloud.tosca.model.ArchiveRoot in project alien4cloud by alien4cloud.
the class ToscaParserSimpleProfileAlien130Test method testCapabilityType.
@SuppressWarnings("unchecked")
@Test
public void testCapabilityType() throws FileNotFoundException, ParsingException {
CapabilityType mockedResult = Mockito.mock(CapabilityType.class);
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(CapabilityType.class), Mockito.eq("tosca.capabilities.Feature"), Mockito.any(Set.class))).thenReturn(mockedResult);
Mockito.when(mockedResult.getDerivedFrom()).thenReturn(Lists.newArrayList("tosca.capabilities.Root"));
ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-capability-type.yml"));
assertNoBlocker(parsingResult);
ArchiveRoot archiveRoot = parsingResult.getResult();
assertNotNull(archiveRoot.getArchive());
Assert.assertEquals(getToscaVersion(), archiveRoot.getArchive().getToscaDefinitionsVersion());
Assert.assertEquals(1, archiveRoot.getCapabilityTypes().size());
Entry<String, CapabilityType> entry = archiveRoot.getCapabilityTypes().entrySet().iterator().next();
Assert.assertEquals("mycompany.mytypes.myapplication.MyFeature", entry.getKey());
CapabilityType capability = entry.getValue();
Assert.assertEquals(Lists.newArrayList("tosca.capabilities.Feature", "tosca.capabilities.Root"), capability.getDerivedFrom());
Assert.assertEquals("a custom feature of my company’s application", capability.getDescription());
}
Aggregations