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;
26 import javax.xml.bind.annotation.XmlRootElement;
29 * Tests the XMLMarshaller to ensure that it's able to marshal and unmarshall a POJO
32 public class XMLMarshallerTest {
35 public void testMarshal() throws Exception {
36 Assert.assertEquals(getXML(), XmlMarshaller.marshal(getPOJO()));
40 public void testUnMarshal() throws Exception {
41 Assert.assertEquals(XmlMarshaller.unMarshal(getXML(), new TestPOJO()), getPOJO());
44 private TestPOJO getPOJO() {
45 TestPOJO testPOJO = new TestPOJO();
46 testPOJO.setFirstName("FN");
47 testPOJO.setLastName("LN");
51 private String getXML() {
52 return "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><testPOJO><firstName>FN</firstName><lastName>LN</lastName></testPOJO>";
56 static class TestPOJO {
64 public String getFirstName() {
68 public void setFirstName(String firstName) {
69 this.firstName = firstName;
72 public String getLastName() {
76 public void setLastName(String lastName) {
77 this.lastName = lastName;
81 public boolean equals(Object o) {
82 if (this == o) return true;
83 if (!(o instanceof TestPOJO)) return false;
85 TestPOJO testPOJO = (TestPOJO) o;
87 if (getFirstName() != null ? !getFirstName().equals(testPOJO.getFirstName()) : testPOJO.getFirstName() != null)
89 return getLastName() != null ? getLastName().equals(testPOJO.getLastName()) : testPOJO.getLastName() == null;
93 public int hashCode() {
94 int result = getFirstName() != null ? getFirstName().hashCode() : 0;
95 result = 31 * result + (getLastName() != null ? getLastName().hashCode() : 0);