Search in sources :

Example 6 with InvocationContext

use of org.eclipse.vorto.plugin.generator.InvocationContext in project vorto by eclipse.

the class HelloWorldGeneratorTest method getMappedElementFunctionbLock.

/*
	 * Test case for checking the attribute mapping and corresponding property value for a function block
	 * 
	 * 
	 */
@Test
public void getMappedElementFunctionbLock() throws Exception {
    MappingBuilder mapping = BuilderUtils.newMapping(new ModelId(ModelType.Mapping, "", "", ""), "helloworld");
    FunctionBlockMappingRule rule = MappingFactory.eINSTANCE.createFunctionBlockMappingRule();
    FunctionBlockPropertySource statusValueSource = MappingFactory.eINSTANCE.createFunctionBlockPropertySource();
    statusValueSource.setModel(functionBlock);
    rule.getSources().add(statusValueSource);
    StereoTypeTarget stereotypeTarget = MappingFactory.eINSTANCE.createStereoTypeTarget();
    stereotypeTarget.setName("OBJECT_ID");
    Attribute objectIDattribute = MappingFactory.eINSTANCE.createAttribute();
    objectIDattribute.setName("ID");
    objectIDattribute.setValue("functionBlockAttributID");
    stereotypeTarget.getAttributes().add(objectIDattribute);
    rule.setTarget(stereotypeTarget);
    mapping.addRule(rule);
    InvocationContext ctx = new InvocationContext(createMappingList(mapping.build()), Collections.emptyMap());
    Property prop = functionBlock.getFunctionblock().getStatus().getProperties().get(0);
    assertNotNull(ctx.getMappedElement(prop, "OBJECT_ID"));
    assertEquals("functionBlockAttributID", ctx.getMappedElement(prop, "OBJECT_ID").getAttributeValue("ID", "functionBlockAttributID"));
}
Also used : FunctionBlockMappingRule(org.eclipse.vorto.core.api.model.mapping.FunctionBlockMappingRule) MappingBuilder(org.eclipse.vorto.core.api.model.BuilderUtils.MappingBuilder) FunctionBlockPropertySource(org.eclipse.vorto.core.api.model.mapping.FunctionBlockPropertySource) Attribute(org.eclipse.vorto.core.api.model.mapping.Attribute) InvocationContext(org.eclipse.vorto.plugin.generator.InvocationContext) StereoTypeTarget(org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget) Property(org.eclipse.vorto.core.api.model.datatype.Property) ModelId(org.eclipse.vorto.core.api.model.model.ModelId) Test(org.junit.Test)

Example 7 with InvocationContext

use of org.eclipse.vorto.plugin.generator.InvocationContext in project vorto by eclipse.

the class BoschIoTSuiteGeneratorTest method generatePython.

/*
   * Check if python file is generated when language is passed as python to BoschIOTSuiteGenerator
   */
@Test
public void generatePython() throws Exception {
    configProperties.put("language", "python");
    InvocationContext context = new InvocationContext(mappingModels, configProperties);
    IGenerationResult iGenerationResult = boschIOTSuiteGenerator.generate(modelProvider(), context);
    Generated generatedfile = zipFileReader(iGenerationResult, "StatusPropertiesFunctionBlock", ".py");
    assertEquals("StatusPropertiesFunctionBlock.py", generatedfile.getFileName());
}
Also used : Generated(org.eclipse.vorto.plugin.generator.utils.Generated) InvocationContext(org.eclipse.vorto.plugin.generator.InvocationContext) IGenerationResult(org.eclipse.vorto.plugin.generator.IGenerationResult) AbstractGeneratorTest(org.eclipse.vorto.plugin.AbstractGeneratorTest) Test(org.junit.Test)

Aggregations

InvocationContext (org.eclipse.vorto.plugin.generator.InvocationContext)7 Test (org.junit.Test)6 AbstractGeneratorTest (org.eclipse.vorto.plugin.AbstractGeneratorTest)4 IGenerationResult (org.eclipse.vorto.plugin.generator.IGenerationResult)4 Generated (org.eclipse.vorto.plugin.generator.utils.Generated)3 MappingBuilder (org.eclipse.vorto.core.api.model.BuilderUtils.MappingBuilder)2 Property (org.eclipse.vorto.core.api.model.datatype.Property)2 Attribute (org.eclipse.vorto.core.api.model.mapping.Attribute)2 StereoTypeTarget (org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget)2 ModelId (org.eclipse.vorto.core.api.model.model.ModelId)2 Context (com.amazonaws.services.lambda.runtime.Context)1 RequestStreamHandler (com.amazonaws.services.lambda.runtime.RequestStreamHandler)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 HashSet (java.util.HashSet)1 Optional (java.util.Optional)1 Set (java.util.Set)1