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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.apex.model.contextmodel.concepts;
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;
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 import org.onap.policy.apex.model.contextmodel.concepts.AxContextAlbums;
34 import org.onap.policy.apex.model.contextmodel.concepts.AxContextModel;
35 import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas;
38 * Context model tests.
40 * @author Liam Fallon (liam.fallon@ericsson.com)
42 public class ContextModelTest {
46 assertNotNull(new AxContextModel());
47 assertNotNull(new AxContextModel(new AxArtifactKey()));
48 assertNotNull(new AxContextModel(new AxArtifactKey(), new AxContextSchemas(), new AxKeyInformation()));
49 assertNotNull(new AxContextModel(new AxArtifactKey(), new AxContextSchemas(), new AxContextAlbums(),
50 new AxKeyInformation()));
52 final AxArtifactKey modelKey = new AxArtifactKey("ModelKey", "0.0.1");
53 final AxArtifactKey schemasKey = new AxArtifactKey("SchemasKey", "0.0.1");
54 final AxArtifactKey albumsKey = new AxArtifactKey("SchemasKey", "0.0.1");
55 final AxArtifactKey keyInfoKey = new AxArtifactKey("SchemasKey", "0.0.1");
56 final AxContextModel model = new AxContextModel(modelKey, new AxContextSchemas(schemasKey),
57 new AxContextAlbums(albumsKey), new AxKeyInformation(keyInfoKey));
62 assertEquals("AxContextModel:(AxContextModel:(key=AxArtifactKey:", model.toString().substring(0, 50));
64 final AxContextModel clonedModel = new AxContextModel(model);
66 assertFalse(model.hashCode() == 0);
68 assertTrue(model.equals(model));
69 assertTrue(model.equals(clonedModel));
70 assertFalse(model.equals((Object)"Hello"));
71 assertFalse(model.equals(new AxContextModel(new AxArtifactKey())));
72 assertFalse(model.equals(new AxContextModel(new AxArtifactKey(), new AxContextSchemas(), new AxContextAlbums(),
73 new AxKeyInformation())));
74 assertFalse(model.equals(new AxContextModel(modelKey, new AxContextSchemas(), new AxContextAlbums(),
75 new AxKeyInformation())));
76 assertFalse(model.equals(new AxContextModel(modelKey, new AxContextSchemas(), new AxContextAlbums(),
77 new AxKeyInformation(keyInfoKey))));
78 assertFalse(model.equals(new AxContextModel(modelKey, new AxContextSchemas(schemasKey), new AxContextAlbums(),
79 new AxKeyInformation(keyInfoKey))));
80 assertTrue(model.equals(new AxContextModel(modelKey, new AxContextSchemas(schemasKey),
81 new AxContextAlbums(albumsKey), new AxKeyInformation(keyInfoKey))));
83 assertEquals(0, model.compareTo(model));
84 assertEquals(0, model.compareTo(clonedModel));
85 assertNotEquals(0, model.compareTo(new AxArtifactKey()));
86 assertNotEquals(0, model.compareTo(new AxContextModel(new AxArtifactKey(), new AxContextSchemas(),
87 new AxContextAlbums(), new AxKeyInformation())));
88 assertNotEquals(0, model.compareTo(new AxContextModel(modelKey, new AxContextSchemas(), new AxContextAlbums(),
89 new AxKeyInformation())));
90 assertNotEquals(0, model.compareTo(new AxContextModel(modelKey, new AxContextSchemas(), new AxContextAlbums(),
91 new AxKeyInformation(keyInfoKey))));
92 assertNotEquals(0, model.compareTo(new AxContextModel(modelKey, new AxContextSchemas(schemasKey),
93 new AxContextAlbums(), new AxKeyInformation(keyInfoKey))));
94 assertEquals(0, model.compareTo(new AxContextModel(modelKey, new AxContextSchemas(schemasKey),
95 new AxContextAlbums(albumsKey), new AxKeyInformation(keyInfoKey))));