Search in sources :

Example 1 with Class

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Class in project legend-sdlc by finos.

the class TestModelGenerationFactory method testSimpleModelGenerationFactory.

@Test
public void testSimpleModelGenerationFactory() {
    GenerationSpecification generationSpecification = this.getTestGenerationSpecification();
    PureModelContextData.Builder builder = PureModelContextData.newBuilder();
    builder.addElement(generationSpecification);
    ModelGenerationFactory factory = ModelGenerationFactory.newFactory(generationSpecification, builder.build());
    factory.processModelGenerator(simpleClassGenerator);
    Assert.assertEquals(2, factory.getFullModel().getElements().size());
    Assert.assertEquals(1, factory.getGeneratedModel().getElements().size());
    PureModelContextData generatedModel = factory.validateAndBuildGeneratedModel();
    Assert.assertEquals(1, generatedModel.getElements().size());
    Class myClass = (Class) generatedModel.getElements().get(0);
    Assert.assertEquals("MyClass", myClass.name);
}
Also used : GenerationSpecification(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.generationSpecification.GenerationSpecification) Class(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Class) PureModelContextData(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData) Test(org.junit.Test)

Example 2 with Class

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Class in project legend-sdlc by finos.

the class TestModelGenerationFactory method testOverridingCoreModel.

@Test
public void testOverridingCoreModel() {
    GenerationSpecification generationSpecification = this.getTestGenerationSpecification();
    PureModelContextData.Builder builder = PureModelContextData.newBuilder();
    builder.addElement(generationSpecification);
    Class myClass = new Class();
    myClass.name = "MyClass";
    myClass._package = "model";
    builder.addElement(myClass);
    ModelGenerationFactory factory = ModelGenerationFactory.newFactory(generationSpecification, builder.build());
    factory.processModelGenerator(simpleClassGenerator);
    RuntimeException runtimeException = Assert.assertThrows(RuntimeException.class, factory::validateAndBuildGeneratedModel);
    Assert.assertEquals("Generated element 'model::MyClass' of type Class can't override existing element of type Class", runtimeException.getMessage());
}
Also used : GenerationSpecification(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.generationSpecification.GenerationSpecification) Class(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Class) PureModelContextData(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData) Test(org.junit.Test)

Example 3 with Class

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Class in project legend-sdlc by finos.

the class TestEntityToPureConverter method testFromEntity.

@Test
public void testFromEntity() {
    Entity entity = TestTools.newClassEntity("EmptyClass", "model::test");
    PackageableElement result = this.converter.fromEntity(entity);
    Assert.assertTrue(result instanceof Class);
    Class resultClass = (Class) result;
    Assert.assertEquals("EmptyClass", resultClass.name);
    Assert.assertEquals("model::test", resultClass._package);
    Assert.assertEquals(Collections.singletonList("meta::pure::metamodel::type::Any"), resultClass.superTypes);
    Assert.assertEquals(Collections.emptyList(), resultClass.properties);
    IllegalArgumentException e = Assert.assertThrows(IllegalArgumentException.class, () -> this.converter.fromEntity(Entity.newEntity("not::a::real::PureEntity", "meta::unknown::NotAClassifier", Collections.emptyMap())));
    String message = e.getMessage();
    Assert.assertNotNull(message);
    String expectedPrefix = "Could not convert entity not::a::real::PureEntity with classifier meta::unknown::NotAClassifier to class PackageableElement";
    if (!message.startsWith(expectedPrefix)) {
        Assert.assertEquals(expectedPrefix, message);
    }
}
Also used : Entity(org.finos.legend.sdlc.domain.model.entity.Entity) PackageableElement(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.PackageableElement) Class(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Class) Test(org.junit.Test)

Example 4 with Class

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Class in project legend-sdlc by finos.

the class TestPureToEntityConverter method testToEntityIfPossible.

@Test
public void testToEntityIfPossible() {
    Class cls = new Class();
    cls.superTypes = Collections.singletonList("meta::pure::metamodel::type::Any");
    cls.name = "EmptyClass";
    cls._package = "model::test";
    Optional<Entity> entity = this.converter.toEntityIfPossible(cls);
    Assert.assertTrue(entity.isPresent());
    TestProtocolToEntityConverter.assertEntityEqualsClass(cls, entity.get());
}
Also used : Entity(org.finos.legend.sdlc.domain.model.entity.Entity) Class(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Class) Test(org.junit.Test)

Example 5 with Class

use of org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Class in project legend-sdlc by finos.

the class TestEntityToProtocolConverter method testFromEntityIfPossible.

@Test
public void testFromEntityIfPossible() {
    ClassEntityConverter converter = new ClassEntityConverter();
    Entity entity = TestTools.newClassEntity("EmptyClass", "model::test");
    Class result = converter.fromEntity(entity);
    assertClassEqualsEntity(entity, result);
    Optional<Class> notAClass = converter.fromEntityIfPossible(TestTools.newEnumerationEntity("SomeEnum", "model::test", "one", "two"));
    Assert.assertFalse(notAClass.isPresent());
}
Also used : Entity(org.finos.legend.sdlc.domain.model.entity.Entity) Class(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Class) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)79 PureModelContextData (org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData)68 SchemaToModelGenerationTest (org.finos.legend.engine.external.shared.format.model.test.SchemaToModelGenerationTest)29 PureModel (org.finos.legend.engine.language.pure.compiler.toPureGraph.PureModel)22 ExecutionNodeExecutor (org.finos.legend.engine.plan.execution.nodes.ExecutionNodeExecutor)17 Class (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Class)17 EngineException (org.finos.legend.engine.shared.core.operational.errorManagement.EngineException)17 ExecutionState (org.finos.legend.engine.plan.execution.nodes.state.ExecutionState)15 SingleExecutionPlan (org.finos.legend.engine.protocol.pure.v1.model.executionPlan.SingleExecutionPlan)15 MutableList (org.eclipse.collections.api.list.MutableList)13 ListIterate (org.eclipse.collections.impl.utility.ListIterate)13 ConstantResult (org.finos.legend.engine.plan.execution.result.ConstantResult)13 Result (org.finos.legend.engine.plan.execution.result.Result)13 RelationalResult (org.finos.legend.engine.plan.execution.stores.relational.result.RelationalResult)13 Type (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Type)13 GenericType (org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.generics.GenericType)13 RichIterable (org.eclipse.collections.api.RichIterable)12 EngineErrorType (org.finos.legend.engine.protocol.pure.v1.model.context.EngineErrorType)12 List (java.util.List)10 Lists (org.eclipse.collections.impl.factory.Lists)10