aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/com/att/nsa/mr/client/impl/MRBaseClientTest.java
diff options
context:
space:
mode:
authorsunil unnava <sunil.unnava@att.com>2018-10-23 10:31:46 -0400
committersunil unnava <sunil.unnava@att.com>2018-10-23 10:33:54 -0400
commit0cb18b0baa2cf750e557262d821bbf2a03326bbe (patch)
tree8ca6880c9cc4f3bfc9d76575ef03ca647863415a /src/test/java/com/att/nsa/mr/client/impl/MRBaseClientTest.java
parent9775bb11c919b0a8d89d81abf1b1a76bb7592f78 (diff)
update the package name
Issue-ID: DMAAP-858 Change-Id: Ia69621ea6ad2ec2ec525800af2a7d3f73aef82ed Signed-off-by: sunil unnava <sunil.unnava@att.com>
Diffstat (limited to 'src/test/java/com/att/nsa/mr/client/impl/MRBaseClientTest.java')
-rw-r--r--src/test/java/com/att/nsa/mr/client/impl/MRBaseClientTest.java471
1 files changed, 0 insertions, 471 deletions
diff --git a/src/test/java/com/att/nsa/mr/client/impl/MRBaseClientTest.java b/src/test/java/com/att/nsa/mr/client/impl/MRBaseClientTest.java
deleted file mode 100644
index 055c94f..0000000
--- a/src/test/java/com/att/nsa/mr/client/impl/MRBaseClientTest.java
+++ /dev/null
@@ -1,471 +0,0 @@
-/*******************************************************************************
- * ============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.MultivaluedMap;
-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.glassfish.jersey.internal.util.collection.StringKeyIgnoreCaseMultivaluedMap;
-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.Mockito;
-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 {
-
- Response response = Mockito.mock(Response.class);
- MultivaluedMap<String, Object> map = new StringKeyIgnoreCaseMultivaluedMap<>();
- map.add("transactionid", "transactionid");
-
- PowerMockito.when(response.getStatus()).thenReturn(200);
- PowerMockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
- PowerMockito.when(response.getHeaders()).thenReturn(map);
-
- PowerMockito.when(
- DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username", "password"))
- .thenReturn(response);
-
- 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 {
-
- Response response = Mockito.mock(Response.class);
- MultivaluedMap<String, Object> map = new StringKeyIgnoreCaseMultivaluedMap<>();
- map.add("transactionid", "transactionid");
-
- PowerMockito.when(response.getStatus()).thenReturn(200);
- PowerMockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
- PowerMockito.when(response.getHeaders()).thenReturn(map);
-
- PowerMockito.when(DmaapClientUtil.getResponsewtBasicAuth(DmaapClientUtil.getTarget("/path"),
- Base64.encodeAsString("username:password"))).thenReturn(response);
-
- 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 {
-
- Response response = Mockito.mock(Response.class);
- MultivaluedMap<String, Object> map = new StringKeyIgnoreCaseMultivaluedMap<>();
- map.add("transactionid", "transactionid");
-
- PowerMockito.when(response.getStatus()).thenReturn(200);
- PowerMockito.when(response.readEntity(String.class)).thenReturn("[[");
- PowerMockito.when(response.getHeaders()).thenReturn(map);
-
- PowerMockito.when(
- DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username", "password"))
- .thenReturn(response);
-
- mrBaseClient.get("/path", "username", "password", "HTTPAUTH");
- assertTrue(true);
- }
-
- @Test
- public void testGetResponse() throws JSONException, HttpException {
-
- Response response = Mockito.mock(Response.class);
- MultivaluedMap<String, Object> map = new StringKeyIgnoreCaseMultivaluedMap<>();
- map.add("transactionid", "transactionid");
-
- PowerMockito.when(response.getStatus()).thenReturn(200);
- PowerMockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
- PowerMockito.when(response.getHeaders()).thenReturn(map);
-
- PowerMockito.when(
- DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username", "password"))
- .thenReturn(response);
-
- mrBaseClient.getResponse("/path", "username", "password", "HTTPAUTH");
- assertTrue(true);
-
- }
-
- @Test
- public void testGetResponse_aaf() throws JSONException, HttpException {
-
- Response response = Mockito.mock(Response.class);
- MultivaluedMap<String, Object> map = new StringKeyIgnoreCaseMultivaluedMap<>();
- map.add("transactionid", "transactionid");
-
- PowerMockito.when(response.getStatus()).thenReturn(200);
- PowerMockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
- PowerMockito.when(response.getHeaders()).thenReturn(map);
-
- PowerMockito.when(DmaapClientUtil.getResponsewtBasicAuth(DmaapClientUtil.getTarget("/path"),
- Base64.encodeAsString("username:password"))).thenReturn(response);
-
- 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 {
-
- Response response = Mockito.mock(Response.class);
- MultivaluedMap<String, Object> map = new StringKeyIgnoreCaseMultivaluedMap<>();
- map.add("transactionid", "transactionid");
-
- PowerMockito.when(response.getStatus()).thenReturn(200);
- PowerMockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
- PowerMockito.when(response.getHeaders()).thenReturn(map);
-
- PowerMockito.when(
- DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username", "password"))
- .thenReturn(response);
-
- 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 {
-
- Response response = Mockito.mock(Response.class);
- MultivaluedMap<String, Object> map = new StringKeyIgnoreCaseMultivaluedMap<>();
- map.add("transactionid", "transactionid");
-
- PowerMockito.when(response.getStatus()).thenReturn(200);
- PowerMockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
- PowerMockito.when(response.getHeaders()).thenReturn(map);
-
- PowerMockito
- .when(DmaapClientUtil.postResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username",
- "password", new String("{\"test\":\"test\"}").getBytes(), "application/json"))
- .thenReturn(response);
-
- 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 {
-
- Response response = Mockito.mock(Response.class);
- MultivaluedMap<String, Object> map = new StringKeyIgnoreCaseMultivaluedMap<>();
- map.add("transactionid", "transactionid");
-
- PowerMockito.when(response.getStatus()).thenReturn(200);
- PowerMockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
- PowerMockito.when(response.getHeaders()).thenReturn(map);
-
- PowerMockito.when(DmaapClientUtil.getResponsewtNoAuth(DmaapClientUtil.getTarget("/path"))).thenReturn(response);
-
- mrBaseClient.getNoAuthResponse("/path", "username", "password", "HTTPAUTH");
- assertTrue(true);
-
- }
-
- @Test
- public void testPost() throws JSONException, HttpException {
-
- Response response = Mockito.mock(Response.class);
- MultivaluedMap<String, Object> map = new StringKeyIgnoreCaseMultivaluedMap<>();
- map.add("transactionid", "transactionid");
-
- PowerMockito.when(response.getStatus()).thenReturn(200);
- PowerMockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
- PowerMockito.when(response.getHeaders()).thenReturn(map);
-
- PowerMockito.when(DmaapClientUtil.postResponsewtBasicAuth(DmaapClientUtil.getTarget("/path"),
- Base64.encodeAsString("username:password"), new String("{\"test\":\"test\"}").getBytes(), "application/json")).thenReturn(response);
-
- 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 {
-
- Response response = Mockito.mock(Response.class);
- MultivaluedMap<String, Object> map = new StringKeyIgnoreCaseMultivaluedMap<>();
- map.add("transactionid", "transactionid");
-
- PowerMockito.when(response.getStatus()).thenReturn(200);
- PowerMockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
- PowerMockito.when(response.getHeaders()).thenReturn(map);
-
- PowerMockito
- .when(DmaapClientUtil.postResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username",
- "password", new String("{\"test\":\"test\"}").getBytes(), "application/json"))
- .thenReturn(response);
-
- 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 {
-
- Response response = Mockito.mock(Response.class);
- MultivaluedMap<String, Object> map = new StringKeyIgnoreCaseMultivaluedMap<>();
- map.add("transactionid", "transactionid");
-
- PowerMockito.when(response.getStatus()).thenReturn(200);
- PowerMockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
- PowerMockito.when(response.getHeaders()).thenReturn(map);
-
- PowerMockito.when(DmaapClientUtil.postResponsewtBasicAuth(DmaapClientUtil.getTarget("/path"),
- Base64.encodeAsString("username:password"), new String("{\"test\":\"test\"}").getBytes(), "application/json")).thenReturn(response);
-
- 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 {
-
- Response response = Mockito.mock(Response.class);
- MultivaluedMap<String, Object> map = new StringKeyIgnoreCaseMultivaluedMap<>();
- map.add("transactionid", "transactionid");
-
- PowerMockito.when(response.getStatus()).thenReturn(200);
- PowerMockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
- PowerMockito.when(response.getHeaders()).thenReturn(map);
-
- PowerMockito.when(
- DmaapClientUtil.getResponsewtCambriaAuth(DmaapClientUtil.getTarget("/path"), "username", "password"))
- .thenReturn(response);
- 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 {
-
- Response response = Mockito.mock(Response.class);
- MultivaluedMap<String, Object> map = new StringKeyIgnoreCaseMultivaluedMap<>();
- map.add("transactionid", "transactionid");
-
- PowerMockito.when(response.getStatus()).thenReturn(200);
- PowerMockito.when(response.readEntity(String.class)).thenReturn("{\"test\":\"test\"}");
- PowerMockito.when(response.getHeaders()).thenReturn(map);
-
- PowerMockito.when(DmaapClientUtil.getResponsewtNoAuth(DmaapClientUtil.getTarget("/path"))).thenReturn(response);
- mrBaseClient.getNoAuth("/path");
- assertTrue(true);
-
- }
-
-
- @Test
- public void testGetHTTPErrorResponseMessage() {
-
- assertEquals(mrBaseClient.getHTTPErrorResponseMessage("<body>testtest</body>"), "testtest");
-
- }
-
- @Test
- public void getGTTPErrorResponseCode() {
-
- assertEquals(mrBaseClient.getHTTPErrorResponseMessage("<body>testtest</body>"), "testtest");
-
- }
-
-}