aboutsummaryrefslogtreecommitdiffstats
path: root/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src
diff options
context:
space:
mode:
Diffstat (limited to 'appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src')
-rw-r--r--appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/impl/DmaapProducerImpl.java9
-rw-r--r--appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/impl/TestDmaapProducerImpl.java82
2 files changed, 10 insertions, 81 deletions
diff --git a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/impl/DmaapProducerImpl.java b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/impl/DmaapProducerImpl.java
index a2f2c9d2b..409dbebf3 100644
--- a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/impl/DmaapProducerImpl.java
+++ b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/impl/DmaapProducerImpl.java
@@ -5,8 +5,6 @@
* Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
- * ================================================================================
- * Modifications Copyright (C) 2019 Ericsson
* =============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -53,11 +51,10 @@ import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.ServiceReference;
-
public class DmaapProducerImpl implements Producer {
private static final EELFLogger LOG = EELFManager.getInstance().getLogger(DmaapProducerImpl.class);
- private static Configuration configuration = ConfigurationFactory.getConfiguration();
+ private static final Configuration configuration = ConfigurationFactory.getConfiguration();
private Set<String> topics;
@@ -202,7 +199,7 @@ public class DmaapProducerImpl implements Producer {
useHttps = yes;
}
- protected MetricService getMetricservice() {
+ private MetricService getMetricservice() {
BundleContext bctx = FrameworkUtil.getBundle(MetricService.class).getBundleContext();
ServiceReference sref = bctx.getServiceReference(MetricService.class.getName());
if (sref != null) {
@@ -223,4 +220,4 @@ public class DmaapProducerImpl implements Producer {
return useHttps;
}
-}
+} \ No newline at end of file
diff --git a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/impl/TestDmaapProducerImpl.java b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/impl/TestDmaapProducerImpl.java
index 206b5a669..e6e665d68 100644
--- a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/impl/TestDmaapProducerImpl.java
+++ b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/test/java/org/onap/appc/adapter/messaging/dmaap/impl/TestDmaapProducerImpl.java
@@ -5,8 +5,6 @@
* Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
* =============================================================================
* Modifications Copyright (C) 2018 IBM.
- * =================================================================================
- * Modifications Copyright (C) 2019 Ericsson
* =============================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,38 +25,18 @@ package org.onap.appc.adapter.messaging.dmaap.impl;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
-import java.io.FileNotFoundException;
-import java.io.IOException;
+import static org.junit.Assert.fail;
+
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Properties;
import java.util.Set;
+
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mockito;
-import org.onap.appc.configuration.Configuration;
-import org.onap.appc.configuration.ConfigurationFactory;
-import org.onap.appc.metricservice.MetricRegistry;
-import org.onap.appc.metricservice.MetricService;
-import org.onap.appc.metricservice.metric.DmaapRequestCounterBuilder;
-import org.onap.appc.metricservice.metric.DmaapRequestCounterMetric;
-import org.onap.appc.metricservice.metric.MetricBuilderFactory;
-import org.onap.appc.metricservice.metric.impl.MetricBuilderFactoryImpl;
-import org.onap.appc.metricservice.policy.PolicyBuilderFactory;
-import org.onap.appc.metricservice.policy.PublishingPolicy;
-import org.onap.appc.metricservice.policy.ScheduledPolicyBuilder;
-import org.osgi.framework.FrameworkUtil;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.reflect.Whitebox;
-import com.att.nsa.mr.client.MRBatchingPublisher;
-import com.att.nsa.mr.client.MRClientFactory;
-
-@RunWith(PowerMockRunner.class)
-@PrepareForTest({ConfigurationFactory.class, FrameworkUtil.class, MRClientFactory.class})
+
public class TestDmaapProducerImpl {
String[] hostList = { "192.168.1.1" };
Collection<String> hosts = new HashSet<String>(Arrays.asList(hostList));
@@ -145,7 +123,6 @@ public class TestDmaapProducerImpl {
@Test
public void testPost() {
- producer = new DmaapProducerImpl(hosts, topic, key, secret);
boolean successful = producer.post("partition", "data");
assertEquals(true, successful);
}
@@ -159,9 +136,9 @@ public class TestDmaapProducerImpl {
producer.close();
}
+
@Test
public void testCloseWithClient() {
- producer = new DmaapProducerImpl(hosts, topic, key, secret);
producer.post("partition", "data");
assertNotNull(producer);
producer.close();
@@ -181,49 +158,4 @@ public class TestDmaapProducerImpl {
}
- @Test
- public void testInitMetric() throws FileNotFoundException, IOException
- {
- Configuration configuration = Mockito.mock(Configuration.class);
- Properties properties = new Properties();
- properties.put("metric.enabled", "true");
- Mockito.when(configuration.getProperties()).thenReturn(properties);
- PowerMockito.mockStatic(MRClientFactory.class);
- PowerMockito.when(MRClientFactory.createConsumer(Mockito.anyString())).thenThrow(new IOException());
- DmaapProducerImpl producer = Mockito.spy(new DmaapProducerImpl(hosts, topic, key, secret));
- Whitebox.setInternalState(DmaapProducerImpl.class, "configuration", configuration);
- MetricService metricService = Mockito.mock(MetricService.class);
- MetricRegistry metricRegistry = Mockito.mock(MetricRegistry.class);
- MetricBuilderFactory metricBuilderFactory = Mockito.spy(new MetricBuilderFactoryImpl());
- DmaapRequestCounterBuilder builder = Mockito.mock(DmaapRequestCounterBuilder.class);
- DmaapRequestCounterMetric metric = Mockito.mock(DmaapRequestCounterMetric.class);
- Mockito.doNothing().when(metric).incrementPublishedMessage();
- Mockito.when(builder.withName(Mockito.anyString())).thenReturn(builder);
- Mockito.when(builder.withType(Mockito.any())).thenReturn(builder);
- Mockito.when(builder.withPublishedMessage(Mockito.anyLong())).thenReturn(builder);
- Mockito.when(builder.withRecievedMessage(Mockito.anyLong())).thenReturn(builder);
- Mockito.when(builder.build()).thenReturn(metric);
- Mockito.when(metricBuilderFactory.dmaapRequestCounterBuilder()).thenReturn(builder);
- Mockito.when(metricRegistry.metric("DMAAP_KPI")).thenReturn(metric);
- Mockito.when(metricRegistry.register(Mockito.any())).thenReturn(true);
- PublishingPolicy policy = Mockito.mock(PublishingPolicy.class);
- PolicyBuilderFactory policyFactory = Mockito.mock(PolicyBuilderFactory.class);
- Mockito.when(metricRegistry.policyBuilderFactory()).thenReturn(policyFactory);
- ScheduledPolicyBuilder policyBuilder = Mockito.mock(ScheduledPolicyBuilder.class);
- Mockito.when(policyBuilder.withPublishers(Mockito.any())).thenReturn(policyBuilder);
- Mockito.when(policyBuilder.withMetrics(Mockito.any())).thenReturn(policyBuilder);
- Mockito.when(policyBuilder.build()).thenReturn(policy);
- Mockito.when(policyFactory.scheduledPolicyBuilder()).thenReturn(policyBuilder);
- Mockito.when(metricRegistry.metricBuilderFactory()).thenReturn(metricBuilderFactory);
- Mockito.when(metricService.createRegistry("APPC")).thenReturn(metricRegistry);
- Mockito.doReturn(metricService).when(producer).getMetricservice();
- Set<MRBatchingPublisher> clients = new HashSet<>();
- MRBatchingPublisher client = Mockito.mock(MRBatchingPublisher.class);
- clients.add(client);
- Mockito.doReturn(0).when(client).send(Mockito.anyString(), Mockito.anyString());
- Whitebox.setInternalState(producer, "clients", clients);
- producer.post(null, null);
- Mockito.verify(policy).init();
- }
-
-}
+} \ No newline at end of file