8f73c0228524eb90ba1356db61d801e0794eb2b7
[so.git] / adapters / mso-sdnc-adapter / src / test / java / org / onap / so / adapters / sdnc / impl / SDNCAdapterPortTypeImplTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.adapters.sdnc.impl;
22
23 import static org.junit.Assert.fail;
24
25 import java.io.File;
26 import java.io.IOException;
27 import java.io.StringWriter;
28
29 import javax.xml.parsers.DocumentBuilder;
30 import javax.xml.parsers.DocumentBuilderFactory;
31 import javax.xml.parsers.ParserConfigurationException;
32 import javax.xml.transform.OutputKeys;
33 import javax.xml.transform.Transformer;
34 import javax.xml.transform.TransformerConfigurationException;
35 import javax.xml.transform.TransformerException;
36 import javax.xml.transform.TransformerFactory;
37 import javax.xml.transform.dom.DOMSource;
38 import javax.xml.transform.stream.StreamResult;
39
40 import org.junit.Test;
41 import org.junit.runner.RunWith;
42 import org.onap.so.adapters.sdnc.RequestHeader;
43 import org.onap.so.adapters.sdnc.SDNCAdapterApplication;
44 import org.onap.so.adapters.sdnc.SDNCAdapterPortType;
45 import org.onap.so.adapters.sdnc.SDNCAdapterRequest;
46 import org.onap.so.adapters.sdnc.SDNCAdapterResponse;
47 import org.springframework.beans.factory.annotation.Autowired;
48 import org.springframework.boot.test.context.SpringBootTest;
49 import org.springframework.test.context.ActiveProfiles;
50 import org.springframework.test.context.junit4.SpringRunner;
51 import org.w3c.dom.Document;
52 import org.xml.sax.SAXException;
53
54 @RunWith(SpringRunner.class)
55 @SpringBootTest(classes = SDNCAdapterApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
56 @ActiveProfiles({"test","non-async"})
57 public class SDNCAdapterPortTypeImplTest {
58
59         @Autowired
60         private SDNCAdapterPortType sdncAdapter;
61         
62         
63         SDNCAdapterRequest sdncAdapterRequest;
64         
65         public void setupTestEntities() throws ParserConfigurationException, SAXException, IOException, TransformerException   {
66                 buildTestRequest();
67         }       
68
69         private void buildTestRequest() throws ParserConfigurationException, SAXException, IOException, TransformerException {  
70                 sdncAdapterRequest= new SDNCAdapterRequest();
71                 File fXmlFile = new File("src/test/resources/sdncTestPayload.xml");
72                 DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
73                 DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
74                 Document doc = dBuilder.parse(fXmlFile);
75                 StringWriter sw = new StringWriter();
76         TransformerFactory tf = TransformerFactory.newInstance();
77         Transformer transformer = tf.newTransformer();
78         transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
79         transformer.setOutputProperty(OutputKeys.METHOD, "xml");
80         transformer.setOutputProperty(OutputKeys.INDENT, "yes");
81         transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
82
83         transformer.transform(new DOMSource(doc), new StreamResult(sw));
84                 System.out.println(sw.toString());
85                 sdncAdapterRequest.setRequestData(sw.toString());
86                 RequestHeader requestHeader = new RequestHeader();
87                 requestHeader.setCallbackUrl("http://localhost:9090/callback");
88                 requestHeader.setMsoAction("gammainternet");
89                 requestHeader.setRequestId("testReqId");
90                 requestHeader.setSvcAction("assign");
91                 requestHeader.setSvcInstanceId("servInstanceId");
92                 requestHeader.setSvcOperation("svc-topology-operation");
93                 sdncAdapterRequest.setRequestHeader(requestHeader );
94         }
95         
96         
97         
98         @Test
99         public void sendRequest() throws ParserConfigurationException, SAXException, IOException, TransformerException  {
100                 // Given
101                 setupTestEntities();
102                 
103                 // When
104                 SDNCAdapterResponse response = sdncAdapter.sdncAdapter(sdncAdapterRequest);
105                 if(response ==null)
106                          fail("Null infraRequest");
107                 
108                 // Then
109                 //assertThat(infraRequest, sameBeanAs(testRequest).ignoring("requestBody").ignoring("endTime").ignoring("startTime").ignoring("modifyTime"));           
110         }
111 }