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.policy.std.test;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotEquals;
26 import java.util.Collections;
27 import java.util.HashMap;
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;
37 * The class <code>MatchesTest</code> contains tests for the class
38 * <code>{@link Matches}</code>.
40 * @generatedBy CodePro at 6/1/16 1:41 PM
41 * @version $Revision: 1.0 $
43 public class MatchesTest {
44 private static final String DUMMY_VAL = "SomethingElse";
46 private static final String CONFIG_NAME = "CONFIG_NAME";
48 private static final String ONAP_NAME = "ONAP_NAME";
51 public void testMatches_SetterGetterMethods() {
52 final Matches objUnderTest = getMatches(ONAP_NAME, CONFIG_NAME, Collections.emptyMap());
54 final Map<String, String> result = objUnderTest.getConfigAttributes();
56 assertEquals(ONAP_NAME, objUnderTest.getOnapName());
57 assertEquals(CONFIG_NAME, objUnderTest.getConfigName());
58 assertEquals(0, result.size());
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());
66 assertEquals(firstObject, secondObject);
67 assertEquals(firstObject.hashCode(), secondObject.hashCode());
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());
75 assertNotEquals(firstObject, secondObject);
76 assertNotEquals(firstObject.hashCode(), secondObject.hashCode());
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));
87 public void testMatchesEqualsMethod_nullObject_NotEqualsAndDifferentHashCode() {
88 final String firstObject = null;
89 final Matches secondObject = getMatches(ONAP_NAME, CONFIG_NAME, Collections.emptyMap());
91 assertNotEquals(firstObject, secondObject);
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());
99 assertNotEquals(firstObject, secondObject);
100 assertNotEquals(firstObject.hashCode(), secondObject.hashCode());
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());
108 assertNotEquals(firstObject, secondObject);
109 assertNotEquals(firstObject.hashCode(), secondObject.hashCode());
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());
117 assertNotEquals(firstObject, secondObject);
118 assertNotEquals(firstObject.hashCode(), secondObject.hashCode());
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());
126 assertEquals(firstObject, secondObject);
127 assertEquals(firstObject.hashCode(), secondObject.hashCode());
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());
135 assertEquals(firstObject, secondObject);
136 assertEquals(firstObject.hashCode(), secondObject.hashCode());
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");
145 final Matches firstObject = getMatches(ONAP_NAME, CONFIG_NAME, firstMap);
146 final Matches secondObject = getMatches(ONAP_NAME, CONFIG_NAME, secondMap);
148 assertNotEquals(firstObject, secondObject);
149 assertNotEquals(firstObject.hashCode(), secondObject.hashCode());
153 public void testMatchesEqualsMethod_NullConfigAttr_NotEqualsAndDifferentHashCode() throws Exception {
154 final Map<String, String> secondMap = new HashMap<>();
155 secondMap.put("key", "value");
157 final Matches firstObject = getMatches(ONAP_NAME, CONFIG_NAME, null);
158 final Matches secondObject = getMatches(ONAP_NAME, CONFIG_NAME, secondMap);
160 assertNotEquals(firstObject, secondObject);
161 assertNotEquals(firstObject.hashCode(), secondObject.hashCode());
165 public void testMatchesEqualsMethod_BothNullConfigAttr_Equals() throws Exception {
167 final Matches firstObject = getMatches(ONAP_NAME, CONFIG_NAME, null);
168 final Matches secondObject = getMatches(ONAP_NAME, CONFIG_NAME, null);
170 assertEquals(firstObject, secondObject);
171 assertEquals(firstObject.hashCode(), secondObject.hashCode());
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);
183 * Perform pre-test initialization.
186 * if the initialization fails for some reason
188 * @generatedBy CodePro at 6/1/16 1:41 PM
191 public void setUp() throws Exception {
192 // add additional set up code here
196 * Perform post-test clean-up.
199 * if the clean-up fails for some reason
201 * @generatedBy CodePro at 6/1/16 1:41 PM
204 public void tearDown() throws Exception {
205 // Add additional tear down code here
212 * the command line arguments
214 * @generatedBy CodePro at 6/1/16 1:41 PM
216 public static void main(final String[] args) {
217 new org.junit.runner.JUnitCore().run(MatchesTest.class);