Replaced all tabs with spaces in java and pom.xml
[so.git] / common / src / test / java / org / onap / so / utils / XMLMarshallerTest.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.onap.so.utils;
22
23 import org.junit.Assert;
24 import org.junit.Test;
25 import javax.xml.bind.annotation.XmlRootElement;
26
27 /**
28  * Tests the XMLMarshaller to ensure that it's able to marshal and unmarshall a POJO
29  */
30
31 public class XMLMarshallerTest {
32
33     @Test
34     public void testMarshal() throws Exception {
35         Assert.assertEquals(getXML(), XmlMarshaller.marshal(getPOJO()));
36     }
37
38     @Test
39     public void testUnMarshal() throws Exception {
40         Assert.assertEquals(XmlMarshaller.unMarshal(getXML(), new TestPOJO()), getPOJO());
41     }
42
43     private TestPOJO getPOJO() {
44         TestPOJO testPOJO = new TestPOJO();
45         testPOJO.setFirstName("FN");
46         testPOJO.setLastName("LN");
47         return testPOJO;
48     }
49
50     private String getXML() {
51         return "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><testPOJO><firstName>FN</firstName><lastName>LN</lastName></testPOJO>";
52     }
53
54     @XmlRootElement
55     static class TestPOJO {
56         String firstName;
57         String lastName;
58
59         public TestPOJO() {}
60
61
62         public String getFirstName() {
63             return firstName;
64         }
65
66         public void setFirstName(String firstName) {
67             this.firstName = firstName;
68         }
69
70         public String getLastName() {
71             return lastName;
72         }
73
74         public void setLastName(String lastName) {
75             this.lastName = lastName;
76         }
77
78         @Override
79         public boolean equals(Object o) {
80             if (this == o)
81                 return true;
82             if (!(o instanceof TestPOJO))
83                 return false;
84
85             TestPOJO testPOJO = (TestPOJO) o;
86
87             if (getFirstName() != null ? !getFirstName().equals(testPOJO.getFirstName())
88                     : testPOJO.getFirstName() != null)
89                 return false;
90             return getLastName() != null ? getLastName().equals(testPOJO.getLastName())
91                     : testPOJO.getLastName() == null;
92         }
93
94         @Override
95         public int hashCode() {
96             int result = getFirstName() != null ? getFirstName().hashCode() : 0;
97             result = 31 * result + (getLastName() != null ? getLastName().hashCode() : 0);
98             return result;
99         }
100     }
101
102
103 }