From b09b897cf869b391f97c6fd5331d04c2946bb9a2 Mon Sep 17 00:00:00 2001 From: Jarek Jarcec Cecho Date: Tue, 27 Oct 2015 10:01:53 -0700 Subject: [PATCH] SQOOP-2641: SQOOP2: Fix test case failure for repository-postgresql (Colin Ma via Jarek Jarcec Cecho) --- repository/repository-postgresql/pom.xml | 6 ++++++ .../postgresql/PostgresqlTestCase.java | 21 +++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/repository/repository-postgresql/pom.xml b/repository/repository-postgresql/pom.xml index bb3859fe..6550bc28 100644 --- a/repository/repository-postgresql/pom.xml +++ b/repository/repository-postgresql/pom.xml @@ -70,6 +70,12 @@ limitations under the License. test-jar test + + + org.mockito + mockito-all + test + diff --git a/repository/repository-postgresql/src/test/java/org/apache/sqoop/integration/repository/postgresql/PostgresqlTestCase.java b/repository/repository-postgresql/src/test/java/org/apache/sqoop/integration/repository/postgresql/PostgresqlTestCase.java index fbaf5ddb..b8b0f526 100644 --- a/repository/repository-postgresql/src/test/java/org/apache/sqoop/integration/repository/postgresql/PostgresqlTestCase.java +++ b/repository/repository-postgresql/src/test/java/org/apache/sqoop/integration/repository/postgresql/PostgresqlTestCase.java @@ -21,12 +21,14 @@ import org.apache.sqoop.common.Direction; import org.apache.sqoop.common.test.db.DatabaseProvider; import org.apache.sqoop.common.test.db.PostgreSQLProvider; +import org.apache.sqoop.connector.ConnectorManager; import org.apache.sqoop.json.DriverBean; import org.apache.sqoop.model.*; import org.apache.sqoop.repository.postgresql.PostgresqlRepositoryHandler; import org.apache.sqoop.submission.SubmissionStatus; import org.apache.sqoop.submission.counter.CounterGroup; import org.apache.sqoop.submission.counter.Counters; +import org.mockito.Mockito; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; @@ -44,11 +46,17 @@ abstract public class PostgresqlTestCase { public static DatabaseProvider provider; public static PostgresqlTestUtils utils; public PostgresqlRepositoryHandler handler; + private ConnectorManager mockConnectorManager; @BeforeClass(alwaysRun = true) public void setUpClass() { provider = new PostgreSQLProvider(); utils = new PostgresqlTestUtils(provider); + + mockConnectorManager = Mockito.mock(ConnectorManager.class); + Mockito.when(mockConnectorManager.getConnectorConfigurable("A")).thenReturn(getConnector(true, true, "A", "org.apache.sqoop.test.A")); + Mockito.when(mockConnectorManager.getConnectorConfigurable("B")).thenReturn(getConnector(true, true, "B", "org.apache.sqoop.test.B")); + ConnectorManager.setInstance(mockConnectorManager); } @BeforeMethod(alwaysRun = true) @@ -165,4 +173,17 @@ protected List getConfigs(String configName1, String configName2) { return configs; } + + protected MConnector getConnector(boolean from, boolean to, String connectorName, String connectorClass) { + MFromConfig fromConfig = null; + MToConfig toConfig = null; + if (from) { + fromConfig = getFromConfig(); + } + if (to) { + toConfig = getToConfig(); + } + return new MConnector(connectorName, connectorClass, "1.0-test", getLinkConfig(), fromConfig, + toConfig); + } } \ No newline at end of file