diff options
Diffstat (limited to 'adapters/mso-sdnc-adapter/src/test/java/org')
3 files changed, 173 insertions, 61 deletions
diff --git a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/impl/InvestigationTest.java b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/impl/InvestigationTest.java new file mode 100644 index 0000000000..234a9d2272 --- /dev/null +++ b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/impl/InvestigationTest.java @@ -0,0 +1,114 @@ +/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.openecomp.mso.adapters.sdnc.impl;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.Scanner;
+import java.util.UUID;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.Test;
+import org.openecomp.mso.properties.MsoJavaProperties;
+import org.openecomp.mso.properties.MsoPropertiesException;
+import org.openecomp.mso.properties.MsoPropertiesFactory;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+public class InvestigationTest {
+
+ private static MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory();
+
+ public static final String SDNC_PROP = MsoJavaProperties.class.getClassLoader().getResource("mso.sdnc.properties").toString().substring(5);
+
+ @Before
+ public final void initBeforeEachTest() throws MsoPropertiesException {
+ msoPropertiesFactory.removeAllMsoProperties();
+ msoPropertiesFactory.initializeMsoProperties("MSO_PROP_SDNC_ADAPTER", SDNC_PROP);
+ }
+
+ @AfterClass
+ public static final void kill () throws MsoPropertiesException {
+
+ msoPropertiesFactory.removeMsoProperties("MSO_PROP_SDNC_ADAPTER");
+ }
+
+ @Test
+ public void run() throws ParserConfigurationException, IOException, SAXException {
+
+ RequestTunables rt = new RequestTunables("reqid","","svc-topology-operation","delete", msoPropertiesFactory);
+ rt.setTunables();
+ /*Document reqDoc = parse();
+ NodeList nodeList = reqDoc.getElementsByTagName("sdncadapterworkflow:SDNCRequestData");
+ Node node = null;
+ System.out.println("nodeList length: "+ nodeList.getLength());
+ for (int i =0; i<nodeList.getLength();i++){
+ node = nodeList.item(i);
+ }
+
+ Document doc = nodeToDocument(node);
+ */
+ Scanner scanner = new Scanner( new File("src/test/resources/sdnc_adapter_request.xml") );
+ String input = scanner.useDelimiter("\\A").next();
+ System.out.println("input: "+input);
+ scanner.close();
+ try {
+ DocumentBuilder db = DocumentBuilderFactory.newInstance().newDocumentBuilder();
+ InputSource is = new InputSource();
+ is.setCharacterStream(new StringReader(input));
+ Document reqDoc = db.parse(is);
+ String sdncReqBody = Utils.genSdncReq(reqDoc, rt);
+ System.out.println(sdncReqBody);
+ String uuid = UUID.randomUUID().toString();
+ System.out.println("uuid: "+uuid);
+ }catch(Exception ex) {
+ throw new IllegalStateException();
+ }
+
+ }
+ public static Document parse() throws ParserConfigurationException, IOException, SAXException {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ factory.setValidating(true);
+ factory.setIgnoringElementContentWhitespace(true);
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ File file = new File("src/test/resources/sdnc_adapter_request.xml");
+ Document doc = builder.parse(file);
+ return doc;
+ }
+ public static Document nodeToDocument (Node node) throws ParserConfigurationException {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ factory.setNamespaceAware(true);
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document newDocument = builder.newDocument();
+ Node importedNode = newDocument.importNode(node, true);
+ newDocument.appendChild(importedNode);
+ return newDocument;
+ }
+}
+ 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 55295fc3ea..17ba0d22f8 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 @@ -20,11 +20,8 @@ package org.openecomp.mso.adapters.sdnc.impl; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; - -import org.junit.BeforeClass; +import org.junit.AfterClass; +import org.junit.Before; import org.junit.Test; import org.openecomp.mso.properties.MsoJavaProperties; @@ -33,22 +30,22 @@ import org.openecomp.mso.properties.MsoPropertiesFactory; public class RequestTunablesTest { - public static MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory(); + private static MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory(); - /** - * This method is called before any test occurs. - * It creates a fake tree from scratch - * @throws MsoPropertiesException - */ - @BeforeClass - 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); - - } + public static final String SDNC_PROP = MsoJavaProperties.class.getClassLoader().getResource("mso.sdnc.properties").toString().substring(5); + + @Before + public final void initBeforeEachTest() throws MsoPropertiesException { + msoPropertiesFactory.removeAllMsoProperties(); + msoPropertiesFactory.initializeMsoProperties("MSO_PROP_SDNC_ADAPTER", SDNC_PROP); + } + + @AfterClass + public static final void kill () throws MsoPropertiesException { + msoPropertiesFactory.removeMsoProperties("MSO_PROP_SDNC_ADAPTER"); + } + /** * Test method for * {@link org.openecomp.mso.adapters.sdnc.impl.RequestTunables#RequestTunables(java.lang.String, java.lang.String, java.lang.String, java.lang.String)} 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 1921a9961a..1746360af0 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 @@ -19,14 +19,9 @@ */ package org.openecomp.mso.adapters.sdnc.sdncrest; -import org.openecomp.mso.adapters.sdncrest.SDNCEvent; -import org.openecomp.mso.adapters.sdncrest.SDNCServiceError; -import org.openecomp.mso.adapters.sdncrest.SDNCServiceRequest; -import org.openecomp.mso.adapters.sdncrest.SDNCServiceResponse; -import org.codehaus.jackson.map.DeserializationConfig; -import org.codehaus.jackson.map.ObjectMapper; -import org.codehaus.jackson.map.SerializationConfig; -import org.junit.Test; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -34,9 +29,15 @@ import java.io.ObjectOutputStream; import java.io.Serializable; import java.util.Arrays; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.assertEquals; +import org.junit.Test; +import org.openecomp.mso.adapters.sdncrest.SDNCEvent; +import org.openecomp.mso.adapters.sdncrest.SDNCServiceError; +import org.openecomp.mso.adapters.sdncrest.SDNCServiceRequest; +import org.openecomp.mso.adapters.sdncrest.SDNCServiceResponse; + +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; @@ -102,14 +103,14 @@ public class ObjectMappingTest { "}" + EOL; private final String PARAMS = - "{\"entry\":[{\"key\":\"P1\",\"value\":\"V1\"},{\"key\":\"P2\",\"value\":\"V2\"},{\"key\":\"P3\",\"value\":\"V3\"}]}"; + "{\"P1\":\"V1\",\"P2\":\"V2\",\"P3\":\"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); + mapper.enable(SerializationFeature.WRAP_ROOT_VALUE); + mapper.enable(DeserializationFeature.UNWRAP_ROOT_VALUE); String json = SDNC_SERVICE_REQUEST; json = json.replace("((BP-TIMEOUT))", "\"bpTimeout\": \"" + "PT5M" + "\"," + EOL); @@ -135,8 +136,8 @@ public class ObjectMappingTest { 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); + mapper.enable(SerializationFeature.WRAP_ROOT_VALUE); + mapper.enable(DeserializationFeature.UNWRAP_ROOT_VALUE); // bpTimeout is optional. String json = SDNC_SERVICE_REQUEST; @@ -163,8 +164,8 @@ public class ObjectMappingTest { 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); + mapper.enable(SerializationFeature.WRAP_ROOT_VALUE); + mapper.enable(DeserializationFeature.UNWRAP_ROOT_VALUE); // Convert source json string to object. String json1 = SDNC_SERVICE_REQUEST; @@ -188,8 +189,8 @@ public class ObjectMappingTest { 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); + mapper.enable(SerializationFeature.WRAP_ROOT_VALUE); + mapper.enable(DeserializationFeature.UNWRAP_ROOT_VALUE); // Convert source json string to object. String json1 = SDNC_SERVICE_REQUEST; @@ -213,8 +214,8 @@ public class ObjectMappingTest { 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); + mapper.enable(SerializationFeature.WRAP_ROOT_VALUE); + mapper.enable(DeserializationFeature.UNWRAP_ROOT_VALUE); String json = SDNC_SERVICE_RESPONSE; json = json.replace("((RESPONSE-MESSAGE))", " \"responseMessage\": \"" + "OK" + "\"," + EOL); @@ -234,8 +235,8 @@ public class ObjectMappingTest { 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); + mapper.enable(SerializationFeature.WRAP_ROOT_VALUE); + mapper.enable(DeserializationFeature.UNWRAP_ROOT_VALUE); // responseMessage is optional. String json = SDNC_SERVICE_RESPONSE; @@ -254,8 +255,8 @@ public class ObjectMappingTest { 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); + mapper.enable(SerializationFeature.WRAP_ROOT_VALUE); + mapper.enable(DeserializationFeature.UNWRAP_ROOT_VALUE); // Convert source json string to object. String json1 = SDNC_SERVICE_RESPONSE; @@ -280,8 +281,8 @@ public class ObjectMappingTest { 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); + mapper.enable(SerializationFeature.WRAP_ROOT_VALUE); + mapper.enable(DeserializationFeature.UNWRAP_ROOT_VALUE); // Convert source json string to object. String json1 = SDNC_SERVICE_RESPONSE; @@ -306,8 +307,8 @@ public class ObjectMappingTest { 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); + mapper.enable(SerializationFeature.WRAP_ROOT_VALUE); + mapper.enable(DeserializationFeature.UNWRAP_ROOT_VALUE); String json = SDNC_SERVICE_ERROR; json = json.replace("((RESPONSE-MESSAGE))", "\"responseMessage\": \"" + "SOMETHING BAD" + "\"," + EOL); @@ -323,8 +324,8 @@ public class ObjectMappingTest { 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); + mapper.enable(SerializationFeature.WRAP_ROOT_VALUE); + mapper.enable(DeserializationFeature.UNWRAP_ROOT_VALUE); // responseMessage is optional. String json = SDNC_SERVICE_ERROR; @@ -341,8 +342,8 @@ public class ObjectMappingTest { 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); + mapper.enable(SerializationFeature.WRAP_ROOT_VALUE); + mapper.enable(DeserializationFeature.UNWRAP_ROOT_VALUE); // Convert source json string to object. String json1 = SDNC_SERVICE_ERROR; @@ -366,8 +367,8 @@ public class ObjectMappingTest { 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); + mapper.enable(SerializationFeature.WRAP_ROOT_VALUE); + mapper.enable(DeserializationFeature.UNWRAP_ROOT_VALUE); // Convert source json string to object. String json1 = SDNC_SERVICE_ERROR; @@ -391,8 +392,8 @@ public class ObjectMappingTest { 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); + mapper.enable(SerializationFeature.WRAP_ROOT_VALUE); + mapper.enable(DeserializationFeature.UNWRAP_ROOT_VALUE); String json = SDNC_EVENT; json = json.replace(EOL + "((EVENT-PARAMS))", "," + EOL + " \"params\": " + PARAMS + EOL); @@ -410,8 +411,8 @@ public class ObjectMappingTest { 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); + mapper.enable(SerializationFeature.WRAP_ROOT_VALUE); + mapper.enable(DeserializationFeature.UNWRAP_ROOT_VALUE); // params are optional. String json = SDNC_EVENT; @@ -428,8 +429,8 @@ public class ObjectMappingTest { 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); + mapper.enable(SerializationFeature.WRAP_ROOT_VALUE); + mapper.enable(DeserializationFeature.UNWRAP_ROOT_VALUE); // Convert source json string to object. String json1 = SDNC_EVENT; |