Search in sources :

Example 1 with Protocol

use of org.finos.legend.engine.protocol.Protocol in project legend-sdlc by finos.

the class TestPureModelContextDataBuilder method testProtocol.

@Test
public void testProtocol() {
    for (String protocol : Lists.immutable.with("pure:1", "pure:1.0.0", "pure:X.X.X", "something:13.17.19", "anything:9999999.123456789.1000000001")) {
        int index = protocol.indexOf(':');
        String name = protocol.substring(0, index);
        String version = protocol.substring(index + 1);
        Protocol expected = new Protocol(name, version);
        Assert.assertSame(protocol, expected, PureModelContextDataBuilder.newBuilder().withProtocol(expected).build().serializer);
        Assert.assertSame(protocol, expected, PureModelContextDataBuilder.newBuilder().withProtocol(expected).build().origin.serializer);
        Assert.assertNull(protocol, PureModelContextDataBuilder.newBuilder().withProtocol(expected).build().origin.sdlcInfo);
        Assert.assertEquals(protocol, expected, PureModelContextDataBuilder.newBuilder().withProtocol(name, version).build().serializer);
        Assert.assertEquals(protocol, expected, PureModelContextDataBuilder.newBuilder().withProtocol(name, version).build().origin.serializer);
        Assert.assertNull(protocol, PureModelContextDataBuilder.newBuilder().withProtocol(name, version).build().origin.sdlcInfo);
    }
}
Also used : Protocol(org.finos.legend.engine.protocol.Protocol) Test(org.junit.Test)

Example 2 with Protocol

use of org.finos.legend.engine.protocol.Protocol in project legend-engine by finos.

the class SchemaToModelGenerator method toPureModelContextData.

private PureModelContextData toPureModelContextData(Root_meta_external_shared_format_binding_Binding binding) {
    PureModelContextData.Builder builder = PureModelContextData.newBuilder().withSerializer(new Protocol("pure", pureVersion));
    Root_meta_pure_model_unit_ResolvedModelUnit resolved = core_pure_model_modelUnit.Root_meta_pure_model_unit_resolve_ModelUnit_1__ResolvedModelUnit_1_(binding._modelUnit(), pureModel.getExecutionSupport());
    LazyIterate.collect(resolved._packageableElements(), e -> {
        if (e instanceof org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class) {
            return transformClass((org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Class<?>) e);
        } else if (e instanceof org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.Association) {
            return transformAssociation((org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.relationship.Association) e);
        } else if (e instanceof org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Enumeration) {
            return transformEnumeration((org.finos.legend.pure.m3.coreinstance.meta.pure.metamodel.type.Enumeration<?>) e);
        } else {
            return null;
        }
    }).select(Objects::nonNull).forEach(builder::addElement);
    builder.addElement(transformBinding(binding));
    return builder.build();
}
Also used : Root_meta_pure_model_unit_ResolvedModelUnit(org.finos.legend.pure.generated.Root_meta_pure_model_unit_ResolvedModelUnit) Protocol(org.finos.legend.engine.protocol.Protocol) PureModelContextData(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData)

Example 3 with Protocol

use of org.finos.legend.engine.protocol.Protocol in project legend-sdlc by finos.

the class TestPureModelContextDataBuilder method testProtocolAndSDLC.

@Test
public void testProtocolAndSDLC() {
    for (String protocol : Lists.immutable.with("pure:1", "pure:1.0.0", "pure:X.X.X", "something:13.17.19", "anything:9999999.123456789.1000000001")) {
        int index = protocol.indexOf(':');
        String protocolName = protocol.substring(0, index);
        String protocolVersion = protocol.substring(index + 1);
        Protocol expectedProtocol = new Protocol(protocolName, protocolVersion);
        for (String sdlc : Lists.immutable.with("proj1:abcd", "proj2:efgh", "something:13.17.19", "anything:9999999.123456789.1000000001")) {
            String message = protocol + " / " + sdlc;
            index = sdlc.indexOf(':');
            String projectId = sdlc.substring(0, index);
            String revisionOrVersionID = sdlc.substring(index + 1);
            TestSDLC expectedSDLC = new TestSDLC(projectId, revisionOrVersionID);
            Assert.assertSame(message, expectedProtocol, PureModelContextDataBuilder.newBuilder().withProtocol(expectedProtocol).withSDLC(expectedSDLC).build().serializer);
            Assert.assertSame(message, expectedProtocol, PureModelContextDataBuilder.newBuilder().withProtocol(expectedProtocol).withSDLC(expectedSDLC).build().origin.serializer);
            Assert.assertSame(message, expectedSDLC, PureModelContextDataBuilder.newBuilder().withProtocol(expectedProtocol).withSDLC(expectedSDLC).build().origin.sdlcInfo);
            Assert.assertEquals(message, expectedProtocol, PureModelContextDataBuilder.newBuilder().withProtocol(protocolName, protocolVersion).withSDLC(expectedSDLC).build().serializer);
            Assert.assertEquals(message, expectedProtocol, PureModelContextDataBuilder.newBuilder().withProtocol(protocolName, protocolVersion).withSDLC(expectedSDLC).build().origin.serializer);
            Assert.assertSame(message, expectedSDLC, PureModelContextDataBuilder.newBuilder().withProtocol(protocolName, protocolVersion).withSDLC(expectedSDLC).build().origin.sdlcInfo);
        }
    }
}
Also used : Protocol(org.finos.legend.engine.protocol.Protocol) Test(org.junit.Test)

Example 4 with Protocol

use of org.finos.legend.engine.protocol.Protocol in project legend-sdlc by finos.

the class TestPureModelContextDataBuilder method testProtocolSDLCAndEntities.

@Test
public void testProtocolSDLCAndEntities() throws Exception {
    String protocolName = "someProtocol";
    String protocolVersion = "3.2.1";
    String project = "someProject";
    String revisionId = "1234567890abcdef";
    PureModelContextDataBuilder builder = PureModelContextDataBuilder.newBuilder();
    Assert.assertEquals(0, builder.getElementCount());
    try (EntityLoader entityLoader = EntityLoader.newEntityLoader(Paths.get(Objects.requireNonNull(getClass().getClassLoader().getResource("pure-model-context-data-builder-test-model")).toURI()))) {
        builder.withProtocol(protocolName, protocolVersion).withSDLC(new TestSDLC(project, revisionId)).withEntities(entityLoader.getAllEntities());
    }
    Assert.assertEquals(3, builder.getElementCount());
    PureModelContextData pureModelContextData = builder.build();
    Assert.assertEquals(new Protocol(protocolName, protocolVersion), pureModelContextData.serializer);
    Assert.assertEquals(new Protocol(protocolName, protocolVersion), pureModelContextData.origin.serializer);
    Assert.assertEquals(new TestSDLC(project, revisionId), pureModelContextData.origin.sdlcInfo);
    Assert.assertEquals(3, pureModelContextData.getElements().size());
    String expectedSourceClass = "Class model::domain::Source\n" + "{\n" + "  oneName: String[1];\n" + "  anotherName: String[0..1];\n" + "  oneDate: StrictDate[0..1];\n" + "  anotherDate: StrictDate[0..1];\n" + "  oneNumber: Integer[0..1];\n" + "  anotherNumber: Integer[0..1];\n" + "}\n";
    String expectedTargetClass = "Class model::domain::Target\n" + "{\n" + "  name: String[1];\n" + "  date: StrictDate[0..1];\n" + "  number: Integer[0..1];\n" + "}\n";
    PureProtocolHelper.assertElementsEqual(Sets.mutable.with(expectedSourceClass, expectedTargetClass), pureModelContextData.getElementsOfType(Class.class));
    String expectedMapping = "Mapping model::mapping::SourceToTargetM2M\n" + "(\n" + "  *model::domain::Target[model_domain_Target]: Pure\n" + "  {\n" + "    ~src model::domain::Source\n" + "    name: $src.oneName,\n" + "    date: $src.anotherDate,\n" + "    number: $src.oneNumber\n" + "  }\n" + ")\n";
    PureProtocolHelper.assertElementsEqual(Sets.mutable.with(expectedMapping), pureModelContextData.getElementsOfType(Mapping.class));
}
Also used : EntityLoader(org.finos.legend.sdlc.serialization.EntityLoader) Class(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Class) Mapping(org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.Mapping) Protocol(org.finos.legend.engine.protocol.Protocol) PureModelContextData(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData) Test(org.junit.Test)

Example 5 with Protocol

use of org.finos.legend.engine.protocol.Protocol in project legend-engine by finos.

the class TestModelManagerPureModelCaching method testPureModelCaching.

@Test
public void testPureModelCaching() {
    ModelManager manager = new ModelManager(DeploymentMode.TEST, new MockModelLoader());
    Protocol protocol = new Protocol("pure", "v1_17_0");
    PackageableElementPointer element0 = new PackageableElementPointer(PackageableElementType.MAPPING, "meta::relational::tests::milestoning::milestoningmap");
    PackageableElementPointer element1 = new PackageableElementPointer(PackageableElementType.STORE, "meta::relational::tests::dbInc");
    PackageableElementPointer element2 = new PackageableElementPointer(PackageableElementType.STORE, "meta::relational::tests::db");
    List<PackageableElementPointer> list = new ArrayList<>();
    list.add(element0);
    list.add(element1);
    list.add(element2);
    PureSDLC pureSDLC = new PureSDLC();
    pureSDLC.packageableElementPointers = list;
    PureModelContextPointer pointer = new PureModelContextPointer();
    pointer.serializer = protocol;
    pointer.sdlcInfo = pureSDLC;
    PureModelContext context = pointer;
    manager.loadModel(context, null, null, null);
    Assert.assertEquals(1, manager.pureModelCache.size());
}
Also used : PureModelContextPointer(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextPointer) PureSDLC(org.finos.legend.engine.protocol.pure.v1.model.context.PureSDLC) PureModelContext(org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContext) ArrayList(java.util.ArrayList) PackageableElementPointer(org.finos.legend.engine.protocol.pure.v1.model.context.PackageableElementPointer) ModelManager(org.finos.legend.engine.language.pure.modelManager.ModelManager) Protocol(org.finos.legend.engine.protocol.Protocol) Test(org.junit.Test)

Aggregations

Protocol (org.finos.legend.engine.protocol.Protocol)5 Test (org.junit.Test)4 PureModelContextData (org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextData)2 ArrayList (java.util.ArrayList)1 ModelManager (org.finos.legend.engine.language.pure.modelManager.ModelManager)1 PackageableElementPointer (org.finos.legend.engine.protocol.pure.v1.model.context.PackageableElementPointer)1 PureModelContext (org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContext)1 PureModelContextPointer (org.finos.legend.engine.protocol.pure.v1.model.context.PureModelContextPointer)1 PureSDLC (org.finos.legend.engine.protocol.pure.v1.model.context.PureSDLC)1 Class (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.domain.Class)1 Mapping (org.finos.legend.engine.protocol.pure.v1.model.packageableElement.mapping.Mapping)1 Root_meta_pure_model_unit_ResolvedModelUnit (org.finos.legend.pure.generated.Root_meta_pure_model_unit_ResolvedModelUnit)1 EntityLoader (org.finos.legend.sdlc.serialization.EntityLoader)1