Skip to content

Commit

Permalink
[BEAM-14048] Use ServiceNow CDAP dependency from Maven central
Browse files Browse the repository at this point in the history
  • Loading branch information
Amar3tto committed May 4, 2022
1 parent 970fe79 commit f440da9
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ class BeamModulePlugin implements Plugin<Project> {
cdap_api : "io.cdap.cdap:cdap-api:$cdap_version",
cdap_common : "io.cdap.cdap:cdap-common:$cdap_version",
cdap_etl_api : "io.cdap.cdap:cdap-etl-api:$cdap_version",
cdap_plugin_service_now : "io.cdap.plugin:servicenow-plugins:1.1.0",
checker_qual : "org.checkerframework:checker-qual:$checkerframework_version",
classgraph : "io.github.classgraph:classgraph:$classgraph_version",
commons_codec : "commons-codec:commons-codec:1.15",
Expand Down
8 changes: 1 addition & 7 deletions sdks/java/io/cdap/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@ interface for integration with CDAP plugins."""
* for details.
*/

allprojects {
repositories {
maven { url 'https://jitpack.io' }
}
}

dependencies {
implementation library.java.guava
implementation library.java.cdap_api
Expand All @@ -51,7 +45,7 @@ dependencies {
implementation library.java.jackson_databind
implementation library.java.slf4j_api
implementation project(path: ":sdks:java:core", configuration: "shadow")
testImplementation "com.github.data-integrations:salesforce:v1.3.9"
testImplementation library.java.cdap_plugin_service_now
testImplementation library.java.cdap_etl_api
testImplementation library.java.vendored_guava_26_0_jre
testImplementation library.java.junit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;

import io.cdap.plugin.salesforce.SalesforceConstants;
import io.cdap.plugin.salesforce.plugin.source.batch.SalesforceSourceConfig;
import io.cdap.plugin.salesforce.plugin.source.batch.util.SalesforceSourceConstants;
import io.cdap.plugin.servicenow.source.ServiceNowSourceConfig;
import io.cdap.plugin.servicenow.source.util.ServiceNowConstants;
import java.io.File;
import java.util.Map;
import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableMap;
Expand All @@ -39,43 +38,46 @@ public class ConfigWrapperTest {

private static final Logger LOG = LoggerFactory.getLogger(ConfigWrapperTest.class);

private static final ImmutableMap<String, Object> TEST_SALESFORCE_PARAMS_MAP =
private static final ImmutableMap<String, Object> TEST_SERVICE_NOW_PARAMS_MAP =
ImmutableMap.<String, java.lang.Object>builder()
.put("sObjectName", "sObject")
.put("datetimeAfter", "datetime")
.put("consumerKey", "key")
.put("consumerSecret", "secret")
.put("username", "user")
.put("password", "password")
.put("loginUrl", "https://www.google.com")
.put(ServiceNowConstants.PROPERTY_CLIENT_ID, "clientId")
.put(ServiceNowConstants.PROPERTY_CLIENT_SECRET, "clientSecret")
.put(ServiceNowConstants.PROPERTY_API_ENDPOINT, "https://www.google.com")
.put(ServiceNowConstants.PROPERTY_QUERY_MODE, "Table")
.put(ServiceNowConstants.PROPERTY_USER, "user")
.put(ServiceNowConstants.PROPERTY_PASSWORD, "password")
.put(ServiceNowConstants.PROPERTY_TABLE_NAME, "tableName")
.put(ServiceNowConstants.PROPERTY_VALUE_TYPE, "Actual")
.put("referenceName", "oldReference")
.build();
private static final String TEST_SALESFORCE_PARAMS_JSON_STRING =

private static final String TEST_SERVICE_NOW_PARAMS_JSON_STRING =
"{\n"
+ "\"sObjectName\": \"sObject\",\n"
+ "\"datetimeAfter\": \"datetime\",\n"
+ "\"consumerKey\": \"key\",\n"
+ "\"consumerSecret\": \"secret\",\n"
+ "\"username\": \"user\",\n"
+ "\"clientId\": \"clientId\",\n"
+ "\"clientSecret\": \"clientSecret\",\n"
+ "\"restApiEndpoint\": \"https://www.google.com\",\n"
+ "\"queryMode\": \"Table\",\n"
+ "\"user\": \"user\",\n"
+ "\"password\": \"password\",\n"
+ "\"loginUrl\": \"https://www.google.com\",\n"
+ "\"referenceName\": \"reference\"\n"
+ "\"tableName\": \"tableName\",\n"
+ "\"valueType\": \"Actual\",\n"
+ "\"referenceName\": \"oldReference\"\n"
+ "}";
private static final String SALESFORCE_TEST_PARAMS_JSON =
"src/test/resources/salesforce_test_params.json";
private static final String SERVICE_NOW_TEST_PARAMS_JSON =
"src/test/resources/service_now_test_params.json";
public static final String REFERENCE_NAME_PARAM_NAME = "referenceName";

@Test
public void testBuildingPluginConfigFromParamsMap() {
try {
String newReferenceName = "new reference name";
SalesforceSourceConfig config =
new ConfigWrapper<>(SalesforceSourceConfig.class)
.withParams(TEST_SALESFORCE_PARAMS_MAP)
ServiceNowSourceConfig config =
new ConfigWrapper<>(ServiceNowSourceConfig.class)
.withParams(TEST_SERVICE_NOW_PARAMS_MAP)
.setParam("referenceName", newReferenceName)
.build();
assertNotNull(config);
validateSalesforceConfigObject(TEST_SALESFORCE_PARAMS_MAP, config);
validateServiceNowConfigObject(TEST_SERVICE_NOW_PARAMS_MAP, config);
assertEquals(newReferenceName, config.referenceName);
} catch (Exception e) {
LOG.error("Error occurred while building the config object", e);
Expand All @@ -87,13 +89,13 @@ public void testBuildingPluginConfigFromParamsMap() {
public void testBuildingPluginConfigFromJsonFile() {
try {
String newReferenceName = "new reference name";
SalesforceSourceConfig config =
new ConfigWrapper<>(SalesforceSourceConfig.class)
.fromJsonFile(new File(SALESFORCE_TEST_PARAMS_JSON))
ServiceNowSourceConfig config =
new ConfigWrapper<>(ServiceNowSourceConfig.class)
.fromJsonFile(new File(SERVICE_NOW_TEST_PARAMS_JSON))
.setParam(REFERENCE_NAME_PARAM_NAME, newReferenceName)
.build();
assertNotNull(config);
validateSalesforceConfigObject(TEST_SALESFORCE_PARAMS_MAP, config);
validateServiceNowConfigObject(TEST_SERVICE_NOW_PARAMS_MAP, config);
assertEquals(newReferenceName, config.referenceName);
} catch (Exception e) {
LOG.error("Error occurred while building the config object", e);
Expand All @@ -105,31 +107,33 @@ public void testBuildingPluginConfigFromJsonFile() {
public void testBuildingPluginConfigFromJsonString() {
try {
String newReferenceName = "new reference name";
SalesforceSourceConfig config =
new ConfigWrapper<>(SalesforceSourceConfig.class)
.fromJsonString(TEST_SALESFORCE_PARAMS_JSON_STRING)
ServiceNowSourceConfig config =
new ConfigWrapper<>(ServiceNowSourceConfig.class)
.fromJsonString(TEST_SERVICE_NOW_PARAMS_JSON_STRING)
.setParam(REFERENCE_NAME_PARAM_NAME, newReferenceName)
.build();
assertNotNull(config);
validateSalesforceConfigObject(TEST_SALESFORCE_PARAMS_MAP, config);
validateServiceNowConfigObject(TEST_SERVICE_NOW_PARAMS_MAP, config);
assertEquals(newReferenceName, config.referenceName);
} catch (Exception e) {
LOG.error("Error occurred while building the config object", e);
fail();
}
}

private static void validateSalesforceConfigObject(
Map<String, Object> params, SalesforceSourceConfig config) {
private static void validateServiceNowConfigObject(
Map<String, Object> params, ServiceNowSourceConfig config) {
assertEquals(params.get(ServiceNowConstants.PROPERTY_CLIENT_ID), config.getClientId());
assertEquals(params.get(ServiceNowConstants.PROPERTY_CLIENT_SECRET), config.getClientSecret());
assertEquals(
params.get(SalesforceSourceConstants.PROPERTY_DATETIME_AFTER), config.getDatetimeAfter());
params.get(ServiceNowConstants.PROPERTY_API_ENDPOINT), config.getRestApiEndpoint());
assertEquals(
params.get(SalesforceSourceConstants.PROPERTY_SOBJECT_NAME), config.getSObjectName());
assertEquals(params.get(SalesforceConstants.PROPERTY_CONSUMER_KEY), config.getConsumerKey());
params.get(ServiceNowConstants.PROPERTY_QUERY_MODE), config.getQueryMode().getValue());
assertEquals(params.get(ServiceNowConstants.PROPERTY_USER), config.getUser());
assertEquals(params.get(ServiceNowConstants.PROPERTY_PASSWORD), config.getPassword());
assertNotNull(config.getValueType());
assertEquals(
params.get(SalesforceConstants.PROPERTY_CONSUMER_SECRET), config.getConsumerSecret());
assertEquals(params.get(SalesforceConstants.PROPERTY_USERNAME), config.getUsername());
assertEquals(params.get(SalesforceConstants.PROPERTY_PASSWORD), config.getPassword());
assertEquals(params.get(SalesforceConstants.PROPERTY_LOGIN_URL), config.getLoginUrl());
params.get(ServiceNowConstants.PROPERTY_VALUE_TYPE), config.getValueType().getValueType());
assertEquals(params.get(ServiceNowConstants.PROPERTY_TABLE_NAME), config.getTableName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;

import io.cdap.plugin.salesforce.SalesforceConstants;
import io.cdap.plugin.salesforce.plugin.source.batch.SalesforceSourceConfig;
import io.cdap.plugin.salesforce.plugin.source.batch.util.SalesforceSourceConstants;
import io.cdap.plugin.servicenow.source.ServiceNowSourceConfig;
import io.cdap.plugin.servicenow.source.util.ServiceNowConstants;
import java.util.HashMap;
import java.util.Map;
import org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableMap;
Expand All @@ -40,26 +39,27 @@ public class PluginConfigInstantiationUtilsTest {
private static final Logger LOG =
LoggerFactory.getLogger(PluginConfigInstantiationUtilsTest.class);

private static final ImmutableMap<String, Object> TEST_SALESFORCE_PARAMS_MAP =
private static final ImmutableMap<String, Object> TEST_SERVICE_NOW_PARAMS_MAP =
ImmutableMap.<String, java.lang.Object>builder()
.put("sObjectName", "sObject")
.put("datetimeAfter", "datetime")
.put("consumerKey", "key")
.put("consumerSecret", "secret")
.put("username", "user")
.put("password", "password")
.put("loginUrl", "https://www.google.com")
.put(ServiceNowConstants.PROPERTY_CLIENT_ID, "clientId")
.put(ServiceNowConstants.PROPERTY_CLIENT_SECRET, "clientSecret")
.put(ServiceNowConstants.PROPERTY_API_ENDPOINT, "https://www.google.com")
.put(ServiceNowConstants.PROPERTY_QUERY_MODE, "Table")
.put(ServiceNowConstants.PROPERTY_USER, "user")
.put(ServiceNowConstants.PROPERTY_PASSWORD, "password")
.put(ServiceNowConstants.PROPERTY_TABLE_NAME, "tableName")
.put(ServiceNowConstants.PROPERTY_VALUE_TYPE, "Actual")
.put("referenceName", "oldReference")
.build();

@Test
public void testBuildingPluginConfigFromParamsMap() {
try {
SalesforceSourceConfig config =
ServiceNowSourceConfig config =
PluginConfigInstantiationUtils.getPluginConfig(
TEST_SALESFORCE_PARAMS_MAP, SalesforceSourceConfig.class);
TEST_SERVICE_NOW_PARAMS_MAP, ServiceNowSourceConfig.class);
assertNotNull(config);
validateSalesforceConfigObject(TEST_SALESFORCE_PARAMS_MAP, config);
validateServiceNowConfigObject(TEST_SERVICE_NOW_PARAMS_MAP, config);
} catch (Exception e) {
LOG.error("Error occurred while building the config object", e);
fail();
Expand All @@ -69,9 +69,9 @@ public void testBuildingPluginConfigFromParamsMap() {
@Test
public void testBuildingPluginConfigFromEmptyParamsMap() {
try {
SalesforceSourceConfig config =
ServiceNowSourceConfig config =
PluginConfigInstantiationUtils.getPluginConfig(
new HashMap<>(), SalesforceSourceConfig.class);
new HashMap<>(), ServiceNowSourceConfig.class);
assertNotNull(config);
} catch (Exception e) {
LOG.error("Error occurred while building the config object", e);
Expand All @@ -82,24 +82,26 @@ public void testBuildingPluginConfigFromEmptyParamsMap() {
@Test
public void testBuildingPluginConfigFromNullClassFail() {
try {
PluginConfigInstantiationUtils.getPluginConfig(TEST_SALESFORCE_PARAMS_MAP, null);
PluginConfigInstantiationUtils.getPluginConfig(TEST_SERVICE_NOW_PARAMS_MAP, null);
fail();
} catch (IllegalArgumentException e) {
assertEquals("Config class must be not null!", e.getMessage());
}
}

private static void validateSalesforceConfigObject(
Map<String, Object> params, SalesforceSourceConfig config) {
private static void validateServiceNowConfigObject(
Map<String, Object> params, ServiceNowSourceConfig config) {
assertEquals(params.get(ServiceNowConstants.PROPERTY_CLIENT_ID), config.getClientId());
assertEquals(params.get(ServiceNowConstants.PROPERTY_CLIENT_SECRET), config.getClientSecret());
assertEquals(
params.get(SalesforceSourceConstants.PROPERTY_DATETIME_AFTER), config.getDatetimeAfter());
params.get(ServiceNowConstants.PROPERTY_API_ENDPOINT), config.getRestApiEndpoint());
assertEquals(
params.get(SalesforceSourceConstants.PROPERTY_SOBJECT_NAME), config.getSObjectName());
assertEquals(params.get(SalesforceConstants.PROPERTY_CONSUMER_KEY), config.getConsumerKey());
params.get(ServiceNowConstants.PROPERTY_QUERY_MODE), config.getQueryMode().getValue());
assertEquals(params.get(ServiceNowConstants.PROPERTY_USER), config.getUser());
assertEquals(params.get(ServiceNowConstants.PROPERTY_PASSWORD), config.getPassword());
assertNotNull(config.getValueType());
assertEquals(
params.get(SalesforceConstants.PROPERTY_CONSUMER_SECRET), config.getConsumerSecret());
assertEquals(params.get(SalesforceConstants.PROPERTY_USERNAME), config.getUsername());
assertEquals(params.get(SalesforceConstants.PROPERTY_PASSWORD), config.getPassword());
assertEquals(params.get(SalesforceConstants.PROPERTY_LOGIN_URL), config.getLoginUrl());
params.get(ServiceNowConstants.PROPERTY_VALUE_TYPE), config.getValueType().getValueType());
assertEquals(params.get(ServiceNowConstants.PROPERTY_TABLE_NAME), config.getTableName());
}
}
10 changes: 0 additions & 10 deletions sdks/java/io/cdap/src/test/resources/salesforce_test_params.json

This file was deleted.

11 changes: 11 additions & 0 deletions sdks/java/io/cdap/src/test/resources/service_now_test_params.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"clientId": "clientId",
"clientSecret": "clientSecret",
"restApiEndpoint": "https://www.google.com",
"queryMode": "Table",
"user": "user",
"password": "password",
"tableName": "tableName",
"valueType": "Actual",
"referenceName": "oldReference"
}

0 comments on commit f440da9

Please sign in to comment.