Changes for checkstyle 8.32
[policy/apex-pdp.git] / model / context-model / src / test / java / org / onap / policy / apex / model / contextmodel / concepts / ContextModelTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  *  Modifications Copyright (C) 2019 Nordix Foundation.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  * 
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  * 
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  * 
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.apex.model.contextmodel.concepts;
23
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertFalse;
26 import static org.junit.Assert.assertNotEquals;
27 import static org.junit.Assert.assertNotNull;
28 import static org.junit.Assert.assertTrue;
29
30 import org.junit.Test;
31 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
32 import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation;
33
34 /**
35  * Context model tests.
36  * 
37  * @author Liam Fallon (liam.fallon@ericsson.com)
38  */
39 public class ContextModelTest {
40
41     @Test
42     public void test() {
43         assertNotNull(new AxContextModel());
44         assertNotNull(new AxContextModel(new AxArtifactKey()));
45         assertNotNull(new AxContextModel(new AxArtifactKey(), new AxContextSchemas(), new AxKeyInformation()));
46         assertNotNull(new AxContextModel(new AxArtifactKey(), new AxContextSchemas(), new AxContextAlbums(),
47                         new AxKeyInformation()));
48
49         final AxArtifactKey modelKey = new AxArtifactKey("ModelKey", "0.0.1");
50         final AxArtifactKey schemasKey = new AxArtifactKey("SchemasKey", "0.0.1");
51         final AxArtifactKey albumsKey = new AxArtifactKey("SchemasKey", "0.0.1");
52         final AxArtifactKey keyInfoKey = new AxArtifactKey("SchemasKey", "0.0.1");
53         final AxContextModel model = new AxContextModel(modelKey, new AxContextSchemas(schemasKey),
54                         new AxContextAlbums(albumsKey), new AxKeyInformation(keyInfoKey));
55         model.register();
56
57         model.clean();
58         assertNotNull(model);
59         assertEquals("AxContextModel:(AxContextModel:(key=AxArtifactKey:", model.toString().substring(0, 50));
60
61         final AxContextModel clonedModel = new AxContextModel(model);
62
63         assertFalse(model.hashCode() == 0);
64
65         assertTrue(model.equals(model));
66         assertTrue(model.equals(clonedModel));
67         assertFalse(model.equals((Object) "Hello"));
68         assertFalse(model.equals(new AxContextModel(new AxArtifactKey())));
69         assertFalse(model.equals(new AxContextModel(new AxArtifactKey(), new AxContextSchemas(), new AxContextAlbums(),
70                         new AxKeyInformation())));
71         assertFalse(model.equals(new AxContextModel(modelKey, new AxContextSchemas(), new AxContextAlbums(),
72                         new AxKeyInformation())));
73         assertFalse(model.equals(new AxContextModel(modelKey, new AxContextSchemas(), new AxContextAlbums(),
74                         new AxKeyInformation(keyInfoKey))));
75         assertFalse(model.equals(new AxContextModel(modelKey, new AxContextSchemas(schemasKey), new AxContextAlbums(),
76                         new AxKeyInformation(keyInfoKey))));
77         assertTrue(model.equals(new AxContextModel(modelKey, new AxContextSchemas(schemasKey),
78                         new AxContextAlbums(albumsKey), new AxKeyInformation(keyInfoKey))));
79
80         assertEquals(0, model.compareTo(model));
81         assertEquals(0, model.compareTo(clonedModel));
82         assertNotEquals(0, model.compareTo(new AxArtifactKey()));
83         assertNotEquals(0, model.compareTo(new AxContextModel(new AxArtifactKey(), new AxContextSchemas(),
84                         new AxContextAlbums(), new AxKeyInformation())));
85         assertNotEquals(0, model.compareTo(new AxContextModel(modelKey, new AxContextSchemas(), new AxContextAlbums(),
86                         new AxKeyInformation())));
87         assertNotEquals(0, model.compareTo(new AxContextModel(modelKey, new AxContextSchemas(), new AxContextAlbums(),
88                         new AxKeyInformation(keyInfoKey))));
89         assertNotEquals(0, model.compareTo(new AxContextModel(modelKey, new AxContextSchemas(schemasKey),
90                         new AxContextAlbums(), new AxKeyInformation(keyInfoKey))));
91         assertEquals(0, model.compareTo(new AxContextModel(modelKey, new AxContextSchemas(schemasKey),
92                         new AxContextAlbums(albumsKey), new AxKeyInformation(keyInfoKey))));
93     }
94 }