use of alien4cloud.paas.model.PaaSNodeTemplate in project alien4cloud by alien4cloud.
the class FunctionEvaluatorTest method getOperationOutputTest.
@Test
public void getOperationOutputTest() {
String computeName = "comp_getOpOutput";
PaaSNodeTemplate computePaaS = builtPaaSNodeTemplates.get(computeName);
// check if outputs referenced in get_operation_outputs on attributes are well registered on the related operation
AbstractInstantiableToscaType tocaElement = computePaaS.getIndexedToscaElement();
IValue oldHostNameAttr = tocaElement.getAttributes().get("old_hostname");
IValue newHostNameAttr = tocaElement.getAttributes().get("new_hostname");
Operation createOp = computePaaS.getInterfaces().get(ToscaNodeLifecycleConstants.STANDARD).getOperations().get(ToscaNodeLifecycleConstants.CREATE);
Operation configOp = computePaaS.getInterfaces().get(ToscaNodeLifecycleConstants.STANDARD).getOperations().get(ToscaNodeLifecycleConstants.CONFIGURE);
Set<OperationOutput> createOutput = createOp.getOutputs();
Set<OperationOutput> configureOutput = configOp.getOutputs();
Assert.assertTrue(oldHostNameAttr instanceof FunctionPropertyValue);
Assert.assertTrue(newHostNameAttr instanceof FunctionPropertyValue);
String output1 = ((FunctionPropertyValue) oldHostNameAttr).getElementNameToFetch();
String output2 = ((FunctionPropertyValue) newHostNameAttr).getElementNameToFetch();
Assert.assertTrue(createOutput.contains(new OperationOutput(output1)));
OperationOutput fullOutput1 = createOp.getOutput(output1);
Assert.assertTrue(fullOutput1.getRelatedAttributes().contains("comp_getOpOutput:old_hostname"));
Assert.assertTrue(configureOutput.contains(new OperationOutput(output2)));
OperationOutput fullOutput2 = configOp.getOutput(output2);
Assert.assertTrue(fullOutput2.getRelatedAttributes().contains("comp_getOpOutput:new_hostname"));
// check if outputs referenced in get_operation_output on an input parameter is well registered on the related operation
IValue param = configOp.getInputParameters().get("OUTPUT_FROM_CREATE");
Assert.assertTrue(param instanceof FunctionPropertyValue);
String output3 = ((FunctionPropertyValue) param).getElementNameToFetch();
Assert.assertTrue(createOutput.contains(new OperationOutput(output3)));
OperationOutput fullOutput3 = configOp.getOutput(output2);
Assert.assertFalse(fullOutput3.getRelatedAttributes().contains("comp_getOpOutput:OUTPUT_FROM_CREATE"));
}
use of alien4cloud.paas.model.PaaSNodeTemplate in project alien4cloud by alien4cloud.
the class FunctionEvaluatorTest method getPropertyWrongDefOrUSageTest.
@Test(expected = BadUsageKeywordException.class)
public void getPropertyWrongDefOrUSageTest() throws Throwable {
String computeName = "comp_tomcat_war";
PaaSNodeTemplate computePaaS = builtPaaSNodeTemplates.get(computeName);
Operation configOp = computePaaS.getIndexedToscaElement().getInterfaces().get(ToscaNodeLifecycleConstants.STANDARD).getOperations().get(ToscaNodeLifecycleConstants.CONFIGURE);
// case keyword SOURCE used on a NodeType
IValue param = configOp.getInputParameters().get("keywordSourceBadUsage");
try {
FunctionEvaluator.evaluateGetPropertyFunction((FunctionPropertyValue) param, computePaaS, builtPaaSNodeTemplates);
} catch (BadUsageKeywordException e) {
// case keyword TARGET used on a NodeType
param = configOp.getInputParameters().get("KeywordTargetBadUsage");
FunctionEvaluator.evaluateGetPropertyFunction((FunctionPropertyValue) param, computePaaS, builtPaaSNodeTemplates);
}
}
use of alien4cloud.paas.model.PaaSNodeTemplate in project alien4cloud by alien4cloud.
the class PaaSUtilsTest method buildFakePaaSNodeTemplate.
private PaaSNodeTemplate buildFakePaaSNodeTemplate(NodeTemplate nodeTemplate, Map<String, Interface> interfaces) {
PaaSNodeTemplate fakePaaSNodeTemplate = Mockito.mock(PaaSNodeTemplate.class);
Mockito.when(fakePaaSNodeTemplate.getTemplate()).thenReturn(nodeTemplate);
Mockito.when(fakePaaSNodeTemplate.getInterfaces()).thenReturn(interfaces);
return fakePaaSNodeTemplate;
}
use of alien4cloud.paas.model.PaaSNodeTemplate in project alien4cloud by alien4cloud.
the class PaaSUtilsTest method injectRelationshipTemplatePropertiesAsInputs.
@Test
public void injectRelationshipTemplatePropertiesAsInputs() throws Exception {
Map<String, PaaSNodeTemplate> nodes = Maps.newHashMap();
PaaSNodeTemplate source = buildPaaSNodeTemplate();
nodes.put(node1, source);
PaaSNodeTemplate target = buildPaaSNodeTemplate();
nodes.put(node2, target);
PaaSRelationshipTemplate paaSRelationshipTemplate = buildFakePaaSRelTemplate(node1, node2, fakeCapa1);
Mockito.when(source.getRelationshipTemplates()).thenReturn(Lists.newArrayList(paaSRelationshipTemplate));
PaaSUtils.processRelationshipTemplateProperties(paaSRelationshipTemplate, nodes);
Operation operation = paaSRelationshipTemplate.getInterfaces().get(interface1).getOperations().get(operation1);
Assert.assertNotNull(operation.getInputParameters());
// assert all relationship properties are inputs properties
Assert.assertTrue(operation.getInputParameters().containsKey(SELF + fake1));
Assert.assertTrue(operation.getInputParameters().containsKey(SELF + fake3));
Assert.assertTrue(operation.getInputParameters().containsKey(SELF + fake5));
Assert.assertTrue(operation.getInputParameters().containsKey(SELF + fake2));
// assert that the property from the operation has not been overrided
Assert.assertEquals(operation.getInputParameters().get(fake1), new ScalarPropertyValue("1_from_operation"));
// check source node inputs
Assert.assertTrue(operation.getInputParameters().containsKey(generateSourceInputName(fake1)));
Assert.assertTrue(operation.getInputParameters().containsKey(generateSourceInputName(fake2)));
Assert.assertTrue(operation.getInputParameters().containsKey(generateSourceInputName(fake3)));
Assert.assertTrue(operation.getInputParameters().containsKey(generateSourceInputName(fake5)));
// check target node inputs
Assert.assertTrue(operation.getInputParameters().containsKey(generateTargetInputName(fake1)));
Assert.assertTrue(operation.getInputParameters().containsKey(generateTargetInputName(fake2)));
Assert.assertTrue(operation.getInputParameters().containsKey(generateTargetInputName(fake3)));
Assert.assertTrue(operation.getInputParameters().containsKey(generateTargetInputName(fake5)));
// check targeted capability inputs
Assert.assertTrue(operation.getInputParameters().containsKey(generateTargetedCapaInputName(fakeCapa1, fake1)));
Assert.assertTrue(operation.getInputParameters().containsKey(generateTargetedCapaInputName(fakeCapa1, fake2)));
Assert.assertTrue(operation.getInputParameters().containsKey(generateTargetedCapaInputName(fakeCapa1, fake5)));
Assert.assertTrue(operation.getInputParameters().containsKey(generateTargetedCapaInputName(fakeCapa1, fake3)));
}
use of alien4cloud.paas.model.PaaSNodeTemplate in project alien4cloud by alien4cloud.
the class PaaSUtilsTest method buildPaaSNodeTemplate.
private PaaSNodeTemplate buildPaaSNodeTemplate() {
Map<String, Capability> capabilities = Maps.newHashMap();
capabilities.put(fakeCapa1, buildFakeCapability());
NodeTemplate nodeTemplate = buildFakeNodeTemplate(capabilities);
Map<String, Operation> operations = Maps.newHashMap();
operations.put(operation1, buildFakeOperation());
Map<String, Interface> interfaces = Maps.newHashMap();
interfaces.put(interface1, buildFakeInterface(operations));
return buildFakePaaSNodeTemplate(nodeTemplate, interfaces);
}
Aggregations