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.openecomp.mso.adapters.sdnc;
23 import static org.junit.Assert.fail;
25 import java.io.ByteArrayInputStream;
26 import java.io.InputStream;
27 import java.io.StringWriter;
28 import java.nio.charset.Charset;
30 import javax.xml.bind.JAXBContext;
31 import javax.xml.bind.JAXBException;
32 import javax.xml.bind.Marshaller;
33 import javax.xml.bind.Unmarshaller;
35 import org.junit.Test;
37 public class ObjectFactoryTest {
39 private Marshaller jaxbMarshaller;
40 private Unmarshaller jaxbUnmarshaller;
43 * Test method for {@link org.openecomp.mso.adapters.sdnc.ObjectFactory#createRequestHeader()}.
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");
57 JAXBContext jaxbContext = JAXBContext.newInstance(RequestHeader.class);
58 jaxbMarshaller = jaxbContext.createMarshaller();
60 JAXBContext jaxbContext2 = JAXBContext.newInstance(RequestHeader.class);
61 jaxbUnmarshaller = jaxbContext2.createUnmarshaller();
63 catch (JAXBException e) {
69 StringWriter writer = new StringWriter();
71 jaxbMarshaller.marshal (rh, writer);
72 } catch (JAXBException e) {
76 String marshalled = writer.toString ();
77 assert(marshalled.contains ("<RequestId>reqid</RequestId>"));
79 InputStream inputStream = new ByteArrayInputStream(marshalled.getBytes(Charset.forName("UTF-8")));
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) {
92 * Test method for {@link org.openecomp.mso.adapters.sdnc.ObjectFactory#createSDNCAdapterResponse()}.
95 public final void testCreateSDNCAdapterResponse () {
96 ObjectFactory of = new ObjectFactory ();
97 SDNCAdapterResponse ar = of.createSDNCAdapterResponse ();