summaryrefslogtreecommitdiffstats
path: root/adapters/mso-sdnc-adapter/src/test
diff options
context:
space:
mode:
authorRob Daugherty <rd472p@att.com>2018-03-09 15:02:18 -0500
committerRob Daugherty <rd472p@att.com>2018-03-09 15:08:14 -0500
commit96b5a685d0c3afddb632e4a68ca7483f933b55dc (patch)
tree246399de05a3d429bf45ef1e5af2b9b0218d99f3 /adapters/mso-sdnc-adapter/src/test
parent4475278c81668109b2b37a1d2720d8f2910641c4 (diff)
Revert Reduce log noise/warnings
This reverts commit 327b17ab250b4c17cf3f91f5e4cd9bffd89f3d1e. It is seriously impeding our ability complete the promised merge of AT&T 1802 code. While I'm all for coding standards, if we are serious about using spaces instead of tabs, then I think we need to (1) agree with the community when this will happen, (2) do consistently in all files, and (3) enforce it. Change-Id: Ib9b996f6b6c7d81ac9ac95d58b0c7d8cc39675ff Issue-ID: SO-368 Signed-off-by: Rob Daugherty <rd472p@att.com>
Diffstat (limited to 'adapters/mso-sdnc-adapter/src/test')
-rw-r--r--adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/ObjectFactoryTest.java51
-rw-r--r--adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/SDNCAdapterRequestTest.java42
-rw-r--r--adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/client/SDNCAdapterCallbackRequestTest.java40
-rw-r--r--adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/impl/RequestTunablesTest.java45
-rw-r--r--adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/sdncrest/ObjectMappingTest.java861
-rw-r--r--adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/util/SDNCRequestIdUtilTest.java17
6 files changed, 529 insertions, 527 deletions
diff --git a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/ObjectFactoryTest.java b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/ObjectFactoryTest.java
index 8b64f9325e..5e3f79add6 100644
--- a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/ObjectFactoryTest.java
+++ b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/ObjectFactoryTest.java
@@ -43,44 +43,45 @@ public class ObjectFactoryTest {
* Test method for {@link org.openecomp.mso.adapters.sdnc.ObjectFactory#createRequestHeader()}.
*/
@Test
- public final void testCreateRequestHeader() {
- ObjectFactory of = new ObjectFactory();
- RequestHeader rh = of.createRequestHeader();
- rh.setCallbackUrl("callback");
- rh.setMsoAction("action");
- rh.setRequestId("reqid");
- rh.setSvcAction("svcAction");
- rh.setSvcInstanceId("svcId");
- rh.setSvcOperation("op");
-
+ public final void testCreateRequestHeader () {
+ ObjectFactory of = new ObjectFactory ();
+ RequestHeader rh = of.createRequestHeader ();
+ rh.setCallbackUrl ("callback");
+ rh.setMsoAction ("action");
+ rh.setRequestId ("reqid");
+ rh.setSvcAction ("svcAction");
+ rh.setSvcInstanceId ("svcId");
+ rh.setSvcOperation ("op");
+
try {
JAXBContext jaxbContext = JAXBContext.newInstance(RequestHeader.class);
jaxbMarshaller = jaxbContext.createMarshaller();
-
+
JAXBContext jaxbContext2 = JAXBContext.newInstance(RequestHeader.class);
jaxbUnmarshaller = jaxbContext2.createUnmarshaller();
- } catch (JAXBException e) {
- e.printStackTrace();
+ }
+ catch (JAXBException e) {
+ e.printStackTrace ();
fail();
return;
}
StringWriter writer = new StringWriter();
try {
- jaxbMarshaller.marshal(rh, writer);
+ jaxbMarshaller.marshal (rh, writer);
} catch (JAXBException e) {
e.printStackTrace();
- fail();
+ fail ();
}
- String marshalled = writer.toString();
- assert (marshalled.contains("<RequestId>reqid</RequestId>"));
-
+ String marshalled = writer.toString ();
+ assert(marshalled.contains ("<RequestId>reqid</RequestId>"));
+
InputStream inputStream = new ByteArrayInputStream(marshalled.getBytes(Charset.forName("UTF-8")));
try {
- RequestHeader res2 = (RequestHeader) jaxbUnmarshaller.unmarshal(inputStream);
- assert (res2.getCallbackUrl().equals("callback"));
- assert (res2.getMsoAction().equals("action"));
- assert (res2.getSvcOperation().equals("op"));
+ RequestHeader res2 = (RequestHeader) jaxbUnmarshaller.unmarshal (inputStream);
+ assert(res2.getCallbackUrl ().equals ("callback"));
+ assert(res2.getMsoAction ().equals ("action"));
+ assert(res2.getSvcOperation ().equals ("op"));
} catch (JAXBException e) {
e.printStackTrace();
fail();
@@ -91,9 +92,9 @@ public class ObjectFactoryTest {
* Test method for {@link org.openecomp.mso.adapters.sdnc.ObjectFactory#createSDNCAdapterResponse()}.
*/
@Test
- public final void testCreateSDNCAdapterResponse() {
- ObjectFactory of = new ObjectFactory();
- SDNCAdapterResponse ar = of.createSDNCAdapterResponse();
+ public final void testCreateSDNCAdapterResponse () {
+ ObjectFactory of = new ObjectFactory ();
+ SDNCAdapterResponse ar = of.createSDNCAdapterResponse ();
assert (ar != null);
}
}
diff --git a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/SDNCAdapterRequestTest.java b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/SDNCAdapterRequestTest.java
index 5fd2c84f1c..fa96b7983e 100644
--- a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/SDNCAdapterRequestTest.java
+++ b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/SDNCAdapterRequestTest.java
@@ -29,26 +29,26 @@ import org.openecomp.mso.adapters.sdnc.RequestHeader;
public class SDNCAdapterRequestTest {
- static Object sd = new SDNCAdapterRequest();
- static RequestHeader rh = new RequestHeader();
-
- @BeforeClass
- public static final void RHeader() {
- rh.setCallbackUrl("callback");
- rh.setMsoAction("action");
- rh.setRequestId("reqid");
- rh.setSvcAction("svcAction");
- rh.setSvcInstanceId("svcId");
- rh.setSvcOperation("op");
- }
-
- @Test
- public final void testtoString() {
- ((SDNCAdapterRequest) sd).setRequestData("data");
- ((SDNCAdapterRequest) sd).setRequestHeader(rh);
- assert (((SDNCAdapterRequest) sd).getRequestData() != null);
- assert (((SDNCAdapterRequest) sd).getRequestData().equals("data"));
- assert (((SDNCAdapterRequest) sd).getRequestHeader().equals(rh));
- }
+ static Object sd= new SDNCAdapterRequest();
+ static RequestHeader rh=new RequestHeader();
+
+ @BeforeClass
+ public static final void RHeader()
+ {
+ rh.setCallbackUrl("callback");
+ rh.setMsoAction ("action");
+ rh.setRequestId ("reqid");
+ rh.setSvcAction ("svcAction");
+ rh.setSvcInstanceId ("svcId");
+ rh.setSvcOperation ("op");
+ }
+ @Test
+ public final void testtoString(){
+ ((SDNCAdapterRequest) sd).setRequestData("data");
+ ((SDNCAdapterRequest) sd).setRequestHeader(rh);
+ assert (((SDNCAdapterRequest) sd).getRequestData()!= null) ;
+ assert(((SDNCAdapterRequest) sd).getRequestData().equals("data"));
+ assert(((SDNCAdapterRequest) sd).getRequestHeader().equals(rh));
+ }
}
diff --git a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/client/SDNCAdapterCallbackRequestTest.java b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/client/SDNCAdapterCallbackRequestTest.java
index cb64528e78..63aa49cf54 100644
--- a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/client/SDNCAdapterCallbackRequestTest.java
+++ b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/client/SDNCAdapterCallbackRequestTest.java
@@ -27,25 +27,27 @@ import org.openecomp.mso.adapters.sdnc.client.SDNCAdapterCallbackRequest;
public class SDNCAdapterCallbackRequestTest {
- static SDNCAdapterCallbackRequest sdc = new SDNCAdapterCallbackRequest();
- static CallbackHeader ch = new CallbackHeader("413658f4-7f42-482e-b834-23a5c15657da-1474471336781", "200", "OK");
-
- @Test
- public void testSDNCAdapterCallbackRequest() {
- sdc.setCallbackHeader(ch);
- sdc.setRequestData("data");
- assert (sdc.getCallbackHeader() != null);
- assert (sdc.getRequestData() != null);
- assert (sdc.getCallbackHeader().equals(ch));
- assert (sdc.getRequestData().equals("data"));
-
- }
-
- @Test
- public void testtoString() {
- assert (ch.toString() != null);
- }
-
+ static SDNCAdapterCallbackRequest sdc = new SDNCAdapterCallbackRequest();
+ static CallbackHeader ch = new CallbackHeader("413658f4-7f42-482e-b834-23a5c15657da-1474471336781","200","OK");
+
+ @Test
+ public void testSDNCAdapterCallbackRequest()
+ {
+ sdc.setCallbackHeader(ch);
+ sdc.setRequestData("data");
+ assert(sdc.getCallbackHeader()!=null);
+ assert(sdc.getRequestData()!=null);
+ assert(sdc.getCallbackHeader().equals(ch));
+ assert(sdc.getRequestData().equals("data"));
+
+ }
+
+ @Test
+ public void testtoString()
+ {
+ assert(ch.toString()!=null);
+ }
+
}
diff --git a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/impl/RequestTunablesTest.java b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/impl/RequestTunablesTest.java
index 0845315f67..55295fc3ea 100644
--- a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/impl/RequestTunablesTest.java
+++ b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/impl/RequestTunablesTest.java
@@ -33,21 +33,20 @@ import org.openecomp.mso.properties.MsoPropertiesFactory;
public class RequestTunablesTest {
- public static MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory();
-
+ public static MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory();
+
/**
* This method is called before any test occurs.
* It creates a fake tree from scratch
- *
- * @throws MsoPropertiesException
+ * @throws MsoPropertiesException
*/
@BeforeClass
- public static final void prepare() throws MsoPropertiesException {
- ClassLoader classLoader = RequestTunablesTest.class.getClassLoader();
- String path = classLoader.getResource("mso.properties").toString().substring(5);
-
+ public static final void prepare () throws MsoPropertiesException {
+ ClassLoader classLoader = RequestTunablesTest.class.getClassLoader ();
+ String path = classLoader.getResource ("mso.properties").toString ().substring (5);
+
msoPropertiesFactory.initializeMsoProperties(RequestTunables.MSO_PROP_SDNC_ADAPTER, path);
-
+
}
/**
@@ -56,20 +55,20 @@ public class RequestTunablesTest {
* .
*/
@Test
- public final void testRequestTunables() {
- RequestTunables rt = new RequestTunables(null, null, "op", null, msoPropertiesFactory);
- assert (rt.getReqId().length() == 0);
- rt = new RequestTunables("reqId", "msoAction", null, "query", msoPropertiesFactory);
- rt.setTunables();
- System.out.println(rt.toString());
- // assert (rt.getReqMethod ().equals ("toto"));
- assert (rt.getTimeout() != null);
- assert (rt.getAction().equals("query"));
- assert (rt.getMsoAction().equals("msoAction"));
- assert (rt.getHeaderName().equals("sdnc-request-header"));
- assert (rt.getOperation().length() == 0);
- assert (rt.getAsyncInd().equals("N"));
- assert (rt.getReqId().equals("reqId"));
+ public final void testRequestTunables () {
+ RequestTunables rt = new RequestTunables (null, null, "op", null,msoPropertiesFactory);
+ assert(rt.getReqId ().length ()==0);
+ rt = new RequestTunables ("reqId", "msoAction", null, "query",msoPropertiesFactory);
+ rt.setTunables ();
+ System.out.println(rt.toString ());
+ // assert (rt.getReqMethod ().equals ("toto"));
+ assert (rt.getTimeout () != null);
+ assert (rt.getAction ().equals ("query"));
+ assert (rt.getMsoAction ().equals ("msoAction"));
+ assert (rt.getHeaderName ().equals ("sdnc-request-header"));
+ assert (rt.getOperation ().length () == 0);
+ assert (rt.getAsyncInd ().equals ("N"));
+ assert (rt.getReqId ().equals ("reqId"));
}
}
diff --git a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/sdncrest/ObjectMappingTest.java b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/sdncrest/ObjectMappingTest.java
index 3b7eef5f42..1921a9961a 100644
--- a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/sdncrest/ObjectMappingTest.java
+++ b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/sdncrest/ObjectMappingTest.java
@@ -39,438 +39,439 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
+
/**
* JSON object mapping tests.
*/
public class ObjectMappingTest {
- private static final String EOL = "\n";
-
- private final String SDNC_SERVICE_REQUEST =
- "{" + EOL +
- " \"SDNCServiceRequest\": {" + EOL +
- " \"requestInformation\": {" + EOL +
- " \"requestId\": \"413658f4-7f42-482e-b834-23a5c15657da\"," + EOL +
- " \"source\": \"CCD\"," + EOL +
- " \"notificationUrl\": \"https://ccd-host:8080/notifications\"" + EOL +
- " }," + EOL +
- " \"serviceInformation\": {" + EOL +
- " \"serviceType\": \"vHNFaaS\"," + EOL +
- " \"serviceInstanceId\": \"74e65b2b637441bca078e63e44bb511b\"," + EOL +
- " \"subscriberName\": \"IST_SG_0902_3003\"," + EOL +
- " \"subscriberGlobalId\": \"IST15_0902_3003\"" + EOL +
- " }," + EOL +
- " \"bpNotificationUrl\": \"http://localhost:8080/mso/SDNCAdapterCallbackService\"," + EOL +
- "((BP-TIMEOUT))" +
- " \"sdncRequestId\": \"413658f4-7f42-482e-b834-23a5c15657da-1474471336781\"," + EOL +
- " \"sdncService\": \"vhnf\"," + EOL +
- " \"sdncOperation\": \"service-topology-cust-assign-operation\"," + EOL +
- " \"sdncServiceDataType\": \"XML\"," + EOL +
- " \"sdncServiceData\": \"<vhnf-cust-stage-information><dhv-service-instance-id>c26dfed652164d60a17461734422b085</dhv-service-instance-id><hnportal-primary-vnf-host-name>HOSTNAME</hnportal-primary-vnf-host-name></vhnf-cust-stage-information>\"" + EOL +
- " }" + EOL +
- "}" + EOL;
-
- private final String SDNC_SERVICE_RESPONSE =
- "{" + EOL +
- " \"SDNCServiceResponse\": {" + EOL +
- " \"sdncRequestId\": \"413658f4-7f42-482e-b834-23a5c15657da-1474471336781\"," + EOL +
- " \"responseCode\": \"200\"," + EOL +
- "((RESPONSE-MESSAGE))" +
- " \"ackFinalIndicator\": \"Y\"" + EOL +
- "((RESPONSE-PARAMS))" +
- " }" + EOL +
- "}" + EOL;
-
- private final String SDNC_SERVICE_ERROR =
- "{" + EOL +
- " \"SDNCServiceError\": {" + EOL +
- " \"sdncRequestId\": \"413658f4-7f42-482e-b834-23a5c15657da-1474471336781\"," + EOL +
- " \"responseCode\": \"500\"," + EOL +
- "((RESPONSE-MESSAGE))" +
- " \"ackFinalIndicator\": \"Y\"" + EOL +
- " }" + EOL +
- "}" + EOL;
-
- private final String SDNC_EVENT =
- "{" + EOL +
- " \"SDNCEvent\": {" + EOL +
- " \"eventType\": \"ACTIVATION\"," + EOL +
- " \"eventCorrelatorType\": \"HOST-NAME\"," + EOL +
- " \"eventCorrelator\": \"USOSTCDALTX0101UJZZ31\"" + EOL +
- "((EVENT-PARAMS))" +
- " }" + EOL +
- "}" + EOL;
-
- private final String PARAMS =
- "{\"entry\":[{\"key\":\"P1\",\"value\":\"V1\"},{\"key\":\"P2\",\"value\":\"V2\"},{\"key\":\"P3\",\"value\":\"V3\"}]}";
-
- @Test
- public final void jsonToSDNCServiceRequest() throws Exception {
- logTest();
- ObjectMapper mapper = new ObjectMapper();
- mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE);
- mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE);
-
- String json = SDNC_SERVICE_REQUEST;
- json = json.replace("((BP-TIMEOUT))", "\"bpTimeout\": \"" + "PT5M" + "\"," + EOL);
-
- SDNCServiceRequest object = mapper.readValue(json, SDNCServiceRequest.class);
- assertEquals("413658f4-7f42-482e-b834-23a5c15657da", object.getRequestInformation().getRequestId());
- assertEquals("CCD", object.getRequestInformation().getSource());
- assertEquals("https://ccd-host:8080/notifications", object.getRequestInformation().getNotificationUrl());
- assertEquals("vHNFaaS", object.getServiceInformation().getServiceType());
- assertEquals("74e65b2b637441bca078e63e44bb511b", object.getServiceInformation().getServiceInstanceId());
- assertEquals("IST_SG_0902_3003", object.getServiceInformation().getSubscriberName());
- assertEquals("IST15_0902_3003", object.getServiceInformation().getSubscriberGlobalId());
- assertEquals("http://localhost:8080/mso/SDNCAdapterCallbackService", object.getBPNotificationUrl());
- assertEquals("PT5M", object.getBPTimeout());
- assertEquals("413658f4-7f42-482e-b834-23a5c15657da-1474471336781", object.getSDNCRequestId());
- assertEquals("vhnf", object.getSDNCService());
- assertEquals("service-topology-cust-assign-operation", object.getSDNCOperation());
- assertEquals("XML", object.getSDNCServiceDataType());
- assertTrue(object.getSDNCServiceData().startsWith("<vhnf-cust-stage-information>"));
- }
-
- @Test
- public final void jsonToSDNCServiceRequestWithoutOptionalFields() throws Exception {
- logTest();
- ObjectMapper mapper = new ObjectMapper();
- mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE);
- mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE);
-
- // bpTimeout is optional.
- String json = SDNC_SERVICE_REQUEST;
- json = json.replace("((BP-TIMEOUT))", "");
-
- SDNCServiceRequest object = mapper.readValue(json, SDNCServiceRequest.class);
- assertEquals("413658f4-7f42-482e-b834-23a5c15657da", object.getRequestInformation().getRequestId());
- assertEquals("CCD", object.getRequestInformation().getSource());
- assertEquals("https://ccd-host:8080/notifications", object.getRequestInformation().getNotificationUrl());
- assertEquals("vHNFaaS", object.getServiceInformation().getServiceType());
- assertEquals("74e65b2b637441bca078e63e44bb511b", object.getServiceInformation().getServiceInstanceId());
- assertEquals("IST_SG_0902_3003", object.getServiceInformation().getSubscriberName());
- assertEquals("IST15_0902_3003", object.getServiceInformation().getSubscriberGlobalId());
- assertEquals("http://localhost:8080/mso/SDNCAdapterCallbackService", object.getBPNotificationUrl());
- assertNull(object.getBPTimeout());
- assertEquals("413658f4-7f42-482e-b834-23a5c15657da-1474471336781", object.getSDNCRequestId());
- assertEquals("vhnf", object.getSDNCService());
- assertEquals("service-topology-cust-assign-operation", object.getSDNCOperation());
- assertEquals("XML", object.getSDNCServiceDataType());
- assertTrue(object.getSDNCServiceData().startsWith("<vhnf-cust-stage-information>"));
- }
-
- @Test
- public final void jsonFromSDNCServiceRequest() throws Exception {
- logTest();
- ObjectMapper mapper = new ObjectMapper();
- mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE);
- mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE);
-
- // Convert source json string to object.
- String json1 = SDNC_SERVICE_REQUEST;
- json1 = json1.replace("((BP-TIMEOUT))", "\"bpTimeout\": \"" + "PT5M" + "\"," + EOL);
- SDNCServiceRequest object1 = mapper.readValue(json1, SDNCServiceRequest.class);
-
- // Convert resulting object back to json.
- String json2 = object1.toJson();
- System.out.println("Generated JSON for " + object1.getClass().getSimpleName()
- + ":" + System.lineSeparator() + json2);
- assertTrue(json2.replaceAll("\\s+", "").startsWith("{\"SDNCServiceRequest\":{"));
-
- // Convert generated json string to another object.
- SDNCServiceRequest object2 = mapper.readValue(json2, SDNCServiceRequest.class);
-
- // Compare the first object to the second object.
- assertTrue(serializedEquals(object1, object2));
- }
-
- @Test
- public final void jsonFromSDNCServiceRequestWithoutOptionalFields() throws Exception {
- logTest();
- ObjectMapper mapper = new ObjectMapper();
- mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE);
- mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE);
-
- // Convert source json string to object.
- String json1 = SDNC_SERVICE_REQUEST;
- json1 = json1.replace("((BP-TIMEOUT))", "");
- SDNCServiceRequest object1 = mapper.readValue(json1, SDNCServiceRequest.class);
-
- // Convert resulting object back to json.
- String json2 = object1.toJson();
- System.out.println("Generated JSON for " + object1.getClass().getSimpleName()
- + ":" + System.lineSeparator() + json2);
- assertTrue(json2.replaceAll("\\s+", "").startsWith("{\"SDNCServiceRequest\":{"));
-
- // Convert generated json string to another object.
- SDNCServiceRequest object2 = mapper.readValue(json2, SDNCServiceRequest.class);
-
- // Compare the first object to the second object.
- assertTrue(serializedEquals(object1, object2));
- }
-
- @Test
- public final void jsonToSDNCServiceResponse() throws Exception {
- logTest();
- ObjectMapper mapper = new ObjectMapper();
- mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE);
- mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE);
-
- String json = SDNC_SERVICE_RESPONSE;
- json = json.replace("((RESPONSE-MESSAGE))", " \"responseMessage\": \"" + "OK" + "\"," + EOL);
- json = json.replace(EOL + "((RESPONSE-PARAMS))", "," + EOL + " \"params\": " + PARAMS + EOL);
-
- SDNCServiceResponse object = mapper.readValue(json, SDNCServiceResponse.class);
- assertEquals("413658f4-7f42-482e-b834-23a5c15657da-1474471336781", object.getSDNCRequestId());
- assertEquals("200", object.getResponseCode());
- assertEquals("OK", object.getResponseMessage());
- assertEquals("Y", object.getAckFinalIndicator());
- assertEquals("V1", object.getParams().get("P1"));
- assertEquals("V2", object.getParams().get("P2"));
- assertEquals("V3", object.getParams().get("P3"));
- }
-
- @Test
- public final void jsonToSDNCServiceResponseWithoutOptionalFields() throws Exception {
- logTest();
- ObjectMapper mapper = new ObjectMapper();
- mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE);
- mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE);
-
- // responseMessage is optional.
- String json = SDNC_SERVICE_RESPONSE;
- json = json.replace("((RESPONSE-MESSAGE))", "");
- json = json.replace("((RESPONSE-PARAMS))", "");
-
- SDNCServiceResponse object = mapper.readValue(json, SDNCServiceResponse.class);
- assertEquals("413658f4-7f42-482e-b834-23a5c15657da-1474471336781", object.getSDNCRequestId());
- assertEquals("200", object.getResponseCode());
- assertNull(object.getResponseMessage());
- assertEquals("Y", object.getAckFinalIndicator());
- assertNull(object.getParams());
- }
-
- @Test
- public final void jsonFromSDNCServiceResponse() throws Exception {
- logTest();
- ObjectMapper mapper = new ObjectMapper();
- mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE);
- mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE);
-
- // Convert source json string to object.
- String json1 = SDNC_SERVICE_RESPONSE;
- json1 = json1.replace("((RESPONSE-MESSAGE))", "\"responseMessage\": \"" + "OK" + "\"," + EOL);
- json1 = json1.replace(EOL + "((RESPONSE-PARAMS))", "," + EOL + " \"params\": " + PARAMS + EOL);
- SDNCServiceResponse object1 = mapper.readValue(json1, SDNCServiceResponse.class);
-
- // Convert resulting object back to json.
- String json2 = object1.toJson();
- System.out.println("Generated JSON for " + object1.getClass().getSimpleName()
- + ":" + System.lineSeparator() + json2);
- assertTrue(json2.replaceAll("\\s+", "").startsWith("{\"SDNCServiceResponse\":{"));
-
- // Convert generated json string to another object.
- SDNCServiceResponse object2 = mapper.readValue(json2, SDNCServiceResponse.class);
-
- // Compare the first object to the second object.
- assertTrue(serializedEquals(object1, object2));
- }
-
- @Test
- public final void jsonFromSDNCServiceResponseWithoutOptionalFields() throws Exception {
- logTest();
- ObjectMapper mapper = new ObjectMapper();
- mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE);
- mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE);
-
- // Convert source json string to object.
- String json1 = SDNC_SERVICE_RESPONSE;
- json1 = json1.replace("((RESPONSE-MESSAGE))", "");
- json1 = json1.replace("((RESPONSE-PARAMS))", "");
- SDNCServiceResponse object1 = mapper.readValue(json1, SDNCServiceResponse.class);
-
- // Convert resulting object back to json.
- String json2 = object1.toJson();
- System.out.println("Generated JSON for " + object1.getClass().getSimpleName()
- + ":" + System.lineSeparator() + json2);
- assertTrue(json2.replaceAll("\\s+", "").startsWith("{\"SDNCServiceResponse\":{"));
-
- // Convert generated json string to another object.
- SDNCServiceResponse object2 = mapper.readValue(json2, SDNCServiceResponse.class);
-
- // Compare the first object to the second object.
- assertTrue(serializedEquals(object1, object2));
- }
-
- @Test
- public final void jsonToSDNCServiceError() throws Exception {
- logTest();
- ObjectMapper mapper = new ObjectMapper();
- mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE);
- mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE);
-
- String json = SDNC_SERVICE_ERROR;
- json = json.replace("((RESPONSE-MESSAGE))", "\"responseMessage\": \"" + "SOMETHING BAD" + "\"," + EOL);
-
- SDNCServiceError object = mapper.readValue(json, SDNCServiceError.class);
- assertEquals("413658f4-7f42-482e-b834-23a5c15657da-1474471336781", object.getSDNCRequestId());
- assertEquals("500", object.getResponseCode());
- assertEquals("SOMETHING BAD", object.getResponseMessage());
- assertEquals("Y", object.getAckFinalIndicator());
- }
-
- @Test
- public final void jsonToSDNCServiceErrorWithoutOptionalFields() throws Exception {
- logTest();
- ObjectMapper mapper = new ObjectMapper();
- mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE);
- mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE);
-
- // responseMessage is optional.
- String json = SDNC_SERVICE_ERROR;
- json = json.replace("((RESPONSE-MESSAGE))", "");
-
- SDNCServiceError object = mapper.readValue(json, SDNCServiceError.class);
- assertEquals("413658f4-7f42-482e-b834-23a5c15657da-1474471336781", object.getSDNCRequestId());
- assertEquals("500", object.getResponseCode());
- assertNull(object.getResponseMessage());
- assertEquals("Y", object.getAckFinalIndicator());
- }
-
- @Test
- public final void jsonFromSDNCServiceError() throws Exception {
- logTest();
- ObjectMapper mapper = new ObjectMapper();
- mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE);
- mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE);
-
- // Convert source json string to object.
- String json1 = SDNC_SERVICE_ERROR;
- json1 = json1.replace("((RESPONSE-MESSAGE))", "\"responseMessage\": \"" + "OK" + "\"," + EOL);
- SDNCServiceError object1 = mapper.readValue(json1, SDNCServiceError.class);
-
- // Convert resulting object back to json.
- String json2 = object1.toJson();
- System.out.println("Generated JSON for " + object1.getClass().getSimpleName()
- + ":" + System.lineSeparator() + json2);
- assertTrue(json2.replaceAll("\\s+", "").startsWith("{\"SDNCServiceError\":{"));
-
- // Convert generated json string to another object.
- SDNCServiceError object2 = mapper.readValue(json2, SDNCServiceError.class);
-
- // Compare the first object to the second object.
- assertTrue(serializedEquals(object1, object2));
- }
-
- @Test
- public final void jsonFromSDNCServiceErrorWithoutOptionalFields() throws Exception {
- logTest();
- ObjectMapper mapper = new ObjectMapper();
- mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE);
- mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE);
-
- // Convert source json string to object.
- String json1 = SDNC_SERVICE_ERROR;
- json1 = json1.replace("((RESPONSE-MESSAGE))", "");
- SDNCServiceError object1 = mapper.readValue(json1, SDNCServiceError.class);
-
- // Convert resulting object back to json.
- String json2 = object1.toJson();
- System.out.println("Generated JSON for " + object1.getClass().getSimpleName()
- + ":" + System.lineSeparator() + json2);
- assertTrue(json2.replaceAll("\\s+", "").startsWith("{\"SDNCServiceError\":{"));
-
- // Convert generated json string to another object.
- SDNCServiceError object2 = mapper.readValue(json2, SDNCServiceError.class);
-
- // Compare the first object to the second object.
- assertTrue(serializedEquals(object1, object2));
- }
-
- @Test
- public final void jsonToSDNCEvent() throws Exception {
- logTest();
- ObjectMapper mapper = new ObjectMapper();
- mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE);
- mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE);
-
- String json = SDNC_EVENT;
- json = json.replace(EOL + "((EVENT-PARAMS))", "," + EOL + " \"params\": " + PARAMS + EOL);
-
- SDNCEvent object = mapper.readValue(json, SDNCEvent.class);
- assertEquals("ACTIVATION", object.getEventType());
- assertEquals("HOST-NAME", object.getEventCorrelatorType());
- assertEquals("USOSTCDALTX0101UJZZ31", object.getEventCorrelator());
- assertEquals("V1", object.getParams().get("P1"));
- assertEquals("V2", object.getParams().get("P2"));
- assertEquals("V3", object.getParams().get("P3"));
- }
-
- @Test
- public final void jsonToSDNCEventWithoutOptionalFields() throws Exception {
- logTest();
- ObjectMapper mapper = new ObjectMapper();
- mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE);
- mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE);
-
- // params are optional.
- String json = SDNC_EVENT;
- json = json.replace("((EVENT-PARAMS))", "");
-
- SDNCEvent object = mapper.readValue(json, SDNCEvent.class);
- assertEquals("ACTIVATION", object.getEventType());
- assertEquals("HOST-NAME", object.getEventCorrelatorType());
- assertEquals("USOSTCDALTX0101UJZZ31", object.getEventCorrelator());
- assertNull(object.getParams());
- }
-
- @Test
- public final void jsonFromSDNCEvent() throws Exception {
- logTest();
- ObjectMapper mapper = new ObjectMapper();
- mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE);
- mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE);
-
- // Convert source json string to object.
- String json1 = SDNC_EVENT;
- json1 = json1.replace(EOL + "((EVENT-PARAMS))", "," + EOL + " \"params\": " + PARAMS + EOL);
- SDNCEvent object1 = mapper.readValue(json1, SDNCEvent.class);
-
- // Convert resulting object back to json.
- String json2 = object1.toJson();
- System.out.println("Generated JSON for " + object1.getClass().getSimpleName()
- + ":" + System.lineSeparator() + json2);
- assertTrue(json2.replaceAll("\\s+", "").startsWith("{\"SDNCEvent\":{"));
-
- // Convert generated json string to another object.
- SDNCEvent object2 = mapper.readValue(json2, SDNCEvent.class);
-
- // Compare the first object to the second object.
- assertTrue(serializedEquals(object1, object2));
- }
-
- /**
- * Tests equality of two objects by comparing their serialized form.
- * WARNING: this works pretty well as long as the objects don't contain
- * collections like maps and sets that are semantically equal, but have
- * different internal ordering of elements.
- */
- private boolean serializedEquals(Serializable object1, Serializable object2) throws IOException {
- ByteArrayOutputStream byteStream1 = new ByteArrayOutputStream();
- ObjectOutputStream objectStream1 = new ObjectOutputStream(byteStream1);
- objectStream1.writeObject(object1);
- objectStream1.close();
-
- ByteArrayOutputStream byteStream2 = new ByteArrayOutputStream();
- ObjectOutputStream objectStream2 = new ObjectOutputStream(byteStream2);
- objectStream2.writeObject(object2);
- objectStream2.close();
-
- return Arrays.equals(byteStream1.toByteArray(), byteStream2.toByteArray());
- }
-
- private void logTest() {
- StackTraceElement[] st = Thread.currentThread().getStackTrace();
- String method = st[2].getMethodName();
- System.out.println("RUNNING TEST: " + method);
- }
+ private static final String EOL = "\n";
+
+ private final String SDNC_SERVICE_REQUEST =
+ "{" + EOL +
+ " \"SDNCServiceRequest\": {" + EOL +
+ " \"requestInformation\": {" + EOL +
+ " \"requestId\": \"413658f4-7f42-482e-b834-23a5c15657da\"," + EOL +
+ " \"source\": \"CCD\"," + EOL +
+ " \"notificationUrl\": \"https://ccd-host:8080/notifications\"" + EOL +
+ " }," + EOL +
+ " \"serviceInformation\": {" + EOL +
+ " \"serviceType\": \"vHNFaaS\"," + EOL +
+ " \"serviceInstanceId\": \"74e65b2b637441bca078e63e44bb511b\"," + EOL +
+ " \"subscriberName\": \"IST_SG_0902_3003\"," + EOL +
+ " \"subscriberGlobalId\": \"IST15_0902_3003\"" + EOL +
+ " }," + EOL +
+ " \"bpNotificationUrl\": \"http://localhost:8080/mso/SDNCAdapterCallbackService\"," + EOL +
+ "((BP-TIMEOUT))" +
+ " \"sdncRequestId\": \"413658f4-7f42-482e-b834-23a5c15657da-1474471336781\"," + EOL +
+ " \"sdncService\": \"vhnf\"," + EOL +
+ " \"sdncOperation\": \"service-topology-cust-assign-operation\"," + EOL +
+ " \"sdncServiceDataType\": \"XML\"," + EOL +
+ " \"sdncServiceData\": \"<vhnf-cust-stage-information><dhv-service-instance-id>c26dfed652164d60a17461734422b085</dhv-service-instance-id><hnportal-primary-vnf-host-name>HOSTNAME</hnportal-primary-vnf-host-name></vhnf-cust-stage-information>\"" + EOL +
+ " }" + EOL +
+ "}" + EOL;
+
+ private final String SDNC_SERVICE_RESPONSE =
+ "{" + EOL +
+ " \"SDNCServiceResponse\": {" + EOL +
+ " \"sdncRequestId\": \"413658f4-7f42-482e-b834-23a5c15657da-1474471336781\"," + EOL +
+ " \"responseCode\": \"200\"," + EOL +
+ "((RESPONSE-MESSAGE))" +
+ " \"ackFinalIndicator\": \"Y\"" + EOL +
+ "((RESPONSE-PARAMS))" +
+ " }" + EOL +
+ "}" + EOL;
+
+ private final String SDNC_SERVICE_ERROR =
+ "{" + EOL +
+ " \"SDNCServiceError\": {" + EOL +
+ " \"sdncRequestId\": \"413658f4-7f42-482e-b834-23a5c15657da-1474471336781\"," + EOL +
+ " \"responseCode\": \"500\"," + EOL +
+ "((RESPONSE-MESSAGE))" +
+ " \"ackFinalIndicator\": \"Y\"" + EOL +
+ " }" + EOL +
+ "}" + EOL;
+
+ private final String SDNC_EVENT =
+ "{" + EOL +
+ " \"SDNCEvent\": {" + EOL +
+ " \"eventType\": \"ACTIVATION\"," + EOL +
+ " \"eventCorrelatorType\": \"HOST-NAME\"," + EOL +
+ " \"eventCorrelator\": \"USOSTCDALTX0101UJZZ31\"" + EOL +
+ "((EVENT-PARAMS))" +
+ " }" + EOL +
+ "}" + EOL;
+
+ private final String PARAMS =
+ "{\"entry\":[{\"key\":\"P1\",\"value\":\"V1\"},{\"key\":\"P2\",\"value\":\"V2\"},{\"key\":\"P3\",\"value\":\"V3\"}]}";
+
+ @Test
+ public final void jsonToSDNCServiceRequest() throws Exception {
+ logTest();
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE);
+ mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE);
+
+ String json = SDNC_SERVICE_REQUEST;
+ json = json.replace("((BP-TIMEOUT))", "\"bpTimeout\": \"" + "PT5M" + "\"," + EOL);
+
+ SDNCServiceRequest object = mapper.readValue(json, SDNCServiceRequest.class);
+ assertEquals("413658f4-7f42-482e-b834-23a5c15657da", object.getRequestInformation().getRequestId());
+ assertEquals("CCD", object.getRequestInformation().getSource());
+ assertEquals("https://ccd-host:8080/notifications", object.getRequestInformation().getNotificationUrl());
+ assertEquals("vHNFaaS", object.getServiceInformation().getServiceType());
+ assertEquals("74e65b2b637441bca078e63e44bb511b", object.getServiceInformation().getServiceInstanceId());
+ assertEquals("IST_SG_0902_3003", object.getServiceInformation().getSubscriberName());
+ assertEquals("IST15_0902_3003", object.getServiceInformation().getSubscriberGlobalId());
+ assertEquals("http://localhost:8080/mso/SDNCAdapterCallbackService", object.getBPNotificationUrl());
+ assertEquals("PT5M", object.getBPTimeout());
+ assertEquals("413658f4-7f42-482e-b834-23a5c15657da-1474471336781", object.getSDNCRequestId());
+ assertEquals("vhnf", object.getSDNCService());
+ assertEquals("service-topology-cust-assign-operation", object.getSDNCOperation());
+ assertEquals("XML", object.getSDNCServiceDataType());
+ assertTrue(object.getSDNCServiceData().startsWith("<vhnf-cust-stage-information>"));
+ }
+
+ @Test
+ public final void jsonToSDNCServiceRequestWithoutOptionalFields() throws Exception {
+ logTest();
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE);
+ mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE);
+
+ // bpTimeout is optional.
+ String json = SDNC_SERVICE_REQUEST;
+ json = json.replace("((BP-TIMEOUT))", "");
+
+ SDNCServiceRequest object = mapper.readValue(json, SDNCServiceRequest.class);
+ assertEquals("413658f4-7f42-482e-b834-23a5c15657da", object.getRequestInformation().getRequestId());
+ assertEquals("CCD", object.getRequestInformation().getSource());
+ assertEquals("https://ccd-host:8080/notifications", object.getRequestInformation().getNotificationUrl());
+ assertEquals("vHNFaaS", object.getServiceInformation().getServiceType());
+ assertEquals("74e65b2b637441bca078e63e44bb511b", object.getServiceInformation().getServiceInstanceId());
+ assertEquals("IST_SG_0902_3003", object.getServiceInformation().getSubscriberName());
+ assertEquals("IST15_0902_3003", object.getServiceInformation().getSubscriberGlobalId());
+ assertEquals("http://localhost:8080/mso/SDNCAdapterCallbackService", object.getBPNotificationUrl());
+ assertNull(object.getBPTimeout());
+ assertEquals("413658f4-7f42-482e-b834-23a5c15657da-1474471336781", object.getSDNCRequestId());
+ assertEquals("vhnf", object.getSDNCService());
+ assertEquals("service-topology-cust-assign-operation", object.getSDNCOperation());
+ assertEquals("XML", object.getSDNCServiceDataType());
+ assertTrue(object.getSDNCServiceData().startsWith("<vhnf-cust-stage-information>"));
+ }
+
+ @Test
+ public final void jsonFromSDNCServiceRequest() throws Exception {
+ logTest();
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE);
+ mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE);
+
+ // Convert source json string to object.
+ String json1 = SDNC_SERVICE_REQUEST;
+ json1 = json1.replace("((BP-TIMEOUT))", "\"bpTimeout\": \"" + "PT5M" + "\"," + EOL);
+ SDNCServiceRequest object1 = mapper.readValue(json1, SDNCServiceRequest.class);
+
+ // Convert resulting object back to json.
+ String json2 = object1.toJson();
+ System.out.println("Generated JSON for " + object1.getClass().getSimpleName()
+ + ":" + System.lineSeparator() + json2);
+ assertTrue(json2.replaceAll("\\s+","").startsWith("{\"SDNCServiceRequest\":{"));
+
+ // Convert generated json string to another object.
+ SDNCServiceRequest object2 = mapper.readValue(json2, SDNCServiceRequest.class);
+
+ // Compare the first object to the second object.
+ assertTrue(serializedEquals(object1, object2));
+ }
+
+ @Test
+ public final void jsonFromSDNCServiceRequestWithoutOptionalFields() throws Exception {
+ logTest();
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE);
+ mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE);
+
+ // Convert source json string to object.
+ String json1 = SDNC_SERVICE_REQUEST;
+ json1 = json1.replace("((BP-TIMEOUT))", "");
+ SDNCServiceRequest object1 = mapper.readValue(json1, SDNCServiceRequest.class);
+
+ // Convert resulting object back to json.
+ String json2 = object1.toJson();
+ System.out.println("Generated JSON for " + object1.getClass().getSimpleName()
+ + ":" + System.lineSeparator() + json2);
+ assertTrue(json2.replaceAll("\\s+","").startsWith("{\"SDNCServiceRequest\":{"));
+
+ // Convert generated json string to another object.
+ SDNCServiceRequest object2 = mapper.readValue(json2, SDNCServiceRequest.class);
+
+ // Compare the first object to the second object.
+ assertTrue(serializedEquals(object1, object2));
+ }
+
+ @Test
+ public final void jsonToSDNCServiceResponse() throws Exception {
+ logTest();
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE);
+ mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE);
+
+ String json = SDNC_SERVICE_RESPONSE;
+ json = json.replace("((RESPONSE-MESSAGE))", " \"responseMessage\": \"" + "OK" + "\"," + EOL);
+ json = json.replace(EOL + "((RESPONSE-PARAMS))", "," + EOL + " \"params\": " + PARAMS + EOL);
+
+ SDNCServiceResponse object = mapper.readValue(json, SDNCServiceResponse.class);
+ assertEquals("413658f4-7f42-482e-b834-23a5c15657da-1474471336781", object.getSDNCRequestId());
+ assertEquals("200", object.getResponseCode());
+ assertEquals("OK", object.getResponseMessage());
+ assertEquals("Y", object.getAckFinalIndicator());
+ assertEquals("V1", object.getParams().get("P1"));
+ assertEquals("V2", object.getParams().get("P2"));
+ assertEquals("V3", object.getParams().get("P3"));
+ }
+
+ @Test
+ public final void jsonToSDNCServiceResponseWithoutOptionalFields() throws Exception {
+ logTest();
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE);
+ mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE);
+
+ // responseMessage is optional.
+ String json = SDNC_SERVICE_RESPONSE;
+ json = json.replace("((RESPONSE-MESSAGE))", "");
+ json = json.replace("((RESPONSE-PARAMS))", "");
+
+ SDNCServiceResponse object = mapper.readValue(json, SDNCServiceResponse.class);
+ assertEquals("413658f4-7f42-482e-b834-23a5c15657da-1474471336781", object.getSDNCRequestId());
+ assertEquals("200", object.getResponseCode());
+ assertNull(object.getResponseMessage());
+ assertEquals("Y", object.getAckFinalIndicator());
+ assertNull(object.getParams());
+ }
+
+ @Test
+ public final void jsonFromSDNCServiceResponse() throws Exception {
+ logTest();
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE);
+ mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE);
+
+ // Convert source json string to object.
+ String json1 = SDNC_SERVICE_RESPONSE;
+ json1 = json1.replace("((RESPONSE-MESSAGE))", "\"responseMessage\": \"" + "OK" + "\"," + EOL);
+ json1 = json1.replace(EOL + "((RESPONSE-PARAMS))", "," + EOL + " \"params\": " + PARAMS + EOL);
+ SDNCServiceResponse object1 = mapper.readValue(json1, SDNCServiceResponse.class);
+
+ // Convert resulting object back to json.
+ String json2 = object1.toJson();
+ System.out.println("Generated JSON for " + object1.getClass().getSimpleName()
+ + ":" + System.lineSeparator() + json2);
+ assertTrue(json2.replaceAll("\\s+","").startsWith("{\"SDNCServiceResponse\":{"));
+
+ // Convert generated json string to another object.
+ SDNCServiceResponse object2 = mapper.readValue(json2, SDNCServiceResponse.class);
+
+ // Compare the first object to the second object.
+ assertTrue(serializedEquals(object1, object2));
+ }
+
+ @Test
+ public final void jsonFromSDNCServiceResponseWithoutOptionalFields() throws Exception {
+ logTest();
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE);
+ mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE);
+
+ // Convert source json string to object.
+ String json1 = SDNC_SERVICE_RESPONSE;
+ json1 = json1.replace("((RESPONSE-MESSAGE))", "");
+ json1 = json1.replace("((RESPONSE-PARAMS))", "");
+ SDNCServiceResponse object1 = mapper.readValue(json1, SDNCServiceResponse.class);
+
+ // Convert resulting object back to json.
+ String json2 = object1.toJson();
+ System.out.println("Generated JSON for " + object1.getClass().getSimpleName()
+ + ":" + System.lineSeparator() + json2);
+ assertTrue(json2.replaceAll("\\s+","").startsWith("{\"SDNCServiceResponse\":{"));
+
+ // Convert generated json string to another object.
+ SDNCServiceResponse object2 = mapper.readValue(json2, SDNCServiceResponse.class);
+
+ // Compare the first object to the second object.
+ assertTrue(serializedEquals(object1, object2));
+ }
+
+ @Test
+ public final void jsonToSDNCServiceError() throws Exception {
+ logTest();
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE);
+ mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE);
+
+ String json = SDNC_SERVICE_ERROR;
+ json = json.replace("((RESPONSE-MESSAGE))", "\"responseMessage\": \"" + "SOMETHING BAD" + "\"," + EOL);
+
+ SDNCServiceError object = mapper.readValue(json, SDNCServiceError.class);
+ assertEquals("413658f4-7f42-482e-b834-23a5c15657da-1474471336781", object.getSDNCRequestId());
+ assertEquals("500", object.getResponseCode());
+ assertEquals("SOMETHING BAD", object.getResponseMessage());
+ assertEquals("Y", object.getAckFinalIndicator());
+ }
+
+ @Test
+ public final void jsonToSDNCServiceErrorWithoutOptionalFields() throws Exception {
+ logTest();
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE);
+ mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE);
+
+ // responseMessage is optional.
+ String json = SDNC_SERVICE_ERROR;
+ json = json.replace("((RESPONSE-MESSAGE))", "");
+
+ SDNCServiceError object = mapper.readValue(json, SDNCServiceError.class);
+ assertEquals("413658f4-7f42-482e-b834-23a5c15657da-1474471336781", object.getSDNCRequestId());
+ assertEquals("500", object.getResponseCode());
+ assertNull(object.getResponseMessage());
+ assertEquals("Y", object.getAckFinalIndicator());
+ }
+
+ @Test
+ public final void jsonFromSDNCServiceError() throws Exception {
+ logTest();
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE);
+ mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE);
+
+ // Convert source json string to object.
+ String json1 = SDNC_SERVICE_ERROR;
+ json1 = json1.replace("((RESPONSE-MESSAGE))", "\"responseMessage\": \"" + "OK" + "\"," + EOL);
+ SDNCServiceError object1 = mapper.readValue(json1, SDNCServiceError.class);
+
+ // Convert resulting object back to json.
+ String json2 = object1.toJson();
+ System.out.println("Generated JSON for " + object1.getClass().getSimpleName()
+ + ":" + System.lineSeparator() + json2);
+ assertTrue(json2.replaceAll("\\s+","").startsWith("{\"SDNCServiceError\":{"));
+
+ // Convert generated json string to another object.
+ SDNCServiceError object2 = mapper.readValue(json2, SDNCServiceError.class);
+
+ // Compare the first object to the second object.
+ assertTrue(serializedEquals(object1, object2));
+ }
+
+ @Test
+ public final void jsonFromSDNCServiceErrorWithoutOptionalFields() throws Exception {
+ logTest();
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE);
+ mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE);
+
+ // Convert source json string to object.
+ String json1 = SDNC_SERVICE_ERROR;
+ json1 = json1.replace("((RESPONSE-MESSAGE))", "");
+ SDNCServiceError object1 = mapper.readValue(json1, SDNCServiceError.class);
+
+ // Convert resulting object back to json.
+ String json2 = object1.toJson();
+ System.out.println("Generated JSON for " + object1.getClass().getSimpleName()
+ + ":" + System.lineSeparator() + json2);
+ assertTrue(json2.replaceAll("\\s+","").startsWith("{\"SDNCServiceError\":{"));
+
+ // Convert generated json string to another object.
+ SDNCServiceError object2 = mapper.readValue(json2, SDNCServiceError.class);
+
+ // Compare the first object to the second object.
+ assertTrue(serializedEquals(object1, object2));
+ }
+
+ @Test
+ public final void jsonToSDNCEvent() throws Exception {
+ logTest();
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE);
+ mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE);
+
+ String json = SDNC_EVENT;
+ json = json.replace(EOL + "((EVENT-PARAMS))", "," + EOL + " \"params\": " + PARAMS + EOL);
+
+ SDNCEvent object = mapper.readValue(json, SDNCEvent.class);
+ assertEquals("ACTIVATION", object.getEventType());
+ assertEquals("HOST-NAME", object.getEventCorrelatorType());
+ assertEquals("USOSTCDALTX0101UJZZ31", object.getEventCorrelator());
+ assertEquals("V1", object.getParams().get("P1"));
+ assertEquals("V2", object.getParams().get("P2"));
+ assertEquals("V3", object.getParams().get("P3"));
+ }
+
+ @Test
+ public final void jsonToSDNCEventWithoutOptionalFields() throws Exception {
+ logTest();
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE);
+ mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE);
+
+ // params are optional.
+ String json = SDNC_EVENT;
+ json = json.replace("((EVENT-PARAMS))", "");
+
+ SDNCEvent object = mapper.readValue(json, SDNCEvent.class);
+ assertEquals("ACTIVATION", object.getEventType());
+ assertEquals("HOST-NAME", object.getEventCorrelatorType());
+ assertEquals("USOSTCDALTX0101UJZZ31", object.getEventCorrelator());
+ assertNull(object.getParams());
+ }
+
+ @Test
+ public final void jsonFromSDNCEvent() throws Exception {
+ logTest();
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.enable(SerializationConfig.Feature.WRAP_ROOT_VALUE);
+ mapper.enable(DeserializationConfig.Feature.UNWRAP_ROOT_VALUE);
+
+ // Convert source json string to object.
+ String json1 = SDNC_EVENT;
+ json1 = json1.replace(EOL + "((EVENT-PARAMS))", "," + EOL + " \"params\": " + PARAMS + EOL);
+ SDNCEvent object1 = mapper.readValue(json1, SDNCEvent.class);
+
+ // Convert resulting object back to json.
+ String json2 = object1.toJson();
+ System.out.println("Generated JSON for " + object1.getClass().getSimpleName()
+ + ":" + System.lineSeparator() + json2);
+ assertTrue(json2.replaceAll("\\s+","").startsWith("{\"SDNCEvent\":{"));
+
+ // Convert generated json string to another object.
+ SDNCEvent object2 = mapper.readValue(json2, SDNCEvent.class);
+
+ // Compare the first object to the second object.
+ assertTrue(serializedEquals(object1, object2));
+ }
+
+ /**
+ * Tests equality of two objects by comparing their serialized form.
+ * WARNING: this works pretty well as long as the objects don't contain
+ * collections like maps and sets that are semantically equal, but have
+ * different internal ordering of elements.
+ */
+ private boolean serializedEquals(Serializable object1, Serializable object2) throws IOException {
+ ByteArrayOutputStream byteStream1 = new ByteArrayOutputStream();
+ ObjectOutputStream objectStream1 = new ObjectOutputStream(byteStream1);
+ objectStream1.writeObject(object1);
+ objectStream1.close();
+
+ ByteArrayOutputStream byteStream2 = new ByteArrayOutputStream();
+ ObjectOutputStream objectStream2 = new ObjectOutputStream(byteStream2);
+ objectStream2.writeObject(object2);
+ objectStream2.close();
+
+ return Arrays.equals(byteStream1.toByteArray(), byteStream2.toByteArray());
+ }
+
+ private void logTest() {
+ StackTraceElement[] st = Thread.currentThread().getStackTrace();
+ String method = st[2].getMethodName();
+ System.out.println("RUNNING TEST: " + method);
+ }
}
diff --git a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/util/SDNCRequestIdUtilTest.java b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/util/SDNCRequestIdUtilTest.java
index a4b4d891d4..275c2acd14 100644
--- a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/util/SDNCRequestIdUtilTest.java
+++ b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/util/SDNCRequestIdUtilTest.java
@@ -21,7 +21,6 @@
package org.openecomp.mso.adapters.sdnc.util;
import java.util.UUID;
-
import org.junit.Test;
@@ -31,14 +30,14 @@ public class SDNCRequestIdUtilTest {
* Test method for {@link org.openecomp.mso.adapters.sdnc.SDNCRequestIdUtil#getSDNCOriginalRequestId()}.
*/
@Test
- public final void testGetSDNCOriginalRequestId() {
- String originalRequestId = UUID.randomUUID().toString();
- String postfixedRequestId = originalRequestId + "-1466203712068";
- String postfixedRequestId2 = originalRequestId + "-1466203712068-2";
-
- assert (SDNCRequestIdUtil.getSDNCOriginalRequestId(postfixedRequestId).equals(originalRequestId));
- assert (SDNCRequestIdUtil.getSDNCOriginalRequestId(postfixedRequestId2).equals(postfixedRequestId2));
-
+ public final void testGetSDNCOriginalRequestId () {
+ String originalRequestId = UUID.randomUUID().toString();
+ String postfixedRequestId = originalRequestId + "-1466203712068";
+ String postfixedRequestId2 = originalRequestId + "-1466203712068-2";
+
+ assert(SDNCRequestIdUtil.getSDNCOriginalRequestId(postfixedRequestId).equals(originalRequestId));
+ assert(SDNCRequestIdUtil.getSDNCOriginalRequestId(postfixedRequestId2).equals(postfixedRequestId2));
+
}
}