b148ef6beedd77b02357d3c66868a0962e5612c2
[policy/apex-pdp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
4  *  Modifications Copyright (C) 2019-2020 Nordix Foundation.
5  *  Modifications Copyright (C) 2021 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  *
19  * SPDX-License-Identifier: Apache-2.0
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.policy.apex.model.contextmodel.concepts;
24
25 import static org.assertj.core.api.Assertions.assertThat;
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertNotEquals;
28 import static org.junit.Assert.assertNotNull;
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         assertThat(model.toString()).startsWith("AxContextModel(super=AxContextModel:(key=AxArtifactKey:");
60
61         final AxContextModel clonedModel = new AxContextModel(model);
62
63         assertNotEquals(0, model.hashCode());
64
65         // disabling sonar because this code tests the equals() method
66         assertEquals(model, model); // NOSONAR
67         assertEquals(model, clonedModel);
68         assertNotEquals(model, (Object) "Hello");
69         assertNotEquals(model, new AxContextModel(new AxArtifactKey()));
70         assertNotEquals(model, new AxContextModel(new AxArtifactKey(), new AxContextSchemas(), new AxContextAlbums(),
71                         new AxKeyInformation()));
72         assertNotEquals(model, new AxContextModel(modelKey, new AxContextSchemas(), new AxContextAlbums(),
73                         new AxKeyInformation()));
74         assertNotEquals(model, new AxContextModel(modelKey, new AxContextSchemas(), new AxContextAlbums(),
75                         new AxKeyInformation(keyInfoKey)));
76         assertNotEquals(model, new AxContextModel(modelKey, new AxContextSchemas(schemasKey), new AxContextAlbums(),
77                         new AxKeyInformation(keyInfoKey)));
78         assertEquals(model, new AxContextModel(modelKey, new AxContextSchemas(schemasKey),
79                         new AxContextAlbums(albumsKey), new AxKeyInformation(keyInfoKey)));
80
81         assertEquals(0, model.compareTo(model));
82         assertEquals(0, model.compareTo(clonedModel));
83         assertNotEquals(0, model.compareTo(new AxArtifactKey()));
84         assertNotEquals(0, model.compareTo(new AxContextModel(new AxArtifactKey(), new AxContextSchemas(),
85                         new AxContextAlbums(), new AxKeyInformation())));
86         assertNotEquals(0, model.compareTo(new AxContextModel(modelKey, new AxContextSchemas(), new AxContextAlbums(),
87                         new AxKeyInformation())));
88         assertNotEquals(0, model.compareTo(new AxContextModel(modelKey, new AxContextSchemas(), new AxContextAlbums(),
89                         new AxKeyInformation(keyInfoKey))));
90         assertNotEquals(0, model.compareTo(new AxContextModel(modelKey, new AxContextSchemas(schemasKey),
91                         new AxContextAlbums(), new AxKeyInformation(keyInfoKey))));
92         assertEquals(0, model.compareTo(new AxContextModel(modelKey, new AxContextSchemas(schemasKey),
93                         new AxContextAlbums(albumsKey), new AxKeyInformation(keyInfoKey))));
94     }
95 }