2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.adapters.sdnc;
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;
30 import java.io.ByteArrayInputStream;
31 import java.io.InputStream;
32 import java.io.StringWriter;
33 import java.nio.charset.Charset;
35 import javax.xml.bind.JAXBContext;
36 import javax.xml.bind.JAXBException;
37 import javax.xml.bind.Marshaller;
38 import javax.xml.bind.Unmarshaller;
40 import org.junit.Test;
42 public class ObjectFactoryTest {
44 private Marshaller jaxbMarshaller;
45 private Unmarshaller jaxbUnmarshaller;
48 * Test method for {@link org.onap.so.adapters.sdnc.ObjectFactory#createRequestHeader()}.
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");
62 JAXBContext jaxbContext = JAXBContext.newInstance(RequestHeader.class);
63 jaxbMarshaller = jaxbContext.createMarshaller();
65 JAXBContext jaxbContext2 = JAXBContext.newInstance(RequestHeader.class);
66 jaxbUnmarshaller = jaxbContext2.createUnmarshaller();
68 catch (JAXBException e) {
74 StringWriter writer = new StringWriter();
76 jaxbMarshaller.marshal (rh, writer);
77 } catch (JAXBException e) {
81 String marshalled = writer.toString ();
82 assertThat(marshalled, containsString("<RequestId>reqid</RequestId>"));
84 InputStream inputStream = new ByteArrayInputStream(marshalled.getBytes(Charset.forName("UTF-8")));
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) {
97 * Test method for {@link org.onap.so.adapters.sdnc.ObjectFactory#createSDNCAdapterResponse()}.
100 public final void testCreateSDNCAdapterResponse () {
101 ObjectFactory of = new ObjectFactory ();
102 SDNCAdapterResponse ar = of.createSDNCAdapterResponse ();
107 public final void testCreateSDNCAdapterRequest () {
108 ObjectFactory of = new ObjectFactory ();
109 SDNCAdapterRequest ar = of.createSDNCAdapterRequest ();