Fix broken unit test in DmaapProducerImpl
Puts tests back to prior to commit Ie4817c5bdf514d4fe7f68b73812bbc2383c8cbbe
Issue-ID: APPC-1423
Change-Id: I2165c9a2ce83db1f9d185f083d41d6e5d7bce269
Signed-off-by: Joss Armstrong <joss.armstrong@ericsson.com>
diff --git a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/pom.xml b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/pom.xml
index 8a2f6d9..1d8cbdb 100644
--- a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/pom.xml
+++ b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/pom.xml
@@ -72,6 +72,12 @@
</dependency>
<dependency>
+ <groupId>equinoxSDK381</groupId>
+ <artifactId>org.eclipse.osgi</artifactId>
+ <version>${equinox.osgi.version}</version>
+ </dependency>
+
+ <dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
</dependency>
@@ -199,4 +205,4 @@
</plugins>
</build>
<version>1.5.0-SNAPSHOT</version>
-</project>
+</project>
\ No newline at end of file
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 a2f2c9d..409dbeb 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.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 @@
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 @@
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 206b5a6..e6e665d 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 @@
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.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})
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
public class TestDmaapProducerImpl {
String[] hostList = { "192.168.1.1" };
Collection<String> hosts = new HashSet<String>(Arrays.asList(hostList));
@@ -145,7 +123,6 @@
@Test
public void testPost() {
- producer = new DmaapProducerImpl(hosts, topic, key, secret);
boolean successful = producer.post("partition", "data");
assertEquals(true, successful);
}
@@ -159,9 +136,9 @@
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 @@
}
- @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