diff options
author | Benjamin, Max (mb388a) <mb388a@us.att.com> | 2018-07-30 15:56:09 -0400 |
---|---|---|
committer | Benjamin, Max (mb388a) <mb388a@us.att.com> | 2018-07-31 11:09:25 -0400 |
commit | 5a6a6de6f1a26a1897e4917a0df613e25a24eb70 (patch) | |
tree | 59a968f27b4b603aacc9d5e7b51fb598aeec5321 /adapters/mso-sdnc-adapter/src/test/java/org/openecomp | |
parent | b6dc38501f3b746426b42d9de4cc883d894149e8 (diff) |
Containerization feature of SO
Change-Id: I95381232eeefcd247a66a5cec370a8ce1c288e18
Issue-ID: SO-670
Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com>
Diffstat (limited to 'adapters/mso-sdnc-adapter/src/test/java/org/openecomp')
13 files changed, 0 insertions, 1265 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 deleted file mode 100644 index c3949a6a79..0000000000 --- a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/ObjectFactoryTest.java +++ /dev/null @@ -1,113 +0,0 @@ -/*- - * ============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; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.hamcrest.CoreMatchers.containsString; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; -import java.io.StringWriter; -import java.nio.charset.Charset; - -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Marshaller; -import javax.xml.bind.Unmarshaller; - -import org.junit.Test; - -public class ObjectFactoryTest { - - private Marshaller jaxbMarshaller; - private Unmarshaller jaxbUnmarshaller; - - /** - * 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"); - - try { - JAXBContext jaxbContext = JAXBContext.newInstance(RequestHeader.class); - jaxbMarshaller = jaxbContext.createMarshaller(); - - JAXBContext jaxbContext2 = JAXBContext.newInstance(RequestHeader.class); - jaxbUnmarshaller = jaxbContext2.createUnmarshaller(); - } - catch (JAXBException e) { - e.printStackTrace (); - fail(); - return; - } - - StringWriter writer = new StringWriter(); - try { - jaxbMarshaller.marshal (rh, writer); - } catch (JAXBException e) { - e.printStackTrace(); - fail (); - } - String marshalled = writer.toString (); - assertThat(marshalled, containsString("<RequestId>reqid</RequestId>")); - - InputStream inputStream = new ByteArrayInputStream(marshalled.getBytes(Charset.forName("UTF-8"))); - try { - RequestHeader res2 = (RequestHeader) jaxbUnmarshaller.unmarshal (inputStream); - assertEquals("callback", res2.getCallbackUrl ()); - assertEquals("action", res2.getMsoAction ()); - assertEquals("op", res2.getSvcOperation ()); - } catch (JAXBException e) { - e.printStackTrace(); - fail(); - } - } - - /** - * Test method for {@link org.openecomp.mso.adapters.sdnc.ObjectFactory#createSDNCAdapterResponse()}. - */ - @Test - public final void testCreateSDNCAdapterResponse () { - ObjectFactory of = new ObjectFactory (); - SDNCAdapterResponse ar = of.createSDNCAdapterResponse (); - assertNotNull(ar); - } - - @Test - public final void testCreateSDNCAdapterRequest () { - ObjectFactory of = new ObjectFactory (); - SDNCAdapterRequest ar = of.createSDNCAdapterRequest (); - assertNotNull(ar); - } - -} 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 deleted file mode 100644 index b9d88406f9..0000000000 --- a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/SDNCAdapterRequestTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/*- - * ============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; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import org.junit.BeforeClass; -import org.junit.Test; -import org.openecomp.mso.adapters.sdnc.SDNCAdapterRequest; -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); - assertNotNull(((SDNCAdapterRequest) sd).getRequestData()) ; - assertEquals("data", ((SDNCAdapterRequest) sd).getRequestData()); - assertEquals(rh, ((SDNCAdapterRequest) sd).getRequestHeader()); - } - -} diff --git a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/client/CallbackHeaderTest.java b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/client/CallbackHeaderTest.java deleted file mode 100644 index 39518e2081..0000000000 --- a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/client/CallbackHeaderTest.java +++ /dev/null @@ -1,49 +0,0 @@ -/* -* ============LICENSE_START======================================================= -* ONAP : SO -* ================================================================================ -* Copyright 2018 TechMahindra -*================================================================================= -* 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.client; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import org.junit.Test; - -public class CallbackHeaderTest { - - static CallbackHeader cb = new CallbackHeader(); - - @Test - public final void testCallbackHeader() { - cb.setRequestId("413658f4-7f42-482e-b834-23a5c15657da-1474471336781"); - cb.setResponseCode("200"); - cb.setResponseMessage("OK"); - assertNotNull(cb.getRequestId()); - assertNotNull(cb.getResponseCode()); - assertNotNull(cb.getResponseMessage()); - assertEquals("413658f4-7f42-482e-b834-23a5c15657da-1474471336781", cb.getRequestId()); - assertEquals("200", cb.getResponseCode()); - assertEquals("OK", cb.getResponseMessage()); - } - - @Test - public void testtoString() { - assertNotNull(cb.toString()); - } -} 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 deleted file mode 100644 index ecffd1c5ad..0000000000 --- a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/client/SDNCAdapterCallbackRequestTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/*- - * ============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.client; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import org.junit.Test; -import org.openecomp.mso.adapters.sdnc.client.CallbackHeader; -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"); - assertNotNull(sdc.getCallbackHeader()); - assertNotNull(sdc.getRequestData()); - assertEquals(ch, sdc.getCallbackHeader()); - assertEquals("data", sdc.getRequestData()); - - } - - @Test - public void testtoString() - { - assertNotNull(ch.toString()); - assertNotNull(sdc.toString()); - } - -} - - 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 deleted file mode 100644 index 234a9d2272..0000000000 --- a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/impl/InvestigationTest.java +++ /dev/null @@ -1,114 +0,0 @@ -/*-
- * ============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 deleted file mode 100644 index 72b11708e6..0000000000 --- a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/impl/RequestTunablesTest.java +++ /dev/null @@ -1,86 +0,0 @@ -/*- - * ============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 static org.junit.Assert.*; - -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; - -public class RequestTunablesTest { - - 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 method for - * {@link org.openecomp.mso.adapters.sdnc.impl.RequestTunables#RequestTunables(java.lang.String, java.lang.String, java.lang.String, java.lang.String)} - * . - */ - @Test - public final void testRequestTunables () { - RequestTunables rt = new RequestTunables (null, null, "op", null,msoPropertiesFactory); - assertEquals(0, rt.getReqId ().length ()); - rt = new RequestTunables ("reqId", "msoAction", null, "query",msoPropertiesFactory); - rt.setTunables (); - System.out.println(rt.toString ()); - // assert (rt.getReqMethod ().equals ("toto")); - assertNotNull(rt.getTimeout ()); - assertEquals("query", rt.getAction ()); - assertEquals("msoAction", rt.getMsoAction ()); - assertEquals("sdnc-request-header", rt.getHeaderName ()); - assertEquals(0, rt.getOperation ().length ()); - assertEquals("N", rt.getAsyncInd ()); - assertEquals("reqId", rt.getReqId ()); - } - - @Test - public final void testRequestTunablesSet() { - RequestTunables rt = new RequestTunables("reqId", "gammainternet", "service-configuration-operation", "changeactivate", msoPropertiesFactory); - rt.setTunables (); - assertNotNull(rt.getTimeout ()); - assertEquals("changeactivate", rt.getAction ()); - assertEquals("gammainternet", rt.getMsoAction ()); - assertEquals("sdnc-request-header", rt.getHeaderName ()); - assertEquals("service-configuration-operation", rt.getOperation ()); - assertEquals("N", rt.getAsyncInd ()); - assertEquals("reqId", rt.getReqId ()); - } - -} diff --git a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/impl/SDNCAdapterRestImplTest.java b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/impl/SDNCAdapterRestImplTest.java deleted file mode 100644 index 98b368f5fa..0000000000 --- a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/impl/SDNCAdapterRestImplTest.java +++ /dev/null @@ -1,79 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2018 Huawei Technologies Co., Ltd. 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 org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.openecomp.mso.HealthCheckUtils; -import org.openecomp.mso.logger.MsoLogger; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; - -import javax.ws.rs.core.Response; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.when; - -@RunWith(PowerMockRunner.class) -@PrepareForTest(SDNCAdapterRestImpl.class) -public class SDNCAdapterRestImplTest { - - SDNCAdapterRestImpl test; - - @Before - public void init(){ - - test = new SDNCAdapterRestImpl(); - } - - @Test - public void testBadReqNoServiceRsp() { - - HealthCheckUtils hCU = PowerMockito.mock(HealthCheckUtils.class); - try { - PowerMockito.whenNew(HealthCheckUtils.class).withNoArguments().thenReturn(hCU); - when(hCU.siteStatusCheck(any(MsoLogger.class))).thenReturn(true); - - } catch (Exception e) { - e.printStackTrace(); - } - - String reqXML = "<xml>test</xml>"; - - Response response = test.MSORequest(reqXML); - assertEquals(400,response.getStatus()); - - response = test.healthcheck("1a25a7c0-4c91-4f74-9a78-8c11b7a57f1a"); - assertEquals(503,response.getStatus()); - - response = test.globalHealthcheck(true); - assertEquals(503,response.getStatus()); - - response = test.nodeHealthcheck(); - assertEquals(503,response.getStatus()); - - } - -} - diff --git a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/impl/SDNCResponseTest.java b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/impl/SDNCResponseTest.java deleted file mode 100644 index f9c885f0eb..0000000000 --- a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/impl/SDNCResponseTest.java +++ /dev/null @@ -1,49 +0,0 @@ -/* -* ============LICENSE_START======================================================= -* ONAP : SO -* ================================================================================ -* Copyright 2018 TechMahindra -*================================================================================= -* 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 static org.junit.Assert.*; - -import org.junit.Test; - -public class SDNCResponseTest { - - private SDNCResponse sdncresponse = new SDNCResponse(null, 0, null); - - @Test - public void testSDNCResponse() - { - sdncresponse.setReqId("reqId"); - sdncresponse.setRespCode(0); - sdncresponse.setRespMsg("respMsg"); - sdncresponse.setSdncRespXml("sdncRespXml"); - assertEquals(sdncresponse.getReqId(), "reqId"); - assertEquals(sdncresponse.getRespCode(), 0); - assertEquals(sdncresponse.getRespMsg(), "respMsg"); - assertEquals(sdncresponse.getSdncRespXml(),"sdncRespXml"); - } - - @Test - public void testtoString() - { - assertNotNull(sdncresponse.toString()); - } -} -
\ No newline at end of file diff --git a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/notify/SDNCNotifyResourceTest.java b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/notify/SDNCNotifyResourceTest.java deleted file mode 100644 index 75cd360663..0000000000 --- a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/notify/SDNCNotifyResourceTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2018 Huawei Technologies Co., Ltd. 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 - *l - * 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.notify; - -import org.junit.Test; -import org.mockito.Mock; - -import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.core.Response; - -import static org.junit.Assert.assertEquals; - -public class SDNCNotifyResourceTest { - - @Mock - HttpServletRequest httpServletRequest; - - SDNCNotifyResource test = new SDNCNotifyResource(); - - @Test - public void testPrintMessage() { - - Response response = test.printMessage(); - assertEquals(200, response.getStatus()); - - response = test.printMessageParam("msg"); - assertEquals(200, response.getStatus()); - - String reqXML = "<xml>test</xml>"; - response = test.SDNCNotify(reqXML, httpServletRequest); - assertEquals(400, response.getStatus()); - - } -} diff --git a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/sdncrest/BPRestCallbackTest.java b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/sdncrest/BPRestCallbackTest.java deleted file mode 100644 index 91cf2c91c7..0000000000 --- a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/sdncrest/BPRestCallbackTest.java +++ /dev/null @@ -1,38 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2018 Huawei Technologies Co., Ltd. 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 - *l - * 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.sdncrest; - -import org.junit.Test; - -import static junit.framework.Assert.assertFalse; - - -public class BPRestCallbackTest { - - @Test - public void testBPRestCallbackException() { - - BPRestCallback test = new BPRestCallback(); - test.send("workflow/","messageType","correlator","message"); - assertFalse(test.send("workflowMessageUrl/", "messageType", "correlator", "message")); - - } -} 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 deleted file mode 100644 index 1746360af0..0000000000 --- a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/sdncrest/ObjectMappingTest.java +++ /dev/null @@ -1,478 +0,0 @@ -/*- - * ============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.sdncrest; - -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; -import java.io.ObjectOutputStream; -import java.io.Serializable; -import java.util.Arrays; - -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; - - - -/** - * 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 = - "{\"P1\":\"V1\",\"P2\":\"V2\",\"P3\":\"V3\"}"; - - @Test - public final void jsonToSDNCServiceRequest() throws Exception { - logTest(); - ObjectMapper mapper = new ObjectMapper(); - 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); - - 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(SerializationFeature.WRAP_ROOT_VALUE); - mapper.enable(DeserializationFeature.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(SerializationFeature.WRAP_ROOT_VALUE); - mapper.enable(DeserializationFeature.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(SerializationFeature.WRAP_ROOT_VALUE); - mapper.enable(DeserializationFeature.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(SerializationFeature.WRAP_ROOT_VALUE); - mapper.enable(DeserializationFeature.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(SerializationFeature.WRAP_ROOT_VALUE); - mapper.enable(DeserializationFeature.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(SerializationFeature.WRAP_ROOT_VALUE); - mapper.enable(DeserializationFeature.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(SerializationFeature.WRAP_ROOT_VALUE); - mapper.enable(DeserializationFeature.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(SerializationFeature.WRAP_ROOT_VALUE); - mapper.enable(DeserializationFeature.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(SerializationFeature.WRAP_ROOT_VALUE); - mapper.enable(DeserializationFeature.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(SerializationFeature.WRAP_ROOT_VALUE); - mapper.enable(DeserializationFeature.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(SerializationFeature.WRAP_ROOT_VALUE); - mapper.enable(DeserializationFeature.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(SerializationFeature.WRAP_ROOT_VALUE); - mapper.enable(DeserializationFeature.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(SerializationFeature.WRAP_ROOT_VALUE); - mapper.enable(DeserializationFeature.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(SerializationFeature.WRAP_ROOT_VALUE); - mapper.enable(DeserializationFeature.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/sdncrest/TypedRequestTunablesTest.java b/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/sdncrest/TypedRequestTunablesTest.java deleted file mode 100644 index 5651f8adab..0000000000 --- a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/sdncrest/TypedRequestTunablesTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2018 Huawei Technologies Co., Ltd. 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.sdncrest; - -import org.junit.Assert; -import org.junit.Test; - -import static junit.framework.Assert.assertEquals; - -public class TypedRequestTunablesTest { - - @Test - public void testTypedRequestTunables() { - - TypedRequestTunables test = new TypedRequestTunables("reqId","myUrlSuffix"); - test.setServiceKey("service","operation"); - assertEquals(test.getReqId(),"reqId"); - Assert.assertNull(test.getError()); - Assert.assertNull(test.getReqMethod()); - Assert.assertNull(test.getTimeout()); - Assert.assertNull(test.getSdncUrl()); - Assert.assertNull(test.getHeaderName()); - Assert.assertNull(test.getNamespace()); - Assert.assertNull(test.getMyUrl()); - Assert.assertFalse(test.setTunables()); - - } - -} - 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 deleted file mode 100644 index 77d22e44df..0000000000 --- a/adapters/mso-sdnc-adapter/src/test/java/org/openecomp/mso/adapters/sdnc/util/SDNCRequestIdUtilTest.java +++ /dev/null @@ -1,45 +0,0 @@ -/*- - * ============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.util; - -import static org.junit.Assert.assertEquals; - -import java.util.UUID; -import org.junit.Test; - - -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"; - - assertEquals(originalRequestId, SDNCRequestIdUtil.getSDNCOriginalRequestId(postfixedRequestId)); - assertEquals(postfixedRequestId2, SDNCRequestIdUtil.getSDNCOriginalRequestId(postfixedRequestId2)); - - } - -} |