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.utils;
23 import org.junit.Assert;
24 import org.junit.Test;
25 import javax.xml.bind.annotation.XmlRootElement;
28 * Tests the XMLMarshaller to ensure that it's able to marshal and unmarshall a POJO
31 public class XMLMarshallerTest {
34 public void testMarshal() throws Exception {
35 Assert.assertEquals(getXML(), XmlMarshaller.marshal(getPOJO()));
39 public void testUnMarshal() throws Exception {
40 Assert.assertEquals(XmlMarshaller.unMarshal(getXML(), new TestPOJO()), getPOJO());
43 private TestPOJO getPOJO() {
44 TestPOJO testPOJO = new TestPOJO();
45 testPOJO.setFirstName("FN");
46 testPOJO.setLastName("LN");
50 private String getXML() {
51 return "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><testPOJO><firstName>FN</firstName><lastName>LN</lastName></testPOJO>";
55 static class TestPOJO {
62 public String getFirstName() {
66 public void setFirstName(String firstName) {
67 this.firstName = firstName;
70 public String getLastName() {
74 public void setLastName(String lastName) {
75 this.lastName = lastName;
79 public boolean equals(Object o) {
82 if (!(o instanceof TestPOJO))
85 TestPOJO testPOJO = (TestPOJO) o;
87 if (getFirstName() != null ? !getFirstName().equals(testPOJO.getFirstName())
88 : testPOJO.getFirstName() != null)
90 return getLastName() != null ? getLastName().equals(testPOJO.getLastName())
91 : testPOJO.getLastName() == null;
95 public int hashCode() {
96 int result = getFirstName() != null ? getFirstName().hashCode() : 0;
97 result = 31 * result + (getLastName() != null ? getLastName().hashCode() : 0);