aboutsummaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/com/att/nsa/mr/client/impl/MRBaseClientTest.java412
-rw-r--r--src/test/java/com/att/nsa/mr/client/impl/MRBatchPublisherTest.java54
-rw-r--r--src/test/java/com/att/nsa/mr/client/impl/MRConsumerImplTest.java17
-rw-r--r--src/test/java/com/att/nsa/mr/client/impl/MRMetaClientTest.java22
-rw-r--r--src/test/java/com/att/nsa/mr/client/impl/MRSimplerBatchConsumerTest.java1
-rw-r--r--src/test/java/com/att/nsa/mr/test/clients/SampleConsumerTest.java5
-rw-r--r--src/test/java/com/att/nsa/mr/test/clients/SamplePublisherTest.java4
-rw-r--r--src/test/java/com/att/nsa/mr/test/clients/SimpleExampleConsumerWithReturnResponseTest.java4
-rw-r--r--src/test/java/com/att/nsa/mr/test/clients/SimpleExamplePublisherWithResponseTest.java5
-rw-r--r--src/test/java/com/att/nsa/mr/tools/ApiKeyCommandTest.java189
-rw-r--r--src/test/java/com/att/nsa/mr/tools/AuthCommandTest.java64
-rw-r--r--src/test/java/com/att/nsa/mr/tools/ClusterCommandTest.java79
-rw-r--r--src/test/java/com/att/nsa/mr/tools/MessageCommandTest.java157
-rw-r--r--src/test/java/com/att/nsa/mr/tools/TopicCommandTest.java192
-rw-r--r--src/test/java/com/att/nsa/mr/tools/TraceCommandTest.java56
15 files changed, 1021 insertions, 240 deletions
diff --git a/src/test/java/com/att/nsa/mr/client/impl/MRBaseClientTest.java b/src/test/java/com/att/nsa/mr/client/impl/MRBaseClientTest.java
new file mode 100644
index 0000000..1c291b9
--- /dev/null
+++ b/src/test/java/com/att/nsa/mr/client/impl/MRBaseClientTest.java
@@ -0,0 +1,412 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * org.onap.dmaap
+ * ================================================================================
+ * 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=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ *
+ *******************************************************************************/
+package com.att.nsa.mr.client.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.net.MalformedURLException;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.ResponseBuilder;
+
+import org.apache.http.HttpException;
+import org.glassfish.jersey.internal.util.Base64;
+import org.json.JSONException;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PowerMockIgnore;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+@RunWith(PowerMockRunner.class)
+@PowerMockIgnore("org.apache.http.conn.ssl.*")
+@PrepareForTest({ DmaapClientUtil.class })
+public class MRBaseClientTest {
+
+ //@InjectMocks
+ private MRBaseClient mrBaseClient;
+ private Collection<String> hosts = new HashSet<>(Arrays.asList("localhost:8080"));
+ private String clientSignature = "topic" + "::" + "cg" + "::" + "cid";
+
+ @Before
+ public void setup() throws MalformedURLException {
+ mrBaseClient=new MRBaseClient(hosts, clientSignature);
+ PowerMockito.mockStatic(DmaapClientUtil.class);
+ }
+
+ @Test
+ public void testGet() throws JSONException, HttpException {
+
+ ResponseBuilder responseBuilder = Response.ok();
+ PowerMockito
+ .when(DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username",
+ "password"))
+ .thenReturn(
+ responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build());
+
+ mrBaseClient.get("/path", "username", "password", "HTTPAUTH");
+ assertTrue(true);
+
+ }
+
+ @Test
+ public void testGet_403() throws JSONException, HttpException {
+ ResponseBuilder responseBuilder = Response.status(403);
+ PowerMockito
+ .when(DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username",
+ "password"))
+ .thenReturn(
+ responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build());
+ mrBaseClient.get("/path", "username", "password", "HTTPAUTH");
+ assertTrue(true);
+
+ }
+
+ @Test
+ public void testGet_basicauth() throws JSONException, HttpException {
+
+ ResponseBuilder responseBuilder = Response.ok();
+ PowerMockito
+ .when(DmaapClientUtil.getResponsewtBasicAuth(DmaapClientUtil.getTarget("/path"),
+ Base64.encodeAsString("username:password")))
+ .thenReturn(
+ responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build());
+
+ mrBaseClient.get("/path", "username", "password", "HTTPAAF");
+ assertTrue(true);
+
+ }
+
+ @Test(expected = HttpException.class)
+ public void testGet_error() throws JSONException, HttpException {
+
+ ResponseBuilder responseBuilder = Response.ok();
+ PowerMockito
+ .when(DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username",
+ "password"))
+ .thenReturn(
+ responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build());
+
+ mrBaseClient.get("/path", null, null, "HTTPAUTH");
+ assertTrue(true);
+
+ }
+
+ @Test
+ public void testGet_wrongjson() throws JSONException, HttpException {
+
+ ResponseBuilder responseBuilder = Response.ok();
+ PowerMockito
+ .when(DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username",
+ "password"))
+ .thenReturn(responseBuilder.header("transactionid", "transactionid").entity("[[").build());
+
+ mrBaseClient.get("/path", "username", "password", "HTTPAUTH");
+ assertTrue(true);
+ }
+
+ @Test
+ public void testGetResponse() throws JSONException, HttpException {
+
+ ResponseBuilder responseBuilder = Response.ok();
+ PowerMockito
+ .when(DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username",
+ "password"))
+ .thenReturn(
+ responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build());
+
+ mrBaseClient.getResponse("/path", "username", "password", "HTTPAUTH");
+ assertTrue(true);
+
+ }
+
+ @Test
+ public void testGetResponse_aaf() throws JSONException, HttpException {
+
+ ResponseBuilder responseBuilder = Response.ok();
+ PowerMockito
+ .when(DmaapClientUtil.getResponsewtBasicAuth(DmaapClientUtil.getTarget("/path"),
+ Base64.encodeAsString("username:password")))
+ .thenReturn(
+ responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build());
+
+ mrBaseClient.getResponse("/path", "username", "password", "HTTPAAF");
+ assertTrue(true);
+
+ }
+
+ @Test(expected = HttpException.class)
+ public void testGetResponse_error() throws JSONException, HttpException {
+
+ ResponseBuilder responseBuilder = Response.ok();
+ PowerMockito
+ .when(DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username",
+ "password"))
+ .thenReturn(
+ responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build());
+
+ mrBaseClient.getResponse("/path", null, null, "HTTPAUTH");
+
+ }
+
+ @Test
+ public void testAuthResponse() throws JSONException, HttpException {
+
+ ResponseBuilder responseBuilder = Response.ok();
+ PowerMockito
+ .when(DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username",
+ "password"))
+ .thenReturn(
+ responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build());
+
+ mrBaseClient.getAuthResponse("/path", "username", "password", "username", "password", "HTTPAUTH");
+ assertTrue(true);
+
+ }
+
+ @Test(expected = HttpException.class)
+ public void testAuthResponsee_error() throws JSONException, HttpException {
+
+ ResponseBuilder responseBuilder = Response.ok();
+ PowerMockito
+ .when(DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username",
+ "password"))
+ .thenReturn(
+ responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build());
+
+ mrBaseClient.getAuthResponse("/path", null, null, null, null, "HTTPAUTH");
+
+ }
+
+ @Test
+ public void testPostAuth() throws JSONException, HttpException {
+
+ ResponseBuilder responseBuilder = Response.ok();
+ PowerMockito
+ .when(DmaapClientUtil.postResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username",
+ "password", new String("{\"test\":\"test\"}").getBytes(), "application/json"))
+ .thenReturn(
+ responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build());
+
+ mrBaseClient.postAuth("/path", new String("{\"test\":\"test\"}").getBytes(), "application/json", "username",
+ "password", "username", "password", "HTTPAUTH");
+ assertTrue(true);
+
+ }
+
+ @Test(expected = HttpException.class)
+ public void testPostAuth_error() throws JSONException, HttpException {
+
+ ResponseBuilder responseBuilder = Response.ok();
+ PowerMockito
+ .when(DmaapClientUtil.postResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username",
+ "password", new String("{\"test\":\"test\"}").getBytes(), "application/json"))
+ .thenReturn(
+ responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build());
+
+ mrBaseClient.postAuth("/path", new String("{\"test\":\"test\"}").getBytes(), "application/json", null, null,
+ null, null, "HTTPAUTH");
+ assertTrue(true);
+
+ }
+
+ @Test
+ public void testGetNoAuthResponse() throws JSONException, HttpException {
+
+ ResponseBuilder responseBuilder = Response.ok();
+ PowerMockito.when(DmaapClientUtil.getResponsewtNoAuth(DmaapClientUtil.getTarget("/path"))).thenReturn(
+ responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build());
+
+ mrBaseClient.getNoAuthResponse("/path", "username", "password", "HTTPAUTH");
+ assertTrue(true);
+
+ }
+
+ @Test
+ public void testPost() throws JSONException, HttpException {
+
+ ResponseBuilder responseBuilder = Response.ok();
+ PowerMockito
+ .when(DmaapClientUtil.getResponsewtBasicAuth(DmaapClientUtil.getTarget("/path"),
+ Base64.encodeAsString("username:password")))
+ .thenReturn(
+ responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build());
+
+ mrBaseClient.post("/path", new String("{\"test\":\"test\"}").getBytes(), "application/json", "username",
+ "password", "HTTPAUTH");
+ assertTrue(true);
+
+ }
+
+ @Test(expected = HttpException.class)
+ public void testPost_error() throws JSONException, HttpException {
+
+ ResponseBuilder responseBuilder = Response.ok();
+ PowerMockito
+ .when(DmaapClientUtil.getResponsewtBasicAuth(DmaapClientUtil.getTarget("/path"),
+ Base64.encodeAsString("username:password")))
+ .thenReturn(
+ responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build());
+
+ mrBaseClient.post("/path", new String("{\"test\":\"test\"}").getBytes(), "application/json", null, null,
+ "HTTPAUTH");
+
+ }
+
+ @Test
+ public void testPostAuthwithResponse() throws JSONException, HttpException {
+
+ ResponseBuilder responseBuilder = Response.ok();
+ PowerMockito
+ .when(DmaapClientUtil.postResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username",
+ "password", new String("{\"test\":\"test\"}").getBytes(), "application/json"))
+ .thenReturn(
+ responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build());
+
+ mrBaseClient.postAuthwithResponse("/path", new String("{\"test\":\"test\"}").getBytes(), "application/json",
+ "username", "password", "username", "password", "HTTPAUTH");
+ assertTrue(true);
+
+ }
+
+ @Test(expected = HttpException.class)
+ public void testPostAuthwithResponse_error() throws JSONException, HttpException {
+
+ ResponseBuilder responseBuilder = Response.ok();
+ PowerMockito
+ .when(DmaapClientUtil.postResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username",
+ "password", new String("{\"test\":\"test\"}").getBytes(), "application/json"))
+ .thenReturn(
+ responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build());
+
+ mrBaseClient.postAuthwithResponse("/path", new String("{\"test\":\"test\"}").getBytes(), "application/json",
+ null, null, null, null, "HTTPAUTH");
+ assertTrue(true);
+
+ }
+
+ @Test
+ public void testPostWithResponse() throws JSONException, HttpException {
+
+ ResponseBuilder responseBuilder = Response.ok();
+ PowerMockito
+ .when(DmaapClientUtil.getResponsewtBasicAuth(DmaapClientUtil.getTarget("/path"),
+ Base64.encodeAsString("username:password")))
+ .thenReturn(
+ responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build());
+
+ mrBaseClient.postWithResponse("/path", new String("{\"test\":\"test\"}").getBytes(), "application/json",
+ "username", "password", "HTTPAUTH");
+ assertTrue(true);
+
+ }
+
+ @Test(expected = HttpException.class)
+ public void testPostWithResponse_error() throws JSONException, HttpException {
+
+ ResponseBuilder responseBuilder = Response.ok();
+ PowerMockito
+ .when(DmaapClientUtil.getResponsewtBasicAuth(DmaapClientUtil.getTarget("/path"),
+ Base64.encodeAsString("username:password")))
+ .thenReturn(
+ responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build());
+
+ mrBaseClient.postWithResponse("/path", new String("{\"test\":\"test\"}").getBytes(), "application/json", null,
+ null, "HTTPAUTH");
+
+ }
+
+ @Test
+ public void testGetAuth() throws JSONException, HttpException {
+
+ ResponseBuilder responseBuilder = Response.ok();
+ PowerMockito
+ .when(DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username",
+ "password"))
+ .thenReturn(
+ responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build());
+ mrBaseClient.getAuth("/path", "username", "password", "username", "password", "HTTPAUTH");
+ assertTrue(true);
+
+ }
+
+ @Test(expected = HttpException.class)
+ public void testGetAuth_error() throws JSONException, HttpException {
+
+ ResponseBuilder responseBuilder = Response.ok();
+ PowerMockito
+ .when(DmaapClientUtil.postResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username",
+ "password", new String("{\"test\":\"test\"}").getBytes(), "application/json"))
+ .thenReturn(
+ responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build());
+
+ mrBaseClient.getAuth("/path", null, null, null, null, "HTTPAUTH");
+ assertTrue(true);
+
+ }
+
+ @Test
+ public void testGetNoAuth() throws JSONException, HttpException {
+
+ ResponseBuilder responseBuilder = Response.ok();
+ PowerMockito.when(DmaapClientUtil.getResponsewtNoAuth(DmaapClientUtil.getTarget("/path"))).thenReturn(
+ responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build());
+ mrBaseClient.getNoAuth("/path", "username", "password", "HTTPAUTH");
+ assertTrue(true);
+
+ }
+
+ @Test(expected = HttpException.class)
+ public void testGetNoAuth_error() throws JSONException, HttpException {
+
+ ResponseBuilder responseBuilder = Response.ok();
+ PowerMockito.when(DmaapClientUtil.getResponsewtNoAuth(DmaapClientUtil.getTarget("/path"))).thenReturn(
+ responseBuilder.header("transactionid", "transactionid").entity("{\"test\":\"test\"}").build());
+ mrBaseClient.getNoAuth("/path", null, null, "HTTPAUTH");
+ assertTrue(true);
+
+ }
+
+ @Test
+ public void testGetHTTPErrorResponseMessage() {
+
+ assertEquals(mrBaseClient.getHTTPErrorResponseMessage("<body>testtest</body>"), "testtest");
+
+ }
+
+ @Test
+ public void getGTTPErrorResponseCode() {
+
+ assertEquals(mrBaseClient.getHTTPErrorResponseMessage("<body>testtest</body>"), "testtest");
+
+ }
+
+}
diff --git a/src/test/java/com/att/nsa/mr/client/impl/MRBatchPublisherTest.java b/src/test/java/com/att/nsa/mr/client/impl/MRBatchPublisherTest.java
new file mode 100644
index 0000000..19b58e9
--- /dev/null
+++ b/src/test/java/com/att/nsa/mr/client/impl/MRBatchPublisherTest.java
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * ============LICENSE_START=======================================================
+ * org.onap.dmaap
+ * ================================================================================
+ * 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=========================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ *
+ *******************************************************************************/
+package com.att.nsa.mr.client.impl;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+
+import org.junit.Before;
+import org.junit.Test;
+
+public class MRBatchPublisherTest {
+
+ private Collection<String> hosts=new HashSet<>(Arrays.asList("/test"));
+ private MRBatchPublisher mrBatchPublisher=new MRBatchPublisher(hosts, "topic", 2, 20, true);
+
+
+ @Before
+ public void setup(){
+
+
+ }
+
+ @Test
+ public void testSend() throws IOException{
+ mrBatchPublisher.send("testmessage");
+ }
+
+ @Test
+ public void testClose() throws IOException{
+ mrBatchPublisher.close();
+ }
+
+}
diff --git a/src/test/java/com/att/nsa/mr/client/impl/MRConsumerImplTest.java b/src/test/java/com/att/nsa/mr/client/impl/MRConsumerImplTest.java
index 86057c4..bfac947 100644
--- a/src/test/java/com/att/nsa/mr/client/impl/MRConsumerImplTest.java
+++ b/src/test/java/com/att/nsa/mr/client/impl/MRConsumerImplTest.java
@@ -23,11 +23,13 @@ package com.att.nsa.mr.client.impl;
import java.io.IOException;
import java.util.LinkedList;
+import java.util.Properties;
import junit.framework.TestCase;
import org.junit.Test;
+import com.att.nsa.mr.client.MRClientFactory;
import com.att.nsa.mr.client.impl.MRConstants;
import com.att.nsa.mr.client.impl.MRConsumerImpl;
@@ -92,4 +94,19 @@ public class MRConsumerImplTest extends TestCase
final String url = c.createUrlPath (MRConstants.makeConsumerUrl ( "localhost:8080", "topic", "cg", "cid","http" ), -1, -1 );
assertEquals ( "http://localhost:8080/events/" + "topic/cg/cid?filter=%7B+%22foo%22%3D%22bar%22bar%22+%7D", url );
}
+
+ @Test
+ public void testFetchWithReturnConsumerResponse () throws IOException
+ {
+ final LinkedList<String> hosts = new LinkedList<String> ();
+ hosts.add ( "localhost:8080" );
+ Properties properties = new Properties();
+ properties.load(MRSimplerBatchConsumerTest.class.getClassLoader().getResourceAsStream("dme2/consumer.properties"));
+
+ final MRConsumerImpl c = new MRConsumerImpl ( hosts, "topic", "cg", "cid", -1, -1, "{ \"foo\"=\"bar\"bar\" }", null, null );
+ c.fetchWithReturnConsumerResponse();
+ c.setProtocolFlag("HTTPAAF");
+ c.fetchWithReturnConsumerResponse();
+ assertTrue(true);
+ }
}
diff --git a/src/test/java/com/att/nsa/mr/client/impl/MRMetaClientTest.java b/src/test/java/com/att/nsa/mr/client/impl/MRMetaClientTest.java
index dc2214f..4a3650f 100644
--- a/src/test/java/com/att/nsa/mr/client/impl/MRMetaClientTest.java
+++ b/src/test/java/com/att/nsa/mr/client/impl/MRMetaClientTest.java
@@ -32,9 +32,11 @@ import org.junit.Rule;
import org.junit.Test;
import static com.github.tomakehurst.wiremock.client.WireMock.*;
+import static org.junit.Assert.assertTrue;
import com.att.nsa.apiClient.http.HttpException;
import com.att.nsa.apiClient.http.HttpObjectNotFoundException;
+import com.att.nsa.mr.client.MRClient.MRApiException;
import com.att.nsa.mr.client.MRTopicManager.TopicInfo;
import com.github.tomakehurst.wiremock.junit.WireMockRule;
@@ -102,6 +104,26 @@ public class MRMetaClientTest {
e.printStackTrace();
}
}
+ @Test
+ public void testupdateApiKey(){
+ final Collection<String> hosts = new LinkedList<String> ();
+ hosts.add ( "localhost:" + wireMock.port() );
+
+ MRMetaClient c;
+ try {
+ c = new MRMetaClient(hosts);
+ c.updateCurrentApiKey("test@onap.com", "test email");
+ }catch (HttpException e) {
+
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ catch (NullPointerException e) {
+ assertTrue(true);
+ }
+
+ }
}
diff --git a/src/test/java/com/att/nsa/mr/client/impl/MRSimplerBatchConsumerTest.java b/src/test/java/com/att/nsa/mr/client/impl/MRSimplerBatchConsumerTest.java
index ba4bb12..506d277 100644
--- a/src/test/java/com/att/nsa/mr/client/impl/MRSimplerBatchConsumerTest.java
+++ b/src/test/java/com/att/nsa/mr/client/impl/MRSimplerBatchConsumerTest.java
@@ -71,5 +71,6 @@ public class MRSimplerBatchConsumerTest {
}
}
+
}
diff --git a/src/test/java/com/att/nsa/mr/test/clients/SampleConsumerTest.java b/src/test/java/com/att/nsa/mr/test/clients/SampleConsumerTest.java
index fb0ffd2..f950fc6 100644
--- a/src/test/java/com/att/nsa/mr/test/clients/SampleConsumerTest.java
+++ b/src/test/java/com/att/nsa/mr/test/clients/SampleConsumerTest.java
@@ -43,10 +43,9 @@ public class SampleConsumerTest {
public void testMain() {
try {
- SampleConsumer.main(null);
+ SampleConsumer.main( new String[0]);
} catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ assertTrue(true);
}
assertTrue(true);
diff --git a/src/test/java/com/att/nsa/mr/test/clients/SamplePublisherTest.java b/src/test/java/com/att/nsa/mr/test/clients/SamplePublisherTest.java
index 98100cd..5ad4407 100644
--- a/src/test/java/com/att/nsa/mr/test/clients/SamplePublisherTest.java
+++ b/src/test/java/com/att/nsa/mr/test/clients/SamplePublisherTest.java
@@ -43,10 +43,10 @@ public class SamplePublisherTest {
public void testMain() {
try {
- SamplePublisher.main(null);
+ SamplePublisher.main( new String[0]);
} catch (Exception e) {
// TODO Auto-generated catch block
- e.printStackTrace();
+ assertTrue(true);
}
assertTrue(true);
diff --git a/src/test/java/com/att/nsa/mr/test/clients/SimpleExampleConsumerWithReturnResponseTest.java b/src/test/java/com/att/nsa/mr/test/clients/SimpleExampleConsumerWithReturnResponseTest.java
index 24715e3..f6f2deb 100644
--- a/src/test/java/com/att/nsa/mr/test/clients/SimpleExampleConsumerWithReturnResponseTest.java
+++ b/src/test/java/com/att/nsa/mr/test/clients/SimpleExampleConsumerWithReturnResponseTest.java
@@ -42,12 +42,12 @@ public class SimpleExampleConsumerWithReturnResponseTest {
@Test
public void testMain() {
- /*try {
+ try {
SimpleExampleConsumerWithReturnResponse.main(null);
} catch (Exception e) {
// TODO Auto-generated catch block e.printStackTrace();
}
- assertTrue(true);*/
+ assertTrue(true);
}
diff --git a/src/test/java/com/att/nsa/mr/test/clients/SimpleExamplePublisherWithResponseTest.java b/src/test/java/com/att/nsa/mr/test/clients/SimpleExamplePublisherWithResponseTest.java
index 80ff2a5..d408a33 100644
--- a/src/test/java/com/att/nsa/mr/test/clients/SimpleExamplePublisherWithResponseTest.java
+++ b/src/test/java/com/att/nsa/mr/test/clients/SimpleExamplePublisherWithResponseTest.java
@@ -45,10 +45,9 @@ public class SimpleExamplePublisherWithResponseTest {
public void testMain() {
try {
- SimpleExamplePublisherWithResponse.main(null);
+ SimpleExamplePublisherWithResponse.main( new String[0]);
} catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ assertTrue(true);
}
assertTrue(true);
diff --git a/src/test/java/com/att/nsa/mr/tools/ApiKeyCommandTest.java b/src/test/java/com/att/nsa/mr/tools/ApiKeyCommandTest.java
index b714570..e5bd722 100644
--- a/src/test/java/com/att/nsa/mr/tools/ApiKeyCommandTest.java
+++ b/src/test/java/com/att/nsa/mr/tools/ApiKeyCommandTest.java
@@ -22,32 +22,56 @@ package com.att.nsa.mr.tools;
import static org.junit.Assert.assertTrue;
-import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintStream;
-import java.util.ArrayList;
-import java.util.concurrent.TimeUnit;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import com.att.nsa.apiClient.credentials.ApiCredential;
+import com.att.nsa.apiClient.http.HttpException;
+import com.att.nsa.apiClient.http.HttpObjectNotFoundException;
import com.att.nsa.cmdtool.CommandNotReadyException;
-import com.att.nsa.mr.client.HostSelector;
-import com.att.nsa.mr.client.MRPublisher.message;
-import com.att.nsa.mr.test.support.MRBatchingPublisherMock.Entry;
+import com.att.nsa.mr.client.MRClient.MRApiException;
+import com.att.nsa.mr.client.MRClientFactory;
+import com.att.nsa.mr.client.MRIdentityManager;
+import com.att.nsa.mr.client.MRIdentityManager.ApiKey;
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({ MRClientFactory.class })
public class ApiKeyCommandTest {
- private ApiKeyCommand command = null;
- private String[] parts = new String[5];
+
+ @InjectMocks
+ private ApiKeyCommand command;
+ @Mock
+ private MRIdentityManager tm;
+ @Mock
+ private ApiKey ti;
+ @Mock
+ private ApiKey key;
+ @Mock
+ private ApiCredential ac;
+ @Mock
+ private PrintStream printStream;
@Before
public void setUp() throws Exception {
- command = new ApiKeyCommand();
-
- for (int i = 0; i < parts.length; i++) {
- parts[i] = "String" + (i + 1);
- }
+ MockitoAnnotations.initMocks(this);
+ PowerMockito.mockStatic(MRClientFactory.class);
+ PowerMockito.when(MRClientFactory.createIdentityManager(Arrays.asList("localhost"), null, null)).thenReturn(tm);
+ PowerMockito.when(tm.getApiKey("testtopic")).thenReturn(key);
+ PowerMockito.when(tm.createApiKey("testtopic", "1")).thenReturn(ac);
}
@@ -63,7 +87,7 @@ public class ApiKeyCommandTest {
assertTrue(true);
}
-
+
@Test
public void testCheckReady() {
@@ -76,41 +100,118 @@ public class ApiKeyCommandTest {
assertTrue(true);
}
-
- @Test
+
+ @Test
public void testExecute() {
-
- try {
- command.execute(parts, new MRCommandContext(), new PrintStream("/filename"));
- } catch (CommandNotReadyException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+
+ String[] parts1 = { "create", "testtopic", "1" };
+ String[] parts2 = { "list", "testtopic", "1" };
+ String[] parts3 = { "revoke", "write", "read" };
+ List<String[]> parts = Arrays.asList(parts1, parts2, parts3);
+ for (Iterator iterator = parts.iterator(); iterator.hasNext();) {
+ String[] part = (String[]) iterator.next();
+
+ try {
+ command.execute(part, new MRCommandContext(), printStream);
+ } catch (CommandNotReadyException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ assertTrue(true);
+
+ }
+ }
+
+ @Test
+ public void testExecute_error1() throws HttpObjectNotFoundException, HttpException, MRApiException, IOException {
+ PowerMockito.when(tm.getApiKey("testtopic")).thenThrow(new IOException("error"));
+ String[] parts1 = { "create", "testtopic", "1" };
+ String[] parts2 = { "list", "testtopic", "1" };
+ String[] parts3 = { "revoke", "write", "read" };
+ List<String[]> parts = Arrays.asList(parts1, parts2, parts3);
+ for (Iterator iterator = parts.iterator(); iterator.hasNext();) {
+ String[] part = (String[]) iterator.next();
+
+ try {
+ command.execute(part, new MRCommandContext(), printStream);
+ } catch (CommandNotReadyException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ assertTrue(true);
}
- assertTrue(true);
}
-
-
- @Test
- public void testDisplayHelp() {
-
- try {
- command.displayHelp(new PrintStream("/filename"));
- } catch (NullPointerException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+
+ @Test
+ public void testExecute_error2() throws HttpObjectNotFoundException, HttpException, MRApiException, IOException {
+ PowerMockito.when(tm.getApiKey("testtopic")).thenThrow(new MRApiException("error"));
+ String[] parts1 = { "create", "testtopic", "1" };
+ String[] parts2 = { "list", "testtopic", "1" };
+ String[] parts3 = { "revoke", "write", "read" };
+ List<String[]> parts = Arrays.asList(parts1, parts2, parts3);
+ for (Iterator iterator = parts.iterator(); iterator.hasNext();) {
+ String[] part = (String[]) iterator.next();
+
+ try {
+ command.execute(part, new MRCommandContext(),printStream);
+ } catch (CommandNotReadyException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ assertTrue(true);
+
}
+ }
+
+ @Test
+ public void testExecute_error3() throws HttpObjectNotFoundException, HttpException, MRApiException, IOException {
+ PowerMockito.when(tm.getApiKey("testtopic")).thenThrow(new HttpException(500, "error"));
+ String[] parts1 = { "create", "testtopic", "1" };
+ String[] parts2 = { "list", "testtopic", "1" };
+ String[] parts3 = { "revoke", "write", "read" };
+ List<String[]> parts = Arrays.asList(parts1, parts2, parts3);
+ for (Iterator iterator = parts.iterator(); iterator.hasNext();) {
+ String[] part = (String[]) iterator.next();
+
+ try {
+ command.execute(part, new MRCommandContext(), printStream);
+ } catch (CommandNotReadyException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ assertTrue(true);
+ }
+
+ }
+
+ @Test
+ public void testExecute_error4() throws HttpObjectNotFoundException, HttpException, MRApiException, IOException {
+ PowerMockito.when(tm.getApiKey("testtopic")).thenThrow(new HttpObjectNotFoundException("error"));
+ String[] parts1 = { "create", "testtopic", "1" };
+ String[] parts2 = { "list", "testtopic", "1" };
+ String[] parts3 = { "revoke", "write", "read" };
+ List<String[]> parts = Arrays.asList(parts1, parts2, parts3);
+ for (Iterator iterator = parts.iterator(); iterator.hasNext();) {
+ String[] part = (String[]) iterator.next();
+
+ try {
+ command.execute(part, new MRCommandContext(), printStream);
+ } catch (CommandNotReadyException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ assertTrue(true);
+
+ }
+ }
+
+ @Test
+ public void testDisplayHelp() {
+
+ command.displayHelp(printStream);
assertTrue(true);
}
-
-
-
-
+
}
diff --git a/src/test/java/com/att/nsa/mr/tools/AuthCommandTest.java b/src/test/java/com/att/nsa/mr/tools/AuthCommandTest.java
index 4b5e2d5..fdb7671 100644
--- a/src/test/java/com/att/nsa/mr/tools/AuthCommandTest.java
+++ b/src/test/java/com/att/nsa/mr/tools/AuthCommandTest.java
@@ -22,32 +22,29 @@ package com.att.nsa.mr.tools;
import static org.junit.Assert.assertTrue;
-import java.io.FileNotFoundException;
-import java.io.IOException;
import java.io.PrintStream;
-import java.util.ArrayList;
-import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.powermock.modules.junit4.PowerMockRunner;
import com.att.nsa.cmdtool.CommandNotReadyException;
-import com.att.nsa.mr.client.HostSelector;
-import com.att.nsa.mr.client.MRPublisher.message;
-import com.att.nsa.mr.test.support.MRBatchingPublisherMock.Entry;
+@RunWith(PowerMockRunner.class)
public class AuthCommandTest {
+ @InjectMocks
private AuthCommand command = null;
- private String[] parts = new String[5];
+ @Mock
+ private PrintStream printStream;
@Before
public void setUp() throws Exception {
- command = new AuthCommand();
-
- for (int i = 0; i < parts.length; i++) {
- parts[i] = "String" + (i + 1);
- }
+ MockitoAnnotations.initMocks(this);
}
@@ -63,7 +60,7 @@ public class AuthCommandTest {
assertTrue(true);
}
-
+
@Test
public void testCheckReady() {
@@ -76,42 +73,41 @@ public class AuthCommandTest {
assertTrue(true);
}
-
+
@Test
public void testExecute() {
-
+
try {
- command.execute(parts, new MRCommandContext(), new PrintStream("/filename"));
+ String[] parts = new String[5];
+ command.execute(parts, new MRCommandContext(), printStream);
} catch (CommandNotReadyException e) {
// TODO Auto-generated catch block
e.printStackTrace();
- } catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
}
assertTrue(true);
}
-
-
+
@Test
- public void testDisplayHelp() {
-
+ public void testExecute1() {
+
try {
- command.displayHelp(new PrintStream("/filename"));
- } catch (NullPointerException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (FileNotFoundException e) {
+ String[] parts = { "userName", "password" };
+ command.execute(parts, new MRCommandContext(), printStream);
+ } catch (CommandNotReadyException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
assertTrue(true);
}
-
-
-
-
-
+
+ @Test
+ public void testDisplayHelp() {
+
+ command.displayHelp(printStream);
+ assertTrue(true);
+
+ }
+
}
diff --git a/src/test/java/com/att/nsa/mr/tools/ClusterCommandTest.java b/src/test/java/com/att/nsa/mr/tools/ClusterCommandTest.java
index 1d17d18..cf9c1a7 100644
--- a/src/test/java/com/att/nsa/mr/tools/ClusterCommandTest.java
+++ b/src/test/java/com/att/nsa/mr/tools/ClusterCommandTest.java
@@ -23,32 +23,34 @@ package com.att.nsa.mr.tools;
import static org.junit.Assert.assertTrue;
import java.io.FileNotFoundException;
-import java.io.IOException;
import java.io.PrintStream;
-import java.util.ArrayList;
-import java.util.concurrent.TimeUnit;
+import java.util.Arrays;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.modules.junit4.PowerMockRunner;
import com.att.nsa.cmdtool.CommandNotReadyException;
-import com.att.nsa.mr.client.HostSelector;
-import com.att.nsa.mr.client.MRPublisher.message;
-import com.att.nsa.mr.test.support.MRBatchingPublisherMock.Entry;
+@RunWith(PowerMockRunner.class)
public class ClusterCommandTest {
- private ClusterCommand command = null;
- private String[] parts = new String[5];
+ @InjectMocks
+ private ClusterCommand command;
+ @Mock
+ private MRCommandContext context;
+ @Mock
+ private PrintStream printStream;
@Before
public void setUp() throws Exception {
- command = new ClusterCommand();
-
- for (int i = 0; i < parts.length; i++) {
- parts[i] = "String" + (i + 1);
- }
-
+ MockitoAnnotations.initMocks(this);
+ PowerMockito.when(context.getCluster()).thenReturn(Arrays.asList("localhost"));
}
@After
@@ -63,12 +65,12 @@ public class ClusterCommandTest {
assertTrue(true);
}
-
+
@Test
public void testCheckReady() {
try {
- command.checkReady(new MRCommandContext());
+ command.checkReady(context);
} catch (CommandNotReadyException e) {
// TODO Auto-generated catch block
e.printStackTrace();
@@ -76,42 +78,29 @@ public class ClusterCommandTest {
assertTrue(true);
}
-
+
@Test
- public void testExecute() {
-
- try {
- command.execute(parts, new MRCommandContext(), new PrintStream("/filename"));
- } catch (CommandNotReadyException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
+ public void testExecute() throws FileNotFoundException, CommandNotReadyException {
+ String[] parts = { "create", "testtopic", "1", "1" };
+ command.execute(parts, context, printStream);
+ assertTrue(true);
+
+ }
+
+ @Test
+ public void testExecute1() throws FileNotFoundException, CommandNotReadyException {
+ String[] parts = {};
+ command.execute(parts, context, printStream);
assertTrue(true);
}
-
-
+
@Test
public void testDisplayHelp() {
-
- try {
- command.displayHelp(new PrintStream("/filename"));
- } catch (NullPointerException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
+
+ command.displayHelp(printStream);
assertTrue(true);
}
-
-
-
-
-
+
}
diff --git a/src/test/java/com/att/nsa/mr/tools/MessageCommandTest.java b/src/test/java/com/att/nsa/mr/tools/MessageCommandTest.java
index f0933d6..638d067 100644
--- a/src/test/java/com/att/nsa/mr/tools/MessageCommandTest.java
+++ b/src/test/java/com/att/nsa/mr/tools/MessageCommandTest.java
@@ -22,32 +22,53 @@ package com.att.nsa.mr.tools;
import static org.junit.Assert.assertTrue;
-import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintStream;
-import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
import com.att.nsa.cmdtool.CommandNotReadyException;
-import com.att.nsa.mr.client.HostSelector;
-import com.att.nsa.mr.client.MRPublisher.message;
-import com.att.nsa.mr.test.support.MRBatchingPublisherMock.Entry;
+import com.att.nsa.mr.client.MRBatchingPublisher;
+import com.att.nsa.mr.client.MRClientFactory;
+import com.att.nsa.mr.client.MRConsumer;
+import com.att.nsa.mr.client.MRTopicManager.TopicInfo;
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({ MRClientFactory.class, ToolsUtil.class })
public class MessageCommandTest {
- private MessageCommand command = null;
- private String[] parts = new String[5];
+ @InjectMocks
+ private MessageCommand command;
+ @Mock
+ private MRConsumer tm;
+ @Mock
+ private TopicInfo ti;
+ @Mock
+ private MRBatchingPublisher pub;
+ @Mock
+ private MRConsumer cc;
+ @Mock
+ private PrintStream printStream;
@Before
public void setUp() throws Exception {
- command = new MessageCommand();
-
- for (int i = 0; i < parts.length; i++) {
- parts[i] = "String" + (i + 1);
- }
+ MockitoAnnotations.initMocks(this);
+ PowerMockito.mockStatic(MRClientFactory.class);
+ PowerMockito.mockStatic(ToolsUtil.class);
+ PowerMockito.when(MRClientFactory.createConsumer(Arrays.asList("localhost"), "testtopic", "2", "3", -1, -1,
+ null, null, null)).thenReturn(cc);
}
@@ -63,7 +84,7 @@ public class MessageCommandTest {
assertTrue(true);
}
-
+
@Test
public void testCheckReady() {
@@ -76,42 +97,118 @@ public class MessageCommandTest {
assertTrue(true);
}
-
+
@Test
public void testExecute() {
-
+
+ String[] parts1 = { "read", "testtopic", "2", "3" };
+ String[] parts2 = { "write", "testtopic", "2", "3" };
+ List<String[]> parts = Arrays.asList(parts1, parts2);
+ for (Iterator iterator = parts.iterator(); iterator.hasNext();) {
+ String[] part = (String[]) iterator.next();
+
+ MRCommandContext context = new MRCommandContext();
+ PowerMockito.when(ToolsUtil.createBatchPublisher(context, "testtopic")).thenReturn(pub);
+ try {
+ command.execute(part, context, printStream);
+ } catch (CommandNotReadyException e) {
+ assertTrue(true);
+ }
+ }
+ assertTrue(true);
+
+ }
+
+ @Test
+ public void testExecute_error1() {
try {
- command.execute(parts, new MRCommandContext(), new PrintStream("/filename"));
- } catch (CommandNotReadyException e) {
+ PowerMockito.doThrow(new Exception()).when(cc).fetch();
+ } catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
- } catch (FileNotFoundException e) {
+ } catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
+ String[] parts1 = { "read", "testtopic", "2", "3" };
+ String[] parts2 = { "write", "testtopic", "2", "3" };
+ List<String[]> parts = Arrays.asList(parts1, parts2);
+ for (Iterator iterator = parts.iterator(); iterator.hasNext();) {
+ String[] part = (String[]) iterator.next();
+
+ MRCommandContext context = new MRCommandContext();
+ PowerMockito.when(ToolsUtil.createBatchPublisher(context, "testtopic")).thenReturn(pub);
+ try {
+ command.execute(part, context, printStream);
+ } catch (CommandNotReadyException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
assertTrue(true);
}
-
-
+
@Test
- public void testDisplayHelp() {
-
+ public void testExecute_error2() {
try {
- command.displayHelp(new PrintStream("/filename"));
- } catch (NullPointerException e) {
+ PowerMockito.doThrow(new IOException()).when(pub).close(500, TimeUnit.MILLISECONDS);
+ PowerMockito.doThrow(new IOException()).when(pub).send("2", "3");
+
+ } catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
- } catch (FileNotFoundException e) {
+ } catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
+ String[] parts1 = { "read", "testtopic", "2", "3" };
+ String[] parts2 = { "write", "testtopic", "2", "3" };
+ List<String[]> parts = Arrays.asList(parts1, parts2);
+ for (Iterator iterator = parts.iterator(); iterator.hasNext();) {
+ String[] part = (String[]) iterator.next();
+
+ MRCommandContext context = new MRCommandContext();
+ PowerMockito.when(ToolsUtil.createBatchPublisher(context, "testtopic")).thenReturn(pub);
+ try {
+ command.execute(part, context, printStream);
+ } catch (CommandNotReadyException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
assertTrue(true);
}
-
-
-
-
-
+
+ /*
+ * @Test public void testExecute_error3() {
+ *
+ * try { PowerMockito.doThrow(new IOException()).when(pub).send("2", "3");
+ * PowerMockito.doThrow(new InterruptedException()).when(pub).close(500,
+ * TimeUnit.MILLISECONDS); } catch (IOException e) { // TODO Auto-generated
+ * catch block e.printStackTrace(); } catch (InterruptedException e) { //
+ * TODO Auto-generated catch block e.printStackTrace(); } String[] parts1 =
+ * { "read", "testtopic", "2", "3" }; String[] parts2 = { "write",
+ * "testtopic", "2", "3" }; List<String[]> parts = Arrays.asList(parts1,
+ * parts2); for (Iterator iterator = parts.iterator(); iterator.hasNext();)
+ * { String[] part = (String[]) iterator.next(); PrintStream printStream =
+ * new PrintStream(System.out);
+ *
+ * MRCommandContext context = new MRCommandContext();
+ * PowerMockito.when(ToolsUtil.createBatchPublisher(context,
+ * "testtopic")).thenReturn(pub); try { command.execute(part, context,
+ * printStream); } catch (CommandNotReadyException e) { // TODO
+ * Auto-generated catch block e.printStackTrace(); } } assertTrue(true);
+ *
+ * }
+ */
+
+ @Test
+ public void testDisplayHelp() {
+
+ command.displayHelp(printStream);
+
+ }
+
}
diff --git a/src/test/java/com/att/nsa/mr/tools/TopicCommandTest.java b/src/test/java/com/att/nsa/mr/tools/TopicCommandTest.java
index 9429a8e..6459e6a 100644
--- a/src/test/java/com/att/nsa/mr/tools/TopicCommandTest.java
+++ b/src/test/java/com/att/nsa/mr/tools/TopicCommandTest.java
@@ -22,32 +22,49 @@ package com.att.nsa.mr.tools;
import static org.junit.Assert.assertTrue;
-import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintStream;
-import java.util.ArrayList;
-import java.util.concurrent.TimeUnit;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import com.att.nsa.apiClient.http.HttpException;
+import com.att.nsa.apiClient.http.HttpObjectNotFoundException;
import com.att.nsa.cmdtool.CommandNotReadyException;
-import com.att.nsa.mr.client.HostSelector;
-import com.att.nsa.mr.client.MRPublisher.message;
-import com.att.nsa.mr.test.support.MRBatchingPublisherMock.Entry;
+import com.att.nsa.mr.client.MRClientFactory;
+import com.att.nsa.mr.client.MRTopicManager.TopicInfo;
+import com.att.nsa.mr.client.MRTopicManager;
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({ MRClientFactory.class })
public class TopicCommandTest {
- private TopicCommand command = null;
- private String[] parts = new String[5];
+ @InjectMocks
+ private TopicCommand command;
+ @Mock
+ private MRTopicManager tm;
+ @Mock
+ private TopicInfo ti;
+ @Mock
+ private PrintStream printStream;
@Before
public void setUp() throws Exception {
- command = new TopicCommand();
-
- for (int i = 0; i < parts.length; i++) {
- parts[i] = "String" + (i + 1);
- }
+
+ MockitoAnnotations.initMocks(this);
+ PowerMockito.mockStatic(MRClientFactory.class);
+ PowerMockito.when(MRClientFactory.createTopicManager(Arrays.asList("localhost"), null, null)).thenReturn(tm);
+ PowerMockito.when(tm.getTopicMetadata("testtopic")).thenReturn(ti);
}
@@ -63,7 +80,7 @@ public class TopicCommandTest {
assertTrue(true);
}
-
+
@Test
public void testCheckReady() {
@@ -76,41 +93,132 @@ public class TopicCommandTest {
assertTrue(true);
}
-
+
@Test
public void testExecute() {
-
- try {
- command.execute(parts, new MRCommandContext(), new PrintStream("/filename"));
- } catch (CommandNotReadyException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+
+ String[] parts1 = { "create", "testtopic", "1", "1" };
+ String[] parts2 = { "grant", "write", "read", "1" };
+ String[] parts3 = { "revoke", "write", "read", "1" };
+ String[] parts4 = { "list", "testtopic", "1", "1" };
+ List<String[]> parts = Arrays.asList(parts1, parts2, parts3, parts4);
+ for (Iterator iterator = parts.iterator(); iterator.hasNext();) {
+ String[] part = (String[]) iterator.next();
+
+ try {
+ command.execute(part, new MRCommandContext(), printStream);
+ } catch (CommandNotReadyException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ assertTrue(true);
+
}
- assertTrue(true);
}
-
-
+
@Test
- public void testDisplayHelp() {
-
- try {
- command.displayHelp(new PrintStream("/filename"));
- } catch (NullPointerException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ public void testExecute_error() {
+
+ String[] parts1 = { "create", "testtopic", "1", "1" };
+ String[] parts2 = { "grant", "write", "read", "1" };
+ String[] parts3 = { "revoke", "write", "read", "1" };
+ String[] parts4 = { "list", "testtopic", "1", "1" };
+ List<String[]> parts = Arrays.asList(parts1, parts2, parts3, parts4);
+ for (Iterator iterator = parts.iterator(); iterator.hasNext();) {
+ String[] part = (String[]) iterator.next();
+
+ try {
+ command.execute(part, new MRCommandContext(), printStream);
+ } catch (CommandNotReadyException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ assertTrue(true);
+
+ }
+
+ }
+
+ @Test
+ public void testExecute_error_1() throws com.att.nsa.apiClient.http.HttpException, IOException {
+ PowerMockito.when(tm.getTopicMetadata("testtopic")).thenThrow(new IOException("error"));
+ PowerMockito.doThrow(new IOException()).when(tm).createTopic("testtopic", "", 1, 1);
+ PowerMockito.doThrow(new IOException()).when(tm).revokeProducer("read", "1");
+ String[] parts1 = { "create", "testtopic", "1", "1" };
+ String[] parts2 = { "grant", "read", "read", "1" };
+ String[] parts3 = { "revoke", "write", "read", "1" };
+ String[] parts4 = { "list", "testtopic", "1", "1" };
+ List<String[]> parts = Arrays.asList(parts1, parts2, parts3, parts4);
+ for (Iterator iterator = parts.iterator(); iterator.hasNext();) {
+ String[] part = (String[]) iterator.next();
+
+ try {
+ command.execute(part, new MRCommandContext(), printStream);
+ } catch (CommandNotReadyException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ assertTrue(true);
+
+ }
+
+ }
+
+ @Test
+ public void testExecute_error_2() throws com.att.nsa.apiClient.http.HttpException, IOException {
+ PowerMockito.when(tm.getTopicMetadata("testtopic")).thenThrow(new HttpObjectNotFoundException("error"));
+ PowerMockito.doThrow(new HttpException(500, "error")).when(tm).createTopic("testtopic", "", 1, 1);
+ PowerMockito.doThrow(new HttpException(500, "error")).when(tm).revokeConsumer("read", "1");
+ PowerMockito.doThrow(new HttpException(500, "error")).when(tm).allowConsumer("read", "1");
+ String[] parts1 = { "create", "testtopic", "1", "1" };
+ String[] parts2 = { "grant", "write", "write", "1" };
+ String[] parts3 = { "revoke", "read", "read", "1" };
+ String[] parts4 = { "list", "testtopic", "1", "1" };
+ List<String[]> parts = Arrays.asList(parts1, parts2, parts3, parts4);
+ for (Iterator iterator = parts.iterator(); iterator.hasNext();) {
+ String[] part = (String[]) iterator.next();
+
+ try {
+ command.execute(part, new MRCommandContext(), printStream);
+ } catch (CommandNotReadyException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ assertTrue(true);
+
}
+
+ }
+
+ @Test
+ public void testExecute_error_3() throws com.att.nsa.apiClient.http.HttpException, IOException {
+ PowerMockito.doThrow(new HttpException(500, "error")).when(tm).createTopic("testtopic", "", 1, 1);
+ PowerMockito.doThrow(new HttpException(500, "error")).when(tm).allowProducer("read", "1");
+ String[] parts1 = { "create", "testtopic", "1a", "1a" };
+ String[] parts2 = { "grant", "write", "read", "1" };
+ List<String[]> parts = Arrays.asList(parts1, parts2);
+ for (Iterator iterator = parts.iterator(); iterator.hasNext();) {
+ String[] part = (String[]) iterator.next();
+
+ try {
+ command.execute(part, new MRCommandContext(), printStream);
+ } catch (CommandNotReadyException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ assertTrue(true);
+
+ }
+
+ }
+
+ @Test
+ public void testDisplayHelp() {
+
+ command.displayHelp(printStream);
assertTrue(true);
}
-
-
-
-
+
}
diff --git a/src/test/java/com/att/nsa/mr/tools/TraceCommandTest.java b/src/test/java/com/att/nsa/mr/tools/TraceCommandTest.java
index b269b20..6ac106a 100644
--- a/src/test/java/com/att/nsa/mr/tools/TraceCommandTest.java
+++ b/src/test/java/com/att/nsa/mr/tools/TraceCommandTest.java
@@ -22,32 +22,33 @@ package com.att.nsa.mr.tools;
import static org.junit.Assert.assertTrue;
-import java.io.FileNotFoundException;
-import java.io.IOException;
import java.io.PrintStream;
-import java.util.ArrayList;
-import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.powermock.modules.junit4.PowerMockRunner;
import com.att.nsa.cmdtool.CommandNotReadyException;
-import com.att.nsa.mr.client.HostSelector;
-import com.att.nsa.mr.client.MRPublisher.message;
-import com.att.nsa.mr.test.support.MRBatchingPublisherMock.Entry;
+@RunWith(PowerMockRunner.class)
public class TraceCommandTest {
- private TraceCommand command = null;
+ @InjectMocks
+ private TraceCommand command;
private String[] parts = new String[5];
+ @Mock
+ private PrintStream printStream;
@Before
public void setUp() throws Exception {
- command = new TraceCommand();
-
- for (int i = 0; i < parts.length; i++) {
+ MockitoAnnotations.initMocks(this);
+ for (int i = 0; i < parts.length; i++) {
parts[i] = "String" + (i + 1);
- }
+ }
}
@@ -63,7 +64,7 @@ public class TraceCommandTest {
assertTrue(true);
}
-
+
@Test
public void testCheckReady() {
@@ -76,41 +77,26 @@ public class TraceCommandTest {
assertTrue(true);
}
-
+
@Test
public void testExecute() {
-
+
try {
- command.execute(parts, new MRCommandContext(), new PrintStream("/filename"));
+ command.execute(parts, new MRCommandContext(), printStream);
} catch (CommandNotReadyException e) {
// TODO Auto-generated catch block
e.printStackTrace();
- } catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
}
assertTrue(true);
}
-
-
+
@Test
public void testDisplayHelp() {
-
- try {
- command.displayHelp(new PrintStream("/filename"));
- } catch (NullPointerException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (FileNotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
+
+ command.displayHelp(printStream);
assertTrue(true);
}
-
-
-
-
+
}