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