7a9b039089cf0369e6e9820a10fe20792ab60a69
[so.git] / adapters / mso-sdnc-adapter / src / test / java / org / onap / so / adapters / sdnc / ObjectFactoryTest.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;
22
23 import static org.assertj.core.api.Assertions.assertThat;
24 import static org.hamcrest.CoreMatchers.containsString;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertNotNull;
27 import static org.junit.Assert.assertThat;
28 import static org.junit.Assert.fail;
29
30 import java.io.ByteArrayInputStream;
31 import java.io.InputStream;
32 import java.io.StringWriter;
33 import java.nio.charset.Charset;
34
35 import javax.xml.bind.JAXBContext;
36 import javax.xml.bind.JAXBException;
37 import javax.xml.bind.Marshaller;
38 import javax.xml.bind.Unmarshaller;
39
40 import org.junit.Test;
41
42 public class ObjectFactoryTest {
43
44     private Marshaller jaxbMarshaller;
45     private Unmarshaller jaxbUnmarshaller;
46
47     /**
48      * Test method for {@link org.onap.so.adapters.sdnc.ObjectFactory#createRequestHeader()}.
49      */
50     @Test
51     public final void testCreateRequestHeader () {
52         ObjectFactory of = new ObjectFactory ();
53         RequestHeader rh = of.createRequestHeader ();
54         rh.setCallbackUrl ("callback");
55         rh.setMsoAction ("action");
56         rh.setRequestId ("reqid");
57         rh.setSvcAction ("svcAction");
58         rh.setSvcInstanceId ("svcId");
59         rh.setSvcOperation ("op");
60         
61         try {
62             JAXBContext jaxbContext = JAXBContext.newInstance(RequestHeader.class);
63             jaxbMarshaller = jaxbContext.createMarshaller();
64         
65             JAXBContext jaxbContext2 = JAXBContext.newInstance(RequestHeader.class);
66             jaxbUnmarshaller = jaxbContext2.createUnmarshaller();
67         }
68         catch (JAXBException e) {
69             e.printStackTrace ();
70             fail();
71             return;
72         }
73
74         StringWriter writer = new StringWriter();
75         try {
76             jaxbMarshaller.marshal (rh, writer);
77         } catch (JAXBException e) {
78             e.printStackTrace();
79             fail ();
80         }
81         String marshalled = writer.toString ();
82         assertThat(marshalled, containsString("<RequestId>reqid</RequestId>"));
83         
84         InputStream inputStream = new ByteArrayInputStream(marshalled.getBytes(Charset.forName("UTF-8")));
85         try {
86             RequestHeader res2 = (RequestHeader) jaxbUnmarshaller.unmarshal (inputStream);
87             assertEquals("callback", res2.getCallbackUrl ());
88             assertEquals("action", res2.getMsoAction ());
89             assertEquals("op", res2.getSvcOperation ());
90         } catch (JAXBException e) {
91             e.printStackTrace();
92             fail();
93         }
94     }
95
96     /**
97      * Test method for {@link org.onap.so.adapters.sdnc.ObjectFactory#createSDNCAdapterResponse()}.
98      */
99     @Test
100     public final void testCreateSDNCAdapterResponse () {
101         ObjectFactory of = new ObjectFactory ();
102         SDNCAdapterResponse ar = of.createSDNCAdapterResponse ();
103         assertNotNull(ar);
104     }
105     
106     @Test
107     public final void testCreateSDNCAdapterRequest () {
108         ObjectFactory of = new ObjectFactory ();
109         SDNCAdapterRequest ar = of.createSDNCAdapterRequest ();
110         assertNotNull(ar);
111     }
112     
113 }