Refactored AaiJsonParserUtil
[holmes/common.git] / holmes-actions / src / test / java / org / onap / holmes / common / utils / JerseyClientTest.java
index 0183740..b0b5714 100644 (file)
@@ -43,9 +43,11 @@ import static org.junit.Assert.assertThat;
 @PowerMockIgnore({"javax.net.ssl.*", "javax.security.*"})
 public class JerseyClientTest {
 
-    private final String ERROR_MSG = "Status code: <404>. Message: Failed to get response from the server. Info: Error";
-    private JerseyClient jerseyClient = new JerseyClient();
+    private final String ERROR_MSG = "Failed to get response from the server. \nURL: http://www.onap.org/holmes/test" +
+            "\nCause: Not Found\nResponse body: Error";
+    private JerseyClient jerseyClient = JerseyClient.newInstance();
     private String url = "http://www.onap.org/holmes/test";
+
     @Rule
     private ExpectedException exception = ExpectedException.none();
 
@@ -62,7 +64,7 @@ public class JerseyClientTest {
         EasyMock.expect(mockedTarget.request()).andReturn(mockedBuilder);
         EasyMock.expect(mockedBuilder.header("Accept", MediaType.APPLICATION_JSON)).andReturn(mockedBuilder);
         EasyMock.expect(mockedBuilder.get()).andReturn(mockedResponse);
-        EasyMock.expect(mockedResponse.getStatus()).andReturn(200);
+        EasyMock.expect(mockedResponse.getStatusInfo()).andReturn(Response.Status.OK);
         EasyMock.expect(mockedResponse.readEntity(String.class)).andReturn("Normal");
 
         WhiteboxImpl.setInternalState(jerseyClient, "client", mockedClient);
@@ -88,7 +90,7 @@ public class JerseyClientTest {
         EasyMock.expect(mockedClient.target(url)).andReturn(mockedTarget);
         EasyMock.expect(mockedTarget.request()).andReturn(mockedBuilder);
         EasyMock.expect(mockedBuilder.get()).andReturn(mockedResponse);
-        EasyMock.expect(mockedResponse.getStatus()).andReturn(200);
+        EasyMock.expect(mockedResponse.getStatusInfo()).andReturn(Response.Status.OK);
         EasyMock.expect(mockedResponse.readEntity(String.class)).andReturn(GsonUtil.beanToJson(bean));
 
         WhiteboxImpl.setInternalState(jerseyClient, "client", mockedClient);
@@ -110,7 +112,7 @@ public class JerseyClientTest {
         EasyMock.expect(mockedClient.target(url)).andReturn(mockedTarget);
         EasyMock.expect(mockedTarget.request()).andReturn(mockedBuilder);
         EasyMock.expect(mockedBuilder.get()).andReturn(mockedResponse);
-        EasyMock.expect(mockedResponse.getStatus()).andReturn(200);
+        EasyMock.expect(mockedResponse.getStatusInfo()).andReturn(Response.Status.OK);
         EasyMock.expect(mockedResponse.readEntity(String.class)).andReturn("Normal");
 
         WhiteboxImpl.setInternalState(jerseyClient, "client", mockedClient);
@@ -133,6 +135,7 @@ public class JerseyClientTest {
         EasyMock.expect(mockedTarget.request()).andReturn(mockedBuilder);
         EasyMock.expect(mockedBuilder.get()).andReturn(mockedResponse);
         EasyMock.expect(mockedResponse.getStatus()).andReturn(404);
+        EasyMock.expect(mockedResponse.getStatusInfo()).andReturn(Response.Status.NOT_FOUND);
         EasyMock.expect(mockedResponse.readEntity(String.class)).andReturn("Error");
 
         WhiteboxImpl.setInternalState(jerseyClient, "client", mockedClient);
@@ -157,7 +160,7 @@ public class JerseyClientTest {
         EasyMock.expect(mockedClient.target(url)).andReturn(mockedTarget);
         EasyMock.expect(mockedTarget.request()).andReturn(mockedBuilder);
         EasyMock.expect(mockedBuilder.post(null)).andReturn(mockedResponse);
-        EasyMock.expect(mockedResponse.getStatus()).andReturn(200);
+        EasyMock.expect(mockedResponse.getStatusInfo()).andReturn(Response.Status.OK);
         EasyMock.expect(mockedResponse.readEntity(String.class)).andReturn("Normal");
 
         WhiteboxImpl.setInternalState(jerseyClient, "client", mockedClient);
@@ -180,6 +183,7 @@ public class JerseyClientTest {
         EasyMock.expect(mockedTarget.request()).andReturn(mockedBuilder);
         EasyMock.expect(mockedBuilder.post(null)).andReturn(mockedResponse);
         EasyMock.expect(mockedResponse.getStatus()).andReturn(404);
+        EasyMock.expect(mockedResponse.getStatusInfo()).andReturn(Response.Status.NOT_FOUND);
         EasyMock.expect(mockedResponse.readEntity(String.class)).andReturn("Error");
 
         WhiteboxImpl.setInternalState(jerseyClient, "client", mockedClient);
@@ -205,7 +209,7 @@ public class JerseyClientTest {
         EasyMock.expect(mockedClient.target(url)).andReturn(mockedTarget);
         EasyMock.expect(mockedTarget.request()).andReturn(mockedBuilder);
         EasyMock.expect(mockedBuilder.post(null)).andReturn(mockedResponse);
-        EasyMock.expect(mockedResponse.getStatus()).andReturn(200);
+        EasyMock.expect(mockedResponse.getStatusInfo()).andReturn(Response.Status.OK);
         EasyMock.expect(mockedResponse.readEntity(String.class)).andReturn(GsonUtil.beanToJson(bean));
 
         WhiteboxImpl.setInternalState(jerseyClient, "client", mockedClient);
@@ -228,7 +232,7 @@ public class JerseyClientTest {
         EasyMock.expect(mockedClient.target(url)).andReturn(mockedTarget);
         EasyMock.expect(mockedTarget.request()).andReturn(mockedBuilder);
         EasyMock.expect(mockedBuilder.put(null)).andReturn(mockedResponse);
-        EasyMock.expect(mockedResponse.getStatus()).andReturn(200);
+        EasyMock.expect(mockedResponse.getStatusInfo()).andReturn(Response.Status.OK);
         EasyMock.expect(mockedResponse.readEntity(String.class)).andReturn("Normal");
 
         WhiteboxImpl.setInternalState(jerseyClient, "client", mockedClient);
@@ -251,7 +255,7 @@ public class JerseyClientTest {
         EasyMock.expect(mockedClient.target(url)).andReturn(mockedTarget);
         EasyMock.expect(mockedTarget.request()).andReturn(mockedBuilder);
         EasyMock.expect(mockedBuilder.put(null)).andReturn(mockedResponse);
-        EasyMock.expect(mockedResponse.getStatus()).andReturn(200);
+        EasyMock.expect(mockedResponse.getStatusInfo()).andReturn(Response.Status.OK);
         EasyMock.expect(mockedResponse.readEntity(String.class)).andReturn(GsonUtil.beanToJson(bean));
 
         WhiteboxImpl.setInternalState(jerseyClient, "client", mockedClient);
@@ -274,7 +278,7 @@ public class JerseyClientTest {
         EasyMock.expect(mockedClient.target(url)).andReturn(mockedTarget);
         EasyMock.expect(mockedTarget.request()).andReturn(mockedBuilder);
         EasyMock.expect(mockedBuilder.put(null)).andReturn(mockedResponse);
-        EasyMock.expect(mockedResponse.getStatus()).andReturn(200);
+        EasyMock.expect(mockedResponse.getStatusInfo()).andReturn(Response.Status.OK);
         EasyMock.expect(mockedResponse.readEntity(String.class)).andReturn(GsonUtil.beanToJson(bean));
 
         WhiteboxImpl.setInternalState(jerseyClient, "client", mockedClient);
@@ -297,6 +301,7 @@ public class JerseyClientTest {
         EasyMock.expect(mockedTarget.request()).andReturn(mockedBuilder);
         EasyMock.expect(mockedBuilder.put(null)).andReturn(mockedResponse);
         EasyMock.expect(mockedResponse.getStatus()).andReturn(404);
+        EasyMock.expect(mockedResponse.getStatusInfo()).andReturn(Response.Status.NOT_FOUND);
         EasyMock.expect(mockedResponse.readEntity(String.class)).andReturn("Error");
 
         WhiteboxImpl.setInternalState(jerseyClient, "client", mockedClient);
@@ -322,7 +327,7 @@ public class JerseyClientTest {
         EasyMock.expect(mockedClient.target(url)).andReturn(mockedTarget);
         EasyMock.expect(mockedTarget.request()).andReturn(mockedBuilder);
         EasyMock.expect(mockedBuilder.delete()).andReturn(mockedResponse);
-        EasyMock.expect(mockedResponse.getStatus()).andReturn(200);
+        EasyMock.expect(mockedResponse.getStatusInfo()).andReturn(Response.Status.OK);
         EasyMock.expect(mockedResponse.readEntity(String.class)).andReturn("Normal");
 
         WhiteboxImpl.setInternalState(jerseyClient, "client", mockedClient);
@@ -345,7 +350,7 @@ public class JerseyClientTest {
         EasyMock.expect(mockedClient.target(url)).andReturn(mockedTarget);
         EasyMock.expect(mockedTarget.request()).andReturn(mockedBuilder);
         EasyMock.expect(mockedBuilder.delete()).andReturn(mockedResponse);
-        EasyMock.expect(mockedResponse.getStatus()).andReturn(200);
+        EasyMock.expect(mockedResponse.getStatusInfo()).andReturn(Response.Status.OK);
         EasyMock.expect(mockedResponse.readEntity(String.class)).andReturn(GsonUtil.beanToJson(bean));
 
         WhiteboxImpl.setInternalState(jerseyClient, "client", mockedClient);
@@ -367,7 +372,7 @@ public class JerseyClientTest {
         EasyMock.expect(mockedClient.target(url)).andReturn(mockedTarget);
         EasyMock.expect(mockedTarget.request()).andReturn(mockedBuilder);
         EasyMock.expect(mockedBuilder.delete()).andReturn(mockedResponse);
-        EasyMock.expect(mockedResponse.getStatus()).andReturn(200);
+        EasyMock.expect(mockedResponse.getStatusInfo()).andReturn(Response.Status.OK);
         EasyMock.expect(mockedResponse.readEntity(String.class)).andReturn("Normal");
 
         WhiteboxImpl.setInternalState(jerseyClient, "client", mockedClient);
@@ -390,6 +395,7 @@ public class JerseyClientTest {
         EasyMock.expect(mockedTarget.request()).andReturn(mockedBuilder);
         EasyMock.expect(mockedBuilder.delete()).andReturn(mockedResponse);
         EasyMock.expect(mockedResponse.getStatus()).andReturn(404);
+        EasyMock.expect(mockedResponse.getStatusInfo()).andReturn(Response.Status.NOT_FOUND);
         EasyMock.expect(mockedResponse.readEntity(String.class)).andReturn("Error");
 
         WhiteboxImpl.setInternalState(jerseyClient, "client", mockedClient);