ae6de38f22a722c4dcbdeed82237336a2ae427bd
[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  * ================================================================================
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.assertNotEquals;
26 import static org.junit.Assert.assertNotNull;
27
28 import org.junit.Test;
29 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
30 import org.onap.policy.apex.model.basicmodel.concepts.AxKeyInformation;
31
32 /**
33  * Context model tests.
34  *
35  * @author Liam Fallon (liam.fallon@ericsson.com)
36  */
37 public class ContextModelTest {
38
39     @Test
40     public void test() {
41         assertNotNull(new AxContextModel());
42         assertNotNull(new AxContextModel(new AxArtifactKey()));
43         assertNotNull(new AxContextModel(new AxArtifactKey(), new AxContextSchemas(), new AxKeyInformation()));
44         assertNotNull(new AxContextModel(new AxArtifactKey(), new AxContextSchemas(), new AxContextAlbums(),
45                         new AxKeyInformation()));
46
47         final AxArtifactKey modelKey = new AxArtifactKey("ModelKey", "0.0.1");
48         final AxArtifactKey schemasKey = new AxArtifactKey("SchemasKey", "0.0.1");
49         final AxArtifactKey albumsKey = new AxArtifactKey("SchemasKey", "0.0.1");
50         final AxArtifactKey keyInfoKey = new AxArtifactKey("SchemasKey", "0.0.1");
51         final AxContextModel model = new AxContextModel(modelKey, new AxContextSchemas(schemasKey),
52                         new AxContextAlbums(albumsKey), new AxKeyInformation(keyInfoKey));
53         model.register();
54
55         model.clean();
56         assertNotNull(model);
57         assertEquals("AxContextModel:(AxContextModel:(key=AxArtifactKey:", model.toString().substring(0, 50));
58
59         final AxContextModel clonedModel = new AxContextModel(model);
60
61         assertNotEquals(0, model.hashCode());
62
63         // disabling sonar because this code tests the equals() method
64         assertEquals(model, model); // NOSONAR
65         assertEquals(model, clonedModel);
66         assertNotEquals(model, "Hello");
67         assertNotEquals(model, new AxContextModel(new AxArtifactKey()));
68         assertNotEquals(model, new AxContextModel(new AxArtifactKey(), new AxContextSchemas(), new AxContextAlbums(),
69                         new AxKeyInformation()));
70         assertNotEquals(model, new AxContextModel(modelKey, new AxContextSchemas(), new AxContextAlbums(),
71                         new AxKeyInformation()));
72         assertNotEquals(model, new AxContextModel(modelKey, new AxContextSchemas(), new AxContextAlbums(),
73                         new AxKeyInformation(keyInfoKey)));
74         assertNotEquals(model, new AxContextModel(modelKey, new AxContextSchemas(schemasKey), new AxContextAlbums(),
75                         new AxKeyInformation(keyInfoKey)));
76         assertEquals(model, new AxContextModel(modelKey, new AxContextSchemas(schemasKey),
77                         new AxContextAlbums(albumsKey), new AxKeyInformation(keyInfoKey)));
78
79         assertEquals(0, model.compareTo(model));
80         assertEquals(0, model.compareTo(clonedModel));
81         assertNotEquals(0, model.compareTo(new AxArtifactKey()));
82         assertNotEquals(0, model.compareTo(new AxContextModel(new AxArtifactKey(), new AxContextSchemas(),
83                         new AxContextAlbums(), new AxKeyInformation())));
84         assertNotEquals(0, model.compareTo(new AxContextModel(modelKey, new AxContextSchemas(), new AxContextAlbums(),
85                         new AxKeyInformation())));
86         assertNotEquals(0, model.compareTo(new AxContextModel(modelKey, new AxContextSchemas(), new AxContextAlbums(),
87                         new AxKeyInformation(keyInfoKey))));
88         assertNotEquals(0, model.compareTo(new AxContextModel(modelKey, new AxContextSchemas(schemasKey),
89                         new AxContextAlbums(), new AxKeyInformation(keyInfoKey))));
90         assertEquals(0, model.compareTo(new AxContextModel(modelKey, new AxContextSchemas(schemasKey),
91                         new AxContextAlbums(albumsKey), new AxKeyInformation(keyInfoKey))));
92     }
93 }