Update css file name in conf.py
[policy/engine.git] / PolicyEngineAPI / src / test / java / org / onap / policy / std / test / MatchesTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * PolicyEngineAPI
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.policy.std.test;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotEquals;
25
26 import java.util.Collections;
27 import java.util.HashMap;
28 import java.util.Map;
29
30 import org.junit.After;
31 import org.junit.Assert;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.onap.policy.std.Matches;
35
36 /**
37  * The class <code>MatchesTest</code> contains tests for the class
38  * <code>{@link Matches}</code>.
39  *
40  * @generatedBy CodePro at 6/1/16 1:41 PM
41  * @version $Revision: 1.0 $
42  */
43 public class MatchesTest {
44     private static final String DUMMY_VAL = "SomethingElse";
45
46     private static final String CONFIG_NAME = "CONFIG_NAME";
47
48     private static final String ONAP_NAME = "ONAP_NAME";
49
50     @Test
51     public void testMatches_SetterGetterMethods() {
52         final Matches objUnderTest = getMatches(ONAP_NAME, CONFIG_NAME, Collections.emptyMap());
53
54         final Map<String, String> result = objUnderTest.getConfigAttributes();
55
56         assertEquals(ONAP_NAME, objUnderTest.getOnapName());
57         assertEquals(CONFIG_NAME, objUnderTest.getConfigName());
58         assertEquals(0, result.size());
59     }
60
61     @Test
62     public void testMatches_EqualsMethod_SameObjectsAndSameHasCode() {
63         final Matches firstObject = getMatches(ONAP_NAME, CONFIG_NAME, Collections.emptyMap());
64         final Matches secondObject = getMatches(ONAP_NAME, CONFIG_NAME, Collections.emptyMap());
65
66         assertEquals(firstObject, secondObject);
67         assertEquals(firstObject.hashCode(), secondObject.hashCode());
68     }
69
70     @Test
71     public void testMatchesEqualsMethod_differentConfigName_NotEqualsAndDifferentHashCode() {
72         final Matches firstObject = getMatches(ONAP_NAME, DUMMY_VAL, Collections.emptyMap());
73         final Matches secondObject = getMatches(ONAP_NAME, CONFIG_NAME, Collections.emptyMap());
74
75         assertNotEquals(firstObject, secondObject);
76         assertNotEquals(firstObject.hashCode(), secondObject.hashCode());
77     }
78
79     @Test
80     public void testMatchesEqualsMethod_differentObjects_NotEquals() {
81         final String firstObject = new String();
82         final Matches secondObject = getMatches(ONAP_NAME, CONFIG_NAME, Collections.emptyMap());
83         Assert.assertFalse(secondObject.equals(firstObject));
84     }
85
86     @Test
87     public void testMatchesEqualsMethod_nullObject_NotEqualsAndDifferentHashCode() {
88         final String firstObject = null;
89         final Matches secondObject = getMatches(ONAP_NAME, CONFIG_NAME, Collections.emptyMap());
90
91         assertNotEquals(firstObject, secondObject);
92     }
93
94     @Test
95     public void testMatchesEqualsMethod_NullConfigName_NotEqualsAndDifferentHashCode() {
96         final Matches firstObject = getMatches(ONAP_NAME, CONFIG_NAME, Collections.emptyMap());
97         final Matches secondObject = getMatches(ONAP_NAME, null, Collections.emptyMap());
98
99         assertNotEquals(firstObject, secondObject);
100         assertNotEquals(firstObject.hashCode(), secondObject.hashCode());
101     }
102
103     @Test
104     public void testMatchesEqualsMethod_differentOnapName_NotEqualsAndDifferentHashCode() throws Exception {
105         final Matches firstObject = getMatches(DUMMY_VAL, CONFIG_NAME, Collections.emptyMap());
106         final Matches secondObject = getMatches(ONAP_NAME, CONFIG_NAME, Collections.emptyMap());
107
108         assertNotEquals(firstObject, secondObject);
109         assertNotEquals(firstObject.hashCode(), secondObject.hashCode());
110     }
111
112     @Test
113     public void testMatchesEqualsMethod_NullOnapName_NotEqualsAndDifferentHashCode() throws Exception {
114         final Matches firstObject = getMatches(null, CONFIG_NAME, Collections.emptyMap());
115         final Matches secondObject = getMatches(ONAP_NAME, CONFIG_NAME, Collections.emptyMap());
116
117         assertNotEquals(firstObject, secondObject);
118         assertNotEquals(firstObject.hashCode(), secondObject.hashCode());
119     }
120
121     @Test
122     public void testMatchesEqualsMethod_BothNullOnapName_Equals() throws Exception {
123         final Matches firstObject = getMatches(null, CONFIG_NAME, Collections.emptyMap());
124         final Matches secondObject = getMatches(null, CONFIG_NAME, Collections.emptyMap());
125
126         assertEquals(firstObject, secondObject);
127         assertEquals(firstObject.hashCode(), secondObject.hashCode());
128     }
129
130     @Test
131     public void testMatchesEqualsMethod_BothNullConfigName_Equals() throws Exception {
132         final Matches firstObject = getMatches(ONAP_NAME, null, Collections.emptyMap());
133         final Matches secondObject = getMatches(ONAP_NAME, null, Collections.emptyMap());
134
135         assertEquals(firstObject, secondObject);
136         assertEquals(firstObject.hashCode(), secondObject.hashCode());
137     }
138
139     @Test
140     public void testMatchesEqualsMethod_DifferentConfigAttr_NotEqualsAndDifferentHashCode() throws Exception {
141         final Map<String, String> firstMap = Collections.emptyMap();
142         final Map<String, String> secondMap = new HashMap<>();
143         secondMap.put("key", "value");
144
145         final Matches firstObject = getMatches(ONAP_NAME, CONFIG_NAME, firstMap);
146         final Matches secondObject = getMatches(ONAP_NAME, CONFIG_NAME, secondMap);
147
148         assertNotEquals(firstObject, secondObject);
149         assertNotEquals(firstObject.hashCode(), secondObject.hashCode());
150     }
151
152     @Test
153     public void testMatchesEqualsMethod_NullConfigAttr_NotEqualsAndDifferentHashCode() throws Exception {
154         final Map<String, String> secondMap = new HashMap<>();
155         secondMap.put("key", "value");
156
157         final Matches firstObject = getMatches(ONAP_NAME, CONFIG_NAME, null);
158         final Matches secondObject = getMatches(ONAP_NAME, CONFIG_NAME, secondMap);
159
160         assertNotEquals(firstObject, secondObject);
161         assertNotEquals(firstObject.hashCode(), secondObject.hashCode());
162     }
163
164     @Test
165     public void testMatchesEqualsMethod_BothNullConfigAttr_Equals() throws Exception {
166
167         final Matches firstObject = getMatches(ONAP_NAME, CONFIG_NAME, null);
168         final Matches secondObject = getMatches(ONAP_NAME, CONFIG_NAME, null);
169
170         assertEquals(firstObject, secondObject);
171         assertEquals(firstObject.hashCode(), secondObject.hashCode());
172     }
173
174     private Matches getMatches(final String onapName, final String configName, final Map<String, String> attributes) {
175         final Matches objUnderTest = new Matches();
176         objUnderTest.setOnapName(onapName);
177         objUnderTest.setConfigName(configName);
178         objUnderTest.setConfigAttributes(attributes);
179         return objUnderTest;
180     }
181
182     /**
183      * Perform pre-test initialization.
184      *
185      * @throws Exception
186      *             if the initialization fails for some reason
187      *
188      * @generatedBy CodePro at 6/1/16 1:41 PM
189      */
190     @Before
191     public void setUp() throws Exception {
192         // add additional set up code here
193     }
194
195     /**
196      * Perform post-test clean-up.
197      *
198      * @throws Exception
199      *             if the clean-up fails for some reason
200      *
201      * @generatedBy CodePro at 6/1/16 1:41 PM
202      */
203     @After
204     public void tearDown() throws Exception {
205         // Add additional tear down code here
206     }
207
208     /**
209      * Launch the test.
210      *
211      * @param args
212      *            the command line arguments
213      *
214      * @generatedBy CodePro at 6/1/16 1:41 PM
215      */
216     public static void main(final String[] args) {
217         new org.junit.runner.JUnitCore().run(MatchesTest.class);
218     }
219 }