Skip to content

Commit

Permalink
add function tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MauricioUyaguari committed Sep 4, 2024
1 parent 3ad5996 commit 25f5c5a
Show file tree
Hide file tree
Showing 13 changed files with 165 additions and 8 deletions.
5 changes: 5 additions & 0 deletions legend-sdlc-test-generation-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@
<artifactId>maven-compat</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-test-runner-function</artifactId>
<scope>test</scope>
</dependency>
<!-- TEST -->
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void testFullModel() throws Exception
assertDirectoryEmpty(outputDir);
executeMojo(projectDir);

SortedMap<String, String> expected = loadExpectedJavaSources("org/finos/legend/sdlc/test/junit/junit4/execution/TestRelationalMapping.java", "org/finos/legend/sdlc/test/junit/junit4/legend/demo/TestSingleQuoteInResultM2M.java", "org/finos/legend/sdlc/test/junit/junit4/model/mapping/TestSourceToTargetM2M.java", "org/finos/legend/sdlc/test/junit/junit4/testTestSuites/TestTestService.java", "org/finos/legend/sdlc/test/junit/junit4/testTestSuites/TestTestService2.java", "org/finos/legend/sdlc/test/junit/junit4/testTestSuites/TestServiceStoreMapping.java");
SortedMap<String, String> expected = loadExpectedJavaSources("org/finos/legend/sdlc/test/junit/junit4/execution/TestRelationalMapping.java", "org/finos/legend/sdlc/test/junit/junit4/legend/demo/TestSingleQuoteInResultM2M.java", "org/finos/legend/sdlc/test/junit/junit4/model/mapping/TestSourceToTargetM2M.java", "org/finos/legend/sdlc/test/junit/junit4/testTestSuites/TestTestService.java", "org/finos/legend/sdlc/test/junit/junit4/testTestSuites/TestTestService2.java", "org/finos/legend/sdlc/test/junit/junit4/testTestSuites/TestServiceStoreMapping.java", "org/finos/legend/sdlc/test/junit/junit4/model/domain/TestFunctionTest__String_0_1_.java");

SortedMap<String, String> actual = loadJavaSourcesFromDirectory(outputDir.toPath());
Assert.assertEquals(expected, actual);
Expand All @@ -125,7 +125,7 @@ public void testFullModelWithExcludedEntities() throws Exception
assertDirectoryEmpty(outputDir);
executeMojo(projectDir);

SortedMap<String, String> expected = loadExpectedJavaSources("org/finos/legend/sdlc/test/junit/junit4/legend/demo/TestSingleQuoteInResultM2M.java", "org/finos/legend/sdlc/test/junit/junit4/model/mapping/TestSourceToTargetM2M.java", "org/finos/legend/sdlc/test/junit/junit4/testTestSuites/TestTestService.java", "org/finos/legend/sdlc/test/junit/junit4/testTestSuites/TestServiceStoreMapping.java");
SortedMap<String, String> expected = loadExpectedJavaSources("org/finos/legend/sdlc/test/junit/junit4/legend/demo/TestSingleQuoteInResultM2M.java", "org/finos/legend/sdlc/test/junit/junit4/model/mapping/TestSourceToTargetM2M.java", "org/finos/legend/sdlc/test/junit/junit4/testTestSuites/TestTestService.java", "org/finos/legend/sdlc/test/junit/junit4/testTestSuites/TestServiceStoreMapping.java", "org/finos/legend/sdlc/test/junit/junit4/model/domain/TestFunctionTest__String_0_1_.java");

SortedMap<String, String> actual = loadJavaSourcesFromDirectory(outputDir.toPath());
Assert.assertEquals(expected, actual);
Expand All @@ -143,7 +143,7 @@ public void testFullModelWithExcludedPackages() throws Exception
assertDirectoryEmpty(outputDir);
executeMojo(projectDir);

SortedMap<String, String> expected = loadExpectedJavaSources("org/finos/legend/sdlc/test/junit/junit4/execution/TestRelationalMapping.java", "org/finos/legend/sdlc/test/junit/junit4/legend/demo/TestSingleQuoteInResultM2M.java");
SortedMap<String, String> expected = loadExpectedJavaSources("org/finos/legend/sdlc/test/junit/junit4/execution/TestRelationalMapping.java", "org/finos/legend/sdlc/test/junit/junit4/legend/demo/TestSingleQuoteInResultM2M.java", "org/finos/legend/sdlc/test/junit/junit4/model/domain/TestFunctionTest__String_0_1_.java");

SortedMap<String, String> actual = loadJavaSourcesFromDirectory(outputDir.toPath());
Assert.assertEquals(expected, actual);
Expand All @@ -161,7 +161,7 @@ public void testFullModelWithExcludedEntitiesAndPackages() throws Exception
assertDirectoryEmpty(outputDir);
executeMojo(projectDir);

SortedMap<String, String> expected = loadExpectedJavaSources("org/finos/legend/sdlc/test/junit/junit4/legend/demo/TestSingleQuoteInResultM2M.java", "org/finos/legend/sdlc/test/junit/junit4/model/mapping/TestSourceToTargetM2M.java");
SortedMap<String, String> expected = loadExpectedJavaSources("org/finos/legend/sdlc/test/junit/junit4/legend/demo/TestSingleQuoteInResultM2M.java", "org/finos/legend/sdlc/test/junit/junit4/model/mapping/TestSourceToTargetM2M.java", "org/finos/legend/sdlc/test/junit/junit4/model/domain/TestFunctionTest__String_0_1_.java");

SortedMap<String, String> actual = loadJavaSourcesFromDirectory(outputDir.toPath());
Assert.assertEquals(expected, actual);
Expand All @@ -179,7 +179,7 @@ public void testFullModelWithDependencies() throws Exception
assertDirectoryEmpty(outputDir);
executeMojo(projectDir);

SortedMap<String, String> expected = loadExpectedJavaSources("org/finos/legend/sdlc/test/junit/junit4/execution/TestRelationalMapping.java", "org/finos/legend/sdlc/test/junit/junit4/legend/demo/TestSingleQuoteInResultM2M.java", "org/finos/legend/sdlc/test/junit/junit4/model/mapping/TestSourceToTargetM2M.java", "org/finos/legend/sdlc/test/junit/junit4/testTestSuites/TestTestService.java", "org/finos/legend/sdlc/test/junit/junit4/testTestSuites/TestTestService2.java", "org/finos/legend/sdlc/test/junit/junit4/testTestSuites/TestServiceStoreMapping.java", "org/finos/legend/sdlc/test/junit/junit4/model/TestMyMapping.java");
SortedMap<String, String> expected = loadExpectedJavaSources("org/finos/legend/sdlc/test/junit/junit4/execution/TestRelationalMapping.java", "org/finos/legend/sdlc/test/junit/junit4/legend/demo/TestSingleQuoteInResultM2M.java", "org/finos/legend/sdlc/test/junit/junit4/model/mapping/TestSourceToTargetM2M.java", "org/finos/legend/sdlc/test/junit/junit4/testTestSuites/TestTestService.java", "org/finos/legend/sdlc/test/junit/junit4/testTestSuites/TestTestService2.java", "org/finos/legend/sdlc/test/junit/junit4/testTestSuites/TestServiceStoreMapping.java", "org/finos/legend/sdlc/test/junit/junit4/model/TestMyMapping.java", "org/finos/legend/sdlc/test/junit/junit4/model/domain/TestFunctionTest__String_0_1_.java");

SortedMap<String, String> actual = loadJavaSourcesFromDirectory(outputDir.toPath());
Assert.assertEquals(expected, actual);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.finos.legend.sdlc.test.junit.junit4.model.domain;

import org.finos.legend.sdlc.test.junit.pure.v1.AbstractTestableTest;

public class TestFunctionTest__String_0_1_ extends AbstractTestableTest
{
@Override
protected String getEntityPath()
{
return "model::domain::FunctionTest__String_$0_1$_";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"classifierPath" : "meta::pure::metamodel::function::ConcreteFunctionDefinition",
"content" : {
"_type" : "function",
"body" : [ {
"_type" : "string",
"value" : ""
} ],
"name" : "FunctionTest__String_$0_1$_",
"package" : "model::domain",
"parameters" : [ ],
"postConstraints" : [ ],
"preConstraints" : [ ],
"returnMultiplicity" : {
"lowerBound" : 0,
"upperBound" : 1
},
"returnType" : "String",
"stereotypes" : [ ],
"taggedValues" : [ ]
}
}
5 changes: 5 additions & 0 deletions legend-sdlc-test-generation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@
<artifactId>classgraph</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-test-runner-function</artifactId>
<scope>test</scope>
</dependency>
<!-- TEST -->
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,26 @@ public void testServiceStoreMapping()
"testTestSuites::ServiceStoreMapping");
}

@Test
public void testFunctionTest()
{
testGeneration(
"model.domain.TestFunctionTest__String_0_1_",
"generated/java/model/domain/TestFunctionTest__String_0_1_.java",
null,
"model::domain::FunctionTest__String_$0_1$_");
testGeneration(
"org.finos.legend.sdlc.test.junit.junit4.model.domain.TestFunctionTest__String_0_1_",
"generated/java/org/finos/legend/sdlc/test/junit/junit4/model/domain/TestFunctionTest__String_0_1_.java",
"org.finos.legend.sdlc.test.junit.junit4",
"model::domain::FunctionTest__String_$0_1$_");
testGeneration(
"other.test.pkg.model.domain.TestFunctionTest__String_0_1_",
"generated/java/other/test/pkg/model/domain/TestFunctionTest__String_0_1_.java",
"other.test.pkg",
"model::domain::FunctionTest__String_$0_1$_");
}

@Test
public void testNonTestable()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ public void testServiceStoreMapping()
testCompilation("testTestSuites.TestServiceStoreMapping", "testTestSuites::ServiceStoreMapping");
}

@Test
public void testFunctionTest()
{
testCompilation("model.domain.TestFunctionTest__String_0_1_", "model::domain::FunctionTest__String_$0_1$_");
}

private void testCompilation(String expectedClassName, String entityPath)
{
testCompilation(Collections.singletonList(expectedClassName), entityPath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,43 @@ public static void cleanUp() throws Exception
@Test
public void testWriteTestClassesWithoutRootPackage() throws IOException
{
testWriteTestClasses(null, "generated/java/execution/TestRelationalMapping.java", "generated/java/execution/TestRelationalMapping.java", "generated/java/legend/demo/TestSingleQuoteInResultM2M.java", "generated/java/model/mapping/TestSourceToTargetM2M.java", "generated/java/testTestSuites/TestTestService.java", "generated/java/testTestSuites/TestTestService2.java", "generated/java/testTestSuites/TestServiceStoreMapping.java", "generated/java/testTestSuites/TestMyServiceIsVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVery_38d23576.java", "generated/java/testTestSuites/TestMyServiceIsââVeryââVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryââââVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryV_a0bb3f4b.java");
testWriteTestClasses(null, "generated/java/execution/TestRelationalMapping.java",
"generated/java/execution/TestRelationalMapping.java", "generated/java/legend/demo/TestSingleQuoteInResultM2M.java",
"generated/java/model/mapping/TestSourceToTargetM2M.java", "generated/java/testTestSuites/TestTestService.java",
"generated/java/testTestSuites/TestTestService2.java", "generated/java/testTestSuites/TestServiceStoreMapping.java",
"generated/java/testTestSuites/TestMyServiceIsVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVery_38d23576.java",
"generated/java/testTestSuites/TestMyServiceIsââVeryââVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryââââVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryV_a0bb3f4b.java",
"generated/java/model/domain/TestFunctionTest__String_0_1_.java");
}

@Test
public void testWriteTestClasses() throws IOException
{
testWriteTestClasses("org.finos.legend.sdlc.test.junit.junit4", "generated/java/org/finos/legend/sdlc/test/junit/junit4/execution/TestRelationalMapping.java", "generated/java/org/finos/legend/sdlc/test/junit/junit4/legend/demo/TestSingleQuoteInResultM2M.java", "generated/java/org/finos/legend/sdlc/test/junit/junit4/model/mapping/TestSourceToTargetM2M.java", "generated/java/org/finos/legend/sdlc/test/junit/junit4/testTestSuites/TestTestService.java", "generated/java/org/finos/legend/sdlc/test/junit/junit4/testTestSuites/TestTestService2.java", "generated/java/org/finos/legend/sdlc/test/junit/junit4/testTestSuites/TestServiceStoreMapping.java", "generated/java/org/finos/legend/sdlc/test/junit/junit4/testTestSuites/TestMyServiceIsVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVery_38d23576.java", "generated/java/org/finos/legend/sdlc/test/junit/junit4/testTestSuites/TestMyServiceIsââVeryââVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryââââVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryV_a0bb3f4b.java");
testWriteTestClasses("org.finos.legend.sdlc.test.junit.junit4",
"generated/java/org/finos/legend/sdlc/test/junit/junit4/execution/TestRelationalMapping.java",
"generated/java/org/finos/legend/sdlc/test/junit/junit4/legend/demo/TestSingleQuoteInResultM2M.java",
"generated/java/org/finos/legend/sdlc/test/junit/junit4/model/mapping/TestSourceToTargetM2M.java",
"generated/java/org/finos/legend/sdlc/test/junit/junit4/testTestSuites/TestTestService.java",
"generated/java/org/finos/legend/sdlc/test/junit/junit4/testTestSuites/TestTestService2.java",
"generated/java/org/finos/legend/sdlc/test/junit/junit4/testTestSuites/TestServiceStoreMapping.java",
"generated/java/org/finos/legend/sdlc/test/junit/junit4/testTestSuites/TestMyServiceIsVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVery_38d23576.java",
"generated/java/org/finos/legend/sdlc/test/junit/junit4/testTestSuites/TestMyServiceIsââVeryââVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryââââVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryV_a0bb3f4b.java",
"generated/java/org/finos/legend/sdlc/test/junit/junit4/model/domain/TestFunctionTest__String_0_1_.java");
}

@Test
public void testWriteTestClassesOtherPackage() throws IOException
{
testWriteTestClasses("other.test.pkg", "generated/java/other/test/pkg/execution/TestRelationalMapping.java", "generated/java/other/test/pkg/legend/demo/TestSingleQuoteInResultM2M.java", "generated/java/other/test/pkg/model/mapping/TestSourceToTargetM2M.java", "generated/java/other/test/pkg/testTestSuites/TestTestService.java", "generated/java/other/test/pkg/testTestSuites/TestTestService2.java", "generated/java/other/test/pkg/testTestSuites/TestServiceStoreMapping.java", "generated/java/other/test/pkg/testTestSuites/TestMyServiceIsVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVery_38d23576.java", "generated/java/other/test/pkg/testTestSuites/TestMyServiceIsââVeryââVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryââââVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryV_a0bb3f4b.java");
testWriteTestClasses("other.test.pkg",
"generated/java/other/test/pkg/execution/TestRelationalMapping.java",
"generated/java/other/test/pkg/legend/demo/TestSingleQuoteInResultM2M.java",
"generated/java/other/test/pkg/model/mapping/TestSourceToTargetM2M.java",
"generated/java/other/test/pkg/testTestSuites/TestTestService.java",
"generated/java/other/test/pkg/testTestSuites/TestTestService2.java",
"generated/java/other/test/pkg/testTestSuites/TestServiceStoreMapping.java",
"generated/java/other/test/pkg/testTestSuites/TestMyServiceIsVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVery_38d23576.java",
"generated/java/other/test/pkg/testTestSuites/TestMyServiceIsââVeryââVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryââââVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryV_a0bb3f4b.java",
"generated/java/other/test/pkg/model/domain/TestFunctionTest__String_0_1_.java");
}

private void testWriteTestClasses(String rootPackage, String... expectedResources) throws IOException
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"classifierPath" : "meta::pure::metamodel::function::ConcreteFunctionDefinition",
"content" : {
"_type" : "function",
"body" : [ {
"_type" : "string",
"value" : ""
} ],
"name" : "FunctionTest__String_$0_1$_",
"package" : "model::domain",
"parameters" : [ ],
"postConstraints" : [ ],
"preConstraints" : [ ],
"returnMultiplicity" : {
"lowerBound" : 0,
"upperBound" : 1
},
"returnType" : "String",
"stereotypes" : [ ],
"taggedValues" : [ ]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package model.domain;

import org.finos.legend.sdlc.test.junit.pure.v1.AbstractTestableTest;

public class TestFunctionTest__String_0_1_ extends AbstractTestableTest
{
@Override
protected String getEntityPath()
{
return "model::domain::FunctionTest__String_$0_1$_";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.finos.legend.sdlc.test.junit.junit4.model.domain;

import org.finos.legend.sdlc.test.junit.pure.v1.AbstractTestableTest;

public class TestFunctionTest__String_0_1_ extends AbstractTestableTest
{
@Override
protected String getEntityPath()
{
return "model::domain::FunctionTest__String_$0_1$_";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package other.test.pkg.model.domain;

import org.finos.legend.sdlc.test.junit.pure.v1.AbstractTestableTest;

public class TestFunctionTest__String_0_1_ extends AbstractTestableTest
{
@Override
protected String getEntityPath()
{
return "model::domain::FunctionTest__String_$0_1$_";
}
}
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,11 @@
<artifactId>legend-engine-test-runner-service</artifactId>
<version>${legend.engine.version}</version>
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-test-runner-function</artifactId>
<version>${legend.engine.version}</version>
</dependency>
<dependency>
<groupId>org.finos.legend.engine</groupId>
<artifactId>legend-engine-executionPlan-execution-store-inMemory</artifactId>
Expand Down

0 comments on commit 25f5c5a

Please sign in to comment.