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