Search in sources :

Example 1 with EntityAttributeSource

use of org.eclipse.vorto.core.api.model.mapping.EntityAttributeSource in project vorto by eclipse.

the class HelloWorldGeneratorTest method getMappedElementEntity.

/*
	 * Test case for checking the attribute mapping and corresponding property value for an entity
	 * 
	 * 
	 */
@Test
public void getMappedElementEntity() throws Exception {
    MappingBuilder mapping = BuilderUtils.newMapping(new ModelId(ModelType.Mapping, "", "", ""), "helloworld");
    EntityMappingRule entityMappingRule = MappingFactory.eINSTANCE.createEntityMappingRule();
    EntityAttributeSource entityAttributeSource = MappingFactory.eINSTANCE.createEntityAttributeSource();
    entityAttributeSource.setModel(_entity);
    entityMappingRule.getSources().add(entityAttributeSource);
    StereoTypeTarget stereotypeTarget = MappingFactory.eINSTANCE.createStereoTypeTarget();
    stereotypeTarget.setName("OBJECT_ID");
    Attribute objectIDattribute = MappingFactory.eINSTANCE.createAttribute();
    objectIDattribute.setName("ID");
    objectIDattribute.setValue("entityAttributID");
    stereotypeTarget.getAttributes().add(objectIDattribute);
    entityMappingRule.setTarget(stereotypeTarget);
    mapping.addRule(entityMappingRule);
    InvocationContext ctx = new InvocationContext(createMappingList(mapping.build()), Collections.emptyMap());
    Property prop = functionBlock.getFunctionblock().getStatus().getProperties().get(0);
    assertNotNull(ctx.getMappedElement(prop, "OBJECT_ID"));
    assertEquals("entityAttributID", ctx.getMappedElement(prop, "OBJECT_ID").getAttributeValue("ID", "entityAttributID"));
}
Also used : EntityMappingRule(org.eclipse.vorto.core.api.model.mapping.EntityMappingRule) MappingBuilder(org.eclipse.vorto.core.api.model.BuilderUtils.MappingBuilder) Attribute(org.eclipse.vorto.core.api.model.mapping.Attribute) EntityAttributeSource(org.eclipse.vorto.core.api.model.mapping.EntityAttributeSource) 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 2 with EntityAttributeSource

use of org.eclipse.vorto.core.api.model.mapping.EntityAttributeSource in project vorto by eclipse.

the class TestEntityMappingFactory method createEntityAttributeSource.

private static EntityAttributeSource createEntityAttributeSource() {
    EntityAttributeSource source = MappingFactory.eINSTANCE.createEntityAttributeSource();
    source.setModel(entity);
    source.setAttribute(ModelAttribute.VERSION);
    return source;
}
Also used : EntityAttributeSource(org.eclipse.vorto.core.api.model.mapping.EntityAttributeSource)

Aggregations

EntityAttributeSource (org.eclipse.vorto.core.api.model.mapping.EntityAttributeSource)2 MappingBuilder (org.eclipse.vorto.core.api.model.BuilderUtils.MappingBuilder)1 Property (org.eclipse.vorto.core.api.model.datatype.Property)1 Attribute (org.eclipse.vorto.core.api.model.mapping.Attribute)1 EntityMappingRule (org.eclipse.vorto.core.api.model.mapping.EntityMappingRule)1 StereoTypeTarget (org.eclipse.vorto.core.api.model.mapping.StereoTypeTarget)1 ModelId (org.eclipse.vorto.core.api.model.model.ModelId)1 InvocationContext (org.eclipse.vorto.plugin.generator.InvocationContext)1 Test (org.junit.Test)1