use of alien4cloud.tosca.model.ArchiveRoot in project alien4cloud by alien4cloud.
the class AbstractToscaParserSimpleProfileTest method testDefinitionVersionValid.
@Test
public void testDefinitionVersionValid() throws FileNotFoundException, ParsingException {
ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-definition-version.yml"));
Assert.assertEquals(0, parsingResult.getContext().getParsingErrors().size());
ArchiveRoot archiveRoot = parsingResult.getResult();
Assert.assertNotNull(archiveRoot.getArchive());
Assert.assertEquals(getToscaVersion(), archiveRoot.getArchive().getToscaDefinitionsVersion());
}
use of alien4cloud.tosca.model.ArchiveRoot in project alien4cloud by alien4cloud.
the class ToscaParserAlien200Test method parseTopologyTemplateWithActivities.
@Test
public void parseTopologyTemplateWithActivities() throws ParsingException {
ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-topology-template-activities.yml"));
assertFalse(parsingResult.getResult().getTopology().getWorkflows().isEmpty());
assertNotNull(parsingResult.getResult().getTopology().getWorkflows().get("install"));
Workflow wf = parsingResult.getResult().getTopology().getWorkflows().get("install");
// check activities
assertEquals(1, wf.getSteps().get("Compute_install").getActivities().size());
assertEquals(1, wf.getSteps().get("Compute_install_0").getActivities().size());
assertEquals(1, wf.getSteps().get("Compute_install_1").getActivities().size());
// check activities of an other step
assertTrue(wf.getSteps().get("Compute_uninstall").getActivities().size() == 1);
assertTrue(wf.getSteps().get("Compute_uninstall_0").getActivities().size() == 1);
assertEquals(1, wf.getSteps().get("Compute_install").getOnSuccess().size());
assertEquals(1, wf.getSteps().get("Compute_install_0").getOnSuccess().size());
assertEquals(1, wf.getSteps().get("Compute_install_1").getOnSuccess().size());
assertEquals(1, wf.getSteps().get("Compute_uninstall").getOnSuccess().size());
assertEquals(0, wf.getSteps().get("Compute_uninstall_0").getOnSuccess().size());
// check onSuccess
assertTrue(wf.getSteps().get("Compute_install").getOnSuccess().contains("Compute_install_0"));
assertTrue(wf.getSteps().get("Compute_install_0").getOnSuccess().contains("Compute_install_1"));
assertTrue(wf.getSteps().get("Compute_install_1").getOnSuccess().contains("Compute_uninstall"));
assertTrue(wf.getSteps().get("Compute_uninstall").getOnSuccess().contains("Compute_uninstall_0"));
}
use of alien4cloud.tosca.model.ArchiveRoot in project alien4cloud by alien4cloud.
the class ToscaParserAlien200Test method parsingInvalidRelationshipTargetInWorkflowStepShouldFail.
@Test
public void parsingInvalidRelationshipTargetInWorkflowStepShouldFail() throws ParsingException {
Mockito.reset(csarRepositorySearchService);
Mockito.when(csarRepositorySearchService.getArchive("tosca-normative-types", "1.0.0-ALIEN14")).thenReturn(Mockito.mock(Csar.class));
NodeType mockType = Mockito.mock(NodeType.class);
Mockito.when(mockType.isAbstract()).thenReturn(true);
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.Root"), Mockito.any(Set.class))).thenReturn(mockType);
Mockito.when(mockType.getCapabilities()).thenReturn(Lists.newArrayList(new CapabilityDefinition("host", "tosca.capabilities.Container", 1)));
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.Compute"), Mockito.any(Set.class))).thenReturn(mockType);
mockType = Mockito.mock(NodeType.class);
Mockito.when(mockType.getRequirements()).thenReturn(Lists.newArrayList(new RequirementDefinition("host", "tosca.capabilities.Container")));
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.SoftwareComponent"), Mockito.any(Set.class))).thenReturn(mockType);
CapabilityType mockCapaType = Mockito.mock(CapabilityType.class);
Mockito.when(mockCapaType.getElementId()).thenReturn("tosca.capabilities.Container");
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(CapabilityType.class), Mockito.eq("tosca.capabilities.Container"), Mockito.any(Set.class))).thenReturn(mockCapaType);
RelationshipType mockRelType = Mockito.mock(RelationshipType.class);
Mockito.when(mockRelType.getElementId()).thenReturn("tosca.relationships.HostedOn");
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(RelationshipType.class), Mockito.eq("tosca.relationships.HostedOn"), Mockito.any(Set.class))).thenReturn(mockRelType);
ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-topology-template-workflow-relationship-operation-invalid-target.yml"));
// Same error is duplicated but is it that bad ?
assertEquals(2, parsingResult.getContext().getParsingErrors().size());
assertEquals(ErrorCode.UNKNWON_WORKFLOW_STEP_RELATIONSHIP_TARGET, parsingResult.getContext().getParsingErrors().get(0).getErrorCode());
}
use of alien4cloud.tosca.model.ArchiveRoot in project alien4cloud by alien4cloud.
the class ToscaParserAlien200Test method testPolicyTypeParsing.
@Test
public void testPolicyTypeParsing() throws ParsingException {
Mockito.reset(csarRepositorySearchService);
Mockito.when(csarRepositorySearchService.getArchive("tosca-normative-types", "1.0.0-ALIEN14")).thenReturn(Mockito.mock(Csar.class));
PolicyType mockRoot = Mockito.mock(PolicyType.class);
Mockito.when(mockRoot.isAbstract()).thenReturn(true);
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(PolicyType.class), Mockito.eq("tosca.policies.Root"), Mockito.any(Set.class))).thenReturn(mockRoot);
NodeType mockType = Mockito.mock(NodeType.class);
Mockito.when(mockType.isAbstract()).thenReturn(true);
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.Root"), Mockito.any(Set.class))).thenReturn(mockType);
Mockito.when(csarRepositorySearchService.getElementInDependencies(Mockito.eq(NodeType.class), Mockito.eq("tosca.nodes.Compute"), Mockito.any(Set.class))).thenReturn(mockType);
ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-policy-type.yml"));
assertEquals(0, parsingResult.getContext().getParsingErrors().size());
ArchiveRoot archiveRoot = parsingResult.getResult();
assertNotNull(archiveRoot.getArchive());
assertEquals(getToscaVersion(), archiveRoot.getArchive().getToscaDefinitionsVersion());
assertEquals(3, archiveRoot.getPolicyTypes().size());
PolicyType minPolicyType = archiveRoot.getPolicyTypes().get("org.alien4cloud.sample.MinimalPolicyType");
assertNotNull(minPolicyType);
assertEquals("org.alien4cloud.test.policies.PolicyTypes", minPolicyType.getArchiveName());
assertEquals("2.0.0-SNAPSHOT", minPolicyType.getArchiveVersion());
assertEquals("org.alien4cloud.sample.MinimalPolicyType", minPolicyType.getElementId());
assertEquals("This is a sample policy type with minimal definition", minPolicyType.getDescription());
assertEquals(1, minPolicyType.getDerivedFrom().size());
assertEquals("tosca.policies.Root", minPolicyType.getDerivedFrom().get(0));
PolicyType simplePolicyType = archiveRoot.getPolicyTypes().get("org.alien4cloud.sample.SimpleConditionPolicyType");
assertNotNull(simplePolicyType);
assertEquals("org.alien4cloud.test.policies.PolicyTypes", simplePolicyType.getArchiveName());
assertEquals("2.0.0-SNAPSHOT", simplePolicyType.getArchiveVersion());
assertEquals("org.alien4cloud.sample.SimpleConditionPolicyType", simplePolicyType.getElementId());
assertEquals("This is a sample policy type with simple definition", simplePolicyType.getDescription());
assertEquals(1, simplePolicyType.getDerivedFrom().size());
assertEquals("tosca.policies.Root", simplePolicyType.getDerivedFrom().get(0));
assertEquals(2, simplePolicyType.getTags().size());
assertEquals("sample_meta", simplePolicyType.getTags().get(0).getName());
assertEquals("a meta data", simplePolicyType.getTags().get(0).getValue());
assertEquals("anoter_meta", simplePolicyType.getTags().get(1).getName());
assertEquals("another meta data", simplePolicyType.getTags().get(1).getValue());
assertEquals(1, simplePolicyType.getProperties().size());
assertNotNull(simplePolicyType.getProperties().get("sample_property"));
assertEquals("string", simplePolicyType.getProperties().get("sample_property").getType());
assertEquals(2, simplePolicyType.getTargets().size());
assertTrue(simplePolicyType.getTargets().contains("tosca.nodes.Compute"));
assertTrue(simplePolicyType.getTargets().contains("tosca.nodes.Root"));
PolicyType policyType = archiveRoot.getPolicyTypes().get("org.alien4cloud.sample.PolicyType");
assertNotNull(policyType);
assertEquals("org.alien4cloud.test.policies.PolicyTypes", policyType.getArchiveName());
assertEquals("2.0.0-SNAPSHOT", policyType.getArchiveVersion());
assertEquals("org.alien4cloud.sample.PolicyType", policyType.getElementId());
assertEquals("This is a sample policy type", policyType.getDescription());
assertEquals(1, policyType.getDerivedFrom().size());
assertEquals("tosca.policies.Root", policyType.getDerivedFrom().get(0));
assertEquals(2, policyType.getTags().size());
assertEquals("sample_meta", policyType.getTags().get(0).getName());
assertEquals("a meta data", policyType.getTags().get(0).getValue());
assertEquals("anoter_meta", policyType.getTags().get(1).getName());
assertEquals("another meta data", policyType.getTags().get(1).getValue());
assertEquals(1, policyType.getProperties().size());
assertNotNull(policyType.getProperties().get("sample_property"));
assertEquals("string", policyType.getProperties().get("sample_property").getType());
assertEquals(2, policyType.getTargets().size());
assertTrue(simplePolicyType.getTargets().contains("tosca.nodes.Compute"));
assertTrue(simplePolicyType.getTargets().contains("tosca.nodes.Root"));
}
use of alien4cloud.tosca.model.ArchiveRoot in project alien4cloud by alien4cloud.
the class ToscaParserAlien200Test method parseTopologyTemplateWithInlineWorkflow.
@Test
public void parseTopologyTemplateWithInlineWorkflow() throws ParsingException {
ParsingResult<ArchiveRoot> parsingResult = parser.parseFile(Paths.get(getRootDirectory(), "tosca-topology-template-inline-workflow.yml"));
assertFalse(parsingResult.getResult().getTopology().getWorkflows().isEmpty());
assertNotNull(parsingResult.getResult().getTopology().getWorkflows().get("install"));
Workflow wf = parsingResult.getResult().getTopology().getWorkflows().get("install");
assertEquals(1, wf.getSteps().get("Compute_install_0").getActivities().size());
assertTrue(wf.getSteps().get("Compute_install_0").getActivities().get(0) instanceof InlineWorkflowActivity);
InlineWorkflowActivity activity = (InlineWorkflowActivity) wf.getSteps().get("Compute_install_0").getActivities().get(0);
assertTrue(activity.getInline().equals("my_custom_wf"));
WorkflowUtils.processInlineWorkflows(parsingResult.getResult().getTopology().getWorkflows());
assertFalse(wf.getSteps().containsKey("Compute_install_0"));
assertTrue(wf.getSteps().containsKey("Compute_install_0_Compute_stop"));
assertTrue(wf.getSteps().containsKey("Compute_install_0_Compute_uninstall"));
assertTrue(wf.getSteps().containsKey("Some_other_inline_Compute_stop"));
assertTrue(wf.getSteps().containsKey("Some_other_inline_Compute_uninstall"));
assertTrue(wf.getSteps().get("Compute_install").getOnSuccess().contains("Compute_install_0_Compute_stop"));
assertTrue(wf.getSteps().get("Compute_install_0_Compute_stop").getPrecedingSteps().contains("Compute_install"));
assertEquals(1, wf.getSteps().get("Compute_install").getOnSuccess().size());
assertEquals(0, wf.getSteps().get("Compute_install").getPrecedingSteps().size());
assertEquals(1, wf.getSteps().get("Compute_install_0_Compute_stop").getPrecedingSteps().size());
assertFalse(wf.getSteps().get("Compute_install").getOnSuccess().contains("Compute_install_0_Compute_uninstall"));
assertFalse(wf.getSteps().get("Compute_install_0_Compute_uninstall").getPrecedingSteps().contains("Compute_install"));
assertTrue(wf.getSteps().get("Compute_install_0_Compute_stop").getOnSuccess().contains("Compute_install_0_Compute_uninstall"));
assertTrue(wf.getSteps().get("Compute_install_0_Compute_uninstall").getPrecedingSteps().contains("Compute_install_0_Compute_stop"));
assertEquals(1, wf.getSteps().get("Compute_install_0_Compute_stop").getOnSuccess().size());
assertEquals(1, wf.getSteps().get("Compute_install_0_Compute_uninstall").getPrecedingSteps().size());
assertEquals(1, wf.getSteps().get("Compute_install_0_Compute_uninstall").getOnSuccess().size());
assertTrue(wf.getSteps().get("Compute_install_0_Compute_uninstall").getOnSuccess().contains("Compute_start"));
assertTrue(wf.getSteps().get("Compute_start").getPrecedingSteps().contains("Compute_install_0_Compute_uninstall"));
assertTrue(wf.getSteps().get("Some_other_inline_Compute_stop").getOnSuccess().contains("Some_other_inline_Compute_uninstall"));
assertTrue(wf.getSteps().get("Some_other_inline_Compute_uninstall").getPrecedingSteps().contains("Some_other_inline_Compute_stop"));
assertTrue(wf.getSteps().get("inception_inline_inception_inline_Compute_stop").getOnSuccess().contains("inception_inline_inception_inline_Compute_uninstall"));
assertTrue(wf.getSteps().get("inception_inline_inception_inline_Compute_uninstall").getPrecedingSteps().contains("inception_inline_inception_inline_Compute_stop"));
}
Aggregations