diff options
author | sunil unnava <su622b@att.com> | 2019-02-11 14:14:18 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-02-11 14:14:18 +0000 |
commit | 2d4ea011b5f22b306cea75991d08e491141e47b1 (patch) | |
tree | 8e0d36abbe6fca89a2ffaa349846b7c66ade8178 | |
parent | 9fc471e59ddd70ef22f838df5be143c85d5b3869 (diff) | |
parent | ff320e967ab3bdd9770314f9012ecb9eb3cdfa6c (diff) |
Merge "Junit for UpdateMirrorMaker.java"
-rw-r--r-- | src/test/java/org/onap/dmaap/mmagent/UpdateMirrorMakerTest.java | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/test/java/org/onap/dmaap/mmagent/UpdateMirrorMakerTest.java b/src/test/java/org/onap/dmaap/mmagent/UpdateMirrorMakerTest.java index 1826026..6fceff1 100644 --- a/src/test/java/org/onap/dmaap/mmagent/UpdateMirrorMakerTest.java +++ b/src/test/java/org/onap/dmaap/mmagent/UpdateMirrorMakerTest.java @@ -22,14 +22,43 @@ import static org.junit.Assert.*; +import org.json.JSONObject; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.junit.runner.RunWith; +import org.onap.dmaap.dmf.mr.CambriaApiException; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.modules.junit4.PowerMockRunner; +@RunWith(PowerMockRunner.class) public class UpdateMirrorMakerTest { + @Rule + public ExpectedException exceptionRule = ExpectedException.none(); + + MirrorMaker mirrorMaker; + UpdateMirrorMaker updateMirrorMaker; + JSONObject jsonObject; + @Before public void setUp() throws Exception { + mirrorMaker = new MirrorMaker(); + updateMirrorMaker = new UpdateMirrorMaker(); + jsonObject = PowerMockito.mock(JSONObject.class); + + mirrorMaker.setConsumer("test"); + PowerMockito.when(jsonObject.has("consumer")).thenReturn(true); + + mirrorMaker.setProducer("test"); + PowerMockito.when(jsonObject.has("producer")).thenReturn(true); + + mirrorMaker.setNumStreams(1); + PowerMockito.when(jsonObject.has("numStreams")).thenReturn(true); + + PowerMockito.when(jsonObject.has("whitelist")).thenReturn(true); } @After @@ -77,5 +106,32 @@ public class UpdateMirrorMakerTest { } + @Test(expected = CambriaApiException.class) + public void testValidateJSONNullConsumer() throws CambriaApiException { + mirrorMaker.setConsumer(null); + updateMirrorMaker.setUpdateMirrorMaker(mirrorMaker); + updateMirrorMaker.validateJSON(jsonObject); + } + @Test(expected = CambriaApiException.class) + public void testValidateJSONNullProducer() throws CambriaApiException { + mirrorMaker.setProducer(null); + updateMirrorMaker.setUpdateMirrorMaker(mirrorMaker); + updateMirrorMaker.validateJSON(jsonObject); + } + + @Test(expected = CambriaApiException.class) + public void testValidateJSONNoNumStreams() throws CambriaApiException { + mirrorMaker.setNumStreams(0); + updateMirrorMaker.setUpdateMirrorMaker(mirrorMaker); + updateMirrorMaker.validateJSON(jsonObject); + } + + @Test(expected = CambriaApiException.class) + public void testValidateJSONWhitelist() throws CambriaApiException { + PowerMockito.when(jsonObject.has("whitelist")).thenReturn(true); + + updateMirrorMaker.setUpdateMirrorMaker(mirrorMaker); + updateMirrorMaker.validateJSON(jsonObject); + } }
\ No newline at end of file |