Skip to content

Commit

Permalink
Add directive transform tests for column directives
Browse files Browse the repository at this point in the history
  • Loading branch information
shrverma committed Jul 29, 2023
1 parent 35dbd45 commit 0e2f335
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import java.util.List;

import static io.cdap.RelationalDirectiveTest.runTransform;
import static org.mockito.ArgumentMatchers.any;

/**
* Tests {@link io.cdap.directives.column.Copy}
Expand Down Expand Up @@ -111,8 +110,8 @@ public void testForceCopy() throws Exception {
public void testRelationColumn() throws DirectiveParseException, RecipeException {
MockRelation relation = new MockRelation(null, null);
Engine engine = new MockEngine();
RelationalTranformContext relationalTranformContext = new MockRelationalTransformContext(engine, any(), any(),
any(), any());
RelationalTranformContext relationalTranformContext = new MockRelationalTransformContext(engine, null, null,
null, null);
String[] recipe = {"copy testColumn testColumn_copy"};
Relation relation1 = runTransform(recipe, relationalTranformContext, relation);
Assert.assertEquals(((MockRelation) relation1).getColumn(), "testColumn_copy");
Expand All @@ -122,8 +121,8 @@ public void testRelationColumn() throws DirectiveParseException, RecipeException
public void testRelationExpression() throws DirectiveParseException, RecipeException {
MockRelation relation = new MockRelation(null, null);
Engine engine = new MockEngine();
RelationalTranformContext relationalTranformContext = new MockRelationalTransformContext(engine, any(), any(),
any(), any());
RelationalTranformContext relationalTranformContext = new MockRelationalTransformContext(engine, null, null,
null, null);
String[] recipe = {"copy testColumn testColumn_copy"};
Relation relation1 = runTransform(recipe, relationalTranformContext, relation);
Assert.assertEquals(((MockExpression) ((MockRelation) relation1).getExpression()).getExpression(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import java.util.List;

import static io.cdap.RelationalDirectiveTest.runTransform;
import static org.mockito.ArgumentMatchers.any;

/**
* Tests {@link Keep}
Expand Down Expand Up @@ -62,8 +61,8 @@ public void testKeep() throws Exception {
public void testRelationColumn() throws DirectiveParseException, RecipeException {
MockRelation relation = new MockRelation(null, null);
Engine engine = new MockEngine();
RelationalTranformContext relationalTranformContext = new MockRelationalTransformContext(engine, any(), any(),
any(), any());
RelationalTranformContext relationalTranformContext = new MockRelationalTransformContext(engine, null, null,
null, null);
String[] recipe = {"keep column1"};
Relation relation1 = runTransform(recipe, relationalTranformContext, relation);
Assert.assertEquals(((MockRelation) relation1).getColumn(), "column1");
Expand All @@ -73,8 +72,8 @@ public void testRelationColumn() throws DirectiveParseException, RecipeException
public void testRelationExpression() throws DirectiveParseException, RecipeException {
MockRelation relation = new MockRelation(null, null);
Engine engine = new MockEngine();
RelationalTranformContext relationalTranformContext = new MockRelationalTransformContext(engine, any(), any(),
any(), any());
RelationalTranformContext relationalTranformContext = new MockRelationalTransformContext(engine, null, null,
null, null);
String[] recipe = {"keep column1"};
Relation relation1 = runTransform(recipe, relationalTranformContext, relation);
Assert.assertEquals(((MockExpression) ((MockRelation) relation1).getExpression()).getExpression(),
Expand All @@ -85,8 +84,8 @@ public void testRelationExpression() throws DirectiveParseException, RecipeExcep
public void testMultipleColumns() throws DirectiveParseException, RecipeException {
MockRelation relation = new MockRelation(null, null);
Engine engine = new MockEngine();
RelationalTranformContext relationalTranformContext = new MockRelationalTransformContext(engine, any(), any(),
any(), any());
RelationalTranformContext relationalTranformContext = new MockRelationalTransformContext(engine, null, null,
null, null);
String[] recipe = {"keep column1,column2,column3"};
Relation relation1 = runTransform(recipe, relationalTranformContext, relation);
String[] outputColumns = ((MockExpression) ((MockRelation) relation1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import java.util.List;

import static io.cdap.RelationalDirectiveTest.runTransform;
import static org.mockito.ArgumentMatchers.any;

/**
* Tests {@link Merge}
Expand Down Expand Up @@ -123,8 +122,8 @@ public void testWithMultipleCharactersAsSeparator() throws Exception {
public void testRelationColumn() throws DirectiveParseException, RecipeException {
MockRelation relation = new MockRelation(null, null);
Engine engine = new MockEngine();
RelationalTranformContext relationalTranformContext = new MockRelationalTransformContext(engine, any(), any(),
any(), any());
RelationalTranformContext relationalTranformContext = new MockRelationalTransformContext(engine, null, null,
null, null);
String[] recipe = {"merge testColumn1 testColumn2 destColumn ','"};
Relation relation1 = runTransform(recipe, relationalTranformContext, relation);
Assert.assertEquals(((MockRelation) relation1).getColumn(), "destColumn");
Expand All @@ -134,8 +133,8 @@ public void testRelationColumn() throws DirectiveParseException, RecipeException
public void testRelationExpression() throws DirectiveParseException, RecipeException {
MockRelation relation = new MockRelation(null, null);
Engine engine = new MockEngine();
RelationalTranformContext relationalTranformContext = new MockRelationalTransformContext(engine, any(), any(),
any(), any());
RelationalTranformContext relationalTranformContext = new MockRelationalTransformContext(engine, null, null,
null, null);
String[] recipe = {"merge testColumn1 testColumn2 destColumn ','"};
Relation relation1 = runTransform(recipe, relationalTranformContext, relation);
Assert.assertEquals(((MockExpression) ((MockRelation) relation1).getExpression()).getExpression(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import java.util.List;

import static io.cdap.RelationalDirectiveTest.runTransform;
import static org.mockito.ArgumentMatchers.any;

/**
* Tests {@link LeftTrim}
Expand Down Expand Up @@ -91,8 +90,8 @@ public void testSentenceLeftTrim() throws Exception {
public void testRelationColumn() throws DirectiveParseException, RecipeException {
MockRelation relation = new MockRelation(null, null);
Engine engine = new MockEngine();
RelationalTranformContext relationalTranformContext = new MockRelationalTransformContext(engine, any(), any(),
any(), any());
RelationalTranformContext relationalTranformContext = new MockRelationalTransformContext(engine, null, null,
null, null);
String[] recipe = {"ltrim testColumn"};
Relation relation1 = runTransform(recipe, relationalTranformContext, relation);
Assert.assertEquals(((MockRelation) relation1).getColumn(), "testColumn");
Expand All @@ -102,8 +101,8 @@ public void testRelationColumn() throws DirectiveParseException, RecipeException
public void testRelationExpression() throws DirectiveParseException, RecipeException {
MockRelation relation = new MockRelation(null, null);
Engine engine = new MockEngine();
RelationalTranformContext relationalTranformContext = new MockRelationalTransformContext(engine, any(), any(),
any(), any());
RelationalTranformContext relationalTranformContext = new MockRelationalTransformContext(engine, null, null,
null, null);
String[] recipe = {"ltrim testColumn"};
Relation relation1 = runTransform(recipe, relationalTranformContext, relation);
Assert.assertEquals(((MockExpression) ((MockRelation) relation1).getExpression()).getExpression(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import java.util.List;

import static io.cdap.RelationalDirectiveTest.runTransform;
import static org.mockito.ArgumentMatchers.any;

/**
* Tests {@link Lower}
Expand Down Expand Up @@ -88,8 +87,8 @@ public void testSentenceLowercasing() throws Exception {
public void testRelationColumn() throws DirectiveParseException, RecipeException {
MockRelation relation = new MockRelation(null, null);
Engine engine = new MockEngine();
RelationalTranformContext relationalTranformContext = new MockRelationalTransformContext(engine, any(), any(),
any(), any());
RelationalTranformContext relationalTranformContext = new MockRelationalTransformContext(engine, null, null,
null, null);
String[] recipe = {"lowercase testColumn"};
Relation relation1 = runTransform(recipe, relationalTranformContext, relation);
Assert.assertEquals(((MockRelation) relation1).getColumn(), "testColumn");
Expand All @@ -99,8 +98,8 @@ public void testRelationColumn() throws DirectiveParseException, RecipeException
public void testRelationExpression() throws DirectiveParseException, RecipeException {
MockRelation relation = new MockRelation(null, null);
Engine engine = new MockEngine();
RelationalTranformContext relationalTranformContext = new MockRelationalTransformContext(engine, any(), any(),
any(), any());
RelationalTranformContext relationalTranformContext = new MockRelationalTransformContext(engine, null, null,
null, null);
String[] recipe = {"lowercase testColumn"};
Relation relation1 = runTransform(recipe, relationalTranformContext, relation);
Assert.assertEquals(((MockExpression) ((MockRelation) relation1).getExpression()).getExpression(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import java.util.List;

import static io.cdap.RelationalDirectiveTest.runTransform;
import static org.mockito.ArgumentMatchers.any;

/**
* Tests {@link RightTrim}
Expand Down Expand Up @@ -91,8 +90,12 @@ public void testSentenceRightTrim() throws Exception {
public void testRelationColumn() throws DirectiveParseException, RecipeException {
MockRelation relation = new MockRelation(null, null);
Engine engine = new MockEngine();
RelationalTranformContext relationalTranformContext = new MockRelationalTransformContext(engine, any(), any(),
any(), any());
RelationalTranformContext relationalTranformContext = new MockRelationalTransformContext(engine, null
, null
,
null
, null
);
String[] recipe = {"rtrim testColumn"};
Relation relation1 = runTransform(recipe, relationalTranformContext, relation);
Assert.assertEquals(((MockRelation) relation1).getColumn(), "testColumn");
Expand All @@ -102,8 +105,12 @@ public void testRelationColumn() throws DirectiveParseException, RecipeException
public void testRelationExpression() throws DirectiveParseException, RecipeException {
MockRelation relation = new MockRelation(null, null);
Engine engine = new MockEngine();
RelationalTranformContext relationalTranformContext = new MockRelationalTransformContext(engine, any(), any(),
any(), any());
RelationalTranformContext relationalTranformContext = new MockRelationalTransformContext(engine, null
, null
,
null
, null
);
String[] recipe = {"rtrim testColumn"};
Relation relation1 = runTransform(recipe, relationalTranformContext, relation);
Assert.assertEquals(((MockExpression) ((MockRelation) relation1).getExpression()).getExpression(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import java.util.List;

import static io.cdap.RelationalDirectiveTest.runTransform;
import static org.mockito.ArgumentMatchers.any;

/**
* Tests {@link TitleCase}
Expand Down Expand Up @@ -90,8 +89,8 @@ public void testSentencesCasing() throws Exception {
public void testRelationColumn() throws DirectiveParseException, RecipeException {
MockRelation relation = new MockRelation(null, null);
Engine engine = new MockEngine();
RelationalTranformContext relationalTranformContext = new MockRelationalTransformContext(engine, any(), any(),
any(), any());
RelationalTranformContext relationalTranformContext = new MockRelationalTransformContext(engine, null, null,
null, null);
String[] recipe = {"titlecase testColumn"};
Relation relation1 = runTransform(recipe, relationalTranformContext, relation);
Assert.assertEquals(((MockRelation) relation1).getColumn(), "testColumn");
Expand All @@ -101,8 +100,8 @@ public void testRelationColumn() throws DirectiveParseException, RecipeException
public void testRelationExpression() throws DirectiveParseException, RecipeException {
MockRelation relation = new MockRelation(null, null);
Engine engine = new MockEngine();
RelationalTranformContext relationalTranformContext = new MockRelationalTransformContext(engine, any(), any(),
any(), any());
RelationalTranformContext relationalTranformContext = new MockRelationalTransformContext(engine, null, null,
null, null);
String[] recipe = {"titlecase testColumn"};
Relation relation1 = runTransform(recipe, relationalTranformContext, relation);
Assert.assertEquals(((MockExpression) ((MockRelation) relation1).getExpression()).getExpression(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import java.util.List;

import static io.cdap.RelationalDirectiveTest.runTransform;
import static org.mockito.ArgumentMatchers.any;

/**
* Tests {@link Trim}
Expand Down Expand Up @@ -111,8 +110,8 @@ public void testSentenceTrim() throws Exception {
public void testRelationColumn() throws DirectiveParseException, RecipeException {
MockRelation relation = new MockRelation(null, null);
Engine engine = new MockEngine();
RelationalTranformContext relationalTranformContext = new MockRelationalTransformContext(engine, any(), any(),
any(), any());
RelationalTranformContext relationalTranformContext = new MockRelationalTransformContext(engine, null, null,
null, null);
String[] recipe = {"trim testColumn"};
Relation relation1 = runTransform(recipe, relationalTranformContext, relation);
Assert.assertEquals(((MockRelation) relation1).getColumn(), "testColumn");
Expand All @@ -122,8 +121,8 @@ public void testRelationColumn() throws DirectiveParseException, RecipeException
public void testRelationExpression() throws DirectiveParseException, RecipeException {
MockRelation relation = new MockRelation(null, null);
Engine engine = new MockEngine();
RelationalTranformContext relationalTranformContext = new MockRelationalTransformContext(engine, any(), any(),
any(), any());
RelationalTranformContext relationalTranformContext = new MockRelationalTransformContext(engine, null, null,
null, null);
String[] recipe = {"trim testColumn"};
Relation relation1 = runTransform(recipe, relationalTranformContext, relation);
Assert.assertEquals(((MockExpression) ((MockRelation) relation1).getExpression()).getExpression(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import java.util.List;

import static io.cdap.RelationalDirectiveTest.runTransform;
import static org.mockito.ArgumentMatchers.any;

/**
* Tests {@link Upper}
Expand Down Expand Up @@ -88,8 +87,8 @@ public void testSentenceLowercasing() throws Exception {
public void testRelationColumn() throws DirectiveParseException, RecipeException {
MockRelation relation = new MockRelation(null, null);
Engine engine = new MockEngine();
RelationalTranformContext relationalTranformContext = new MockRelationalTransformContext(engine, any(), any(),
any(), any());
RelationalTranformContext relationalTranformContext = new MockRelationalTransformContext(engine, null, null,
null, null);
String[] recipe = {"uppercase testColumn"};
Relation relation1 = runTransform(recipe, relationalTranformContext, relation);
Assert.assertEquals(((MockRelation) relation1).getColumn(), "testColumn");
Expand All @@ -101,8 +100,8 @@ public void testRelationColumn() throws DirectiveParseException, RecipeException
public void testRelationExpression() throws DirectiveParseException, RecipeException {
MockRelation relation = new MockRelation(null, null);
Engine engine = new MockEngine();
RelationalTranformContext relationalTranformContext = new MockRelationalTransformContext(engine, any(), any(),
any(), any());
RelationalTranformContext relationalTranformContext = new MockRelationalTransformContext(engine, null, null,
null, null);
String[] recipe = {"uppercase testColumn"};
Relation relation1 = runTransform(recipe, relationalTranformContext, relation);
Assert.assertEquals(((MockExpression) ((MockRelation) relation1).getExpression()).getExpression(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void relationalTransformTest () throws Exception {
}

@Test
public void InvalidRelationTest () {
public void invalidRelationTest () {
Wrangler wrangler = new Wrangler(new Wrangler.Config("jexl", "No",
"false", "uppercase :Name", null,
null, null, null, null));
Expand All @@ -95,7 +95,7 @@ public static Relation runTransform(String[] recipe,
GrammarBasedParser parser = new GrammarBasedParser("default",
new MigrateToV2(recipe).migrate(), registry);
List<Directive> directives = parser.parse();
for(Directive directive : directives) {
for (Directive directive : directives) {
relation = directive.transform(relationalTranformContext, relation);
}
return relation;
Expand Down

0 comments on commit 0e2f335

Please sign in to comment.