diff options
author | 2019-07-12 11:35:54 +0530 | |
---|---|---|
committer | 2019-07-12 14:50:21 +0530 | |
commit | c818065d90aad39e61992ee44fa13568b80ee7b3 (patch) | |
tree | 02126cd73fbdd7c825b7a120a54699fb340ba3ac /src/test/java/org/onap/dcae/common/publishing | |
parent | 20d8093fd688f0385b7bb9b8e4b09ff60ef23f26 (diff) |
Issue-ID: DCAEGEN2-1661 Fix Some Compilation warnings, sonar issue
Signed-off-by: s00370346 <swarup.nayak1@huawei.com>
Change-Id: Id01028b87c101ff2544d93c68a59f9cc46020d8d
Diffstat (limited to 'src/test/java/org/onap/dcae/common/publishing')
3 files changed, 69 insertions, 34 deletions
diff --git a/src/test/java/org/onap/dcae/common/publishing/DMaaPEventPublisherTest.java b/src/test/java/org/onap/dcae/common/publishing/DMaaPEventPublisherTest.java index 2865b75..79ac03b 100644 --- a/src/test/java/org/onap/dcae/common/publishing/DMaaPEventPublisherTest.java +++ b/src/test/java/org/onap/dcae/common/publishing/DMaaPEventPublisherTest.java @@ -18,6 +18,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.dcae.common.publishing; import static io.vavr.API.Option; @@ -40,14 +41,17 @@ public class DMaaPEventPublisherTest { private DMaaPEventPublisher eventPublisher; private CambriaBatchingPublisher cambriaPublisher; - private DMaaPPublishersCache DMaaPPublishersCache; + private DMaaPPublishersCache dmaapPublishersCache; + /** + * Setup before test. + */ @Before public void setUp() { cambriaPublisher = mock(CambriaBatchingPublisher.class); - DMaaPPublishersCache = mock(DMaaPPublishersCache.class); - when(DMaaPPublishersCache.getPublisher(anyString())).thenReturn(Option(cambriaPublisher)); - eventPublisher = new DMaaPEventPublisher(DMaaPPublishersCache, mock(Logger.class)); + dmaapPublishersCache = mock(DMaaPPublishersCache.class); + when(dmaapPublishersCache.getPublisher(anyString())).thenReturn(Option(cambriaPublisher)); + eventPublisher = new DMaaPEventPublisher(dmaapPublishersCache, mock(Logger.class)); } @Test @@ -74,6 +78,6 @@ public class DMaaPEventPublisherTest { eventPublisher.sendEvent(event, STREAM_ID); // then - verify(DMaaPPublishersCache).closePublisherFor(STREAM_ID); + verify(dmaapPublishersCache).closePublisherFor(STREAM_ID); } }
\ No newline at end of file diff --git a/src/test/java/org/onap/dcae/common/publishing/DMaaPPublishersCacheTest.java b/src/test/java/org/onap/dcae/common/publishing/DMaaPPublishersCacheTest.java index 2884e44..6f3696d 100644 --- a/src/test/java/org/onap/dcae/common/publishing/DMaaPPublishersCacheTest.java +++ b/src/test/java/org/onap/dcae/common/publishing/DMaaPPublishersCacheTest.java @@ -18,6 +18,7 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.dcae.common.publishing; import static io.vavr.API.List; @@ -43,22 +44,41 @@ import org.onap.dcae.common.publishing.DMaaPPublishersCache.OnPublisherRemovalLi public class DMaaPPublishersCacheTest { private String streamId1; - private Map<String, PublisherConfig> dMaaPConfigs; - + private Map<String, PublisherConfig> dmaapconfigs; + private Map<String, PublisherConfig> dmaapconfigs2; + /** + * Setup before test. + */ @Before public void setUp() { streamId1 = "sampleStream1"; - dMaaPConfigs = Map("sampleStream1", new PublisherConfig(List("destination1"), "topic1")); + dmaapconfigs = Map("sampleStream1", new PublisherConfig(List("destination1"), "topic1")); + dmaapconfigs2 = Map("sampleStream1", new PublisherConfig(List("destination1"), + "topic1", "user", "pass")); + } @Test public void shouldReturnTheSameCachedInstanceOnConsecutiveRetrievals() { // given - DMaaPPublishersCache dMaaPPublishersCache = new DMaaPPublishersCache(dMaaPConfigs); + DMaaPPublishersCache dmaapPublishersCache = new DMaaPPublishersCache(dmaapconfigs); + + // when + Option<CambriaBatchingPublisher> firstPublisher = dmaapPublishersCache.getPublisher(streamId1); + Option<CambriaBatchingPublisher> secondPublisher = dmaapPublishersCache.getPublisher(streamId1); + + // then + assertSame("should return same instance", firstPublisher.get(), secondPublisher.get()); + } + + @Test + public void shouldReturnTheSameCachedInstanceOnConsecutiveRetrievals2() { + // given + DMaaPPublishersCache dmaapPublishersCache = new DMaaPPublishersCache(dmaapconfigs2); // when - Option<CambriaBatchingPublisher> firstPublisher = dMaaPPublishersCache.getPublisher(streamId1); - Option<CambriaBatchingPublisher> secondPublisher = dMaaPPublishersCache.getPublisher(streamId1); + Option<CambriaBatchingPublisher> firstPublisher = dmaapPublishersCache.getPublisher(streamId1); + Option<CambriaBatchingPublisher> secondPublisher = dmaapPublishersCache.getPublisher(streamId1); // then assertSame("should return same instance", firstPublisher.get(), secondPublisher.get()); @@ -69,14 +89,14 @@ public class DMaaPPublishersCacheTest { // given CambriaBatchingPublisher cambriaPublisherMock1 = mock(CambriaBatchingPublisher.class); CambriaPublishersCacheLoader cacheLoaderMock = mock(CambriaPublishersCacheLoader.class); - DMaaPPublishersCache dMaaPPublishersCache = new DMaaPPublishersCache(cacheLoaderMock, + DMaaPPublishersCache dmaapPublishersCache = new DMaaPPublishersCache(cacheLoaderMock, new OnPublisherRemovalListener(), - dMaaPConfigs); + dmaapconfigs); when(cacheLoaderMock.load(streamId1)).thenReturn(cambriaPublisherMock1); // when - dMaaPPublishersCache.getPublisher(streamId1); - dMaaPPublishersCache.closePublisherFor(streamId1); + dmaapPublishersCache.getPublisher(streamId1); + dmaapPublishersCache.closePublisherFor(streamId1); // then verify(cambriaPublisherMock1).close(20, TimeUnit.SECONDS); @@ -84,12 +104,12 @@ public class DMaaPPublishersCacheTest { } @Test - public void shouldReturnNoneIfThereIsNoDMaaPConfigurationForGivenStreamID() { + public void shouldReturnNoneIfThereIsNoDmaaPConfigurationForGivenStreamId() { // given - DMaaPPublishersCache dMaaPPublishersCache = new DMaaPPublishersCache(dMaaPConfigs); + DMaaPPublishersCache dmaapPublishersCache = new DMaaPPublishersCache(dmaapconfigs); // then - assertTrue("should not exist", dMaaPPublishersCache.getPublisher("non-existing").isEmpty()); + assertTrue("should not exist", dmaapPublishersCache.getPublisher("non-existing").isEmpty()); } @@ -106,19 +126,22 @@ public class DMaaPPublishersCacheTest { secondDomain, new PublisherConfig(List("destination2"), "topic2", "user", "pass")); - Map<String, PublisherConfig> newConfig = Map(firstDomain, new PublisherConfig(List("destination1"), "topic1"), - secondDomain, new PublisherConfig(List("destination2"), "topic2")); - DMaaPPublishersCache dMaaPPublishersCache = new DMaaPPublishersCache(cacheLoaderMock, + + DMaaPPublishersCache dmaapPublishersCache = new DMaaPPublishersCache(cacheLoaderMock, new OnPublisherRemovalListener(), oldConfig); + final Map<String, PublisherConfig> newConfig = Map(firstDomain, + new PublisherConfig(List("destination1"), "topic1"), + secondDomain, new PublisherConfig(List("destination2"), "topic2")); + when(cacheLoaderMock.load(firstDomain)).thenReturn(cambriaPublisherMock1); when(cacheLoaderMock.load(secondDomain)).thenReturn(cambriaPublisherMock2); - dMaaPPublishersCache.getPublisher(firstDomain); - dMaaPPublishersCache.getPublisher(secondDomain); + dmaapPublishersCache.getPublisher(firstDomain); + dmaapPublishersCache.getPublisher(secondDomain); // when - dMaaPPublishersCache.reconfigure(newConfig); + dmaapPublishersCache.reconfigure(newConfig); // then verify(cambriaPublisherMock2).close(20, TimeUnit.SECONDS); diff --git a/src/test/java/org/onap/dcae/common/publishing/JsonParserTest.java b/src/test/java/org/onap/dcae/common/publishing/JsonParserTest.java index f00df2c..54d0cfc 100644 --- a/src/test/java/org/onap/dcae/common/publishing/JsonParserTest.java +++ b/src/test/java/org/onap/dcae/common/publishing/JsonParserTest.java @@ -17,22 +17,30 @@ * limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.onap.dcae.common.publishing;
-import java.util.Map;
+import static org.junit.Assert.assertEquals;
+import java.util.Map;
import org.junit.Test;
import org.onap.dcae.common.JsonParser;
-import junit.framework.Assert;
-
-
public class JsonParserTest {
- @Test
- public void convertToPropertiesTest() throws Exception {
- String testJson="{\"prop2\"=\"value\", \"prop1\"=\"value\"}";
- Map<String, String> response= JsonParser.convertToProperties(testJson);
- Assert.assertEquals("value", response.get("prop2"));
- }
+ @Test
+ public void convertToPropertiesTest() throws Exception {
+ String testJson = "{\"prop2\"=\"value\", \"prop1\"=\"value\"}";
+ Map<String, String> response = JsonParser.convertToProperties(testJson);
+ assertEquals("value", response.get("prop2"));
+ }
+
+ @Test
+ public void convertToPropertiesTestwithArray() throws Exception {
+ String testJson = "{\"metadatum\": [{\"metaname\": \"remote-id\",\"metaval\": \"AC9.0234.0337\","
+ + "\"resource-version\": \"1553802421110\"},{\"metaname\": \"svlan\",\"metaval\": \"100\","
+ + "\"resource-version\": \"1553802421082\"}]}";
+ Map<String, String> response = JsonParser.convertToProperties(testJson);
+ assertEquals("100", response.get("metadatum[1].metaval"));
+ }
}
|