2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Copyright (C) 2017 Amdocs
8 * =============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 * ============LICENSE_END=========================================================
25 package org.onap.appc.metadata.objects;
27 import static org.onap.appc.metadata.objects.DependencyModelIdentifier.prime;
28 import org.junit.Assert;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.powermock.reflect.Whitebox;
33 public class DependencyModelIdentifierTest {
34 private static final String vnfType = "vnfType";
35 private static final String vnfType2 = "vnfType2";
36 private static final String cVersion = "catalogVersion";
37 private DependencyModelIdentifier identifier;
38 private DependencyModelIdentifier identifier1;
39 private DependencyModelIdentifier identifier2;
40 private DependencyModelIdentifier identifier3;
43 public void setUp() throws Exception {
44 identifier = new DependencyModelIdentifier(vnfType, cVersion);
45 identifier1 = new DependencyModelIdentifier(null, null);
46 identifier2 = new DependencyModelIdentifier(vnfType, null);
47 identifier3 = new DependencyModelIdentifier(null, cVersion);
51 public void testConstructorAndGetterAndToString() throws Exception {
52 Assert.assertEquals(vnfType, Whitebox.getInternalState(identifier, "vnfType"));
53 Assert.assertEquals(cVersion, Whitebox.getInternalState(identifier, "catalogVersion"));
55 Assert.assertEquals(vnfType, identifier.getVnfType());
56 Assert.assertEquals(cVersion, identifier.getCatalogVersion());
59 String.format(DependencyModelIdentifier.TO_STRING_FORMAT, vnfType, cVersion),
60 identifier.toString());
64 public void testHashCode() throws Exception {
65 Assert.assertEquals((prime + vnfType.hashCode()) * prime + cVersion.hashCode(),
66 identifier.hashCode());
67 Assert.assertEquals(prime * prime, identifier1.hashCode());
68 Assert.assertEquals((prime + vnfType.hashCode()) * prime, identifier2.hashCode());
69 Assert.assertEquals(prime * prime + cVersion.hashCode(), identifier3.hashCode());
73 public void testEquals() throws Exception {
74 // other object is null
75 Assert.assertFalse(identifier.equals(null));
76 // other object is wrong data type
77 Assert.assertFalse(identifier.equals("abc"));
80 Assert.assertFalse(identifier1.equals(identifier));
82 DependencyModelIdentifier identifier4 = new DependencyModelIdentifier(vnfType2, cVersion);
83 Assert.assertFalse(identifier.equals(identifier4));
84 // same vnfType, my catalogVerson is null
85 Assert.assertFalse(identifier2.equals(identifier));
86 // same vnfType and both catalogVersion are null
87 identifier4 = new DependencyModelIdentifier(vnfType, null);
88 Assert.assertTrue(identifier2.equals(identifier4));
90 Assert.assertFalse(identifier.equals(identifier1));
91 Assert.assertFalse(identifier.equals(identifier2));
92 Assert.assertFalse(identifier.equals(identifier3));
94 Assert.assertFalse(identifier2.equals(identifier1));
95 Assert.assertFalse(identifier2.equals(identifier3));
98 Assert.assertFalse(identifier3.equals(identifier));
99 Assert.assertFalse(identifier3.equals(identifier1));
100 Assert.assertFalse(identifier3.equals(identifier2));
102 identifier4 = new DependencyModelIdentifier(vnfType, cVersion);
103 Assert.assertTrue(identifier.equals(identifier4));