summaryrefslogtreecommitdiffstats
path: root/models-interactions/model-impl/so
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2019-06-14 19:20:55 -0400
committerJim Hahn <jrh3@att.com>2019-06-17 12:31:32 -0400
commitba6267f5bd58dd7a3a0d6363e7ac4c27705e9f40 (patch)
tree658afb8b0500180302e837b0f90e0372c82b7062 /models-interactions/model-impl/so
parentf59ec395bf1e41df894f884e70ff3185280668c0 (diff)
Fix sonar issues in models: sdc to vfc
sdc sdnc snr so vfc Still haven't done the "rest" project yet, as still awaiting removal of www.examples.org. Change-Id: Icc4948799e2423bd4568232ee5629b88b7ecb996 Issue-ID: POLICY-1791 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-interactions/model-impl/so')
-rw-r--r--models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoManager.java1
-rw-r--r--models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoDummyServer.java18
-rw-r--r--models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoManagerTest.java326
-rw-r--r--models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoRequestInfoTest.java24
-rw-r--r--models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoResponseWrapperTest.java8
5 files changed, 158 insertions, 219 deletions
diff --git a/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoManager.java b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoManager.java
index 888afe2ae..6e2494b72 100644
--- a/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoManager.java
+++ b/models-interactions/model-impl/so/src/main/java/org/onap/policy/so/SoManager.java
@@ -68,6 +68,7 @@ public final class SoManager {
private String user;
private String password;
+ @FunctionalInterface
public interface SoCallback {
public void onSoResponseWrapper(SoResponseWrapper wrapper);
}
diff --git a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoDummyServer.java b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoDummyServer.java
index e9c338356..d7e7a1166 100644
--- a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoDummyServer.java
+++ b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoDummyServer.java
@@ -36,6 +36,7 @@ import javax.ws.rs.core.Response;
@Path("/SO")
public class SoDummyServer {
+ private static final String ONGOING = "ONGOING";
private static int postMessagesReceived = 0;
private static int putMessagesReceived = 0;
private static int statMessagesReceived = 0;
@@ -113,9 +114,9 @@ public class SoDummyServer {
SoResponse response = ongoingRequestMap.get(nsInstanceId);
- int iterationsLeft = Integer.valueOf(response.getRequest().getRequestScope());
+ int iterationsLeft = Integer.parseInt(response.getRequest().getRequestScope());
if (--iterationsLeft > 0) {
- response.getRequest().setRequestScope(new Integer(iterationsLeft).toString());
+ response.getRequest().setRequestScope(Integer.toString(iterationsLeft));
String responseString = new Gson().toJson(response, SoResponse.class);
return Response.status(response.getHttpResponseCode()).entity(responseString).build();
}
@@ -158,12 +159,7 @@ public class SoDummyServer {
return Response.status(400).build();
}
- SoRequest request = null;
- try {
- request = new Gson().fromJson(jsonString, SoRequest.class);
- } catch (Exception e) {
- return Response.status(400).build();
- }
+ SoRequest request = new Gson().fromJson(jsonString, SoRequest.class);
if (request == null) {
return Response.status(400).build();
@@ -206,7 +202,7 @@ public class SoDummyServer {
if ("ReturnOnging202".equals(request.getRequestType())) {
ongoingRequestMap.put(request.getRequestId().toString(), response);
- response.getRequest().getRequestStatus().setRequestState("ONGOING");
+ response.getRequest().getRequestStatus().setRequestState(ONGOING);
response.setHttpResponseCode(202);
String responseString = new Gson().toJson(response, SoResponse.class);
return Response.status(response.getHttpResponseCode())
@@ -217,7 +213,7 @@ public class SoDummyServer {
if ("ReturnOnging200".equals(request.getRequestType())) {
ongoingRequestMap.put(request.getRequestId().toString(), response);
- response.getRequest().getRequestStatus().setRequestState("ONGOING");
+ response.getRequest().getRequestStatus().setRequestState(ONGOING);
response.setHttpResponseCode(200);
String responseString = new Gson().toJson(response, SoResponse.class);
return Response.status(response.getHttpResponseCode())
@@ -228,7 +224,7 @@ public class SoDummyServer {
if ("ReturnBadAfterWait".equals(request.getRequestType())) {
ongoingRequestMap.put(request.getRequestId().toString(), response);
- response.getRequest().getRequestStatus().setRequestState("ONGOING");
+ response.getRequest().getRequestStatus().setRequestState(ONGOING);
response.setHttpResponseCode(200);
String responseString = new Gson().toJson(response, SoResponse.class);
return Response.status(response.getHttpResponseCode())
diff --git a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoManagerTest.java b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoManagerTest.java
index 03ac06dd5..aa3562ae5 100644
--- a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoManagerTest.java
+++ b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoManagerTest.java
@@ -28,13 +28,11 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import java.io.IOException;
import java.net.URI;
import java.util.UUID;
import java.util.concurrent.Future;
-import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
@@ -49,6 +47,19 @@ import org.junit.Test;
import org.onap.policy.so.SoManager.SoCallback;
public class SoManagerTest implements SoCallback {
+ private static final String LOCALHOST_99999999 = "http:/localhost:99999999";
+ private static final String CITIZEN = "citizen";
+ private static final String RETURN_ONGING202 = "ReturnOnging202";
+ private static final String RETURN_ONGING200 = "ReturnOnging200";
+ private static final String RETURN_FAILED = "ReturnFailed";
+ private static final String RETURN_COMPLETED = "ReturnCompleted";
+ private static final String RETURN_BAD_JSON = "ReturnBadJson";
+ private static final String RETURN_BAD_AFTER_WAIT = "ReturnBadAfterWait";
+ private static final String ONGOING = "ONGOING";
+ private static final String FAILED = "FAILED";
+ private static final String COMPLETE = "COMPLETE";
+ private static final String DATE1 = "2018-03-23 16:31";
+ private static final String SERVICE_INSTANTIATION_V7 = "/serviceInstantiation/v7";
private static final String BASE_URI = "http://localhost:46553/TestSOManager";
private static final String BASE_SO_URI = BASE_URI + "/SO";
private static HttpServer server;
@@ -68,99 +79,100 @@ public class SoManagerTest implements SoCallback {
}
@AfterClass
- public static void tearDown() throws Exception {
+ public static void tearDown() {
server.shutdown();
}
@Test
- public void testGrizzlyServer() throws ClientProtocolException, IOException {
- CloseableHttpClient httpclient = HttpClients.createDefault();
- HttpGet httpGet = new HttpGet("http://localhost:46553/TestSOManager/SO/Stats");
- CloseableHttpResponse response = httpclient.execute(httpGet);
-
- String returnBody = EntityUtils.toString(response.getEntity(), "UTF-8");
- assertTrue(returnBody.matches("^\\{\"GET\": [0-9]*,\"STAT\": [0-9]*,\"POST\": [0-9]*,\"PUT\": [0-9]*,"
- + "\"DELETE\": [0-9]*\\}$"));
+ public void testGrizzlyServer() throws IOException {
+ try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
+ HttpGet httpGet = new HttpGet("http://localhost:46553/TestSOManager/SO/Stats");
+ CloseableHttpResponse response = httpclient.execute(httpGet);
+
+ String returnBody = EntityUtils.toString(response.getEntity(), "UTF-8");
+ assertTrue(returnBody.matches("^\\{\"GET\": [0-9]*,\"STAT\": [0-9]*,\"POST\": [0-9]*,\"PUT\": [0-9]*,"
+ + "\"DELETE\": [0-9]*\\}$"));
+ }
}
@Test
- public void testServiceInstantiation() throws IOException {
+ public void testServiceInstantiation() {
SoManager manager = new SoManager(null, null, null);
assertNotNull(manager);
manager.setRestGetTimeout(100);
- SoResponse response = manager.createModuleInstance("http:/localhost:99999999", BASE_SO_URI, "sean",
- "citizen", null);
+ SoResponse response = manager.createModuleInstance(LOCALHOST_99999999, BASE_SO_URI, "sean",
+ CITIZEN, null);
assertNull(response);
- response = manager.createModuleInstance(BASE_SO_URI + "/serviceInstantiation/v7", BASE_SO_URI, "sean",
- "citizen", null);
+ response = manager.createModuleInstance(BASE_SO_URI + SERVICE_INSTANTIATION_V7, BASE_SO_URI, "sean",
+ CITIZEN, null);
assertNull(response);
- response = manager.createModuleInstance(BASE_SO_URI + "/serviceInstantiation/v7", BASE_SO_URI, "sean",
- "citizen", new SoRequest());
+ response = manager.createModuleInstance(BASE_SO_URI + SERVICE_INSTANTIATION_V7, BASE_SO_URI, "sean",
+ CITIZEN, new SoRequest());
assertNull(response);
SoRequest request = new SoRequest();
request.setRequestId(UUID.randomUUID());
request.setRequestScope("Test");
- request.setRequestType("ReturnBadJson");
- request.setStartTime("2018-03-23 16:31");
+ request.setRequestType(RETURN_BAD_JSON);
+ request.setStartTime(DATE1);
request.setRequestStatus(new SoRequestStatus());
- request.getRequestStatus().setRequestState("ONGOING");
+ request.getRequestStatus().setRequestState(ONGOING);
- response = manager.createModuleInstance(BASE_SO_URI + "/serviceInstantiation/v7", BASE_SO_URI, "sean",
- "citizen", request);
+ response = manager.createModuleInstance(BASE_SO_URI + SERVICE_INSTANTIATION_V7, BASE_SO_URI, "sean",
+ CITIZEN, request);
assertNull(response);
- request.setRequestType("ReturnCompleted");
- response = manager.createModuleInstance(BASE_SO_URI + "/serviceInstantiation/v7", BASE_SO_URI, "sean",
- "citizen", request);
+ request.setRequestType(RETURN_COMPLETED);
+ response = manager.createModuleInstance(BASE_SO_URI + SERVICE_INSTANTIATION_V7, BASE_SO_URI, "sean",
+ CITIZEN, request);
assertNotNull(response);
- assertEquals("COMPLETE", response.getRequest().getRequestStatus().getRequestState());
+ assertEquals(COMPLETE, response.getRequest().getRequestStatus().getRequestState());
- request.setRequestType("ReturnFailed");
- response = manager.createModuleInstance(BASE_SO_URI + "/serviceInstantiation/v7", BASE_SO_URI, "sean",
- "citizen", request);
+ request.setRequestType(RETURN_FAILED);
+ response = manager.createModuleInstance(BASE_SO_URI + SERVICE_INSTANTIATION_V7, BASE_SO_URI, "sean",
+ CITIZEN, request);
assertNotNull(response);
- assertEquals("FAILED", response.getRequest().getRequestStatus().getRequestState());
+ assertEquals(FAILED, response.getRequest().getRequestStatus().getRequestState());
// Use scope to set the number of iterations we'll wait for
- request.setRequestType("ReturnOnging200");
- request.setRequestScope(new Integer(10).toString());
- response = manager.createModuleInstance(BASE_SO_URI + "/serviceInstantiation/v7", BASE_SO_URI, "sean",
- "citizen", request);
+ request.setRequestType(RETURN_ONGING200);
+ request.setRequestScope("10");
+ response = manager.createModuleInstance(BASE_SO_URI + SERVICE_INSTANTIATION_V7, BASE_SO_URI, "sean",
+ CITIZEN, request);
assertNotNull(response);
assertNotNull(response.getRequest());
- assertEquals("COMPLETE", response.getRequest().getRequestStatus().getRequestState());
+ assertEquals(COMPLETE, response.getRequest().getRequestStatus().getRequestState());
- request.setRequestType("ReturnOnging202");
- request.setRequestScope(new Integer(20).toString());
- response = manager.createModuleInstance(BASE_SO_URI + "/serviceInstantiation/v7", BASE_SO_URI, "sean",
- "citizen", request);
+ request.setRequestType(RETURN_ONGING202);
+ request.setRequestScope("20");
+ response = manager.createModuleInstance(BASE_SO_URI + SERVICE_INSTANTIATION_V7, BASE_SO_URI, "sean",
+ CITIZEN, request);
assertNotNull(response);
assertNotNull(response.getRequest());
- assertEquals("COMPLETE", response.getRequest().getRequestStatus().getRequestState());
+ assertEquals(COMPLETE, response.getRequest().getRequestStatus().getRequestState());
// Test timeout after 20 attempts for a response
- request.setRequestType("ReturnOnging202");
- request.setRequestScope(new Integer(21).toString());
- response = manager.createModuleInstance(BASE_SO_URI + "/serviceInstantiation/v7", BASE_SO_URI, "sean",
- "citizen", request);
+ request.setRequestType(RETURN_ONGING202);
+ request.setRequestScope("21");
+ response = manager.createModuleInstance(BASE_SO_URI + SERVICE_INSTANTIATION_V7, BASE_SO_URI, "sean",
+ CITIZEN, request);
assertNull(response);
// Test bad response after 3 attempts for a response
- request.setRequestType("ReturnBadAfterWait");
- request.setRequestScope(new Integer(3).toString());
- response = manager.createModuleInstance(BASE_SO_URI + "/serviceInstantiation/v7", BASE_SO_URI, "sean",
- "citizen", request);
+ request.setRequestType(RETURN_BAD_AFTER_WAIT);
+ request.setRequestScope("3");
+ response = manager.createModuleInstance(BASE_SO_URI + SERVICE_INSTANTIATION_V7, BASE_SO_URI, "sean",
+ CITIZEN, request);
assertNull(response);
}
@Test
- public void testVfModuleCreation() throws IOException {
- SoManager manager = new SoManager("http:/localhost:99999999", "sean", "citizen");
+ public void testVfModuleCreation() throws Exception {
+ SoManager manager = new SoManager(LOCALHOST_99999999, "sean", CITIZEN);
assertNotNull(manager);
manager.setRestGetTimeout(100);
@@ -168,117 +180,81 @@ public class SoManagerTest implements SoCallback {
soRequest.setOperationType(SoOperationType.SCALE_OUT);
Future<SoResponse> asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this,
UUID.randomUUID().toString(), UUID.randomUUID().toString(), soRequest);
- try {
- SoResponse response = asyncRestCallFuture.get();
- assertEquals(999, response.getHttpResponseCode());
- } catch (Exception e) {
- fail("test should not throw an exception");
- }
+ SoResponse response = asyncRestCallFuture.get();
+ assertEquals(999, response.getHttpResponseCode());
- manager = new SoManager(BASE_SO_URI, "sean", "citizen");
+ manager = new SoManager(BASE_SO_URI, "sean", CITIZEN);
manager.setRestGetTimeout(100);
asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this, UUID.randomUUID().toString(),
UUID.randomUUID().toString(), soRequest);
- try {
- SoResponse response = asyncRestCallFuture.get();
- assertEquals(999, response.getHttpResponseCode());
- } catch (Exception e) {
- fail("test should not throw an exception");
- }
+ response = asyncRestCallFuture.get();
+ assertEquals(999, response.getHttpResponseCode());
SoRequest request = new SoRequest();
request.setRequestId(UUID.randomUUID());
request.setRequestScope("Test");
- request.setRequestType("ReturnBadJson");
- request.setStartTime("2018-03-23 16:31");
+ request.setRequestType(RETURN_BAD_JSON);
+ request.setStartTime(DATE1);
request.setRequestStatus(new SoRequestStatus());
- request.getRequestStatus().setRequestState("ONGOING");
+ request.getRequestStatus().setRequestState(ONGOING);
request.setOperationType(SoOperationType.SCALE_OUT);
asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this, UUID.randomUUID().toString(),
UUID.randomUUID().toString(), request);
- try {
- SoResponse response = asyncRestCallFuture.get();
- assertEquals(999, response.getHttpResponseCode());
- } catch (Exception e) {
- fail("test should not throw an exception");
- }
+ response = asyncRestCallFuture.get();
+ assertEquals(999, response.getHttpResponseCode());
- request.setRequestType("ReturnCompleted");
+ request.setRequestType(RETURN_COMPLETED);
asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this, UUID.randomUUID().toString(),
UUID.randomUUID().toString(), request);
- try {
- SoResponse response = asyncRestCallFuture.get();
- assertEquals("COMPLETE", response.getRequest().getRequestStatus().getRequestState());
- } catch (Exception e) {
- fail("test should not throw an exception");
- }
+ response = asyncRestCallFuture.get();
+ assertEquals(COMPLETE, response.getRequest().getRequestStatus().getRequestState());
- request.setRequestType("ReturnFailed");
+ request.setRequestType(RETURN_FAILED);
asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this, UUID.randomUUID().toString(),
UUID.randomUUID().toString(), request);
- try {
- SoResponse response = asyncRestCallFuture.get();
- assertEquals("FAILED", response.getRequest().getRequestStatus().getRequestState());
- } catch (Exception e) {
- fail("test should not throw an exception");
- }
+ response = asyncRestCallFuture.get();
+ assertEquals(FAILED, response.getRequest().getRequestStatus().getRequestState());
// Use scope to set the number of iterations we'll wait for
- request.setRequestType("ReturnOnging200");
- request.setRequestScope(new Integer(10).toString());
+ request.setRequestType(RETURN_ONGING200);
+ request.setRequestScope("10");
asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this, UUID.randomUUID().toString(),
UUID.randomUUID().toString(), request);
- try {
- SoResponse response = asyncRestCallFuture.get();
- assertNotNull(response.getRequest());
- assertEquals("COMPLETE", response.getRequest().getRequestStatus().getRequestState());
- } catch (Exception e) {
- fail("test should not throw an exception");
- }
+ response = asyncRestCallFuture.get();
+ assertNotNull(response.getRequest());
+ assertEquals(COMPLETE, response.getRequest().getRequestStatus().getRequestState());
- request.setRequestType("ReturnOnging202");
- request.setRequestScope(new Integer(20).toString());
+ request.setRequestType(RETURN_ONGING202);
+ request.setRequestScope("20");
asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this, UUID.randomUUID().toString(),
UUID.randomUUID().toString(), request);
- try {
- SoResponse response = asyncRestCallFuture.get();
- assertNotNull(response.getRequest());
- assertEquals("COMPLETE", response.getRequest().getRequestStatus().getRequestState());
- } catch (Exception e) {
- fail("test should not throw an exception");
- }
+ response = asyncRestCallFuture.get();
+ assertNotNull(response.getRequest());
+ assertEquals(COMPLETE, response.getRequest().getRequestStatus().getRequestState());
// Test timeout after 20 attempts for a response
- request.setRequestType("ReturnOnging202");
- request.setRequestScope(new Integer(21).toString());
+ request.setRequestType(RETURN_ONGING202);
+ request.setRequestScope("21");
asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this, UUID.randomUUID().toString(),
UUID.randomUUID().toString(), request);
- try {
- SoResponse response = asyncRestCallFuture.get();
- assertEquals(999, response.getHttpResponseCode());
- } catch (Exception e) {
- fail("test should not throw an exception");
- }
+ response = asyncRestCallFuture.get();
+ assertEquals(999, response.getHttpResponseCode());
// Test bad response after 3 attempts for a response
- request.setRequestType("ReturnBadAfterWait");
- request.setRequestScope(new Integer(3).toString());
+ request.setRequestType(RETURN_BAD_AFTER_WAIT);
+ request.setRequestScope("3");
asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this, UUID.randomUUID().toString(),
UUID.randomUUID().toString(), request);
- try {
- SoResponse response = asyncRestCallFuture.get();
- assertEquals(999, response.getHttpResponseCode());
- } catch (Exception e) {
- fail("test should not throw an exception");
- }
+ response = asyncRestCallFuture.get();
+ assertEquals(999, response.getHttpResponseCode());
}
@Test
- public void testVfModuleDeletion() {
- SoManager manager = new SoManager("http:/localhost:99999999", "sean", "citizen");
+ public void testVfModuleDeletion() throws Exception {
+ SoManager manager = new SoManager(LOCALHOST_99999999, "sean", CITIZEN);
assertNotNull(manager);
manager.setRestGetTimeout(100);
@@ -286,113 +262,77 @@ public class SoManagerTest implements SoCallback {
soRequest.setOperationType(SoOperationType.DELETE_VF_MODULE);
Future<SoResponse> asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this,
UUID.randomUUID().toString(), UUID.randomUUID().toString(), UUID.randomUUID().toString(), soRequest);
- try {
- SoResponse response = asyncRestCallFuture.get();
- assertEquals(999, response.getHttpResponseCode());
- } catch (Exception e) {
- fail("test should not throw an exception");
- }
+ SoResponse response = asyncRestCallFuture.get();
+ assertEquals(999, response.getHttpResponseCode());
- manager = new SoManager(BASE_SO_URI, "sean", "citizen");
+ manager = new SoManager(BASE_SO_URI, "sean", CITIZEN);
manager.setRestGetTimeout(100);
asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this, UUID.randomUUID().toString(),
UUID.randomUUID().toString(), UUID.randomUUID().toString(), soRequest);
- try {
- SoResponse response = asyncRestCallFuture.get();
- assertEquals(999, response.getHttpResponseCode());
- } catch (Exception e) {
- fail("test should not throw an exception");
- }
+ response = asyncRestCallFuture.get();
+ assertEquals(999, response.getHttpResponseCode());
SoRequest request = new SoRequest();
request.setRequestId(UUID.randomUUID());
request.setRequestScope("Test");
- request.setRequestType("ReturnBadJson");
- request.setStartTime("2018-03-23 16:31");
+ request.setRequestType(RETURN_BAD_JSON);
+ request.setStartTime(DATE1);
request.setRequestStatus(new SoRequestStatus());
- request.getRequestStatus().setRequestState("ONGOING");
+ request.getRequestStatus().setRequestState(ONGOING);
request.setOperationType(SoOperationType.DELETE_VF_MODULE);
asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this, UUID.randomUUID().toString(),
UUID.randomUUID().toString(), UUID.randomUUID().toString(), request);
- try {
- SoResponse response = asyncRestCallFuture.get();
- assertEquals(999, response.getHttpResponseCode());
- } catch (Exception e) {
- fail("test should not throw an exception");
- }
+ response = asyncRestCallFuture.get();
+ assertEquals(999, response.getHttpResponseCode());
- request.setRequestType("ReturnCompleted");
+ request.setRequestType(RETURN_COMPLETED);
asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this, UUID.randomUUID().toString(),
UUID.randomUUID().toString(), UUID.randomUUID().toString(), request);
- try {
- SoResponse response = asyncRestCallFuture.get();
- assertEquals("COMPLETE", response.getRequest().getRequestStatus().getRequestState());
- } catch (Exception e) {
- fail("test should not throw an exception");
- }
+ response = asyncRestCallFuture.get();
+ assertEquals(COMPLETE, response.getRequest().getRequestStatus().getRequestState());
- request.setRequestType("ReturnFailed");
+ request.setRequestType(RETURN_FAILED);
asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this, UUID.randomUUID().toString(),
UUID.randomUUID().toString(), UUID.randomUUID().toString(), request);
- try {
- SoResponse response = asyncRestCallFuture.get();
- assertEquals("FAILED", response.getRequest().getRequestStatus().getRequestState());
- } catch (Exception e) {
- fail("test should not throw an exception");
- }
+ response = asyncRestCallFuture.get();
+ assertEquals(FAILED, response.getRequest().getRequestStatus().getRequestState());
// Use scope to set the number of iterations we'll wait for
- request.setRequestType("ReturnOnging200");
- request.setRequestScope(new Integer(10).toString());
+ request.setRequestType(RETURN_ONGING200);
+ request.setRequestScope("10");
asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this, UUID.randomUUID().toString(),
UUID.randomUUID().toString(), UUID.randomUUID().toString(), request);
- try {
- SoResponse response = asyncRestCallFuture.get();
- assertNotNull(response.getRequest());
- assertEquals("COMPLETE", response.getRequest().getRequestStatus().getRequestState());
- } catch (Exception e) {
- fail("test should not throw an exception");
- }
+ response = asyncRestCallFuture.get();
+ assertNotNull(response.getRequest());
+ assertEquals(COMPLETE, response.getRequest().getRequestStatus().getRequestState());
- request.setRequestType("ReturnOnging202");
- request.setRequestScope(new Integer(20).toString());
+ request.setRequestType(RETURN_ONGING202);
+ request.setRequestScope("20");
asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this, UUID.randomUUID().toString(),
UUID.randomUUID().toString(), UUID.randomUUID().toString(), request);
- try {
- SoResponse response = asyncRestCallFuture.get();
- assertNotNull(response.getRequest());
- assertEquals("COMPLETE", response.getRequest().getRequestStatus().getRequestState());
- } catch (Exception e) {
- fail("test should not throw an exception");
- }
+ response = asyncRestCallFuture.get();
+ assertNotNull(response.getRequest());
+ assertEquals(COMPLETE, response.getRequest().getRequestStatus().getRequestState());
// Test timeout after 20 attempts for a response
- request.setRequestType("ReturnOnging202");
- request.setRequestScope(new Integer(21).toString());
+ request.setRequestType(RETURN_ONGING202);
+ request.setRequestScope("21");
asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this, UUID.randomUUID().toString(),
UUID.randomUUID().toString(), UUID.randomUUID().toString(), request);
- try {
- SoResponse response = asyncRestCallFuture.get();
- assertEquals(999, response.getHttpResponseCode());
- } catch (Exception e) {
- fail("test should not throw an exception");
- }
+ response = asyncRestCallFuture.get();
+ assertEquals(999, response.getHttpResponseCode());
// Test bad response after 3 attempts for a response
- request.setRequestType("ReturnBadAfterWait");
- request.setRequestScope(new Integer(3).toString());
+ request.setRequestType(RETURN_BAD_AFTER_WAIT);
+ request.setRequestScope("3");
asyncRestCallFuture = manager.asyncSoRestCall(UUID.randomUUID().toString(), this, UUID.randomUUID().toString(),
UUID.randomUUID().toString(), UUID.randomUUID().toString(), request);
- try {
- SoResponse response = asyncRestCallFuture.get();
- assertEquals(999, response.getHttpResponseCode());
- } catch (Exception e) {
- fail("test should not throw an exception");
- }
+ response = asyncRestCallFuture.get();
+ assertEquals(999, response.getHttpResponseCode());
}
@Override
diff --git a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoRequestInfoTest.java b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoRequestInfoTest.java
index 2302696ee..dd7db84f3 100644
--- a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoRequestInfoTest.java
+++ b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoRequestInfoTest.java
@@ -3,7 +3,6 @@
* so
* ================================================================================
* Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved
* Modifications Copyright (C) 2019 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -23,7 +22,8 @@
package org.onap.policy.so;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
import org.junit.Test;
@@ -33,16 +33,16 @@ public class SoRequestInfoTest {
public void testConstructor() {
SoRequestInfo obj = new SoRequestInfo();
- assertTrue(obj.getBillingAccountNumber() == null);
- assertTrue(obj.getCallbackUrl() == null);
- assertTrue(obj.getCorrelator() == null);
- assertTrue(obj.getInstanceName() == null);
- assertTrue(obj.getOrderNumber() == null);
- assertTrue(obj.getOrderVersion() == null);
- assertTrue(obj.getProductFamilyId() == null);
- assertTrue(obj.getRequestorId() == null);
- assertTrue(obj.getSource() == null);
- assertTrue(obj.isSuppressRollback() == false);
+ assertNull(obj.getBillingAccountNumber());
+ assertNull(obj.getCallbackUrl());
+ assertNull(obj.getCorrelator());
+ assertNull(obj.getInstanceName());
+ assertNull(obj.getOrderNumber());
+ assertNull(obj.getOrderVersion());
+ assertNull(obj.getProductFamilyId());
+ assertNull(obj.getRequestorId());
+ assertNull(obj.getSource());
+ assertFalse(obj.isSuppressRollback());
}
@Test
diff --git a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoResponseWrapperTest.java b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoResponseWrapperTest.java
index deedc79c5..fdc59965a 100644
--- a/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoResponseWrapperTest.java
+++ b/models-interactions/model-impl/so/src/test/java/org/onap/policy/so/SoResponseWrapperTest.java
@@ -32,19 +32,21 @@ import org.junit.Test;
public class SoResponseWrapperTest {
+ private static final String REQ_ID = "reqID";
+
@Test
public void testConstructor() {
SoResponse response = new SoResponse();
- SoResponseWrapper obj = new SoResponseWrapper(response, "reqID");
+ SoResponseWrapper obj = new SoResponseWrapper(response, REQ_ID);
assertEquals(response, obj.getSoResponse());
- assertEquals("reqID", obj.getRequestId());
+ assertEquals(REQ_ID, obj.getRequestId());
}
@Test
public void testSetGet() {
SoResponse response = new SoResponse();
- SoResponseWrapper obj = new SoResponseWrapper(response, "reqID");
+ SoResponseWrapper obj = new SoResponseWrapper(response, REQ_ID);
SoResponse response2 = new SoResponse();
response2.setHttpResponseCode(2008);