163e50018b7c881c0b3b2bd9db3d07e686fa477b
[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  * @author Liam Fallon (liam.fallon@ericsson.com)
38  */
39 public class TestContextModel {
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(), new AxKeyInformation()));
47         
48         final AxArtifactKey modelKey = new AxArtifactKey("ModelKey", "0.0.1");
49         final AxArtifactKey schemasKey = new AxArtifactKey("SchemasKey", "0.0.1");
50         final AxArtifactKey albumsKey = new AxArtifactKey("SchemasKey", "0.0.1");
51         final AxArtifactKey keyInfoKey = new AxArtifactKey("SchemasKey", "0.0.1");
52         final AxContextModel model = new AxContextModel(modelKey, new AxContextSchemas(schemasKey), 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         assertFalse(model.hashCode() == 0);
62
63         assertTrue(model.equals(model));
64         assertTrue(model.equals(clonedModel));
65         assertFalse(model.equals("Hello"));
66         assertFalse(model.equals(new AxContextModel(new AxArtifactKey())));
67         assertFalse(model.equals(new AxContextModel(new AxArtifactKey(), new AxContextSchemas(), new AxContextAlbums(), new AxKeyInformation())));
68         assertFalse(model.equals(new AxContextModel(modelKey, new AxContextSchemas(), new AxContextAlbums(), new AxKeyInformation())));
69         assertFalse(model.equals(new AxContextModel(modelKey, new AxContextSchemas(), new AxContextAlbums(), new AxKeyInformation(keyInfoKey))));
70         assertFalse(model.equals(new AxContextModel(modelKey, new AxContextSchemas(schemasKey), new AxContextAlbums(), new AxKeyInformation(keyInfoKey))));
71         assertTrue(model.equals(new AxContextModel(modelKey, new AxContextSchemas(schemasKey), new AxContextAlbums(albumsKey), new AxKeyInformation(keyInfoKey))));
72
73         assertEquals(0, model.compareTo(model));
74         assertEquals(0, model.compareTo(clonedModel));
75         assertNotEquals(0, model.compareTo(new AxArtifactKey()));
76         assertNotEquals(0, model.compareTo(new AxContextModel(new AxArtifactKey(), new AxContextSchemas(), new AxContextAlbums(), new AxKeyInformation())));
77         assertNotEquals(0, model.compareTo(new AxContextModel(modelKey, new AxContextSchemas(), new AxContextAlbums(), new AxKeyInformation())));
78         assertNotEquals(0, model.compareTo(new AxContextModel(modelKey, new AxContextSchemas(), new AxContextAlbums(), new AxKeyInformation(keyInfoKey))));
79         assertNotEquals(0, model.compareTo(new AxContextModel(modelKey, new AxContextSchemas(schemasKey), new AxContextAlbums(), new AxKeyInformation(keyInfoKey))));
80         assertEquals(0, model.compareTo(new AxContextModel(modelKey, new AxContextSchemas(schemasKey), new AxContextAlbums(albumsKey), new AxKeyInformation(keyInfoKey))));
81     }
82 }