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);
}
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());
}
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);
}
}
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());
}
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());
}
Aggregations