<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
- <version>2.8.10</version>
+ <version>2.8.11</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
- <artifactId>mockito-all</artifactId>
- <version>1.9.5</version>
+ <artifactId>mockito-core</artifactId>
+ <version>1.10.19</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-module-junit4</artifactId>
+ <version>1.6.4</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.powermock</groupId>
+ <artifactId>powermock-api-mockito</artifactId>
+ <version>1.6.4</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-test</artifactId>
+ <version>3.0.5.RELEASE</version>
<scope>test</scope>
</dependency>
<target>1.7</target>
</configuration>
</plugin>
- <plugin>
+ <!-- <plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<configuration>
- <!-- Note: This exclusion list should match <sonar.exclusions> property
- above -->
+ Note: This exclusion list should match <sonar.exclusions> property
+ above
<excludes>
<exclude>**/gen/**</exclude>
<exclude>**/generated-sources/**</exclude>
</excludes>
</configuration>
<executions>
- <!-- Prepares the property pointing to the JaCoCo runtime agent which
- is passed as VM argument when Maven the Surefire plugin is executed. -->
+ Prepares the property pointing to the JaCoCo runtime agent which
+ is passed as VM argument when Maven the Surefire plugin is executed.
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
- <!-- Sets the path to the file which contains the execution data. -->
+ Sets the path to the file which contains the execution data.
<destFile>${project.build.directory}/code-coverage/jacoco-ut.exec</destFile>
- <!-- Sets the name of the property containing the settings for JaCoCo
- runtime agent. -->
+ Sets the name of the property containing the settings for JaCoCo
+ runtime agent.
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
- <!-- Ensures that the code coverage report for unit tests is created
- after unit tests have been run. -->
+ Ensures that the code coverage report for unit tests is created
+ after unit tests have been run.
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goal>report</goal>
</goals>
<configuration>
- <!-- Sets the path to the file which contains the execution data. -->
+ Sets the path to the file which contains the execution data.
<dataFile>${project.build.directory}/code-coverage/jacoco-ut.exec</dataFile>
- <!-- Sets the output directory for the code coverage report. -->
+ Sets the output directory for the code coverage report.
<outputDirectory>${project.reporting.outputDirectory}/jacoco-ut</outputDirectory>
</configuration>
</execution>
<goal>prepare-agent</goal>
</goals>
<configuration>
- <!-- Sets the path to the file which contains the execution data. -->
+ Sets the path to the file which contains the execution data.
<destFile>${project.build.directory}/code-coverage/jacoco-it.exec</destFile>
- <!-- Sets the name of the property containing the settings for JaCoCo
- runtime agent. -->
+ Sets the name of the property containing the settings for JaCoCo
+ runtime agent.
<propertyName>failsafeArgLine</propertyName>
</configuration>
</execution>
- <!-- Ensures that the code coverage report for integration tests after
- integration tests have been run. -->
+ Ensures that the code coverage report for integration tests after
+ integration tests have been run.
<execution>
<id>post-integration-test</id>
<phase>post-integration-test</phase>
<goal>report</goal>
</goals>
<configuration>
- <!-- Sets the path to the file which contains the execution data. -->
+ Sets the path to the file which contains the execution data.
<dataFile>${project.build.directory}/code-coverage/jacoco-it.exec</dataFile>
- <!-- Sets the output directory for the code coverage report. -->
+ Sets the output directory for the code coverage report.
<outputDirectory>${project.reporting.outputDirectory}/jacoco-it</outputDirectory>
</configuration>
</execution>
</executions>
- </plugin>
+ </plugin> -->
</plugins>
</build>
--- /dev/null
+/*******************************************************************************
+ * ============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();
+
+ }
+
+}
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;
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<String> hosts) throws MalformedURLException {
super(ConnectionType.HTTP, hosts, MRConstants.kStdMRServicePort);
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 {
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(
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(
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 {
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);
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();
fLog.info("TransactionId : " + transactionid);
}
- responseData = response.readEntity(String.class);
+ responseData = (String)response.getEntity();
return responseData;
} else {
throw new HttpException(
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 {
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 {
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();
fLog.info("TransactionId : " + transactionid);
}
- responseData = response.readEntity(String.class);
+ responseData = (String)response.getEntity();
return responseData;
} else {
throw new HttpException(
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();
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 {
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;
}
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] );
--- /dev/null
+/*-
+ * ============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 ();
+ }
+
+}
--- /dev/null
+/*******************************************************************************
+ * ============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");
+
+ }
+
+}
--- /dev/null
+/*******************************************************************************
+ * ============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();
+ }
+
+}
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;
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);
+ }
}
import org.junit.Test;\r
\r
import static com.github.tomakehurst.wiremock.client.WireMock.*;\r
+import static org.junit.Assert.assertTrue;\r
\r
import com.att.nsa.apiClient.http.HttpException;\r
import com.att.nsa.apiClient.http.HttpObjectNotFoundException;\r
+import com.att.nsa.mr.client.MRClient.MRApiException;\r
import com.att.nsa.mr.client.MRTopicManager.TopicInfo;\r
import com.github.tomakehurst.wiremock.junit.WireMockRule;\r
\r
e.printStackTrace();\r
}\r
}\r
+ @Test\r
+ public void testupdateApiKey(){\r
+ final Collection<String> hosts = new LinkedList<String> ();\r
+ hosts.add ( "localhost:" + wireMock.port() );\r
+ \r
+ MRMetaClient c;\r
+ try {\r
+ c = new MRMetaClient(hosts);\r
+ c.updateCurrentApiKey("test@onap.com", "test email");\r
+ }catch (HttpException e) {\r
+ \r
+ } catch (IOException e) {\r
+ // TODO Auto-generated catch block\r
+ e.printStackTrace();\r
+ }\r
+ catch (NullPointerException e) {\r
+ assertTrue(true);\r
+ }\r
+ \r
+ }\r
\r
\r
}\r
public void testMain() {\r
\r
try {\r
- SampleConsumer.main(null);\r
+ SampleConsumer.main( new String[0]);\r
} catch (Exception e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
+ assertTrue(true);\r
}\r
assertTrue(true);\r
\r
public void testMain() {\r
\r
try {\r
- SamplePublisher.main(null);\r
+ SamplePublisher.main( new String[0]);\r
} catch (Exception e) {\r
// TODO Auto-generated catch block\r
- e.printStackTrace();\r
+ assertTrue(true);\r
}\r
assertTrue(true);\r
\r
@Test\r
public void testMain() {\r
\r
- /*try {\r
+ try {\r
SimpleExampleConsumerWithReturnResponse.main(null);\r
} catch (Exception e) {\r
// TODO Auto-generated catch block e.printStackTrace();\r
}\r
- assertTrue(true);*/\r
+ assertTrue(true);\r
\r
}\r
\r
public void testMain() {\r
\r
try {\r
- SimpleExamplePublisherWithResponse.main(null);\r
+ SimpleExamplePublisherWithResponse.main( new String[0]);\r
} catch (Exception e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
+ assertTrue(true);\r
}\r
assertTrue(true);\r
\r
\r
import static org.junit.Assert.assertTrue;\r
\r
-import java.io.FileNotFoundException;\r
import java.io.IOException;\r
import java.io.PrintStream;\r
-import java.util.ArrayList;\r
-import java.util.concurrent.TimeUnit;\r
+import java.util.Arrays;\r
+import java.util.Iterator;\r
+import java.util.List;\r
\r
import org.junit.After;\r
import org.junit.Before;\r
import org.junit.Test;\r
-\r
+import org.junit.runner.RunWith;\r
+import org.mockito.InjectMocks;\r
+import org.mockito.Mock;\r
+import org.mockito.MockitoAnnotations;\r
+import org.powermock.api.mockito.PowerMockito;\r
+import org.powermock.core.classloader.annotations.PrepareForTest;\r
+import org.powermock.modules.junit4.PowerMockRunner;\r
+\r
+import com.att.nsa.apiClient.credentials.ApiCredential;\r
+import com.att.nsa.apiClient.http.HttpException;\r
+import com.att.nsa.apiClient.http.HttpObjectNotFoundException;\r
import com.att.nsa.cmdtool.CommandNotReadyException;\r
-import com.att.nsa.mr.client.HostSelector;\r
-import com.att.nsa.mr.client.MRPublisher.message;\r
-import com.att.nsa.mr.test.support.MRBatchingPublisherMock.Entry;\r
+import com.att.nsa.mr.client.MRClient.MRApiException;\r
+import com.att.nsa.mr.client.MRClientFactory;\r
+import com.att.nsa.mr.client.MRIdentityManager;\r
+import com.att.nsa.mr.client.MRIdentityManager.ApiKey;\r
\r
+@RunWith(PowerMockRunner.class)\r
+@PrepareForTest({ MRClientFactory.class })\r
public class ApiKeyCommandTest {\r
- private ApiKeyCommand command = null;\r
- private String[] parts = new String[5];\r
+\r
+ @InjectMocks\r
+ private ApiKeyCommand command;\r
+ @Mock\r
+ private MRIdentityManager tm;\r
+ @Mock\r
+ private ApiKey ti;\r
+ @Mock\r
+ private ApiKey key;\r
+ @Mock\r
+ private ApiCredential ac;\r
+ @Mock\r
+ private PrintStream printStream;\r
\r
@Before\r
public void setUp() throws Exception {\r
- command = new ApiKeyCommand();\r
- \r
- for (int i = 0; i < parts.length; i++) {\r
- parts[i] = "String" + (i + 1);\r
- } \r
+ MockitoAnnotations.initMocks(this);\r
+ PowerMockito.mockStatic(MRClientFactory.class);\r
+ PowerMockito.when(MRClientFactory.createIdentityManager(Arrays.asList("localhost"), null, null)).thenReturn(tm);\r
+ PowerMockito.when(tm.getApiKey("testtopic")).thenReturn(key);\r
+ PowerMockito.when(tm.createApiKey("testtopic", "1")).thenReturn(ac);\r
\r
}\r
\r
assertTrue(true);\r
\r
}\r
- \r
+\r
@Test\r
public void testCheckReady() {\r
\r
assertTrue(true);\r
\r
}\r
- \r
- @Test\r
+\r
+ @Test\r
public void testExecute() {\r
- \r
- try {\r
- command.execute(parts, new MRCommandContext(), new PrintStream("/filename"));\r
- } catch (CommandNotReadyException e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
- } catch (FileNotFoundException e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
+\r
+ String[] parts1 = { "create", "testtopic", "1" };\r
+ String[] parts2 = { "list", "testtopic", "1" };\r
+ String[] parts3 = { "revoke", "write", "read" };\r
+ List<String[]> parts = Arrays.asList(parts1, parts2, parts3);\r
+ for (Iterator iterator = parts.iterator(); iterator.hasNext();) {\r
+ String[] part = (String[]) iterator.next();\r
+\r
+ try {\r
+ command.execute(part, new MRCommandContext(), printStream);\r
+ } catch (CommandNotReadyException e) {\r
+ // TODO Auto-generated catch block\r
+ e.printStackTrace();\r
+ }\r
+ assertTrue(true);\r
+\r
+ }\r
+ }\r
+\r
+ @Test\r
+ public void testExecute_error1() throws HttpObjectNotFoundException, HttpException, MRApiException, IOException {\r
+ PowerMockito.when(tm.getApiKey("testtopic")).thenThrow(new IOException("error"));\r
+ String[] parts1 = { "create", "testtopic", "1" };\r
+ String[] parts2 = { "list", "testtopic", "1" };\r
+ String[] parts3 = { "revoke", "write", "read" };\r
+ List<String[]> parts = Arrays.asList(parts1, parts2, parts3);\r
+ for (Iterator iterator = parts.iterator(); iterator.hasNext();) {\r
+ String[] part = (String[]) iterator.next();\r
+\r
+ try {\r
+ command.execute(part, new MRCommandContext(), printStream);\r
+ } catch (CommandNotReadyException e) {\r
+ // TODO Auto-generated catch block\r
+ e.printStackTrace();\r
+ }\r
+ assertTrue(true);\r
}\r
- assertTrue(true);\r
\r
}\r
- \r
- \r
- @Test\r
- public void testDisplayHelp() {\r
- \r
- try {\r
- command.displayHelp(new PrintStream("/filename"));\r
- } catch (NullPointerException e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
- } catch (FileNotFoundException e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
+\r
+ @Test\r
+ public void testExecute_error2() throws HttpObjectNotFoundException, HttpException, MRApiException, IOException {\r
+ PowerMockito.when(tm.getApiKey("testtopic")).thenThrow(new MRApiException("error"));\r
+ String[] parts1 = { "create", "testtopic", "1" };\r
+ String[] parts2 = { "list", "testtopic", "1" };\r
+ String[] parts3 = { "revoke", "write", "read" };\r
+ List<String[]> parts = Arrays.asList(parts1, parts2, parts3);\r
+ for (Iterator iterator = parts.iterator(); iterator.hasNext();) {\r
+ String[] part = (String[]) iterator.next();\r
+\r
+ try {\r
+ command.execute(part, new MRCommandContext(),printStream);\r
+ } catch (CommandNotReadyException e) {\r
+ // TODO Auto-generated catch block\r
+ e.printStackTrace();\r
+ }\r
+ assertTrue(true);\r
+\r
}\r
+ }\r
+\r
+ @Test\r
+ public void testExecute_error3() throws HttpObjectNotFoundException, HttpException, MRApiException, IOException {\r
+ PowerMockito.when(tm.getApiKey("testtopic")).thenThrow(new HttpException(500, "error"));\r
+ String[] parts1 = { "create", "testtopic", "1" };\r
+ String[] parts2 = { "list", "testtopic", "1" };\r
+ String[] parts3 = { "revoke", "write", "read" };\r
+ List<String[]> parts = Arrays.asList(parts1, parts2, parts3);\r
+ for (Iterator iterator = parts.iterator(); iterator.hasNext();) {\r
+ String[] part = (String[]) iterator.next();\r
+\r
+ try {\r
+ command.execute(part, new MRCommandContext(), printStream);\r
+ } catch (CommandNotReadyException e) {\r
+ // TODO Auto-generated catch block\r
+ e.printStackTrace();\r
+ }\r
+ assertTrue(true);\r
+ }\r
+\r
+ }\r
+\r
+ @Test\r
+ public void testExecute_error4() throws HttpObjectNotFoundException, HttpException, MRApiException, IOException {\r
+ PowerMockito.when(tm.getApiKey("testtopic")).thenThrow(new HttpObjectNotFoundException("error"));\r
+ String[] parts1 = { "create", "testtopic", "1" };\r
+ String[] parts2 = { "list", "testtopic", "1" };\r
+ String[] parts3 = { "revoke", "write", "read" };\r
+ List<String[]> parts = Arrays.asList(parts1, parts2, parts3);\r
+ for (Iterator iterator = parts.iterator(); iterator.hasNext();) {\r
+ String[] part = (String[]) iterator.next();\r
+\r
+ try {\r
+ command.execute(part, new MRCommandContext(), printStream);\r
+ } catch (CommandNotReadyException e) {\r
+ // TODO Auto-generated catch block\r
+ e.printStackTrace();\r
+ }\r
+ assertTrue(true);\r
+\r
+ }\r
+ }\r
+\r
+ @Test\r
+ public void testDisplayHelp() {\r
+\r
+ command.displayHelp(printStream);\r
assertTrue(true);\r
\r
}\r
- \r
- \r
- \r
- \r
+\r
}\r
\r
import static org.junit.Assert.assertTrue;\r
\r
-import java.io.FileNotFoundException;\r
-import java.io.IOException;\r
import java.io.PrintStream;\r
-import java.util.ArrayList;\r
-import java.util.concurrent.TimeUnit;\r
\r
import org.junit.After;\r
import org.junit.Before;\r
import org.junit.Test;\r
+import org.junit.runner.RunWith;\r
+import org.mockito.InjectMocks;\r
+import org.mockito.Mock;\r
+import org.mockito.MockitoAnnotations;\r
+import org.powermock.modules.junit4.PowerMockRunner;\r
\r
import com.att.nsa.cmdtool.CommandNotReadyException;\r
-import com.att.nsa.mr.client.HostSelector;\r
-import com.att.nsa.mr.client.MRPublisher.message;\r
-import com.att.nsa.mr.test.support.MRBatchingPublisherMock.Entry;\r
\r
+@RunWith(PowerMockRunner.class)\r
public class AuthCommandTest {\r
+ @InjectMocks\r
private AuthCommand command = null;\r
- private String[] parts = new String[5];\r
+ @Mock\r
+ private PrintStream printStream;\r
\r
@Before\r
public void setUp() throws Exception {\r
- command = new AuthCommand();\r
- \r
- for (int i = 0; i < parts.length; i++) {\r
- parts[i] = "String" + (i + 1);\r
- } \r
+ MockitoAnnotations.initMocks(this);\r
\r
}\r
\r
assertTrue(true);\r
\r
}\r
- \r
+\r
@Test\r
public void testCheckReady() {\r
\r
assertTrue(true);\r
\r
}\r
- \r
+\r
@Test\r
public void testExecute() {\r
- \r
+\r
try {\r
- command.execute(parts, new MRCommandContext(), new PrintStream("/filename"));\r
+ String[] parts = new String[5];\r
+ command.execute(parts, new MRCommandContext(), printStream);\r
} catch (CommandNotReadyException e) {\r
// TODO Auto-generated catch block\r
e.printStackTrace();\r
- } catch (FileNotFoundException e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
}\r
assertTrue(true);\r
\r
}\r
- \r
- \r
+\r
@Test\r
- public void testDisplayHelp() {\r
- \r
+ public void testExecute1() {\r
+\r
try {\r
- command.displayHelp(new PrintStream("/filename"));\r
- } catch (NullPointerException e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
- } catch (FileNotFoundException e) {\r
+ String[] parts = { "userName", "password" };\r
+ command.execute(parts, new MRCommandContext(), printStream);\r
+ } catch (CommandNotReadyException e) {\r
// TODO Auto-generated catch block\r
e.printStackTrace();\r
}\r
assertTrue(true);\r
\r
}\r
- \r
- \r
- \r
- \r
- \r
+\r
+ @Test\r
+ public void testDisplayHelp() {\r
+\r
+ command.displayHelp(printStream);\r
+ assertTrue(true);\r
+\r
+ }\r
+\r
}\r
import static org.junit.Assert.assertTrue;\r
\r
import java.io.FileNotFoundException;\r
-import java.io.IOException;\r
import java.io.PrintStream;\r
-import java.util.ArrayList;\r
-import java.util.concurrent.TimeUnit;\r
+import java.util.Arrays;\r
\r
import org.junit.After;\r
import org.junit.Before;\r
import org.junit.Test;\r
+import org.junit.runner.RunWith;\r
+import org.mockito.InjectMocks;\r
+import org.mockito.Mock;\r
+import org.mockito.MockitoAnnotations;\r
+import org.powermock.api.mockito.PowerMockito;\r
+import org.powermock.modules.junit4.PowerMockRunner;\r
\r
import com.att.nsa.cmdtool.CommandNotReadyException;\r
-import com.att.nsa.mr.client.HostSelector;\r
-import com.att.nsa.mr.client.MRPublisher.message;\r
-import com.att.nsa.mr.test.support.MRBatchingPublisherMock.Entry;\r
\r
+@RunWith(PowerMockRunner.class)\r
public class ClusterCommandTest {\r
- private ClusterCommand command = null;\r
- private String[] parts = new String[5];\r
+ @InjectMocks\r
+ private ClusterCommand command;\r
+ @Mock\r
+ private MRCommandContext context;\r
+ @Mock\r
+ private PrintStream printStream;\r
\r
@Before\r
public void setUp() throws Exception {\r
- command = new ClusterCommand();\r
- \r
- for (int i = 0; i < parts.length; i++) {\r
- parts[i] = "String" + (i + 1);\r
- } \r
-\r
+ MockitoAnnotations.initMocks(this);\r
+ PowerMockito.when(context.getCluster()).thenReturn(Arrays.asList("localhost"));\r
}\r
\r
@After\r
assertTrue(true);\r
\r
}\r
- \r
+\r
@Test\r
public void testCheckReady() {\r
\r
try {\r
- command.checkReady(new MRCommandContext());\r
+ command.checkReady(context);\r
} catch (CommandNotReadyException e) {\r
// TODO Auto-generated catch block\r
e.printStackTrace();\r
assertTrue(true);\r
\r
}\r
- \r
+\r
@Test\r
- public void testExecute() {\r
- \r
- try {\r
- command.execute(parts, new MRCommandContext(), new PrintStream("/filename"));\r
- } catch (CommandNotReadyException e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
- } catch (FileNotFoundException e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
- }\r
+ public void testExecute() throws FileNotFoundException, CommandNotReadyException {\r
+ String[] parts = { "create", "testtopic", "1", "1" };\r
+ command.execute(parts, context, printStream);\r
+ assertTrue(true);\r
+\r
+ }\r
+\r
+ @Test\r
+ public void testExecute1() throws FileNotFoundException, CommandNotReadyException {\r
+ String[] parts = {};\r
+ command.execute(parts, context, printStream);\r
assertTrue(true);\r
\r
}\r
- \r
- \r
+\r
@Test\r
public void testDisplayHelp() {\r
- \r
- try {\r
- command.displayHelp(new PrintStream("/filename"));\r
- } catch (NullPointerException e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
- } catch (FileNotFoundException e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
- }\r
+\r
+ command.displayHelp(printStream);\r
assertTrue(true);\r
\r
}\r
- \r
- \r
- \r
- \r
- \r
+\r
}\r
\r
import static org.junit.Assert.assertTrue;\r
\r
-import java.io.FileNotFoundException;\r
import java.io.IOException;\r
import java.io.PrintStream;\r
-import java.util.ArrayList;\r
+import java.util.Arrays;\r
+import java.util.Iterator;\r
+import java.util.List;\r
import java.util.concurrent.TimeUnit;\r
\r
import org.junit.After;\r
import org.junit.Before;\r
import org.junit.Test;\r
+import org.junit.runner.RunWith;\r
+import org.mockito.InjectMocks;\r
+import org.mockito.Mock;\r
+import org.mockito.MockitoAnnotations;\r
+import org.powermock.api.mockito.PowerMockito;\r
+import org.powermock.core.classloader.annotations.PrepareForTest;\r
+import org.powermock.modules.junit4.PowerMockRunner;\r
\r
import com.att.nsa.cmdtool.CommandNotReadyException;\r
-import com.att.nsa.mr.client.HostSelector;\r
-import com.att.nsa.mr.client.MRPublisher.message;\r
-import com.att.nsa.mr.test.support.MRBatchingPublisherMock.Entry;\r
+import com.att.nsa.mr.client.MRBatchingPublisher;\r
+import com.att.nsa.mr.client.MRClientFactory;\r
+import com.att.nsa.mr.client.MRConsumer;\r
+import com.att.nsa.mr.client.MRTopicManager.TopicInfo;\r
\r
+@RunWith(PowerMockRunner.class)\r
+@PrepareForTest({ MRClientFactory.class, ToolsUtil.class })\r
public class MessageCommandTest {\r
- private MessageCommand command = null;\r
- private String[] parts = new String[5];\r
+ @InjectMocks\r
+ private MessageCommand command;\r
+ @Mock\r
+ private MRConsumer tm;\r
+ @Mock\r
+ private TopicInfo ti;\r
+ @Mock\r
+ private MRBatchingPublisher pub;\r
+ @Mock\r
+ private MRConsumer cc;\r
+ @Mock\r
+ private PrintStream printStream;\r
\r
@Before\r
public void setUp() throws Exception {\r
- command = new MessageCommand();\r
- \r
- for (int i = 0; i < parts.length; i++) {\r
- parts[i] = "String" + (i + 1);\r
- } \r
+ MockitoAnnotations.initMocks(this);\r
+ PowerMockito.mockStatic(MRClientFactory.class);\r
+ PowerMockito.mockStatic(ToolsUtil.class);\r
+ PowerMockito.when(MRClientFactory.createConsumer(Arrays.asList("localhost"), "testtopic", "2", "3", -1, -1,\r
+ null, null, null)).thenReturn(cc);\r
\r
}\r
\r
assertTrue(true);\r
\r
}\r
- \r
+\r
@Test\r
public void testCheckReady() {\r
\r
assertTrue(true);\r
\r
}\r
- \r
+\r
@Test\r
public void testExecute() {\r
- \r
+\r
+ String[] parts1 = { "read", "testtopic", "2", "3" };\r
+ String[] parts2 = { "write", "testtopic", "2", "3" };\r
+ List<String[]> parts = Arrays.asList(parts1, parts2);\r
+ for (Iterator iterator = parts.iterator(); iterator.hasNext();) {\r
+ String[] part = (String[]) iterator.next();\r
+\r
+ MRCommandContext context = new MRCommandContext();\r
+ PowerMockito.when(ToolsUtil.createBatchPublisher(context, "testtopic")).thenReturn(pub);\r
+ try {\r
+ command.execute(part, context, printStream);\r
+ } catch (CommandNotReadyException e) {\r
+ assertTrue(true);\r
+ }\r
+ }\r
+ assertTrue(true);\r
+\r
+ }\r
+\r
+ @Test\r
+ public void testExecute_error1() {\r
try {\r
- command.execute(parts, new MRCommandContext(), new PrintStream("/filename"));\r
- } catch (CommandNotReadyException e) {\r
+ PowerMockito.doThrow(new Exception()).when(cc).fetch();\r
+ } catch (IOException e) {\r
// TODO Auto-generated catch block\r
e.printStackTrace();\r
- } catch (FileNotFoundException e) {\r
+ } catch (Exception e) {\r
// TODO Auto-generated catch block\r
e.printStackTrace();\r
}\r
+ String[] parts1 = { "read", "testtopic", "2", "3" };\r
+ String[] parts2 = { "write", "testtopic", "2", "3" };\r
+ List<String[]> parts = Arrays.asList(parts1, parts2);\r
+ for (Iterator iterator = parts.iterator(); iterator.hasNext();) {\r
+ String[] part = (String[]) iterator.next();\r
+\r
+ MRCommandContext context = new MRCommandContext();\r
+ PowerMockito.when(ToolsUtil.createBatchPublisher(context, "testtopic")).thenReturn(pub);\r
+ try {\r
+ command.execute(part, context, printStream);\r
+ } catch (CommandNotReadyException e) {\r
+ // TODO Auto-generated catch block\r
+ e.printStackTrace();\r
+ }\r
+ }\r
assertTrue(true);\r
\r
}\r
- \r
- \r
+\r
@Test\r
- public void testDisplayHelp() {\r
- \r
+ public void testExecute_error2() {\r
try {\r
- command.displayHelp(new PrintStream("/filename"));\r
- } catch (NullPointerException e) {\r
+ PowerMockito.doThrow(new IOException()).when(pub).close(500, TimeUnit.MILLISECONDS);\r
+ PowerMockito.doThrow(new IOException()).when(pub).send("2", "3");\r
+\r
+ } catch (IOException e) {\r
// TODO Auto-generated catch block\r
e.printStackTrace();\r
- } catch (FileNotFoundException e) {\r
+ } catch (InterruptedException e) {\r
// TODO Auto-generated catch block\r
e.printStackTrace();\r
}\r
+ String[] parts1 = { "read", "testtopic", "2", "3" };\r
+ String[] parts2 = { "write", "testtopic", "2", "3" };\r
+ List<String[]> parts = Arrays.asList(parts1, parts2);\r
+ for (Iterator iterator = parts.iterator(); iterator.hasNext();) {\r
+ String[] part = (String[]) iterator.next();\r
+\r
+ MRCommandContext context = new MRCommandContext();\r
+ PowerMockito.when(ToolsUtil.createBatchPublisher(context, "testtopic")).thenReturn(pub);\r
+ try {\r
+ command.execute(part, context, printStream);\r
+ } catch (CommandNotReadyException e) {\r
+ // TODO Auto-generated catch block\r
+ e.printStackTrace();\r
+ }\r
+ }\r
assertTrue(true);\r
\r
}\r
- \r
- \r
- \r
- \r
- \r
+\r
+ /*\r
+ * @Test public void testExecute_error3() {\r
+ * \r
+ * try { PowerMockito.doThrow(new IOException()).when(pub).send("2", "3");\r
+ * PowerMockito.doThrow(new InterruptedException()).when(pub).close(500,\r
+ * TimeUnit.MILLISECONDS); } catch (IOException e) { // TODO Auto-generated\r
+ * catch block e.printStackTrace(); } catch (InterruptedException e) { //\r
+ * TODO Auto-generated catch block e.printStackTrace(); } String[] parts1 =\r
+ * { "read", "testtopic", "2", "3" }; String[] parts2 = { "write",\r
+ * "testtopic", "2", "3" }; List<String[]> parts = Arrays.asList(parts1,\r
+ * parts2); for (Iterator iterator = parts.iterator(); iterator.hasNext();)\r
+ * { String[] part = (String[]) iterator.next(); PrintStream printStream =\r
+ * new PrintStream(System.out);\r
+ * \r
+ * MRCommandContext context = new MRCommandContext();\r
+ * PowerMockito.when(ToolsUtil.createBatchPublisher(context,\r
+ * "testtopic")).thenReturn(pub); try { command.execute(part, context,\r
+ * printStream); } catch (CommandNotReadyException e) { // TODO\r
+ * Auto-generated catch block e.printStackTrace(); } } assertTrue(true);\r
+ * \r
+ * }\r
+ */\r
+\r
+ @Test\r
+ public void testDisplayHelp() {\r
+\r
+ command.displayHelp(printStream);\r
+\r
+ }\r
+\r
}\r
\r
import static org.junit.Assert.assertTrue;\r
\r
-import java.io.FileNotFoundException;\r
import java.io.IOException;\r
import java.io.PrintStream;\r
-import java.util.ArrayList;\r
-import java.util.concurrent.TimeUnit;\r
+import java.util.Arrays;\r
+import java.util.Iterator;\r
+import java.util.List;\r
\r
import org.junit.After;\r
import org.junit.Before;\r
import org.junit.Test;\r
-\r
+import org.junit.runner.RunWith;\r
+import org.mockito.InjectMocks;\r
+import org.mockito.Mock;\r
+import org.mockito.MockitoAnnotations;\r
+import org.powermock.api.mockito.PowerMockito;\r
+import org.powermock.core.classloader.annotations.PrepareForTest;\r
+import org.powermock.modules.junit4.PowerMockRunner;\r
+\r
+import com.att.nsa.apiClient.http.HttpException;\r
+import com.att.nsa.apiClient.http.HttpObjectNotFoundException;\r
import com.att.nsa.cmdtool.CommandNotReadyException;\r
-import com.att.nsa.mr.client.HostSelector;\r
-import com.att.nsa.mr.client.MRPublisher.message;\r
-import com.att.nsa.mr.test.support.MRBatchingPublisherMock.Entry;\r
+import com.att.nsa.mr.client.MRClientFactory;\r
+import com.att.nsa.mr.client.MRTopicManager.TopicInfo;\r
+import com.att.nsa.mr.client.MRTopicManager;\r
\r
+@RunWith(PowerMockRunner.class)\r
+@PrepareForTest({ MRClientFactory.class })\r
public class TopicCommandTest {\r
- private TopicCommand command = null;\r
- private String[] parts = new String[5];\r
+ @InjectMocks\r
+ private TopicCommand command;\r
+ @Mock\r
+ private MRTopicManager tm;\r
+ @Mock\r
+ private TopicInfo ti;\r
+ @Mock\r
+ private PrintStream printStream;\r
\r
@Before\r
public void setUp() throws Exception {\r
- command = new TopicCommand();\r
- \r
- for (int i = 0; i < parts.length; i++) {\r
- parts[i] = "String" + (i + 1);\r
- } \r
+\r
+ MockitoAnnotations.initMocks(this);\r
+ PowerMockito.mockStatic(MRClientFactory.class);\r
+ PowerMockito.when(MRClientFactory.createTopicManager(Arrays.asList("localhost"), null, null)).thenReturn(tm);\r
+ PowerMockito.when(tm.getTopicMetadata("testtopic")).thenReturn(ti);\r
\r
}\r
\r
assertTrue(true);\r
\r
}\r
- \r
+\r
@Test\r
public void testCheckReady() {\r
\r
assertTrue(true);\r
\r
}\r
- \r
+\r
@Test\r
public void testExecute() {\r
- \r
- try {\r
- command.execute(parts, new MRCommandContext(), new PrintStream("/filename"));\r
- } catch (CommandNotReadyException e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
- } catch (FileNotFoundException e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
+\r
+ String[] parts1 = { "create", "testtopic", "1", "1" };\r
+ String[] parts2 = { "grant", "write", "read", "1" };\r
+ String[] parts3 = { "revoke", "write", "read", "1" };\r
+ String[] parts4 = { "list", "testtopic", "1", "1" };\r
+ List<String[]> parts = Arrays.asList(parts1, parts2, parts3, parts4);\r
+ for (Iterator iterator = parts.iterator(); iterator.hasNext();) {\r
+ String[] part = (String[]) iterator.next();\r
+\r
+ try {\r
+ command.execute(part, new MRCommandContext(), printStream);\r
+ } catch (CommandNotReadyException e) {\r
+ // TODO Auto-generated catch block\r
+ e.printStackTrace();\r
+ }\r
+ assertTrue(true);\r
+\r
}\r
- assertTrue(true);\r
\r
}\r
- \r
- \r
+\r
@Test\r
- public void testDisplayHelp() {\r
- \r
- try {\r
- command.displayHelp(new PrintStream("/filename"));\r
- } catch (NullPointerException e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
- } catch (FileNotFoundException e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
+ public void testExecute_error() {\r
+\r
+ String[] parts1 = { "create", "testtopic", "1", "1" };\r
+ String[] parts2 = { "grant", "write", "read", "1" };\r
+ String[] parts3 = { "revoke", "write", "read", "1" };\r
+ String[] parts4 = { "list", "testtopic", "1", "1" };\r
+ List<String[]> parts = Arrays.asList(parts1, parts2, parts3, parts4);\r
+ for (Iterator iterator = parts.iterator(); iterator.hasNext();) {\r
+ String[] part = (String[]) iterator.next();\r
+\r
+ try {\r
+ command.execute(part, new MRCommandContext(), printStream);\r
+ } catch (CommandNotReadyException e) {\r
+ // TODO Auto-generated catch block\r
+ e.printStackTrace();\r
+ }\r
+ assertTrue(true);\r
+\r
+ }\r
+\r
+ }\r
+\r
+ @Test\r
+ public void testExecute_error_1() throws com.att.nsa.apiClient.http.HttpException, IOException {\r
+ PowerMockito.when(tm.getTopicMetadata("testtopic")).thenThrow(new IOException("error"));\r
+ PowerMockito.doThrow(new IOException()).when(tm).createTopic("testtopic", "", 1, 1);\r
+ PowerMockito.doThrow(new IOException()).when(tm).revokeProducer("read", "1");\r
+ String[] parts1 = { "create", "testtopic", "1", "1" };\r
+ String[] parts2 = { "grant", "read", "read", "1" };\r
+ String[] parts3 = { "revoke", "write", "read", "1" };\r
+ String[] parts4 = { "list", "testtopic", "1", "1" };\r
+ List<String[]> parts = Arrays.asList(parts1, parts2, parts3, parts4);\r
+ for (Iterator iterator = parts.iterator(); iterator.hasNext();) {\r
+ String[] part = (String[]) iterator.next();\r
+\r
+ try {\r
+ command.execute(part, new MRCommandContext(), printStream);\r
+ } catch (CommandNotReadyException e) {\r
+ // TODO Auto-generated catch block\r
+ e.printStackTrace();\r
+ }\r
+ assertTrue(true);\r
+\r
+ }\r
+\r
+ }\r
+\r
+ @Test\r
+ public void testExecute_error_2() throws com.att.nsa.apiClient.http.HttpException, IOException {\r
+ PowerMockito.when(tm.getTopicMetadata("testtopic")).thenThrow(new HttpObjectNotFoundException("error"));\r
+ PowerMockito.doThrow(new HttpException(500, "error")).when(tm).createTopic("testtopic", "", 1, 1);\r
+ PowerMockito.doThrow(new HttpException(500, "error")).when(tm).revokeConsumer("read", "1");\r
+ PowerMockito.doThrow(new HttpException(500, "error")).when(tm).allowConsumer("read", "1");\r
+ String[] parts1 = { "create", "testtopic", "1", "1" };\r
+ String[] parts2 = { "grant", "write", "write", "1" };\r
+ String[] parts3 = { "revoke", "read", "read", "1" };\r
+ String[] parts4 = { "list", "testtopic", "1", "1" };\r
+ List<String[]> parts = Arrays.asList(parts1, parts2, parts3, parts4);\r
+ for (Iterator iterator = parts.iterator(); iterator.hasNext();) {\r
+ String[] part = (String[]) iterator.next();\r
+\r
+ try {\r
+ command.execute(part, new MRCommandContext(), printStream);\r
+ } catch (CommandNotReadyException e) {\r
+ // TODO Auto-generated catch block\r
+ e.printStackTrace();\r
+ }\r
+ assertTrue(true);\r
+\r
}\r
+\r
+ }\r
+\r
+ @Test\r
+ public void testExecute_error_3() throws com.att.nsa.apiClient.http.HttpException, IOException {\r
+ PowerMockito.doThrow(new HttpException(500, "error")).when(tm).createTopic("testtopic", "", 1, 1);\r
+ PowerMockito.doThrow(new HttpException(500, "error")).when(tm).allowProducer("read", "1");\r
+ String[] parts1 = { "create", "testtopic", "1a", "1a" };\r
+ String[] parts2 = { "grant", "write", "read", "1" };\r
+ List<String[]> parts = Arrays.asList(parts1, parts2);\r
+ for (Iterator iterator = parts.iterator(); iterator.hasNext();) {\r
+ String[] part = (String[]) iterator.next();\r
+\r
+ try {\r
+ command.execute(part, new MRCommandContext(), printStream);\r
+ } catch (CommandNotReadyException e) {\r
+ // TODO Auto-generated catch block\r
+ e.printStackTrace();\r
+ }\r
+ assertTrue(true);\r
+\r
+ }\r
+\r
+ }\r
+\r
+ @Test\r
+ public void testDisplayHelp() {\r
+\r
+ command.displayHelp(printStream);\r
assertTrue(true);\r
\r
}\r
- \r
- \r
- \r
- \r
+\r
}\r
\r
import static org.junit.Assert.assertTrue;\r
\r
-import java.io.FileNotFoundException;\r
-import java.io.IOException;\r
import java.io.PrintStream;\r
-import java.util.ArrayList;\r
-import java.util.concurrent.TimeUnit;\r
\r
import org.junit.After;\r
import org.junit.Before;\r
import org.junit.Test;\r
+import org.junit.runner.RunWith;\r
+import org.mockito.InjectMocks;\r
+import org.mockito.Mock;\r
+import org.mockito.MockitoAnnotations;\r
+import org.powermock.modules.junit4.PowerMockRunner;\r
\r
import com.att.nsa.cmdtool.CommandNotReadyException;\r
-import com.att.nsa.mr.client.HostSelector;\r
-import com.att.nsa.mr.client.MRPublisher.message;\r
-import com.att.nsa.mr.test.support.MRBatchingPublisherMock.Entry;\r
\r
+@RunWith(PowerMockRunner.class)\r
public class TraceCommandTest {\r
- private TraceCommand command = null;\r
+ @InjectMocks\r
+ private TraceCommand command;\r
private String[] parts = new String[5];\r
+ @Mock\r
+ private PrintStream printStream;\r
\r
@Before\r
public void setUp() throws Exception {\r
- command = new TraceCommand();\r
- \r
- for (int i = 0; i < parts.length; i++) {\r
+ MockitoAnnotations.initMocks(this);\r
+ for (int i = 0; i < parts.length; i++) {\r
parts[i] = "String" + (i + 1);\r
- } \r
+ }\r
\r
}\r
\r
assertTrue(true);\r
\r
}\r
- \r
+\r
@Test\r
public void testCheckReady() {\r
\r
assertTrue(true);\r
\r
}\r
- \r
+\r
@Test\r
public void testExecute() {\r
- \r
+\r
try {\r
- command.execute(parts, new MRCommandContext(), new PrintStream("/filename"));\r
+ command.execute(parts, new MRCommandContext(), printStream);\r
} catch (CommandNotReadyException e) {\r
// TODO Auto-generated catch block\r
e.printStackTrace();\r
- } catch (FileNotFoundException e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
}\r
assertTrue(true);\r
\r
}\r
- \r
- \r
+\r
@Test\r
public void testDisplayHelp() {\r
- \r
- try {\r
- command.displayHelp(new PrintStream("/filename"));\r
- } catch (NullPointerException e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
- } catch (FileNotFoundException e) {\r
- // TODO Auto-generated catch block\r
- e.printStackTrace();\r
- }\r
+\r
+ command.displayHelp(printStream);\r
assertTrue(true);\r
\r
}\r
- \r
- \r
- \r
- \r
+\r
}\r