From 173a07c146746f85c17f2d58f2ded84b99818f9a Mon Sep 17 00:00:00 2001 From: Sunil Unnava Date: Tue, 6 Mar 2018 11:41:18 -0500 Subject: testcases for code coverage Issue-ID: DMAAP-271 Change-Id: I9b11a61d1098598f8dc6c687a10ebf765128d977 Signed-off-by: Sunil Unnava --- pom.xml | 64 ++-- .../att/nsa/mr/client/impl/DmaapClientUtil.java | 74 ++++ .../com/att/nsa/mr/client/impl/MRBaseClient.java | 146 +++----- .../java/com/att/nsa/mr/tools/MessageCommand.java | 7 +- src/main/java/com/att/nsa/mr/tools/ToolsUtil.java | 37 ++ .../att/nsa/mr/client/impl/MRBaseClientTest.java | 412 +++++++++++++++++++++ .../nsa/mr/client/impl/MRBatchPublisherTest.java | 54 +++ .../att/nsa/mr/client/impl/MRConsumerImplTest.java | 17 + .../att/nsa/mr/client/impl/MRMetaClientTest.java | 22 ++ .../mr/client/impl/MRSimplerBatchConsumerTest.java | 1 + .../nsa/mr/test/clients/SampleConsumerTest.java | 5 +- .../nsa/mr/test/clients/SamplePublisherTest.java | 4 +- ...impleExampleConsumerWithReturnResponseTest.java | 4 +- .../SimpleExamplePublisherWithResponseTest.java | 5 +- .../com/att/nsa/mr/tools/ApiKeyCommandTest.java | 189 +++++++--- .../java/com/att/nsa/mr/tools/AuthCommandTest.java | 64 ++-- .../com/att/nsa/mr/tools/ClusterCommandTest.java | 79 ++-- .../com/att/nsa/mr/tools/MessageCommandTest.java | 157 ++++++-- .../com/att/nsa/mr/tools/TopicCommandTest.java | 192 +++++++--- .../com/att/nsa/mr/tools/TraceCommandTest.java | 56 ++- 20 files changed, 1225 insertions(+), 364 deletions(-) create mode 100644 src/main/java/com/att/nsa/mr/client/impl/DmaapClientUtil.java create mode 100644 src/main/java/com/att/nsa/mr/tools/ToolsUtil.java create mode 100644 src/test/java/com/att/nsa/mr/client/impl/MRBaseClientTest.java create mode 100644 src/test/java/com/att/nsa/mr/client/impl/MRBatchPublisherTest.java diff --git a/pom.xml b/pom.xml index 28858d5..142d125 100644 --- a/pom.xml +++ b/pom.xml @@ -84,7 +84,7 @@ com.fasterxml.jackson.core jackson-databind - 2.8.10 + 2.8.11 org.apache.httpcomponents @@ -170,8 +170,26 @@ org.mockito - mockito-all - 1.9.5 + mockito-core + 1.10.19 + test + + + org.powermock + powermock-module-junit4 + 1.6.4 + test + + + org.powermock + powermock-api-mockito + 1.6.4 + test + + + org.springframework + spring-test + 3.0.5.RELEASE test @@ -265,13 +283,13 @@ 1.7 - + + Note: This exclusion list should match property + above **/gen/** **/generated-sources/** @@ -280,23 +298,23 @@ - + Prepares the property pointing to the JaCoCo runtime agent which + is passed as VM argument when Maven the Surefire plugin is executed. pre-unit-test prepare-agent - + Sets the path to the file which contains the execution data. ${project.build.directory}/code-coverage/jacoco-ut.exec - + Sets the name of the property containing the settings for JaCoCo + runtime agent. surefireArgLine - + Ensures that the code coverage report for unit tests is created + after unit tests have been run. post-unit-test test @@ -304,9 +322,9 @@ report - + Sets the path to the file which contains the execution data. ${project.build.directory}/code-coverage/jacoco-ut.exec - + Sets the output directory for the code coverage report. ${project.reporting.outputDirectory}/jacoco-ut @@ -317,15 +335,15 @@ prepare-agent - + Sets the path to the file which contains the execution data. ${project.build.directory}/code-coverage/jacoco-it.exec - + Sets the name of the property containing the settings for JaCoCo + runtime agent. failsafeArgLine - + Ensures that the code coverage report for integration tests after + integration tests have been run. post-integration-test post-integration-test @@ -333,14 +351,14 @@ report - + Sets the path to the file which contains the execution data. ${project.build.directory}/code-coverage/jacoco-it.exec - + Sets the output directory for the code coverage report. ${project.reporting.outputDirectory}/jacoco-it - + --> diff --git a/src/main/java/com/att/nsa/mr/client/impl/DmaapClientUtil.java b/src/main/java/com/att/nsa/mr/client/impl/DmaapClientUtil.java new file mode 100644 index 0000000..6adf236 --- /dev/null +++ b/src/main/java/com/att/nsa/mr/client/impl/DmaapClientUtil.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * ============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 javax.ws.rs.client.Client; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Entity; +import javax.ws.rs.client.WebTarget; +import javax.ws.rs.core.Response; + +import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; + +public class DmaapClientUtil { + + private static final String MR_AUTH_CONSTANT = "X-CambriaAuth"; + private static final String MR_DATE_CONSTANT = "X-CambriaDate"; + + public static WebTarget getTarget(final String path, final String username, final String password) { + + Client client = ClientBuilder.newClient(); + HttpAuthenticationFeature feature = HttpAuthenticationFeature.universal(username, password); + client.register(feature); + + return client.target(path); + } + + public static WebTarget getTarget(final String path) { + + Client client = ClientBuilder.newClient(); + return client.target(path); + } + + public static Response getResponsewtCambriaAuth(WebTarget target, String username, String password) { + return target.request().header(MR_AUTH_CONSTANT, username).header(MR_DATE_CONSTANT, password).get(); + + } + + public static Response postResponsewtCambriaAuth(WebTarget target, String username, String password,byte[] data, String contentType) { + return target.request().header(MR_AUTH_CONSTANT, username).header(MR_DATE_CONSTANT, password).post(Entity.entity(data, contentType)); + + } + + public static Response getResponsewtBasicAuth(WebTarget target, String authHeader) { + + return target.request().header("Authorization", "Basic " + authHeader).get(); + + } + + public static Response getResponsewtNoAuth(WebTarget target) { + + return target.request().get(); + + } + +} diff --git a/src/main/java/com/att/nsa/mr/client/impl/MRBaseClient.java b/src/main/java/com/att/nsa/mr/client/impl/MRBaseClient.java index 999d7ef..5511282 100644 --- a/src/main/java/com/att/nsa/mr/client/impl/MRBaseClient.java +++ b/src/main/java/com/att/nsa/mr/client/impl/MRBaseClient.java @@ -27,14 +27,10 @@ import java.util.Set; import java.util.TreeSet; import java.util.concurrent.TimeUnit; -import javax.ws.rs.client.Client; -import javax.ws.rs.client.ClientBuilder; -import javax.ws.rs.client.Entity; import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.Response; import org.apache.http.HttpException; -import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature; import org.glassfish.jersey.internal.util.Base64; import org.json.JSONArray; import org.json.JSONException; @@ -52,8 +48,6 @@ import com.att.nsa.mr.test.clients.ProtocolTypeConstants; public class MRBaseClient extends HttpClient implements MRClient { - private static final String MR_AUTH_CONSTANT = "X-CambriaAuth"; - private static final String MR_DATE_CONSTANT = "X-CambriaDate"; protected MRBaseClient(Collection hosts) throws MalformedURLException { super(ConnectionType.HTTP, hosts, MRConstants.kStdMRServicePort); @@ -103,15 +97,12 @@ public class MRBaseClient extends HttpClient implements MRClient { public JSONObject post(final String path, final byte[] data, final String contentType, final String username, final String password, final String protocolFlag) throws HttpException, JSONException { if ((null != username && null != password)) { - WebTarget target = null; - - Response response = null; - - target = getTarget(path, username, password); + WebTarget target=null; + Response response=null; + target = DmaapClientUtil.getTarget(path, username, password); String encoding = Base64.encodeAsString(username + ":" + password); - response = target.request().header("Authorization", "Basic " + encoding) - .post(Entity.entity(data, contentType)); + response = DmaapClientUtil.getResponsewtBasicAuth(target, encoding); return getResponseDataInJson(response); } else { @@ -125,17 +116,14 @@ public class MRBaseClient extends HttpClient implements MRClient { throws HttpException, JSONException { String responseData = null; if ((null != username && null != password)) { - WebTarget target = null; - - Response response = null; - - target = getTarget(path, username, password); + WebTarget target=null; + Response response=null; + target = DmaapClientUtil.getTarget(path, username, password); String encoding = Base64.encodeAsString(username + ":" + password); - response = target.request().header("Authorization", "Basic " + encoding) - .post(Entity.entity(data, contentType)); + response = DmaapClientUtil.getResponsewtBasicAuth(target, encoding); - responseData = response.readEntity(String.class); + responseData = (String)response.getEntity(); return responseData; } else { throw new HttpException( @@ -147,13 +135,10 @@ public class MRBaseClient extends HttpClient implements MRClient { final String authDate, final String username, final String password, final String protocolFlag) throws HttpException, JSONException { if ((null != username && null != password)) { - WebTarget target = null; - - Response response = null; - target = getTarget(path, username, password); - response = target.request().header(MR_AUTH_CONSTANT, authKey).header(MR_DATE_CONSTANT, authDate) - .post(Entity.entity(data, contentType)); - + WebTarget target=null; + Response response=null; + target = DmaapClientUtil.getTarget(path, username, password); + response =DmaapClientUtil.postResponsewtCambriaAuth(target, authKey, authDate, data, contentType); return getResponseDataInJson(response); } else { throw new HttpException( @@ -166,13 +151,11 @@ public class MRBaseClient extends HttpClient implements MRClient { final String protocolFlag) throws HttpException, JSONException { String responseData = null; if ((null != username && null != password)) { - WebTarget target = null; - - Response response = null; - target = getTarget(path, username, password); - response = target.request().header(MR_AUTH_CONSTANT, authKey).header(MR_DATE_CONSTANT, authDate) - .post(Entity.entity(data, contentType)); - responseData = response.readEntity(String.class); + WebTarget target=null; + Response response=null; + target = DmaapClientUtil.getTarget(path, username, password); + response = DmaapClientUtil.postResponsewtCambriaAuth(target, authKey, authDate, data, contentType); + responseData = (String)response.getEntity(); return responseData; } else { @@ -185,17 +168,17 @@ public class MRBaseClient extends HttpClient implements MRClient { throws HttpException, JSONException { if (null != username && null != password) { - WebTarget target = null; - - Response response = null; + WebTarget target=null; + Response response=null; + if (ProtocolTypeConstants.AUTH_KEY.getValue().equalsIgnoreCase(protocolFlag)) { - target = getTarget(path); - response = target.request().header(MR_AUTH_CONSTANT, username).header(MR_DATE_CONSTANT, password).get(); + target = DmaapClientUtil.getTarget(path); + response = DmaapClientUtil.getResponsewtCambriaAuth(target, username, password); } else { - target = getTarget(path, username, password); + target = DmaapClientUtil.getTarget(path, username, password); String encoding = Base64.encodeAsString(username + ":" + password); - response = target.request().header("Authorization", "Basic " + encoding).get(); + response = DmaapClientUtil.getResponsewtBasicAuth(target, encoding); } return getResponseDataInJson(response); @@ -209,17 +192,15 @@ public class MRBaseClient extends HttpClient implements MRClient { final String protocolFlag) throws HttpException, JSONException { String responseData = null; if (null != username && null != password) { - - WebTarget target = null; - - Response response = null; + WebTarget target=null; + Response response=null; if (ProtocolTypeConstants.AUTH_KEY.getValue().equalsIgnoreCase(protocolFlag)) { - target = getTarget(path); - response = target.request().header(MR_AUTH_CONSTANT, username).header(MR_DATE_CONSTANT, password).get(); + target = DmaapClientUtil.getTarget(path); + response = DmaapClientUtil.getResponsewtCambriaAuth(target, username, password); } else { - target = getTarget(path, username, password); + target = DmaapClientUtil.getTarget(path, username, password); String encoding = Base64.encodeAsString(username + ":" + password); - response = target.request().header("Authorization", "Basic " + encoding).get(); + response = DmaapClientUtil.getResponsewtBasicAuth(target, encoding); } MRClientFactory.HTTPHeadersMap = response.getHeaders(); @@ -228,7 +209,7 @@ public class MRBaseClient extends HttpClient implements MRClient { fLog.info("TransactionId : " + transactionid); } - responseData = response.readEntity(String.class); + responseData = (String)response.getEntity(); return responseData; } else { throw new HttpException( @@ -239,12 +220,10 @@ public class MRBaseClient extends HttpClient implements MRClient { public JSONObject getAuth(final String path, final String authKey, final String authDate, final String username, final String password, final String protocolFlag) throws HttpException, JSONException { if (null != username && null != password) { - - WebTarget target = null; - - Response response = null; - target = getTarget(path, username, password); - response = target.request().header(MR_AUTH_CONSTANT, authKey).header(MR_DATE_CONSTANT, authDate).get(); + WebTarget target=null; + Response response=null; + target = DmaapClientUtil.getTarget(path, username, password); + response = DmaapClientUtil.getResponsewtCambriaAuth(target, authKey, authDate); return getResponseDataInJson(response); } else { @@ -256,12 +235,10 @@ public class MRBaseClient extends HttpClient implements MRClient { public JSONObject getNoAuth(final String path, final String username, final String password, final String protocolFlag) throws HttpException, JSONException { if (null != username && null != password) { - - WebTarget target = null; - - Response response = null; - target = getTarget(path, username, password); - response = target.request().get(); + WebTarget target=null; + Response response=null; + target = DmaapClientUtil.getTarget(path, username, password); + response = DmaapClientUtil.getResponsewtNoAuth(target); return getResponseDataInJson(response); } else { @@ -274,12 +251,10 @@ public class MRBaseClient extends HttpClient implements MRClient { final String password, final String protocolFlag) throws HttpException, JSONException { String responseData = null; if (null != username && null != password) { - - WebTarget target = null; - - Response response = null; - target = getTarget(path, username, password); - response = target.request().header(MR_AUTH_CONSTANT, authKey).header(MR_DATE_CONSTANT, authDate).get(); + WebTarget target=null; + Response response=null; + target = DmaapClientUtil.getTarget(path, username, password); + response = DmaapClientUtil.getResponsewtCambriaAuth(target, authKey, authDate); MRClientFactory.HTTPHeadersMap = response.getHeaders(); @@ -288,7 +263,7 @@ public class MRBaseClient extends HttpClient implements MRClient { fLog.info("TransactionId : " + transactionid); } - responseData = response.readEntity(String.class); + responseData = (String)response.getEntity(); return responseData; } else { throw new HttpException( @@ -299,12 +274,10 @@ public class MRBaseClient extends HttpClient implements MRClient { public String getNoAuthResponse(String path, final String username, final String password, final String protocolFlag) throws HttpException, JSONException { String responseData = null; - - WebTarget target = null; - - Response response = null; - target = getTarget(path, username, password); - response = target.request().get(); + WebTarget target=null; + Response response=null; + target = DmaapClientUtil.getTarget(path, username, password); + response = DmaapClientUtil.getResponsewtNoAuth(target); MRClientFactory.HTTPHeadersMap = response.getHeaders(); @@ -313,28 +286,11 @@ public class MRBaseClient extends HttpClient implements MRClient { fLog.info("TransactionId : " + transactionid); } - responseData = response.readEntity(String.class); + responseData = (String)response.getEntity(); return responseData; } - private WebTarget getTarget(final String path, final String username, final String password) { - - Client client = ClientBuilder.newClient(); - - // Using UNIVERSAL as it supports both BASIC and DIGEST authentication - // types. - HttpAuthenticationFeature feature = HttpAuthenticationFeature.universal(username, password); - client.register(feature); - - return client.target(path); - } - - private WebTarget getTarget(final String path) { - - Client client = ClientBuilder.newClient(); - return client.target(path); - } private JSONObject getResponseDataInJson(Response response) throws JSONException { try { @@ -370,7 +326,7 @@ public class MRBaseClient extends HttpClient implements MRClient { jsonObject.put("status", response.getStatus()); return jsonObject; } - String responseData = response.readEntity(String.class); + String responseData = (String)response.getEntity(); JSONTokener jsonTokener = new JSONTokener(responseData); JSONObject jsonObject = null; diff --git a/src/main/java/com/att/nsa/mr/tools/MessageCommand.java b/src/main/java/com/att/nsa/mr/tools/MessageCommand.java index 354dc18..1c0e666 100644 --- a/src/main/java/com/att/nsa/mr/tools/MessageCommand.java +++ b/src/main/java/com/att/nsa/mr/tools/MessageCommand.java @@ -85,12 +85,7 @@ public class MessageCommand implements Command } else { - final MRBatchingPublisher pub = new PublisherBuilder (). - usingHosts ( context.getCluster () ). - onTopic ( parts[1] ). - authenticatedBy ( context.getApiKey(), context.getApiPwd() ). - build () - ; + final MRBatchingPublisher pub=ToolsUtil.createBatchPublisher(context, parts[1]); try { pub.send ( parts[2], parts[3] ); diff --git a/src/main/java/com/att/nsa/mr/tools/ToolsUtil.java b/src/main/java/com/att/nsa/mr/tools/ToolsUtil.java new file mode 100644 index 0000000..228a1ca --- /dev/null +++ b/src/main/java/com/att/nsa/mr/tools/ToolsUtil.java @@ -0,0 +1,37 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP Policy Engine + * ================================================================================ + * Copyright (C) 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========================================================= + */ + +package com.att.nsa.mr.tools; + +import com.att.nsa.mr.client.MRBatchingPublisher; +import com.att.nsa.mr.client.MRClientBuilders.PublisherBuilder; + +public class ToolsUtil { + + public static MRBatchingPublisher createBatchPublisher(MRCommandContext context,String topicName){ + + return new PublisherBuilder (). + usingHosts ( context.getCluster () ). + onTopic (topicName). + authenticatedBy ( context.getApiKey(), context.getApiPwd() ). + build (); + } + +} 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 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("testtest"), "testtest"); + + } + + @Test + public void getGTTPErrorResponseCode() { + + assertEquals(mrBaseClient.getHTTPErrorResponseMessage("testtest"), "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 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 hosts = new LinkedList (); + 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 hosts = new LinkedList (); + 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 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 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 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 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 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 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 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 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 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 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 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 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 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 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); } - - - - + } -- cgit 1.2.3-korg