diff options
Diffstat (limited to 'dcae-analytics-cdap-plugins/src/test/java/org/openecomp/dcae/apod/analytics/cdap/plugins/batch/sink')
4 files changed, 309 insertions, 308 deletions
diff --git a/dcae-analytics-cdap-plugins/src/test/java/org/openecomp/dcae/apod/analytics/cdap/plugins/batch/sink/dmaap/DMaaPMROutputFormatProviderTest.java b/dcae-analytics-cdap-plugins/src/test/java/org/openecomp/dcae/apod/analytics/cdap/plugins/batch/sink/dmaap/DMaaPMROutputFormatProviderTest.java index 71ce4d8..beeb19b 100644 --- a/dcae-analytics-cdap-plugins/src/test/java/org/openecomp/dcae/apod/analytics/cdap/plugins/batch/sink/dmaap/DMaaPMROutputFormatProviderTest.java +++ b/dcae-analytics-cdap-plugins/src/test/java/org/openecomp/dcae/apod/analytics/cdap/plugins/batch/sink/dmaap/DMaaPMROutputFormatProviderTest.java @@ -1,77 +1,77 @@ -/* - * ===============================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.batch.sink.dmaap; - -import org.junit.Test; -import org.openecomp.dcae.apod.analytics.cdap.common.CDAPPluginConstants.DMaaPMRSinkHadoopConfigFields; -import org.openecomp.dcae.apod.analytics.cdap.plugins.BaseAnalyticsCDAPPluginsUnitTest; -import org.openecomp.dcae.apod.analytics.cdap.plugins.domain.config.dmaap.TestDMaaPMRSinkPluginConfig; -import org.openecomp.dcae.apod.analytics.common.AnalyticsConstants; - -import java.util.Map; - -import static org.junit.Assert.assertTrue; - -/** - * @author Rajiv Singla . Creation Date: 1/30/2017. - */ -public class DMaaPMROutputFormatProviderTest extends BaseAnalyticsCDAPPluginsUnitTest { - - - @Test - public void testDMaaPMROutputFormatProviderWhenConfigIsMissingNonRequiredValues() throws Exception { - final TestDMaaPMRSinkPluginConfig sinkPluginConfig = new TestDMaaPMRSinkPluginConfig(); - sinkPluginConfig.setHostName(DMAAP_MR_SINK_PLUGIN_HOST_NAME); - sinkPluginConfig.setTopicName(DMAAP_MR_SINK_PLUGIN_TOPIC_NAME); - final DMaaPMROutputFormatProvider dMaaPMROutputFormatProvider = - new DMaaPMROutputFormatProvider(sinkPluginConfig); - final Map<String, String> outputFormatConfiguration = - dMaaPMROutputFormatProvider.getOutputFormatConfiguration(); - final String hostName = outputFormatConfiguration.get(DMaaPMRSinkHadoopConfigFields.HOST_NAME); - assertTrue(hostName.equals(DMAAP_MR_SINK_PLUGIN_HOST_NAME)); - final String topicName = outputFormatConfiguration.get(DMaaPMRSinkHadoopConfigFields.TOPIC_NAME); - assertTrue(topicName.equals(DMAAP_MR_SINK_PLUGIN_TOPIC_NAME)); - final String portNumber = outputFormatConfiguration.get(DMaaPMRSinkHadoopConfigFields.PORT_NUMBER); - assertTrue(portNumber.equals(AnalyticsConstants.DEFAULT_PORT_NUMBER.toString())); - final String protocol = outputFormatConfiguration.get(DMaaPMRSinkHadoopConfigFields.PROTOCOL); - assertTrue(protocol.equals(AnalyticsConstants.DEFAULT_PROTOCOL)); - } - - @Test - public void testGetOutputFormatClassName() throws Exception { - final DMaaPMROutputFormatProvider dMaaPMROutputFormatProvider = - new DMaaPMROutputFormatProvider(getTestDMaaPMRSinkPluginConfig()); - final String outputFormatClassName = dMaaPMROutputFormatProvider.getOutputFormatClassName(); - assertTrue(outputFormatClassName.equals(DMaaPMROutputFormat.class.getName())); - } - - @Test - public void testGetOutputFormatConfiguration() throws Exception { - final TestDMaaPMRSinkPluginConfig testDMaaPMRSinkPluginConfig = getTestDMaaPMRSinkPluginConfig(); - final DMaaPMROutputFormatProvider dMaaPMROutputFormatProvider = - new DMaaPMROutputFormatProvider(testDMaaPMRSinkPluginConfig); - final Map<String, String> outputFormatConfiguration = - dMaaPMROutputFormatProvider.getOutputFormatConfiguration(); - assertTrue(outputFormatConfiguration.size() == 9); - - } - -} +/*
+ * ===============================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.batch.sink.dmaap;
+
+import org.junit.Test;
+import org.openecomp.dcae.apod.analytics.cdap.common.CDAPPluginConstants.DMaaPMRSinkHadoopConfigFields;
+import org.openecomp.dcae.apod.analytics.cdap.plugins.BaseAnalyticsCDAPPluginsUnitTest;
+import org.openecomp.dcae.apod.analytics.cdap.plugins.domain.config.dmaap.TestDMaaPMRSinkPluginConfig;
+import org.openecomp.dcae.apod.analytics.common.AnalyticsConstants;
+
+import java.util.Map;
+
+import static org.junit.Assert.assertTrue;
+
+/**
+ * @author Rajiv Singla . Creation Date: 1/30/2017.
+ */
+public class DMaaPMROutputFormatProviderTest extends BaseAnalyticsCDAPPluginsUnitTest {
+
+
+ @Test
+ public void testDMaaPMROutputFormatProviderWhenConfigIsMissingNonRequiredValues() throws Exception {
+ final TestDMaaPMRSinkPluginConfig sinkPluginConfig = new TestDMaaPMRSinkPluginConfig();
+ sinkPluginConfig.setHostName(DMAAP_MR_SINK_PLUGIN_HOST_NAME);
+ sinkPluginConfig.setTopicName(DMAAP_MR_SINK_PLUGIN_TOPIC_NAME);
+ final DMaaPMROutputFormatProvider dMaaPMROutputFormatProvider =
+ new DMaaPMROutputFormatProvider(sinkPluginConfig);
+ final Map<String, String> outputFormatConfiguration =
+ dMaaPMROutputFormatProvider.getOutputFormatConfiguration();
+ final String hostName = outputFormatConfiguration.get(DMaaPMRSinkHadoopConfigFields.HOST_NAME);
+ assertTrue(hostName.equals(DMAAP_MR_SINK_PLUGIN_HOST_NAME));
+ final String topicName = outputFormatConfiguration.get(DMaaPMRSinkHadoopConfigFields.TOPIC_NAME);
+ assertTrue(topicName.equals(DMAAP_MR_SINK_PLUGIN_TOPIC_NAME));
+ final String portNumber = outputFormatConfiguration.get(DMaaPMRSinkHadoopConfigFields.PORT_NUMBER);
+ assertTrue(portNumber.equals(AnalyticsConstants.DEFAULT_PORT_NUMBER.toString()));
+ final String protocol = outputFormatConfiguration.get(DMaaPMRSinkHadoopConfigFields.PROTOCOL);
+ assertTrue(protocol.equals(AnalyticsConstants.DEFAULT_PROTOCOL));
+ }
+
+ @Test
+ public void testGetOutputFormatClassName() throws Exception {
+ final DMaaPMROutputFormatProvider dMaaPMROutputFormatProvider =
+ new DMaaPMROutputFormatProvider(getTestDMaaPMRSinkPluginConfig());
+ final String outputFormatClassName = dMaaPMROutputFormatProvider.getOutputFormatClassName();
+ assertTrue(outputFormatClassName.equals(DMaaPMROutputFormat.class.getName()));
+ }
+
+ @Test
+ public void testGetOutputFormatConfiguration() throws Exception {
+ final TestDMaaPMRSinkPluginConfig testDMaaPMRSinkPluginConfig = getTestDMaaPMRSinkPluginConfig();
+ final DMaaPMROutputFormatProvider dMaaPMROutputFormatProvider =
+ new DMaaPMROutputFormatProvider(testDMaaPMRSinkPluginConfig);
+ final Map<String, String> outputFormatConfiguration =
+ dMaaPMROutputFormatProvider.getOutputFormatConfiguration();
+ assertTrue(outputFormatConfiguration.size() == 9);
+
+ }
+
+}
diff --git a/dcae-analytics-cdap-plugins/src/test/java/org/openecomp/dcae/apod/analytics/cdap/plugins/batch/sink/dmaap/DMaaPMROutputFormatTest.java b/dcae-analytics-cdap-plugins/src/test/java/org/openecomp/dcae/apod/analytics/cdap/plugins/batch/sink/dmaap/DMaaPMROutputFormatTest.java index f20e94e..97e16c3 100644 --- a/dcae-analytics-cdap-plugins/src/test/java/org/openecomp/dcae/apod/analytics/cdap/plugins/batch/sink/dmaap/DMaaPMROutputFormatTest.java +++ b/dcae-analytics-cdap-plugins/src/test/java/org/openecomp/dcae/apod/analytics/cdap/plugins/batch/sink/dmaap/DMaaPMROutputFormatTest.java @@ -1,75 +1,75 @@ -/* - * ===============================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.batch.sink.dmaap; - -import org.apache.hadoop.io.NullWritable; -import org.apache.hadoop.mapreduce.JobContext; -import org.apache.hadoop.mapreduce.OutputCommitter; -import org.apache.hadoop.mapreduce.RecordWriter; -import org.apache.hadoop.mapreduce.TaskAttemptContext; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mockito; -import org.openecomp.dcae.apod.analytics.cdap.plugins.BaseAnalyticsCDAPPluginsUnitTest; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.when; - -/** - * @author Rajiv Singla . Creation Date: 1/30/2017. - */ -public class DMaaPMROutputFormatTest extends BaseAnalyticsCDAPPluginsUnitTest { - - private DMaaPMROutputFormat dMaaPMROutputFormat; - - @Before - public void before() { - dMaaPMROutputFormat = new DMaaPMROutputFormat(); - } - - @Test - public void testGetRecordWriter() throws Exception { - final TaskAttemptContext taskAttemptContext = Mockito.mock(TaskAttemptContext.class); - when(taskAttemptContext.getConfiguration()).thenReturn(getTestConfiguration()); - final RecordWriter<String, NullWritable> recordWriter = dMaaPMROutputFormat.getRecordWriter(taskAttemptContext); - assertNotNull(recordWriter); - final JobContext jobContext = Mockito.mock(JobContext.class); - dMaaPMROutputFormat.checkOutputSpecs(jobContext); - } - - @Test - public void testGetOutputCommitter() throws Exception { - final TaskAttemptContext taskAttemptContext = Mockito.mock(TaskAttemptContext.class); - final OutputCommitter outputCommitter = dMaaPMROutputFormat.getOutputCommitter(taskAttemptContext); - assertTrue(outputCommitter.getClass().equals(DMaaPMROutputFormat.NoOpOutputCommitter.class)); - final JobContext jobContext = Mockito.mock(JobContext.class); - outputCommitter.setupJob(jobContext); - outputCommitter.setupTask(taskAttemptContext); - assertFalse(outputCommitter.needsTaskCommit(taskAttemptContext)); - outputCommitter.commitJob(jobContext); - outputCommitter.commitTask(taskAttemptContext); - outputCommitter.abortTask(taskAttemptContext); - - } - -} +/*
+ * ===============================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.batch.sink.dmaap;
+
+import org.apache.hadoop.io.NullWritable;
+import org.apache.hadoop.mapreduce.JobContext;
+import org.apache.hadoop.mapreduce.OutputCommitter;
+import org.apache.hadoop.mapreduce.RecordWriter;
+import org.apache.hadoop.mapreduce.TaskAttemptContext;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.openecomp.dcae.apod.analytics.cdap.plugins.BaseAnalyticsCDAPPluginsUnitTest;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.when;
+
+/**
+ * @author Rajiv Singla . Creation Date: 1/30/2017.
+ */
+public class DMaaPMROutputFormatTest extends BaseAnalyticsCDAPPluginsUnitTest {
+
+ private DMaaPMROutputFormat dMaaPMROutputFormat;
+
+ @Before
+ public void before() {
+ dMaaPMROutputFormat = new DMaaPMROutputFormat();
+ }
+
+ @Test
+ public void testGetRecordWriter() throws Exception {
+ final TaskAttemptContext taskAttemptContext = Mockito.mock(TaskAttemptContext.class);
+ when(taskAttemptContext.getConfiguration()).thenReturn(getTestConfiguration());
+ final RecordWriter<String, NullWritable> recordWriter = dMaaPMROutputFormat.getRecordWriter(taskAttemptContext);
+ assertNotNull(recordWriter);
+ final JobContext jobContext = Mockito.mock(JobContext.class);
+ dMaaPMROutputFormat.checkOutputSpecs(jobContext);
+ }
+
+ @Test
+ public void testGetOutputCommitter() throws Exception {
+ final TaskAttemptContext taskAttemptContext = Mockito.mock(TaskAttemptContext.class);
+ final OutputCommitter outputCommitter = dMaaPMROutputFormat.getOutputCommitter(taskAttemptContext);
+ assertTrue(outputCommitter.getClass().equals(DMaaPMROutputFormat.NoOpOutputCommitter.class));
+ final JobContext jobContext = Mockito.mock(JobContext.class);
+ outputCommitter.setupJob(jobContext);
+ outputCommitter.setupTask(taskAttemptContext);
+ assertFalse(outputCommitter.needsTaskCommit(taskAttemptContext));
+ outputCommitter.commitJob(jobContext);
+ outputCommitter.commitTask(taskAttemptContext);
+ outputCommitter.abortTask(taskAttemptContext);
+
+ }
+
+}
diff --git a/dcae-analytics-cdap-plugins/src/test/java/org/openecomp/dcae/apod/analytics/cdap/plugins/batch/sink/dmaap/DMaaPMRRecordWriterTest.java b/dcae-analytics-cdap-plugins/src/test/java/org/openecomp/dcae/apod/analytics/cdap/plugins/batch/sink/dmaap/DMaaPMRRecordWriterTest.java index f65d815..611392c 100644 --- a/dcae-analytics-cdap-plugins/src/test/java/org/openecomp/dcae/apod/analytics/cdap/plugins/batch/sink/dmaap/DMaaPMRRecordWriterTest.java +++ b/dcae-analytics-cdap-plugins/src/test/java/org/openecomp/dcae/apod/analytics/cdap/plugins/batch/sink/dmaap/DMaaPMRRecordWriterTest.java @@ -1,62 +1,62 @@ -/* - * ===============================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.batch.sink.dmaap; - -import org.apache.hadoop.mapreduce.TaskAttemptContext; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mockito; -import org.openecomp.dcae.apod.analytics.cdap.plugins.BaseAnalyticsCDAPPluginsUnitTest; -import org.openecomp.dcae.apod.analytics.dmaap.service.publisher.DMaaPMRPublisher; - -import java.util.Arrays; - -import static org.mockito.Mockito.times; - -/** - * @author Rajiv Singla . Creation Date: 1/30/2017. - */ -public class DMaaPMRRecordWriterTest extends BaseAnalyticsCDAPPluginsUnitTest { - - private DMaaPMRPublisher publisher; - private DMaaPMRRecordWriter dMaaPMRRecordWriter; - - @Before - public void before() { - publisher = Mockito.mock(DMaaPMRPublisher.class); - dMaaPMRRecordWriter = new DMaaPMRRecordWriter(publisher); - } - - @Test - public void testWrite() throws Exception { - final String testMessage = "test Message"; - dMaaPMRRecordWriter.write(testMessage, null); - Mockito.verify(publisher, times(1)).publish(Arrays.asList(testMessage)); - } - - @Test - public void testClose() throws Exception { - final TaskAttemptContext taskAttemptContext = Mockito.mock(TaskAttemptContext.class); - dMaaPMRRecordWriter.close(taskAttemptContext); - Mockito.verify(publisher, times(1)).flush(); - } - -} +/*
+ * ===============================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.batch.sink.dmaap;
+
+import org.apache.hadoop.mapreduce.TaskAttemptContext;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.openecomp.dcae.apod.analytics.cdap.plugins.BaseAnalyticsCDAPPluginsUnitTest;
+import org.openecomp.dcae.apod.analytics.dmaap.service.publisher.DMaaPMRPublisher;
+
+import java.util.Arrays;
+
+import static org.mockito.Mockito.times;
+
+/**
+ * @author Rajiv Singla . Creation Date: 1/30/2017.
+ */
+public class DMaaPMRRecordWriterTest extends BaseAnalyticsCDAPPluginsUnitTest {
+
+ private DMaaPMRPublisher publisher;
+ private DMaaPMRRecordWriter dMaaPMRRecordWriter;
+
+ @Before
+ public void before() {
+ publisher = Mockito.mock(DMaaPMRPublisher.class);
+ dMaaPMRRecordWriter = new DMaaPMRRecordWriter(publisher);
+ }
+
+ @Test
+ public void testWrite() throws Exception {
+ final String testMessage = "test Message";
+ dMaaPMRRecordWriter.write(testMessage, null);
+ Mockito.verify(publisher, times(1)).publish(Arrays.asList(testMessage));
+ }
+
+ @Test
+ public void testClose() throws Exception {
+ final TaskAttemptContext taskAttemptContext = Mockito.mock(TaskAttemptContext.class);
+ dMaaPMRRecordWriter.close(taskAttemptContext);
+ Mockito.verify(publisher, times(1)).flush();
+ }
+
+}
diff --git a/dcae-analytics-cdap-plugins/src/test/java/org/openecomp/dcae/apod/analytics/cdap/plugins/batch/sink/dmaap/DMaaPMRSinkTest.java b/dcae-analytics-cdap-plugins/src/test/java/org/openecomp/dcae/apod/analytics/cdap/plugins/batch/sink/dmaap/DMaaPMRSinkTest.java index 48e746f..3ad16d9 100644 --- a/dcae-analytics-cdap-plugins/src/test/java/org/openecomp/dcae/apod/analytics/cdap/plugins/batch/sink/dmaap/DMaaPMRSinkTest.java +++ b/dcae-analytics-cdap-plugins/src/test/java/org/openecomp/dcae/apod/analytics/cdap/plugins/batch/sink/dmaap/DMaaPMRSinkTest.java @@ -1,94 +1,95 @@ -/* - * ===============================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.batch.sink.dmaap; - -import co.cask.cdap.api.data.format.StructuredRecord; -import co.cask.cdap.api.data.schema.Schema; -import co.cask.cdap.etl.api.Emitter; -import co.cask.cdap.etl.api.PipelineConfigurer; -import co.cask.cdap.etl.api.StageConfigurer; -import co.cask.cdap.etl.api.batch.BatchSinkContext; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mockito; -import org.openecomp.dcae.apod.analytics.cdap.common.exception.CDAPSettingsException; -import org.openecomp.dcae.apod.analytics.cdap.plugins.BaseAnalyticsCDAPPluginsUnitTest; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.doNothing; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -/** - * @author Rajiv Singla . Creation Date: 1/30/2017. - */ -public class DMaaPMRSinkTest extends BaseAnalyticsCDAPPluginsUnitTest { - - private DMaaPMRSink dMaaPMRSink; - - @Before - public void before() { - dMaaPMRSink = new DMaaPMRSink(getTestDMaaPMRSinkPluginConfig()); - } - - @Test - public void testConfigurePipeline() throws Exception { - final PipelineConfigurer pipelineConfigurer = Mockito.mock(PipelineConfigurer.class); - final StageConfigurer stageConfigurer = Mockito.mock(StageConfigurer.class); - when(pipelineConfigurer.getStageConfigurer()).thenReturn(stageConfigurer); - when(stageConfigurer.getInputSchema()).thenReturn(getDMaaPMRSinkTestSchema()); - dMaaPMRSink.configurePipeline(pipelineConfigurer); - verify(stageConfigurer, times(1)).getInputSchema(); - } - - @Test(expected = CDAPSettingsException.class) - public void testConfigurePipelineWithInvalidSchema() throws Exception { - final PipelineConfigurer pipelineConfigurer = Mockito.mock(PipelineConfigurer.class); - final StageConfigurer stageConfigurer = Mockito.mock(StageConfigurer.class); - when(pipelineConfigurer.getStageConfigurer()).thenReturn(stageConfigurer); - when(stageConfigurer.getInputSchema()).thenReturn(Schema.recordOf( - "DMaaPMRSinkInvalidSchema", - Schema.Field.of("message1", Schema.of(Schema.Type.STRING)), - Schema.Field.of("field1", Schema.of(Schema.Type.STRING)) - )); - dMaaPMRSink.configurePipeline(pipelineConfigurer); - } - - @Test - public void testPrepareRun() throws Exception { - final BatchSinkContext batchSinkContext = Mockito.mock(BatchSinkContext.class); - dMaaPMRSink.prepareRun(batchSinkContext); - } - - @Test - public void testTransform() throws Exception { - final StructuredRecord structuredRecord = Mockito.mock(StructuredRecord.class); - final Emitter emitter = Mockito.mock(Emitter.class); - final String incomingTestMessage = "test message"; - when(structuredRecord.get( - eq(getTestDMaaPMRSinkPluginConfig().getMessageColumnName()))).thenReturn(incomingTestMessage); - doNothing().when(emitter).emit(any()); - dMaaPMRSink.transform(structuredRecord, emitter); - } - -} +/*
+ * ===============================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.batch.sink.dmaap;
+
+import co.cask.cdap.api.data.format.StructuredRecord;
+import co.cask.cdap.api.data.schema.Schema;
+import co.cask.cdap.etl.api.Emitter;
+import co.cask.cdap.etl.api.PipelineConfigurer;
+import co.cask.cdap.etl.api.StageConfigurer;
+import co.cask.cdap.etl.api.batch.BatchSinkContext;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.openecomp.dcae.apod.analytics.cdap.common.exception.CDAPSettingsException;
+import org.openecomp.dcae.apod.analytics.cdap.plugins.BaseAnalyticsCDAPPluginsUnitTest;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+/**
+ * @author Rajiv Singla . Creation Date: 1/30/2017.
+ */
+public class DMaaPMRSinkTest extends BaseAnalyticsCDAPPluginsUnitTest {
+
+ private DMaaPMRSink dMaaPMRSink;
+
+ @Before
+ public void before() {
+ dMaaPMRSink = new DMaaPMRSink(getTestDMaaPMRSinkPluginConfig());
+ }
+
+ @Test
+ public void testConfigurePipeline() throws Exception {
+ final PipelineConfigurer pipelineConfigurer = Mockito.mock(PipelineConfigurer.class);
+ final StageConfigurer stageConfigurer = Mockito.mock(StageConfigurer.class);
+ when(pipelineConfigurer.getStageConfigurer()).thenReturn(stageConfigurer);
+ when(stageConfigurer.getInputSchema()).thenReturn(getDMaaPMRSinkTestSchema());
+ dMaaPMRSink.configurePipeline(pipelineConfigurer);
+ verify(stageConfigurer, times(1)).getInputSchema();
+ }
+
+ @Test(expected = CDAPSettingsException.class)
+ public void testConfigurePipelineWithInvalidSchema() throws Exception {
+ final PipelineConfigurer pipelineConfigurer = Mockito.mock(PipelineConfigurer.class);
+ final StageConfigurer stageConfigurer = Mockito.mock(StageConfigurer.class);
+ when(pipelineConfigurer.getStageConfigurer()).thenReturn(stageConfigurer);
+ when(stageConfigurer.getInputSchema()).thenReturn(Schema.recordOf(
+ "DMaaPMRSinkInvalidSchema",
+ Schema.Field.of("message1", Schema.of(Schema.Type.STRING)),
+ Schema.Field.of("field1", Schema.of(Schema.Type.STRING))
+ ));
+ dMaaPMRSink.configurePipeline(pipelineConfigurer);
+ }
+
+ @Test
+ public void testPrepareRun() throws Exception {
+ final BatchSinkContext batchSinkContext = Mockito.mock(BatchSinkContext.class);
+ dMaaPMRSink.prepareRun(batchSinkContext);
+ }
+
+ @Test
+ @SuppressWarnings("unchecked")
+ public void testTransform() throws Exception {
+ final StructuredRecord structuredRecord = Mockito.mock(StructuredRecord.class);
+ final Emitter emitter = Mockito.mock(Emitter.class);
+ final String incomingTestMessage = "test message";
+ when(structuredRecord.get(
+ eq(getTestDMaaPMRSinkPluginConfig().getMessageColumnName()))).thenReturn(incomingTestMessage);
+ doNothing().when(emitter).emit(any());
+ dMaaPMRSink.transform(structuredRecord, emitter);
+ }
+
+}
|