Skip to content

Commit

Permalink
finos#1378 added java helper and tests in dedicated module to keep ja…
Browse files Browse the repository at this point in the history
…va and scala separate to keep build happy
  • Loading branch information
naleeha committed Jul 4, 2024
1 parent 1722cae commit 48a8864
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 35 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
<module>benchmark</module>
<module>example</module>
<module>plugin</module>
<module>vuu-java</module>
</modules>

<dependencies>
Expand Down
106 changes: 106 additions & 0 deletions vuu-java/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.finos.vuu</groupId>
<artifactId>vuu-parent</artifactId>
<version>0.9.65-SNAPSHOT</version>
</parent>

<artifactId>vuu-java</artifactId>

<dependencies>
<dependency>
<groupId>org.finos.vuu</groupId>
<artifactId>vuu</artifactId>
<version>0.9.65-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.finos.vuu</groupId>
<artifactId>vuu</artifactId>
<version>0.9.65-SNAPSHOT</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>

<plugins>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>

<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<!--version>3.0.0-M4</version-->
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>${maven.compiler.source}</source>
<release>${maven.compiler.target}</release>
</configuration>
<dependencies>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>6.2</version> <!-- Use newer version of ASM -->
</dependency>

</dependencies>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.2</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>

</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.finos.vuu.api.TableDef;
import org.finos.vuu.core.table.Columns;
import org.finos.vuu.core.table.RowWithData;
import org.finos.vuu.test.FakeDataSource;
import org.finos.vuu.test.FakeInMemoryTable;
import org.finos.vuu.util.schema.ExternalEntitySchemaBuilder;
import org.finos.vuu.util.schema.SchemaMapper;
Expand All @@ -19,6 +18,7 @@
import org.junit.experimental.runners.Enclosed;
import org.junit.runner.RunWith;
import scala.jdk.javaapi.OptionConverters;
import test.helper.FakeDataSource;

import java.math.BigDecimal;
import java.util.List;
Expand All @@ -32,7 +32,7 @@
public class SchemaMapperJavaFunctionalTest {

private static String queryName = "myQuery";
private static final FakeDataSource<SchemaJavaTestData> dataSource = new FakeDataSource<>();
private static final FakeDataSource dataSource = new FakeDataSource();
private static final Clock clock = new TestFriendlyClock(10001L);

@Before
Expand All @@ -59,16 +59,17 @@ public void when_table_columns_and_entity_fields_match_exactly() throws Exceptio
var table = new FakeInMemoryTable("SchemaMapJavaTest", tableDef);
dataSource.setUpResultAsListOfValues(
queryName,
ScalaList.of(ScalaList.of("testId1", 5, 10.5))
List.of(List.of("testId1", 5, 10.5))
);

getDataAndUpdateTable(queryName, schemaMapper, table);

var existingRows = toJava(table.pullAllRows());
var existingRows = table.pullAllRows();
assertEquals(existingRows.size(), 1);
assertEquals(existingRows.get(0).get("Id"), "testId1");
assertEquals(existingRows.get(0).get("ClientId"), 5);
assertEquals(existingRows.get(0).get("NotionalValue"), 10.5);
var exitingFirstRow = existingRows.iterator().next();
assertEquals(exitingFirstRow.get("Id"), "testId1");
assertEquals(exitingFirstRow.get("ClientId"), 5);
assertEquals(exitingFirstRow.get("NotionalValue"), 10.5);
}

@Test
Expand Down Expand Up @@ -99,16 +100,17 @@ public void when_table_columns_and_entity_fields_does_not_match_exactly() throws
var table = new FakeInMemoryTable("SchemaMapJavaTest", tableDef);
dataSource.setUpResultAsListOfValues(
queryName,
ScalaList.of(ScalaList.of("testId1", 5, 10.5))
List.of(List.of("testId1", 5, 10.5))
);

getDataAndUpdateTable(queryName, schemaMapper, table);

var existingRows = toJava(table.pullAllRows());
var existingRows = table.pullAllRows();
assertEquals(existingRows.size(), 1);
assertEquals(existingRows.get(0).get("Id"), "testId1");
assertEquals(existingRows.get(0).get("ClientId"), 5);
assertEquals(existingRows.get(0).get("SomeOtherName"), 10.5);
var exitingFirstRow = existingRows.iterator().next();
assertEquals(exitingFirstRow.get("Id"), "testId1");
assertEquals(exitingFirstRow.get("ClientId"), 5);
assertEquals(exitingFirstRow.get("SomeOtherName"), 10.5);

}

Expand Down Expand Up @@ -144,15 +146,16 @@ public void when_table_columns_and_entity_fields_has_different_types() throws Ex
var table = new FakeInMemoryTable("SchemaMapJavaTest", tableDef);
dataSource.setUpResultAsListOfValues(
queryName,
ScalaList.of(ScalaList.of(10, new BigDecimal("1.0001")))
List.of(List.of(10, new BigDecimal("1.0001")))
);

getDataAndUpdateTable(queryName, schemaMapper, table);

var existingRows = toJava(table.pullAllRows());
var existingRows = table.pullAllRows();
assertEquals(existingRows.size(), 1);
assertEquals(existingRows.get(0).get("Id"), "10");
assertEquals(existingRows.get(0).get("doubleValue"), 1.0001d);
var exitingFirstRow = existingRows.iterator().next();
assertEquals(exitingFirstRow.get("Id"), "10");
assertEquals(exitingFirstRow.get("doubleValue"), 1.0001d);
}
}

Expand All @@ -172,8 +175,7 @@ private static RowWithData mapToRow(SchemaMapper schemaMapper, List<Object> valu
}

private static List<List<Object>> getQueryResult(String queryName) throws Exception {
return OptionConverters.toJava(dataSource.getAsListOfValues(queryName))
.map(listOfLists -> toJava(listOfLists.map(ScalaCollectionConverter::toJava).toList()))
return dataSource.getAsListOfValues(queryName)
.orElseThrow(() -> new Exception("Query does not exist in store. make sure it is setup"));
}
}
20 changes: 20 additions & 0 deletions vuu-java/src/test/java/test/helper/FakeDataSource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package test.helper;

import java.util.HashMap;
import java.util.List;
import java.util.Optional;

public class FakeDataSource {

private HashMap<String, List<List<Object>>> queryToValuesResultMap = new HashMap<>();

public void setUpResultAsListOfValues(String queryName, List<List<Object>> resultValues) {
queryToValuesResultMap.put(queryName, resultValues);
}

public Optional<List<List<Object>>> getAsListOfValues(String queryName) {
return queryToValuesResultMap.containsKey(queryName)
? Optional.of(queryToValuesResultMap.get(queryName))
: Optional.empty();
}
}
6 changes: 0 additions & 6 deletions vuu/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,6 @@
<version>${scala.version}</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.scalatest</groupId>
Expand Down
11 changes: 0 additions & 11 deletions vuu/src/test/java/org/finos/vuu/util/ScalaList.java

This file was deleted.

0 comments on commit 48a8864

Please sign in to comment.