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.openecomp.appc.metadata.objects;
27 import org.junit.Assert;
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.powermock.reflect.Whitebox;
32 import static org.openecomp.appc.metadata.objects.DependencyModelIdentifier.prime;
34 public class DependencyModelIdentifierTest {
35 private static final String vnfType = "vnfType";
36 private static final String vnfType2 = "vnfType2";
37 private static final String cVersion = "catalogVersion";
38 private DependencyModelIdentifier identifier;
39 private DependencyModelIdentifier identifier1;
40 private DependencyModelIdentifier identifier2;
41 private DependencyModelIdentifier identifier3;
44 public void setUp() throws Exception {
45 identifier = new DependencyModelIdentifier(vnfType, cVersion);
46 identifier1 = new DependencyModelIdentifier(null, null);
47 identifier2 = new DependencyModelIdentifier(vnfType, null);
48 identifier3 = new DependencyModelIdentifier(null, cVersion);
52 public void testConstructorAndGetterAndToString() throws Exception {
53 Assert.assertEquals(vnfType, Whitebox.getInternalState(identifier, "vnfType"));
54 Assert.assertEquals(cVersion, Whitebox.getInternalState(identifier, "catalogVersion"));
56 Assert.assertEquals(vnfType, identifier.getVnfType());
57 Assert.assertEquals(cVersion, identifier.getCatalogVersion());
59 Assert.assertEquals(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(), identifier.hashCode());
66 Assert.assertEquals(prime * prime, identifier1.hashCode());
67 Assert.assertEquals((prime + vnfType.hashCode()) * prime , identifier2.hashCode());
68 Assert.assertEquals(prime* prime + cVersion.hashCode(), identifier3.hashCode());
72 public void testEquals() throws Exception {
73 // other object is null
74 Assert.assertFalse(identifier.equals(null));
75 // other object is wrong data type
76 Assert.assertFalse(identifier.equals("abc"));
79 Assert.assertFalse(identifier1.equals(identifier));
81 DependencyModelIdentifier identifier4 = new DependencyModelIdentifier(vnfType2, cVersion);
82 Assert.assertFalse(identifier.equals(identifier4));
83 // same vnfType, my catalogVerson is null
84 Assert.assertFalse(identifier2.equals(identifier));
85 // same vnfType and both catalogVersion are null
86 identifier4 = new DependencyModelIdentifier(vnfType, null);
87 Assert.assertTrue(identifier2.equals(identifier4));
89 Assert.assertFalse(identifier.equals(identifier1));
90 Assert.assertFalse(identifier.equals(identifier2));
91 Assert.assertFalse(identifier.equals(identifier3));
93 Assert.assertFalse(identifier2.equals(identifier1));
94 Assert.assertFalse(identifier2.equals(identifier3));
97 Assert.assertFalse(identifier3.equals(identifier));
98 Assert.assertFalse(identifier3.equals(identifier1));
99 Assert.assertFalse(identifier3.equals(identifier2));
101 identifier4 = new DependencyModelIdentifier(vnfType, cVersion);
102 Assert.assertTrue(identifier.equals(identifier4));