From 928f50ed209a6980b737b1df1cedb7265dfc6327 Mon Sep 17 00:00:00 2001 From: Dennis Crissman Date: Fri, 7 Nov 2014 15:08:51 -0500 Subject: [PATCH] fix Join needDistinct and add unit test --- .../lightblue/metadata/rdbms/model/Join.java | 11 ++-- .../metadata/rdbms/model/JoinTest.java | 50 +++++++++++++++++++ 2 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 metadata/src/test/java/com/redhat/lightblue/metadata/rdbms/model/JoinTest.java diff --git a/metadata/src/main/java/com/redhat/lightblue/metadata/rdbms/model/Join.java b/metadata/src/main/java/com/redhat/lightblue/metadata/rdbms/model/Join.java index bcfddd5..3978889 100644 --- a/metadata/src/main/java/com/redhat/lightblue/metadata/rdbms/model/Join.java +++ b/metadata/src/main/java/com/redhat/lightblue/metadata/rdbms/model/Join.java @@ -18,12 +18,13 @@ */ package com.redhat.lightblue.metadata.rdbms.model; -import com.redhat.lightblue.metadata.parser.MetadataParser; -import com.redhat.lightblue.metadata.rdbms.converter.SimpleConverter; -import com.redhat.lightblue.common.rdbms.RDBMSConstants; import java.util.ArrayList; import java.util.List; +import com.redhat.lightblue.common.rdbms.RDBMSConstants; +import com.redhat.lightblue.metadata.parser.MetadataParser; +import com.redhat.lightblue.metadata.rdbms.converter.SimpleConverter; + /** * * @author lcestari @@ -42,7 +43,7 @@ public void parse(MetadataParser p, T t) { String jts = p.getStringProperty(t, "joinTablesStatement"); Object needDistinct1 = p.getValueProperty(t, "needDistinct"); if(needDistinct1 != null) { - Boolean needDistinct = (Boolean) needDistinct1; + this.needDistinct = (Boolean) needDistinct1; } List pmsT = p.getObjectList(t, "projectionMappings"); List pms = parseProjectionMappings(p, pmsT); @@ -50,8 +51,6 @@ public void parse(MetadataParser p, T t) { this.tables = ts; this.joinTablesStatement = jts; this.projectionMappings = pms; - this.needDistinct = needDistinct; - } @Override diff --git a/metadata/src/test/java/com/redhat/lightblue/metadata/rdbms/model/JoinTest.java b/metadata/src/test/java/com/redhat/lightblue/metadata/rdbms/model/JoinTest.java new file mode 100644 index 0000000..7596265 --- /dev/null +++ b/metadata/src/test/java/com/redhat/lightblue/metadata/rdbms/model/JoinTest.java @@ -0,0 +1,50 @@ +package com.redhat.lightblue.metadata.rdbms.model; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; + +import org.junit.Test; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.node.JsonNodeFactory; +import com.redhat.lightblue.metadata.parser.Extensions; +import com.redhat.lightblue.metadata.parser.JSONMetadataParser; +import com.redhat.lightblue.metadata.parser.MetadataParser; +import com.redhat.lightblue.metadata.types.DefaultTypes; +import com.redhat.lightblue.util.JsonUtils; + +public class JoinTest { + + @Test + public void testParse_DistinctTrue() throws IOException{ + MetadataParser p = new JSONMetadataParser( + new Extensions(), + new DefaultTypes(), + new JsonNodeFactory(true)); + + JsonNode node = JsonUtils.json("{\"tables\":[{\"name\":\"tname\"}],\"needDistinct\":true,\"projectionMappings\":[{\"column\":\"c\",\"field\":\"f\"}]}"); + + Join join = new Join(); + join.parse(p, node); + + assertTrue(join.isNeedDistinct()); + } + + @Test + public void testParse_DistinctFalse() throws IOException{ + MetadataParser p = new JSONMetadataParser( + new Extensions(), + new DefaultTypes(), + new JsonNodeFactory(true)); + + JsonNode node = JsonUtils.json("{\"tables\":[{\"name\":\"tname\"}],\"needDistinct\":false,\"projectionMappings\":[{\"column\":\"c\",\"field\":\"f\"}]}"); + + Join join = new Join(); + join.parse(p, node); + + assertFalse(join.isNeedDistinct()); + } + +}