From 751f974b78aa93bff9597208eb53f4151103fc28 Mon Sep 17 00:00:00 2001 From: shrverma Date: Wed, 26 Jul 2023 13:54:31 +0000 Subject: [PATCH 1/5] Add function validation tests --- wrangler-transform/pom.xml | 6 +++ .../cdap/wrangler/WranglerTransformTest.java | 50 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 wrangler-transform/src/test/java/io/cdap/wrangler/WranglerTransformTest.java diff --git a/wrangler-transform/pom.xml b/wrangler-transform/pom.xml index c99f8e3d8..cd314bcfa 100644 --- a/wrangler-transform/pom.xml +++ b/wrangler-transform/pom.xml @@ -84,6 +84,12 @@ + + org.mockito + mockito-core + 2.23.0 + test + diff --git a/wrangler-transform/src/test/java/io/cdap/wrangler/WranglerTransformTest.java b/wrangler-transform/src/test/java/io/cdap/wrangler/WranglerTransformTest.java new file mode 100644 index 000000000..cb21cd86d --- /dev/null +++ b/wrangler-transform/src/test/java/io/cdap/wrangler/WranglerTransformTest.java @@ -0,0 +1,50 @@ +/* + * Copyright © 2023 Cask Data, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package io.cdap.wrangler; + +import io.cdap.cdap.etl.api.relational.InvalidRelation; +import io.cdap.cdap.etl.api.relational.Relation; + +import org.junit.Assert; +import org.junit.Test; + +import static org.mockito.Mockito.mock; + +public class WranglerTransformTest { + + @Test(expected = RuntimeException.class) + public void relationalTransformTest () throws Exception { + Wrangler wrangler = new Wrangler(new Wrangler.Config("sql", "Yes", + "true", "uppercase :Name", null, + null, null, null, null)); + Relation relation = mock(Relation.class); + Relation resultRelation = mock(Relation.class); + resultRelation = wrangler.transform(null, relation); + //Assert.assertEquals(resultRelation, wrangler.transform(null, relation)); + } + + @Test + public void InvalidRelationTest () { + Wrangler wrangler = new Wrangler(new Wrangler.Config("jexl", "No", + "false", "uppercase :Name", null, + null, null, null, null)); + Relation relation = mock(Relation.class); + Relation invalidrelation = new InvalidRelation("Plugin is not configured for relational transformation"); + Assert.assertEquals(invalidrelation.getValidationError(), + wrangler.transform(null, relation).getValidationError()); + } +} From 35dbd45c926ffad782005dfe8eff92c6c0136d2c Mon Sep 17 00:00:00 2001 From: shrverma Date: Sat, 29 Jul 2023 14:07:32 +0000 Subject: [PATCH 2/5] Add directive transform tests --- .../src/test/java/io/cdap/MockEngine.java | 38 +++++++ .../src/test/java/io/cdap/MockExpression.java | 42 ++++++++ .../java/io/cdap/MockExpressionFactory.java | 52 +++++++++ .../src/test/java/io/cdap/MockRelation.java | 81 ++++++++++++++ .../cdap/MockRelationalTransformContext.java | 102 ++++++++++++++++++ .../java/io/cdap/RelationalDirectiveTest.java | 53 +++++++++ .../io/cdap/directives/column/CopyTest.java | 33 ++++++ .../io/cdap/directives/column/KeepTest.java | 49 +++++++++ .../io/cdap/directives/column/MergeTest.java | 35 ++++++ .../io/cdap/directives/column/RenameTest.java | 11 ++ .../transformation/LeftTrimTest.java | 35 ++++++ .../directives/transformation/LowerTest.java | 36 +++++++ .../transformation/RightTrimTest.java | 35 ++++++ .../transformation/TitleCaseTest.java | 36 +++++++ .../directives/transformation/TrimTest.java | 35 ++++++ .../directives/transformation/UpperTest.java | 38 +++++++ .../cdap/wrangler/WranglerTransformTest.java | 57 +++++++++- 17 files changed, 766 insertions(+), 2 deletions(-) create mode 100644 wrangler-core/src/test/java/io/cdap/MockEngine.java create mode 100644 wrangler-core/src/test/java/io/cdap/MockExpression.java create mode 100644 wrangler-core/src/test/java/io/cdap/MockExpressionFactory.java create mode 100644 wrangler-core/src/test/java/io/cdap/MockRelation.java create mode 100644 wrangler-core/src/test/java/io/cdap/MockRelationalTransformContext.java create mode 100644 wrangler-core/src/test/java/io/cdap/RelationalDirectiveTest.java diff --git a/wrangler-core/src/test/java/io/cdap/MockEngine.java b/wrangler-core/src/test/java/io/cdap/MockEngine.java new file mode 100644 index 000000000..fd9fdc18b --- /dev/null +++ b/wrangler-core/src/test/java/io/cdap/MockEngine.java @@ -0,0 +1,38 @@ +/* + * Copyright © 2023 Cask Data, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package io.cdap; + +import io.cdap.cdap.etl.api.relational.Capability; +import io.cdap.cdap.etl.api.relational.Engine; +import io.cdap.cdap.etl.api.relational.ExpressionFactory; +import io.cdap.cdap.etl.api.relational.StringExpressionFactoryType; +import java.util.Collections; +import java.util.List; +import java.util.Set; + +public class MockEngine implements Engine { + + @Override + public Set getCapabilities() { + return Collections.singleton(StringExpressionFactoryType.SQL); + } + + @Override + public List> getExpressionFactories() { + return Collections.singletonList(new MockExpressionFactory()); + } +} diff --git a/wrangler-core/src/test/java/io/cdap/MockExpression.java b/wrangler-core/src/test/java/io/cdap/MockExpression.java new file mode 100644 index 000000000..0f5d2960d --- /dev/null +++ b/wrangler-core/src/test/java/io/cdap/MockExpression.java @@ -0,0 +1,42 @@ +/* + * Copyright © 2023 Cask Data, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package io.cdap; + +import io.cdap.cdap.etl.api.relational.Expression; + +public class MockExpression implements Expression { + + private final String expression; + + + public MockExpression(String expression) { + this.expression = expression; + } + + public boolean isValid() { + return true; + } + + public String getExpression() { + return this.expression; + } + + @Override + public String getValidationError() { + return null; + } +} diff --git a/wrangler-core/src/test/java/io/cdap/MockExpressionFactory.java b/wrangler-core/src/test/java/io/cdap/MockExpressionFactory.java new file mode 100644 index 000000000..0a8f11404 --- /dev/null +++ b/wrangler-core/src/test/java/io/cdap/MockExpressionFactory.java @@ -0,0 +1,52 @@ +/* + * Copyright © 2023 Cask Data, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package io.cdap; + +import io.cdap.cdap.etl.api.relational.Capability; +import io.cdap.cdap.etl.api.relational.CoreExpressionCapabilities; +import io.cdap.cdap.etl.api.relational.Expression; +import io.cdap.cdap.etl.api.relational.ExpressionFactory; +import io.cdap.cdap.etl.api.relational.ExpressionFactoryType; +import io.cdap.cdap.etl.api.relational.StringExpressionFactoryType; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; + +public class MockExpressionFactory implements ExpressionFactory { + + @Override +public ExpressionFactoryType getType() { + return StringExpressionFactoryType.SQL; +} + private static final Set CAPABILITIES = Collections.unmodifiableSet( + new HashSet() {{ + add(StringExpressionFactoryType.SQL); + add(CoreExpressionCapabilities.CAN_GET_QUALIFIED_DATASET_NAME); + add(CoreExpressionCapabilities.CAN_GET_QUALIFIED_COLUMN_NAME); + add(CoreExpressionCapabilities.CAN_SET_DATASET_ALIAS); + }}); + + @Override + public Set getCapabilities() { + return CAPABILITIES; + } + + @Override + public Expression compile(String expression) { + return new MockExpression(expression); + } +} diff --git a/wrangler-core/src/test/java/io/cdap/MockRelation.java b/wrangler-core/src/test/java/io/cdap/MockRelation.java new file mode 100644 index 000000000..ebaa097d5 --- /dev/null +++ b/wrangler-core/src/test/java/io/cdap/MockRelation.java @@ -0,0 +1,81 @@ +/* + * Copyright © 2023 Cask Data, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package io.cdap; + +import io.cdap.cdap.etl.api.relational.Expression; +import io.cdap.cdap.etl.api.relational.Relation; +import java.util.Map; +import java.util.stream.Collectors; +import javax.annotation.Nullable; + +public class MockRelation implements Relation { + String column; + + Expression expression; + + public MockRelation(@Nullable String column, @Nullable Expression expression) { + this.column = column; + this.expression = expression; + } + @Override + public boolean isValid() { + return true; + } + + @Override + public String getValidationError() { + return null; + } + + @Override + public Relation setColumn(String column, Expression value) { + return new MockRelation(column, value); + } + + @Override + public Relation dropColumn(String column) { + return new MockRelation(column, null); + } + + @Override + public Relation select(Map columnExpMap) { + String columns = columnExpMap.entrySet() + .stream() + .map(column -> column.getKey()) + .collect(Collectors.joining(",")); + + String expressions = columnExpMap.entrySet() + .stream() + .map(column -> ((MockExpression) column.getValue()).getExpression()) + .collect(Collectors.joining(",")); + + return new MockRelation(columns, new MockExpression(expressions)); + } + + @Override + public Relation filter(Expression filter) { + return new MockRelation(null, filter); + } + + public String getColumn() { + return this.column; + } + + public Expression getExpression() { + return this.expression; + } +} diff --git a/wrangler-core/src/test/java/io/cdap/MockRelationalTransformContext.java b/wrangler-core/src/test/java/io/cdap/MockRelationalTransformContext.java new file mode 100644 index 000000000..295cdb43c --- /dev/null +++ b/wrangler-core/src/test/java/io/cdap/MockRelationalTransformContext.java @@ -0,0 +1,102 @@ +/* + * Copyright © 2023 Cask Data, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package io.cdap; + +import io.cdap.cdap.api.data.schema.Schema; +import io.cdap.cdap.api.feature.FeatureFlagsProvider; +import io.cdap.cdap.etl.api.engine.sql.StandardSQLCapabilities; +import io.cdap.cdap.etl.api.relational.Capability; +import io.cdap.cdap.etl.api.relational.Engine; +import io.cdap.cdap.etl.api.relational.Relation; +import io.cdap.cdap.etl.api.relational.RelationalTranformContext; +import java.util.Collection; +import java.util.Collections; +import java.util.Map; +import java.util.Set; + +/** + * Basic implementation of the {@link RelationalTranformContext} with single output port + */ +public class MockRelationalTransformContext implements RelationalTranformContext { + private Engine engine; + private Map inputMap; + private Map inputSchemas; + private Schema outputSchema; + private FeatureFlagsProvider featureFlagsProvider; + private Relation outputRelation; + + + public MockRelationalTransformContext(Engine engine, + Map inputMap, + Map inputSchemas, + Schema outputSchema, + FeatureFlagsProvider featureFlagsProvider) { + this.engine = engine; + this.inputMap = inputMap; + this.inputSchemas = inputSchemas; + this.outputSchema = outputSchema; + this.featureFlagsProvider = featureFlagsProvider; + } + + @Override + public Engine getEngine() { + return engine; + } + + @Override + public Relation getInputRelation(String inputStage) { + return inputMap.get(inputStage); + } + + @Override + public Set getInputRelationNames() { + return Collections.unmodifiableSet(inputMap.keySet()); + } + + @Override + public Schema getInputSchema(String inputStage) { + return inputSchemas.get(inputStage); + } + + @Override + public Schema getOutputSchema() { + return outputSchema; + } + + @Override + public void setOutputRelation(Relation outputRelation) { + this.outputRelation = outputRelation; + } + + @Override + public void setOutputRelation(String portName, Relation outputDataSet) { + throw new UnsupportedOperationException("Only single output is supported"); + } + + @Override + public boolean isFeatureEnabled(String name) { + return this.featureFlagsProvider.isFeatureEnabled(name); + } + + public Relation getOutputRelation() { + return outputRelation; + } + + public Collection getDefaultLanguageCapabilityList() { + return Collections.singleton(StandardSQLCapabilities.POSTGRES); + } +} diff --git a/wrangler-core/src/test/java/io/cdap/RelationalDirectiveTest.java b/wrangler-core/src/test/java/io/cdap/RelationalDirectiveTest.java new file mode 100644 index 000000000..ea9bc4e52 --- /dev/null +++ b/wrangler-core/src/test/java/io/cdap/RelationalDirectiveTest.java @@ -0,0 +1,53 @@ +/* + * Copyright © 2023 Cask Data, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package io.cdap; + +import io.cdap.cdap.etl.api.relational.Relation; +import io.cdap.cdap.etl.api.relational.RelationalTranformContext; +import io.cdap.wrangler.api.Directive; +import io.cdap.wrangler.api.DirectiveLoadException; +import io.cdap.wrangler.api.DirectiveParseException; +import io.cdap.wrangler.api.RecipeException; +import io.cdap.wrangler.parser.GrammarBasedParser; +import io.cdap.wrangler.parser.MigrateToV2; +import io.cdap.wrangler.registry.DirectiveRegistry; +import io.cdap.wrangler.registry.SystemDirectiveRegistry; +import java.util.List; + +public class RelationalDirectiveTest { + + public static Relation runTransform(String[] recipe, + RelationalTranformContext relationalTranformContext, + Relation relation) + throws DirectiveParseException, RecipeException { + DirectiveRegistry registry; + registry = SystemDirectiveRegistry.INSTANCE; + try { + registry.reload("default"); + } catch (DirectiveLoadException e) { + throw new RuntimeException(e); + } + + GrammarBasedParser parser = new GrammarBasedParser("default", + new MigrateToV2(recipe).migrate(), registry); + List directives = parser.parse(); + for (Directive directive : directives) { + relation = directive.transform(relationalTranformContext, relation); + } + return relation; + } +} diff --git a/wrangler-core/src/test/java/io/cdap/directives/column/CopyTest.java b/wrangler-core/src/test/java/io/cdap/directives/column/CopyTest.java index daed64b86..307cf9304 100644 --- a/wrangler-core/src/test/java/io/cdap/directives/column/CopyTest.java +++ b/wrangler-core/src/test/java/io/cdap/directives/column/CopyTest.java @@ -16,7 +16,15 @@ package io.cdap.directives.column; +import io.cdap.MockEngine; +import io.cdap.MockExpression; +import io.cdap.MockRelation; +import io.cdap.MockRelationalTransformContext; +import io.cdap.cdap.etl.api.relational.Engine; +import io.cdap.cdap.etl.api.relational.Relation; +import io.cdap.cdap.etl.api.relational.RelationalTranformContext; import io.cdap.wrangler.TestingRig; +import io.cdap.wrangler.api.DirectiveParseException; import io.cdap.wrangler.api.RecipeException; import io.cdap.wrangler.api.Row; import org.junit.Assert; @@ -25,6 +33,9 @@ import java.util.Arrays; import java.util.List; +import static io.cdap.RelationalDirectiveTest.runTransform; +import static org.mockito.ArgumentMatchers.any; + /** * Tests {@link io.cdap.directives.column.Copy} */ @@ -96,4 +107,26 @@ public void testForceCopy() throws Exception { Assert.assertEquals(rows.get(2).getValue("body_2"), rows.get(2).getValue("body_1")); } + @Test + 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()); + String[] recipe = {"copy testColumn testColumn_copy"}; + Relation relation1 = runTransform(recipe, relationalTranformContext, relation); + Assert.assertEquals(((MockRelation) relation1).getColumn(), "testColumn_copy"); + } + + @Test + 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()); + String[] recipe = {"copy testColumn testColumn_copy"}; + Relation relation1 = runTransform(recipe, relationalTranformContext, relation); + Assert.assertEquals(((MockExpression) ((MockRelation) relation1).getExpression()).getExpression(), + "testColumn"); + } } diff --git a/wrangler-core/src/test/java/io/cdap/directives/column/KeepTest.java b/wrangler-core/src/test/java/io/cdap/directives/column/KeepTest.java index 709e0a19c..8904a852e 100644 --- a/wrangler-core/src/test/java/io/cdap/directives/column/KeepTest.java +++ b/wrangler-core/src/test/java/io/cdap/directives/column/KeepTest.java @@ -16,7 +16,16 @@ package io.cdap.directives.column; +import io.cdap.MockEngine; +import io.cdap.MockExpression; +import io.cdap.MockRelation; +import io.cdap.MockRelationalTransformContext; +import io.cdap.cdap.etl.api.relational.Engine; +import io.cdap.cdap.etl.api.relational.Relation; +import io.cdap.cdap.etl.api.relational.RelationalTranformContext; import io.cdap.wrangler.TestingRig; +import io.cdap.wrangler.api.DirectiveParseException; +import io.cdap.wrangler.api.RecipeException; import io.cdap.wrangler.api.Row; import org.junit.Assert; import org.junit.Test; @@ -24,6 +33,9 @@ import java.util.Arrays; import java.util.List; +import static io.cdap.RelationalDirectiveTest.runTransform; +import static org.mockito.ArgumentMatchers.any; + /** * Tests {@link Keep} */ @@ -45,4 +57,41 @@ public void testKeep() throws Exception { Assert.assertTrue(rows.size() == 1); Assert.assertEquals(2, rows.get(0).width()); } + + @Test + 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()); + String[] recipe = {"keep column1"}; + Relation relation1 = runTransform(recipe, relationalTranformContext, relation); + Assert.assertEquals(((MockRelation) relation1).getColumn(), "column1"); + } + + @Test + 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()); + String[] recipe = {"keep column1"}; + Relation relation1 = runTransform(recipe, relationalTranformContext, relation); + Assert.assertEquals(((MockExpression) ((MockRelation) relation1).getExpression()).getExpression(), + "column1"); + } + + @Test + 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()); + String[] recipe = {"keep column1,column2,column3"}; + Relation relation1 = runTransform(recipe, relationalTranformContext, relation); + String[] outputColumns = ((MockExpression) ((MockRelation) relation1) + .getExpression()).getExpression().split(","); + Assert.assertEquals(outputColumns.length, 3); + } + } diff --git a/wrangler-core/src/test/java/io/cdap/directives/column/MergeTest.java b/wrangler-core/src/test/java/io/cdap/directives/column/MergeTest.java index 66224f473..494256ce7 100644 --- a/wrangler-core/src/test/java/io/cdap/directives/column/MergeTest.java +++ b/wrangler-core/src/test/java/io/cdap/directives/column/MergeTest.java @@ -16,7 +16,16 @@ package io.cdap.directives.column; +import io.cdap.MockEngine; +import io.cdap.MockExpression; +import io.cdap.MockRelation; +import io.cdap.MockRelationalTransformContext; +import io.cdap.cdap.etl.api.relational.Engine; +import io.cdap.cdap.etl.api.relational.Relation; +import io.cdap.cdap.etl.api.relational.RelationalTranformContext; import io.cdap.wrangler.TestingRig; +import io.cdap.wrangler.api.DirectiveParseException; +import io.cdap.wrangler.api.RecipeException; import io.cdap.wrangler.api.Row; import org.junit.Assert; import org.junit.Ignore; @@ -25,6 +34,9 @@ import java.util.Arrays; import java.util.List; +import static io.cdap.RelationalDirectiveTest.runTransform; +import static org.mockito.ArgumentMatchers.any; + /** * Tests {@link Merge} */ @@ -106,4 +118,27 @@ public void testWithMultipleCharactersAsSeparator() throws Exception { Assert.assertEquals(1, rows.size()); Assert.assertEquals("Root---Joltie", rows.get(0).getValue("C")); } + + @Test + 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()); + String[] recipe = {"merge testColumn1 testColumn2 destColumn ','"}; + Relation relation1 = runTransform(recipe, relationalTranformContext, relation); + Assert.assertEquals(((MockRelation) relation1).getColumn(), "destColumn"); + } + + @Test + 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()); + String[] recipe = {"merge testColumn1 testColumn2 destColumn ','"}; + Relation relation1 = runTransform(recipe, relationalTranformContext, relation); + Assert.assertEquals(((MockExpression) ((MockRelation) relation1).getExpression()).getExpression(), + "CONCAT(testColumn1,',',testColumn2)"); + } } diff --git a/wrangler-core/src/test/java/io/cdap/directives/column/RenameTest.java b/wrangler-core/src/test/java/io/cdap/directives/column/RenameTest.java index 1faec2db8..02691d3ee 100644 --- a/wrangler-core/src/test/java/io/cdap/directives/column/RenameTest.java +++ b/wrangler-core/src/test/java/io/cdap/directives/column/RenameTest.java @@ -16,7 +16,15 @@ package io.cdap.directives.column; +import io.cdap.MockEngine; +import io.cdap.MockExpression; +import io.cdap.MockRelation; +import io.cdap.MockRelationalTransformContext; +import io.cdap.cdap.etl.api.relational.Engine; +import io.cdap.cdap.etl.api.relational.Relation; +import io.cdap.cdap.etl.api.relational.RelationalTranformContext; import io.cdap.wrangler.TestingRig; +import io.cdap.wrangler.api.DirectiveParseException; import io.cdap.wrangler.api.RecipeException; import io.cdap.wrangler.api.Row; import org.junit.Assert; @@ -25,6 +33,9 @@ import java.util.Arrays; import java.util.List; +import static io.cdap.RelationalDirectiveTest.runTransform; +import static org.mockito.ArgumentMatchers.any; + /** * Tests {@link Rename} */ diff --git a/wrangler-core/src/test/java/io/cdap/directives/transformation/LeftTrimTest.java b/wrangler-core/src/test/java/io/cdap/directives/transformation/LeftTrimTest.java index 0fb060ee7..b00116035 100644 --- a/wrangler-core/src/test/java/io/cdap/directives/transformation/LeftTrimTest.java +++ b/wrangler-core/src/test/java/io/cdap/directives/transformation/LeftTrimTest.java @@ -16,7 +16,16 @@ package io.cdap.directives.transformation; +import io.cdap.MockEngine; +import io.cdap.MockExpression; +import io.cdap.MockRelation; +import io.cdap.MockRelationalTransformContext; +import io.cdap.cdap.etl.api.relational.Engine; +import io.cdap.cdap.etl.api.relational.Relation; +import io.cdap.cdap.etl.api.relational.RelationalTranformContext; import io.cdap.wrangler.TestingRig; +import io.cdap.wrangler.api.DirectiveParseException; +import io.cdap.wrangler.api.RecipeException; import io.cdap.wrangler.api.Row; import org.junit.Assert; import org.junit.Test; @@ -24,6 +33,9 @@ import java.util.Arrays; import java.util.List; +import static io.cdap.RelationalDirectiveTest.runTransform; +import static org.mockito.ArgumentMatchers.any; + /** * Tests {@link LeftTrim} */ @@ -74,4 +86,27 @@ public void testSentenceLeftTrim() throws Exception { Assert.assertEquals("TITLE IS TITLE ", rows.get(3).getValue("body")); Assert.assertEquals("TITLE IS TITLE ", rows.get(4).getValue("body")); } + + @Test + 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()); + String[] recipe = {"ltrim testColumn"}; + Relation relation1 = runTransform(recipe, relationalTranformContext, relation); + Assert.assertEquals(((MockRelation) relation1).getColumn(), "testColumn"); + } + + @Test + 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()); + String[] recipe = {"ltrim testColumn"}; + Relation relation1 = runTransform(recipe, relationalTranformContext, relation); + Assert.assertEquals(((MockExpression) ((MockRelation) relation1).getExpression()).getExpression(), + "LTRIM(testColumn)"); + } } diff --git a/wrangler-core/src/test/java/io/cdap/directives/transformation/LowerTest.java b/wrangler-core/src/test/java/io/cdap/directives/transformation/LowerTest.java index 674fed2a9..797c5049d 100644 --- a/wrangler-core/src/test/java/io/cdap/directives/transformation/LowerTest.java +++ b/wrangler-core/src/test/java/io/cdap/directives/transformation/LowerTest.java @@ -16,7 +16,16 @@ package io.cdap.directives.transformation; +import io.cdap.MockEngine; +import io.cdap.MockExpression; +import io.cdap.MockRelation; +import io.cdap.MockRelationalTransformContext; +import io.cdap.cdap.etl.api.relational.Engine; +import io.cdap.cdap.etl.api.relational.Relation; +import io.cdap.cdap.etl.api.relational.RelationalTranformContext; import io.cdap.wrangler.TestingRig; +import io.cdap.wrangler.api.DirectiveParseException; +import io.cdap.wrangler.api.RecipeException; import io.cdap.wrangler.api.Row; import org.junit.Assert; import org.junit.Test; @@ -24,6 +33,9 @@ import java.util.Arrays; import java.util.List; +import static io.cdap.RelationalDirectiveTest.runTransform; +import static org.mockito.ArgumentMatchers.any; + /** * Tests {@link Lower} */ @@ -71,4 +83,28 @@ public void testSentenceLowercasing() throws Exception { Assert.assertEquals("title is title", rows.get(2).getValue("body")); Assert.assertEquals("title is title", rows.get(3).getValue("body")); } + + @Test + 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()); + String[] recipe = {"lowercase testColumn"}; + Relation relation1 = runTransform(recipe, relationalTranformContext, relation); + Assert.assertEquals(((MockRelation) relation1).getColumn(), "testColumn"); + } + + @Test + 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()); + String[] recipe = {"lowercase testColumn"}; + Relation relation1 = runTransform(recipe, relationalTranformContext, relation); + Assert.assertEquals(((MockExpression) ((MockRelation) relation1).getExpression()).getExpression(), + "LOWER(testColumn)"); + } + } diff --git a/wrangler-core/src/test/java/io/cdap/directives/transformation/RightTrimTest.java b/wrangler-core/src/test/java/io/cdap/directives/transformation/RightTrimTest.java index 749ee3dd1..9f0ef260a 100644 --- a/wrangler-core/src/test/java/io/cdap/directives/transformation/RightTrimTest.java +++ b/wrangler-core/src/test/java/io/cdap/directives/transformation/RightTrimTest.java @@ -16,7 +16,16 @@ package io.cdap.directives.transformation; +import io.cdap.MockEngine; +import io.cdap.MockExpression; +import io.cdap.MockRelation; +import io.cdap.MockRelationalTransformContext; +import io.cdap.cdap.etl.api.relational.Engine; +import io.cdap.cdap.etl.api.relational.Relation; +import io.cdap.cdap.etl.api.relational.RelationalTranformContext; import io.cdap.wrangler.TestingRig; +import io.cdap.wrangler.api.DirectiveParseException; +import io.cdap.wrangler.api.RecipeException; import io.cdap.wrangler.api.Row; import org.junit.Assert; import org.junit.Test; @@ -24,6 +33,9 @@ import java.util.Arrays; import java.util.List; +import static io.cdap.RelationalDirectiveTest.runTransform; +import static org.mockito.ArgumentMatchers.any; + /** * Tests {@link RightTrim} */ @@ -74,4 +86,27 @@ public void testSentenceRightTrim() throws Exception { Assert.assertEquals(" TITLE IS TITLE", rows.get(3).getValue("body")); Assert.assertEquals(" TITLE IS TITLE", rows.get(4).getValue("body")); } + + @Test + 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()); + String[] recipe = {"rtrim testColumn"}; + Relation relation1 = runTransform(recipe, relationalTranformContext, relation); + Assert.assertEquals(((MockRelation) relation1).getColumn(), "testColumn"); + } + + @Test + 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()); + String[] recipe = {"rtrim testColumn"}; + Relation relation1 = runTransform(recipe, relationalTranformContext, relation); + Assert.assertEquals(((MockExpression) ((MockRelation) relation1).getExpression()).getExpression(), + "RTRIM(testColumn)"); + } } diff --git a/wrangler-core/src/test/java/io/cdap/directives/transformation/TitleCaseTest.java b/wrangler-core/src/test/java/io/cdap/directives/transformation/TitleCaseTest.java index f9e671954..2c62743ad 100644 --- a/wrangler-core/src/test/java/io/cdap/directives/transformation/TitleCaseTest.java +++ b/wrangler-core/src/test/java/io/cdap/directives/transformation/TitleCaseTest.java @@ -16,7 +16,16 @@ package io.cdap.directives.transformation; +import io.cdap.MockEngine; +import io.cdap.MockExpression; +import io.cdap.MockRelation; +import io.cdap.MockRelationalTransformContext; +import io.cdap.cdap.etl.api.relational.Engine; +import io.cdap.cdap.etl.api.relational.Relation; +import io.cdap.cdap.etl.api.relational.RelationalTranformContext; import io.cdap.wrangler.TestingRig; +import io.cdap.wrangler.api.DirectiveParseException; +import io.cdap.wrangler.api.RecipeException; import io.cdap.wrangler.api.Row; import org.junit.Assert; import org.junit.Test; @@ -24,6 +33,9 @@ import java.util.Arrays; import java.util.List; +import static io.cdap.RelationalDirectiveTest.runTransform; +import static org.mockito.ArgumentMatchers.any; + /** * Tests {@link TitleCase} */ @@ -73,4 +85,28 @@ public void testSentencesCasing() throws Exception { Assert.assertEquals("Title Is Title", rows.get(3).getValue("body")); } + + @Test + 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()); + String[] recipe = {"titlecase testColumn"}; + Relation relation1 = runTransform(recipe, relationalTranformContext, relation); + Assert.assertEquals(((MockRelation) relation1).getColumn(), "testColumn"); + } + + @Test + 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()); + String[] recipe = {"titlecase testColumn"}; + Relation relation1 = runTransform(recipe, relationalTranformContext, relation); + Assert.assertEquals(((MockExpression) ((MockRelation) relation1).getExpression()).getExpression(), + "initcap(testColumn)"); + } + } diff --git a/wrangler-core/src/test/java/io/cdap/directives/transformation/TrimTest.java b/wrangler-core/src/test/java/io/cdap/directives/transformation/TrimTest.java index 1fddd69ac..05c19228e 100644 --- a/wrangler-core/src/test/java/io/cdap/directives/transformation/TrimTest.java +++ b/wrangler-core/src/test/java/io/cdap/directives/transformation/TrimTest.java @@ -16,7 +16,16 @@ package io.cdap.directives.transformation; +import io.cdap.MockEngine; +import io.cdap.MockExpression; +import io.cdap.MockRelation; +import io.cdap.MockRelationalTransformContext; +import io.cdap.cdap.etl.api.relational.Engine; +import io.cdap.cdap.etl.api.relational.Relation; +import io.cdap.cdap.etl.api.relational.RelationalTranformContext; import io.cdap.wrangler.TestingRig; +import io.cdap.wrangler.api.DirectiveParseException; +import io.cdap.wrangler.api.RecipeException; import io.cdap.wrangler.api.Row; import org.junit.Assert; import org.junit.Test; @@ -24,6 +33,9 @@ import java.util.Arrays; import java.util.List; +import static io.cdap.RelationalDirectiveTest.runTransform; +import static org.mockito.ArgumentMatchers.any; + /** * Tests {@link Trim} */ @@ -94,4 +106,27 @@ public void testSentenceTrim() throws Exception { Assert.assertEquals(expected, rows.get(i).getValue("body")); } } + + @Test + 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()); + String[] recipe = {"trim testColumn"}; + Relation relation1 = runTransform(recipe, relationalTranformContext, relation); + Assert.assertEquals(((MockRelation) relation1).getColumn(), "testColumn"); + } + + @Test + 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()); + String[] recipe = {"trim testColumn"}; + Relation relation1 = runTransform(recipe, relationalTranformContext, relation); + Assert.assertEquals(((MockExpression) ((MockRelation) relation1).getExpression()).getExpression(), + "TRIM(testColumn)"); + } } diff --git a/wrangler-core/src/test/java/io/cdap/directives/transformation/UpperTest.java b/wrangler-core/src/test/java/io/cdap/directives/transformation/UpperTest.java index e531c441c..cabdf6769 100644 --- a/wrangler-core/src/test/java/io/cdap/directives/transformation/UpperTest.java +++ b/wrangler-core/src/test/java/io/cdap/directives/transformation/UpperTest.java @@ -16,7 +16,16 @@ package io.cdap.directives.transformation; +import io.cdap.MockEngine; +import io.cdap.MockExpression; +import io.cdap.MockRelation; +import io.cdap.MockRelationalTransformContext; +import io.cdap.cdap.etl.api.relational.Engine; +import io.cdap.cdap.etl.api.relational.Relation; +import io.cdap.cdap.etl.api.relational.RelationalTranformContext; import io.cdap.wrangler.TestingRig; +import io.cdap.wrangler.api.DirectiveParseException; +import io.cdap.wrangler.api.RecipeException; import io.cdap.wrangler.api.Row; import org.junit.Assert; import org.junit.Test; @@ -24,6 +33,9 @@ import java.util.Arrays; import java.util.List; +import static io.cdap.RelationalDirectiveTest.runTransform; +import static org.mockito.ArgumentMatchers.any; + /** * Tests {@link Upper} */ @@ -71,4 +83,30 @@ public void testSentenceLowercasing() throws Exception { Assert.assertEquals("TITLE IS TITLE", rows.get(2).getValue("body")); Assert.assertEquals("TITLE IS TITLE", rows.get(3).getValue("body")); } + + @Test + 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()); + String[] recipe = {"uppercase testColumn"}; + Relation relation1 = runTransform(recipe, relationalTranformContext, relation); + Assert.assertEquals(((MockRelation) relation1).getColumn(), "testColumn"); + Assert.assertEquals(((MockExpression) ((MockRelation) relation1).getExpression()).getExpression(), + "UPPER(testColumn)"); + } + + @Test + 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()); + String[] recipe = {"uppercase testColumn"}; + Relation relation1 = runTransform(recipe, relationalTranformContext, relation); + Assert.assertEquals(((MockExpression) ((MockRelation) relation1).getExpression()).getExpression(), + "UPPER(testColumn)"); + } + } diff --git a/wrangler-transform/src/test/java/io/cdap/wrangler/WranglerTransformTest.java b/wrangler-transform/src/test/java/io/cdap/wrangler/WranglerTransformTest.java index cb21cd86d..d53c808ab 100644 --- a/wrangler-transform/src/test/java/io/cdap/wrangler/WranglerTransformTest.java +++ b/wrangler-transform/src/test/java/io/cdap/wrangler/WranglerTransformTest.java @@ -16,14 +16,46 @@ package io.cdap.wrangler; +import io.cdap.cdap.api.data.schema.Schema; +import io.cdap.cdap.etl.api.relational.Capability; +import io.cdap.cdap.etl.api.relational.Engine; +import io.cdap.cdap.etl.api.relational.Expression; +import io.cdap.cdap.etl.api.relational.ExpressionFactory; +import io.cdap.cdap.etl.api.relational.ExpressionFactoryType; import io.cdap.cdap.etl.api.relational.InvalidRelation; import io.cdap.cdap.etl.api.relational.Relation; +import io.cdap.cdap.etl.api.relational.RelationalTranformContext; +import io.cdap.directives.transformation.Lower; +import io.cdap.wrangler.api.Directive; +import io.cdap.wrangler.api.DirectiveLoadException; +import io.cdap.wrangler.api.DirectiveParseException; +import io.cdap.wrangler.api.RecipeException; +import io.cdap.wrangler.parser.GrammarBasedParser; +import io.cdap.wrangler.parser.MigrateToV2; +import io.cdap.wrangler.registry.DirectiveRegistry; +import io.cdap.wrangler.registry.SystemDirectiveRegistry; +import io.cdap.wrangler.utils.SqlExpressionGenerator; +import org.apache.poi.ss.formula.functions.T; import org.junit.Assert; import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.junit.MockitoJUnitRunner; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.util.Optional; +import java.util.Set; + +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; + public class WranglerTransformTest { @Test(expected = RuntimeException.class) @@ -34,7 +66,6 @@ public void relationalTransformTest () throws Exception { Relation relation = mock(Relation.class); Relation resultRelation = mock(Relation.class); resultRelation = wrangler.transform(null, relation); - //Assert.assertEquals(resultRelation, wrangler.transform(null, relation)); } @Test @@ -43,8 +74,30 @@ public void InvalidRelationTest () { "false", "uppercase :Name", null, null, null, null, null)); Relation relation = mock(Relation.class); - Relation invalidrelation = new InvalidRelation("Plugin is not configured for relational transformation"); + Relation invalidrelation = new InvalidRelation("Plugin is not con" + + "figured for relational transformation"); Assert.assertEquals(invalidrelation.getValidationError(), wrangler.transform(null, relation).getValidationError()); } + + public static Relation runTransform(String[] recipe, + RelationalTranformContext relationalTranformContext, + Relation relation) + throws DirectiveParseException, RecipeException { + DirectiveRegistry registry; + registry = SystemDirectiveRegistry.INSTANCE; + try { + registry.reload("default"); + } catch (DirectiveLoadException e) { + throw new RuntimeException(e); + } + + GrammarBasedParser parser = new GrammarBasedParser("default", + new MigrateToV2(recipe).migrate(), registry); + List directives = parser.parse(); + for(Directive directive : directives) { + relation = directive.transform(relationalTranformContext, relation); + } + return relation; + } } From 0e2f335da23c7d852a6f656e5d6a8145b33158b7 Mon Sep 17 00:00:00 2001 From: shrverma Date: Sat, 29 Jul 2023 17:12:42 +0000 Subject: [PATCH 3/5] Add directive transform tests for column directives --- .../io/cdap/directives/column/CopyTest.java | 9 ++++----- .../io/cdap/directives/column/KeepTest.java | 13 ++++++------- .../io/cdap/directives/column/MergeTest.java | 9 ++++----- .../directives/transformation/LeftTrimTest.java | 9 ++++----- .../directives/transformation/LowerTest.java | 9 ++++----- .../transformation/RightTrimTest.java | 17 ++++++++++++----- .../transformation/TitleCaseTest.java | 9 ++++----- .../directives/transformation/TrimTest.java | 9 ++++----- .../directives/transformation/UpperTest.java | 9 ++++----- .../io/cdap/wrangler/WranglerTransformTest.java | 4 ++-- 10 files changed, 48 insertions(+), 49 deletions(-) diff --git a/wrangler-core/src/test/java/io/cdap/directives/column/CopyTest.java b/wrangler-core/src/test/java/io/cdap/directives/column/CopyTest.java index 307cf9304..0e3418ff3 100644 --- a/wrangler-core/src/test/java/io/cdap/directives/column/CopyTest.java +++ b/wrangler-core/src/test/java/io/cdap/directives/column/CopyTest.java @@ -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} @@ -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"); @@ -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(), diff --git a/wrangler-core/src/test/java/io/cdap/directives/column/KeepTest.java b/wrangler-core/src/test/java/io/cdap/directives/column/KeepTest.java index 8904a852e..77cda9347 100644 --- a/wrangler-core/src/test/java/io/cdap/directives/column/KeepTest.java +++ b/wrangler-core/src/test/java/io/cdap/directives/column/KeepTest.java @@ -34,7 +34,6 @@ import java.util.List; import static io.cdap.RelationalDirectiveTest.runTransform; -import static org.mockito.ArgumentMatchers.any; /** * Tests {@link Keep} @@ -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"); @@ -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(), @@ -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) diff --git a/wrangler-core/src/test/java/io/cdap/directives/column/MergeTest.java b/wrangler-core/src/test/java/io/cdap/directives/column/MergeTest.java index 494256ce7..3597253ea 100644 --- a/wrangler-core/src/test/java/io/cdap/directives/column/MergeTest.java +++ b/wrangler-core/src/test/java/io/cdap/directives/column/MergeTest.java @@ -35,7 +35,6 @@ import java.util.List; import static io.cdap.RelationalDirectiveTest.runTransform; -import static org.mockito.ArgumentMatchers.any; /** * Tests {@link Merge} @@ -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"); @@ -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(), diff --git a/wrangler-core/src/test/java/io/cdap/directives/transformation/LeftTrimTest.java b/wrangler-core/src/test/java/io/cdap/directives/transformation/LeftTrimTest.java index b00116035..f325370f4 100644 --- a/wrangler-core/src/test/java/io/cdap/directives/transformation/LeftTrimTest.java +++ b/wrangler-core/src/test/java/io/cdap/directives/transformation/LeftTrimTest.java @@ -34,7 +34,6 @@ import java.util.List; import static io.cdap.RelationalDirectiveTest.runTransform; -import static org.mockito.ArgumentMatchers.any; /** * Tests {@link LeftTrim} @@ -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"); @@ -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(), diff --git a/wrangler-core/src/test/java/io/cdap/directives/transformation/LowerTest.java b/wrangler-core/src/test/java/io/cdap/directives/transformation/LowerTest.java index 797c5049d..b7fdce1de 100644 --- a/wrangler-core/src/test/java/io/cdap/directives/transformation/LowerTest.java +++ b/wrangler-core/src/test/java/io/cdap/directives/transformation/LowerTest.java @@ -34,7 +34,6 @@ import java.util.List; import static io.cdap.RelationalDirectiveTest.runTransform; -import static org.mockito.ArgumentMatchers.any; /** * Tests {@link Lower} @@ -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"); @@ -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(), diff --git a/wrangler-core/src/test/java/io/cdap/directives/transformation/RightTrimTest.java b/wrangler-core/src/test/java/io/cdap/directives/transformation/RightTrimTest.java index 9f0ef260a..43b06c121 100644 --- a/wrangler-core/src/test/java/io/cdap/directives/transformation/RightTrimTest.java +++ b/wrangler-core/src/test/java/io/cdap/directives/transformation/RightTrimTest.java @@ -34,7 +34,6 @@ import java.util.List; import static io.cdap.RelationalDirectiveTest.runTransform; -import static org.mockito.ArgumentMatchers.any; /** * Tests {@link RightTrim} @@ -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"); @@ -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(), diff --git a/wrangler-core/src/test/java/io/cdap/directives/transformation/TitleCaseTest.java b/wrangler-core/src/test/java/io/cdap/directives/transformation/TitleCaseTest.java index 2c62743ad..695b78080 100644 --- a/wrangler-core/src/test/java/io/cdap/directives/transformation/TitleCaseTest.java +++ b/wrangler-core/src/test/java/io/cdap/directives/transformation/TitleCaseTest.java @@ -34,7 +34,6 @@ import java.util.List; import static io.cdap.RelationalDirectiveTest.runTransform; -import static org.mockito.ArgumentMatchers.any; /** * Tests {@link TitleCase} @@ -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"); @@ -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(), diff --git a/wrangler-core/src/test/java/io/cdap/directives/transformation/TrimTest.java b/wrangler-core/src/test/java/io/cdap/directives/transformation/TrimTest.java index 05c19228e..476177c5f 100644 --- a/wrangler-core/src/test/java/io/cdap/directives/transformation/TrimTest.java +++ b/wrangler-core/src/test/java/io/cdap/directives/transformation/TrimTest.java @@ -34,7 +34,6 @@ import java.util.List; import static io.cdap.RelationalDirectiveTest.runTransform; -import static org.mockito.ArgumentMatchers.any; /** * Tests {@link Trim} @@ -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"); @@ -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(), diff --git a/wrangler-core/src/test/java/io/cdap/directives/transformation/UpperTest.java b/wrangler-core/src/test/java/io/cdap/directives/transformation/UpperTest.java index cabdf6769..1569d2eb9 100644 --- a/wrangler-core/src/test/java/io/cdap/directives/transformation/UpperTest.java +++ b/wrangler-core/src/test/java/io/cdap/directives/transformation/UpperTest.java @@ -34,7 +34,6 @@ import java.util.List; import static io.cdap.RelationalDirectiveTest.runTransform; -import static org.mockito.ArgumentMatchers.any; /** * Tests {@link Upper} @@ -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"); @@ -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(), diff --git a/wrangler-transform/src/test/java/io/cdap/wrangler/WranglerTransformTest.java b/wrangler-transform/src/test/java/io/cdap/wrangler/WranglerTransformTest.java index d53c808ab..4b6b261fd 100644 --- a/wrangler-transform/src/test/java/io/cdap/wrangler/WranglerTransformTest.java +++ b/wrangler-transform/src/test/java/io/cdap/wrangler/WranglerTransformTest.java @@ -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)); @@ -95,7 +95,7 @@ public static Relation runTransform(String[] recipe, GrammarBasedParser parser = new GrammarBasedParser("default", new MigrateToV2(recipe).migrate(), registry); List directives = parser.parse(); - for(Directive directive : directives) { + for (Directive directive : directives) { relation = directive.transform(relationalTranformContext, relation); } return relation; From a42222341c3c1a39b75982807c9fe5787b3a50a6 Mon Sep 17 00:00:00 2001 From: shrverma Date: Sat, 29 Jul 2023 17:15:50 +0000 Subject: [PATCH 4/5] Refactor code --- .../cdap/wrangler/WranglerTransformTest.java | 22 +------------------ 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/wrangler-transform/src/test/java/io/cdap/wrangler/WranglerTransformTest.java b/wrangler-transform/src/test/java/io/cdap/wrangler/WranglerTransformTest.java index 4b6b261fd..a40bd3cc7 100644 --- a/wrangler-transform/src/test/java/io/cdap/wrangler/WranglerTransformTest.java +++ b/wrangler-transform/src/test/java/io/cdap/wrangler/WranglerTransformTest.java @@ -79,25 +79,5 @@ public void invalidRelationTest () { Assert.assertEquals(invalidrelation.getValidationError(), wrangler.transform(null, relation).getValidationError()); } - - public static Relation runTransform(String[] recipe, - RelationalTranformContext relationalTranformContext, - Relation relation) - throws DirectiveParseException, RecipeException { - DirectiveRegistry registry; - registry = SystemDirectiveRegistry.INSTANCE; - try { - registry.reload("default"); - } catch (DirectiveLoadException e) { - throw new RuntimeException(e); - } - - GrammarBasedParser parser = new GrammarBasedParser("default", - new MigrateToV2(recipe).migrate(), registry); - List directives = parser.parse(); - for (Directive directive : directives) { - relation = directive.transform(relationalTranformContext, relation); - } - return relation; - } + } From 45ee8350710acaf65ce5fc2f2f1afe5e15ab5b1a Mon Sep 17 00:00:00 2001 From: shrverma Date: Thu, 10 Aug 2023 12:12:34 +0000 Subject: [PATCH 5/5] Refactor code --- .../cdap/MockRelationalTransformContext.java | 7 ----- .../io/cdap/directives/column/RenameTest.java | 11 ------- .../transformation/RightTrimTest.java | 16 +++------- .../cdap/wrangler/WranglerTransformTest.java | 31 ------------------- 4 files changed, 4 insertions(+), 61 deletions(-) diff --git a/wrangler-core/src/test/java/io/cdap/MockRelationalTransformContext.java b/wrangler-core/src/test/java/io/cdap/MockRelationalTransformContext.java index 295cdb43c..8fb066802 100644 --- a/wrangler-core/src/test/java/io/cdap/MockRelationalTransformContext.java +++ b/wrangler-core/src/test/java/io/cdap/MockRelationalTransformContext.java @@ -28,9 +28,6 @@ import java.util.Map; import java.util.Set; -/** - * Basic implementation of the {@link RelationalTranformContext} with single output port - */ public class MockRelationalTransformContext implements RelationalTranformContext { private Engine engine; private Map inputMap; @@ -39,7 +36,6 @@ public class MockRelationalTransformContext implements RelationalTranformContext private FeatureFlagsProvider featureFlagsProvider; private Relation outputRelation; - public MockRelationalTransformContext(Engine engine, Map inputMap, Map inputSchemas, @@ -92,9 +88,6 @@ public boolean isFeatureEnabled(String name) { return this.featureFlagsProvider.isFeatureEnabled(name); } - public Relation getOutputRelation() { - return outputRelation; - } public Collection getDefaultLanguageCapabilityList() { return Collections.singleton(StandardSQLCapabilities.POSTGRES); diff --git a/wrangler-core/src/test/java/io/cdap/directives/column/RenameTest.java b/wrangler-core/src/test/java/io/cdap/directives/column/RenameTest.java index 02691d3ee..1faec2db8 100644 --- a/wrangler-core/src/test/java/io/cdap/directives/column/RenameTest.java +++ b/wrangler-core/src/test/java/io/cdap/directives/column/RenameTest.java @@ -16,15 +16,7 @@ package io.cdap.directives.column; -import io.cdap.MockEngine; -import io.cdap.MockExpression; -import io.cdap.MockRelation; -import io.cdap.MockRelationalTransformContext; -import io.cdap.cdap.etl.api.relational.Engine; -import io.cdap.cdap.etl.api.relational.Relation; -import io.cdap.cdap.etl.api.relational.RelationalTranformContext; import io.cdap.wrangler.TestingRig; -import io.cdap.wrangler.api.DirectiveParseException; import io.cdap.wrangler.api.RecipeException; import io.cdap.wrangler.api.Row; import org.junit.Assert; @@ -33,9 +25,6 @@ import java.util.Arrays; import java.util.List; -import static io.cdap.RelationalDirectiveTest.runTransform; -import static org.mockito.ArgumentMatchers.any; - /** * Tests {@link Rename} */ diff --git a/wrangler-core/src/test/java/io/cdap/directives/transformation/RightTrimTest.java b/wrangler-core/src/test/java/io/cdap/directives/transformation/RightTrimTest.java index 43b06c121..993eb6a55 100644 --- a/wrangler-core/src/test/java/io/cdap/directives/transformation/RightTrimTest.java +++ b/wrangler-core/src/test/java/io/cdap/directives/transformation/RightTrimTest.java @@ -90,12 +90,8 @@ 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, null - , null - , - null - , null - ); + 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"); @@ -105,12 +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, null - , null - , - null - , null - ); + 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(), diff --git a/wrangler-transform/src/test/java/io/cdap/wrangler/WranglerTransformTest.java b/wrangler-transform/src/test/java/io/cdap/wrangler/WranglerTransformTest.java index a40bd3cc7..f843931c4 100644 --- a/wrangler-transform/src/test/java/io/cdap/wrangler/WranglerTransformTest.java +++ b/wrangler-transform/src/test/java/io/cdap/wrangler/WranglerTransformTest.java @@ -16,43 +16,12 @@ package io.cdap.wrangler; -import io.cdap.cdap.api.data.schema.Schema; -import io.cdap.cdap.etl.api.relational.Capability; -import io.cdap.cdap.etl.api.relational.Engine; -import io.cdap.cdap.etl.api.relational.Expression; -import io.cdap.cdap.etl.api.relational.ExpressionFactory; -import io.cdap.cdap.etl.api.relational.ExpressionFactoryType; import io.cdap.cdap.etl.api.relational.InvalidRelation; import io.cdap.cdap.etl.api.relational.Relation; -import io.cdap.cdap.etl.api.relational.RelationalTranformContext; -import io.cdap.directives.transformation.Lower; -import io.cdap.wrangler.api.Directive; -import io.cdap.wrangler.api.DirectiveLoadException; -import io.cdap.wrangler.api.DirectiveParseException; -import io.cdap.wrangler.api.RecipeException; -import io.cdap.wrangler.parser.GrammarBasedParser; -import io.cdap.wrangler.parser.MigrateToV2; -import io.cdap.wrangler.registry.DirectiveRegistry; -import io.cdap.wrangler.registry.SystemDirectiveRegistry; -import io.cdap.wrangler.utils.SqlExpressionGenerator; -import org.apache.poi.ss.formula.functions.T; import org.junit.Assert; import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.junit.MockitoJUnitRunner; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; -import java.util.Optional; -import java.util.Set; - -import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock;