aboutsummaryrefslogtreecommitdiffstats
path: root/dcae-analytics-cdap-plugins/src/test/java/org/openecomp/dcae/apod/analytics/cdap/plugins/utils
diff options
context:
space:
mode:
Diffstat (limited to 'dcae-analytics-cdap-plugins/src/test/java/org/openecomp/dcae/apod/analytics/cdap/plugins/utils')
-rw-r--r--dcae-analytics-cdap-plugins/src/test/java/org/openecomp/dcae/apod/analytics/cdap/plugins/utils/CDAPPluginUtilsTest.java171
-rw-r--r--dcae-analytics-cdap-plugins/src/test/java/org/openecomp/dcae/apod/analytics/cdap/plugins/utils/DMaaPSinkConfigMapperTest.java57
-rw-r--r--dcae-analytics-cdap-plugins/src/test/java/org/openecomp/dcae/apod/analytics/cdap/plugins/utils/DMaaPSourceConfigMapperTest.java64
3 files changed, 292 insertions, 0 deletions
diff --git a/dcae-analytics-cdap-plugins/src/test/java/org/openecomp/dcae/apod/analytics/cdap/plugins/utils/CDAPPluginUtilsTest.java b/dcae-analytics-cdap-plugins/src/test/java/org/openecomp/dcae/apod/analytics/cdap/plugins/utils/CDAPPluginUtilsTest.java
new file mode 100644
index 0000000..1483749
--- /dev/null
+++ b/dcae-analytics-cdap-plugins/src/test/java/org/openecomp/dcae/apod/analytics/cdap/plugins/utils/CDAPPluginUtilsTest.java
@@ -0,0 +1,171 @@
+/*
+ * ===============================LICENSE_START======================================
+ * dcae-analytics
+ * ================================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============================LICENSE_END===========================================
+ */
+
+package org.openecomp.dcae.apod.analytics.cdap.plugins.utils;
+
+import co.cask.cdap.api.data.format.StructuredRecord;
+import co.cask.cdap.api.data.schema.Schema;
+import org.junit.Test;
+import org.openecomp.dcae.apod.analytics.cdap.plugins.BaseAnalyticsCDAPPluginsUnitTest;
+import org.openecomp.dcae.apod.analytics.common.exception.DCAEAnalyticsRuntimeException;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+
+/**
+ * @author Rajiv Singla . Creation Date: 1/30/2017.
+ */
+public class CDAPPluginUtilsTest extends BaseAnalyticsCDAPPluginsUnitTest {
+
+
+ @Test
+ public void testValidateSchemaContainsFieldsWhenSchemaIsNotNull() throws Exception {
+ final Schema dMaaPMRSinkTestSchema = getDMaaPMRSinkTestSchema();
+ CDAPPluginUtils.validateSchemaContainsFields(dMaaPMRSinkTestSchema, "message");
+ }
+
+ @Test
+ public void testValidateSchemaContainsFieldsWhenInputSchemaIsNull() throws Exception {
+ CDAPPluginUtils.validateSchemaContainsFields(null, "message");
+ }
+
+ @Test
+ public void testCreateStructuredRecord() throws Exception {
+ final StructuredRecord testMessage = CDAPPluginUtils.createDMaaPMRResponseStructuredRecord("testMessage");
+ assertNotNull(testMessage);
+ }
+
+
+ @Test
+ public void testCreateOutputStructuredRecordBuilder() throws Exception {
+
+ final String messageFieldName = "message";
+ final String firstInputFieldName = "inputField1";
+ final String secondInputFieldName = "inputField2";
+
+
+ final Schema inputSchema = Schema.recordOf(
+ "inputSchema",
+ Schema.Field.of(messageFieldName, Schema.of(Schema.Type.STRING)),
+ Schema.Field.of(firstInputFieldName, Schema.nullableOf(Schema.of(Schema.Type.STRING))),
+ Schema.Field.of(secondInputFieldName, Schema.nullableOf(Schema.of(Schema.Type.STRING)))
+ );
+
+ final String addedFieldName = "addedField";
+ final Schema outputSchema = Schema.recordOf(
+ "outputSchema",
+ Schema.Field.of(messageFieldName, Schema.of(Schema.Type.STRING)),
+ Schema.Field.of(firstInputFieldName, Schema.nullableOf(Schema.of(Schema.Type.STRING))),
+ Schema.Field.of(addedFieldName, Schema.nullableOf(Schema.of(Schema.Type.STRING))) // added field
+ // missing second Input Field
+ );
+
+ // input structured record
+ final String messageFieldValue = "Message String";
+ final String firstFieldValue = "Input Field 1";
+ final String secondFieldValue = "Input Field 2";
+ final StructuredRecord inputSR = StructuredRecord.builder(inputSchema)
+ .set(messageFieldName, messageFieldValue)
+ .set(firstInputFieldName, firstFieldValue)
+ .set(secondInputFieldName, secondFieldValue)
+ .build();
+
+ final StructuredRecord.Builder outputStructuredRecordBuilder =
+ CDAPPluginUtils.createOutputStructuredRecordBuilder(outputSchema, inputSR);
+
+ final String addedFieldValue = "Added Field Value";
+ final StructuredRecord outputSR = outputStructuredRecordBuilder
+ .set(addedFieldName, addedFieldValue)
+ .build();
+
+ assertThat("Added Field field value copied correctly",
+ outputSR.get(addedFieldName).toString(), is(addedFieldValue));
+
+ assertThat("Output SR has message field copied correctly",
+ outputSR.get(messageFieldName).toString(), is(messageFieldValue));
+
+ assertThat("First Field value copied correctly",
+ outputSR.get(firstInputFieldName).toString(), is(firstFieldValue));
+
+ assertNull("Second Field value is null as output schema does not have the field",
+ outputSR.get(secondInputFieldName));
+
+ }
+
+
+ @Test
+ public void testAddFieldValueToStructuredRecordBuilder() throws Exception {
+
+ final String messageFieldName = "message";
+ final String firstInputFieldName = "inputField1";
+ final String addedFieldName = "addedField";
+ final String firstFieldValue = "Input Field 1";
+ final String addedFieldValue = "Added Field Value";
+ final Schema outputSchema = Schema.recordOf(
+ "outputSchema",
+ Schema.Field.of(messageFieldName, Schema.of(Schema.Type.STRING)),
+ Schema.Field.of(firstInputFieldName, Schema.nullableOf(Schema.of(Schema.Type.STRING))),
+ Schema.Field.of(addedFieldName, Schema.nullableOf(Schema.of(Schema.Type.STRING))) // added field
+ );
+
+ final StructuredRecord.Builder outputSRBuilder = StructuredRecord.builder(outputSchema)
+ .set(messageFieldName, "Some message")
+ .set(firstInputFieldName, firstFieldValue);
+
+ final StructuredRecord.Builder addedFieldSRBuilder = CDAPPluginUtils.addFieldValueToStructuredRecordBuilder(
+ outputSRBuilder, outputSchema, addedFieldName, addedFieldValue);
+
+ // Try adding field to output Structured record that is not in output schema
+ final String nonExistentFieldName = "fieldNotInOutputSchema";
+ final String nonExistentFieldValue = "Some Value";
+ final StructuredRecord outputSR = CDAPPluginUtils.addFieldValueToStructuredRecordBuilder(
+ addedFieldSRBuilder, outputSchema, nonExistentFieldName, nonExistentFieldValue).build();
+
+ assertThat("Output SR must contain added Field which is in output schema",
+ outputSR.get(addedFieldName).toString(), is(addedFieldValue));
+ assertNull("Output SR must not contain field that is not in output schema",
+ outputSR.get(nonExistentFieldName));
+
+ }
+
+ @Test(expected = DCAEAnalyticsRuntimeException.class)
+ public void testValidateSchemaFieldTypeWhenInputSchemaIsNotValidJson() throws Exception {
+ CDAPPluginUtils.validateSchemaFieldType("Invalid Schema", "field1", Schema.Type.STRING);
+ }
+
+ @Test(expected = DCAEAnalyticsRuntimeException.class)
+ public void testSetOutputSchemaWhenOutputSchemaIsNotValidJson() throws Exception {
+ CDAPPluginUtils.setOutputSchema(null, "Invalid output Schema");
+ }
+
+ @Test(expected = DCAEAnalyticsRuntimeException.class)
+ public void testExtractFieldMappingsWhenFieldMappingValueIsEmpty() throws Exception {
+ CDAPPluginUtils.extractFieldMappings("path1:,path2:value2");
+ }
+
+ @Test(expected = DCAEAnalyticsRuntimeException.class)
+ public void testExtractFieldMappingsWhenFieldMappingAreBlank() throws Exception {
+ CDAPPluginUtils.extractFieldMappings("path1: ,path2:value2");
+ }
+
+
+}
diff --git a/dcae-analytics-cdap-plugins/src/test/java/org/openecomp/dcae/apod/analytics/cdap/plugins/utils/DMaaPSinkConfigMapperTest.java b/dcae-analytics-cdap-plugins/src/test/java/org/openecomp/dcae/apod/analytics/cdap/plugins/utils/DMaaPSinkConfigMapperTest.java
new file mode 100644
index 0000000..bbd5c13
--- /dev/null
+++ b/dcae-analytics-cdap-plugins/src/test/java/org/openecomp/dcae/apod/analytics/cdap/plugins/utils/DMaaPSinkConfigMapperTest.java
@@ -0,0 +1,57 @@
+/*
+ * ===============================LICENSE_START======================================
+ * dcae-analytics
+ * ================================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============================LICENSE_END===========================================
+ */
+
+package org.openecomp.dcae.apod.analytics.cdap.plugins.utils;
+
+import org.apache.hadoop.conf.Configuration;
+import org.junit.Test;
+import org.openecomp.dcae.apod.analytics.cdap.plugins.BaseAnalyticsCDAPPluginsUnitTest;
+import org.openecomp.dcae.apod.analytics.dmaap.domain.config.DMaaPMRPublisherConfig;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+
+/**
+ * @author Rajiv Singla . Creation Date: 1/30/2017.
+ */
+public class DMaaPSinkConfigMapperTest extends BaseAnalyticsCDAPPluginsUnitTest {
+
+
+ @Test
+ public void testMapToPublisherConfig() throws Exception {
+
+ final Configuration testConfiguration = getTestConfiguration();
+ final DMaaPMRPublisherConfig publisherConfig = DMaaPSinkConfigMapper.map(testConfiguration);
+
+ assertNotNull(publisherConfig);
+ assertThat(publisherConfig.getHostName(), is(DMAAP_MR_SINK_PLUGIN_HOST_NAME));
+ assertThat(publisherConfig.getTopicName(), is(DMAAP_MR_SINK_PLUGIN_TOPIC_NAME));
+ assertThat(publisherConfig.getPortNumber(), is(DMAAP_MR_SINK_PLUGIN_PORT_NUMBER));
+ assertThat(publisherConfig.getProtocol(), is(DMAAP_MR_SINK_PLUGIN_PROTOCOL));
+ assertThat(publisherConfig.getUserName(), is(DMAAP_MR_SINK_PLUGIN_USERNAME));
+ assertThat(publisherConfig.getUserPassword(), is(DMAAP_MR_SINK_PLUGIN_PASSWORD));
+ assertThat(publisherConfig.getContentType(), is(DMAAP_MR_SINK_PLUGIN_CONTENT_TYPE));
+ assertThat(publisherConfig.getMaxBatchSize(), is(DMAAP_MR_SINK_PLUGIN_MAX_BATCH_SIZE));
+ assertThat(publisherConfig.getMaxRecoveryQueueSize(), is(DMAAP_MR_SINK_PLUGIN_MAX_RECOVERY_QUEUE_SIZE));
+
+ }
+
+}
diff --git a/dcae-analytics-cdap-plugins/src/test/java/org/openecomp/dcae/apod/analytics/cdap/plugins/utils/DMaaPSourceConfigMapperTest.java b/dcae-analytics-cdap-plugins/src/test/java/org/openecomp/dcae/apod/analytics/cdap/plugins/utils/DMaaPSourceConfigMapperTest.java
new file mode 100644
index 0000000..4f4d751
--- /dev/null
+++ b/dcae-analytics-cdap-plugins/src/test/java/org/openecomp/dcae/apod/analytics/cdap/plugins/utils/DMaaPSourceConfigMapperTest.java
@@ -0,0 +1,64 @@
+/*
+ * ===============================LICENSE_START======================================
+ * dcae-analytics
+ * ================================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * 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.
+ * ============================LICENSE_END===========================================
+ */
+
+package org.openecomp.dcae.apod.analytics.cdap.plugins.utils;
+
+import org.junit.Test;
+import org.openecomp.dcae.apod.analytics.cdap.plugins.BaseAnalyticsCDAPPluginsUnitTest;
+import org.openecomp.dcae.apod.analytics.cdap.plugins.domain.config.dmaap.TestDMaaPMRSourcePluginConfig;
+import org.openecomp.dcae.apod.analytics.dmaap.domain.config.DMaaPMRSubscriberConfig;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThat;
+
+/**
+ * @author Rajiv Singla . Creation Date: 1/24/2017.
+ */
+public class DMaaPSourceConfigMapperTest extends BaseAnalyticsCDAPPluginsUnitTest {
+
+ @Test
+ public void testMapToSubscriberConfig() throws Exception {
+
+ final TestDMaaPMRSourcePluginConfig testDMaaPMRSourcePluginConfig = getTestDMaaPMRSourcePluginConfig();
+ final DMaaPMRSubscriberConfig subscriberConfig = DMaaPSourceConfigMapper.map(testDMaaPMRSourcePluginConfig);
+
+ assertNotNull(subscriberConfig);
+ assertThat(subscriberConfig.getHostName(), is(DMAAP_MR_SOURCE_PLUGIN_HOST_NAME));
+ assertThat(subscriberConfig.getTopicName(), is(DMAAP_MR_SOURCE_PLUGIN_TOPIC_NAME));
+ assertThat(subscriberConfig.getPortNumber(), is(DMAAP_MR_SOURCE_PLUGIN_PORT_NUMBER));
+ assertThat(subscriberConfig.getProtocol(), is(DMAAP_MR_SOURCE_PLUGIN_PROTOCOL));
+ assertThat(subscriberConfig.getUserName(), is(DMAAP_MR_SOURCE_PLUGIN_USERNAME));
+ assertThat(subscriberConfig.getUserPassword(), is(DMAAP_MR_SOURCE_PLUGIN_PASSWORD));
+ assertThat(subscriberConfig.getContentType(), is(DMAAP_MR_SOURCE_PLUGIN_CONTENT_TYPE));
+ assertThat(subscriberConfig.getConsumerGroup(), is(DMAAP_MR_SOURCE_PLUGIN_CONSUMER_GROUP));
+ assertThat(subscriberConfig.getConsumerId(), is(DMAAP_MR_SOURCE_PLUGIN_CONSUMER_ID));
+ assertThat(subscriberConfig.getMessageLimit(), is(DMAAP_MR_SOURCE_PLUGIN_MESSAGE_LIMIT));
+ assertThat(subscriberConfig.getTimeoutMS(), is(DMAAP_MR_SOURCE_PLUGIN_TIMEOUT));
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void testMapToSubscriberConfigWhenSubscriberHostNameIsEmpty() throws Exception {
+ final TestDMaaPMRSourcePluginConfig testDMaaPMRSourcePluginConfig = getTestDMaaPMRSourcePluginConfig();
+ testDMaaPMRSourcePluginConfig.setHostName(null);
+ DMaaPSourceConfigMapper.map(testDMaaPMRSourcePluginConfig);
+
+ }
+}