99d377261b80b4bec203dc401fbdf6b9241c1b08
[policy/apex-pdp.git] / model / event-model / src / test / java / org / onap / policy / apex / model / eventmodel / concepts / EventModelTest.java
1 /*-
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
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.eventmodel.concepts;
23
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;
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 import org.onap.policy.apex.model.contextmodel.concepts.AxContextSchemas;
34 import org.onap.policy.apex.model.eventmodel.concepts.AxEventModel;
35 import org.onap.policy.apex.model.eventmodel.concepts.AxEvents;
36
37 /**
38  * Test event models.
39  * @author Liam Fallon (liam.fallon@ericsson.com)
40  */
41 public class EventModelTest {
42
43     @Test
44     public void testEventModel() {
45         assertNotNull(new AxEventModel());
46         assertNotNull(new AxEventModel(new AxArtifactKey()));
47         assertNotNull(
48                 new AxEventModel(new AxArtifactKey(), new AxContextSchemas(), new AxKeyInformation(), new AxEvents()));
49
50         final AxArtifactKey modelKey = new AxArtifactKey("ModelKey", "0.0.1");
51         final AxArtifactKey schemasKey = new AxArtifactKey("SchemasKey", "0.0.1");
52         final AxArtifactKey eventsKey = new AxArtifactKey("EventsKey", "0.0.1");
53         final AxArtifactKey keyInfoKey = new AxArtifactKey("SchemasKey", "0.0.1");
54         final AxEventModel model = new AxEventModel(modelKey, new AxContextSchemas(schemasKey),
55                 new AxKeyInformation(keyInfoKey), new AxEvents(eventsKey));
56         model.register();
57
58         model.clean();
59         assertNotNull(model);
60         assertEquals("AxEventModel:(AxEventModel:(key=AxArtifactKey:(nam", model.toString().substring(0, 50));
61
62         final AxEventModel clonedModel = new AxEventModel(model);
63
64         assertFalse(model.hashCode() == 0);
65
66         assertTrue(model.equals(model));
67         assertTrue(model.equals(clonedModel));
68         assertFalse(model.equals((Object)"Hello"));
69         assertFalse(model.equals(new AxEventModel(new AxArtifactKey())));
70         assertFalse(model.equals(new AxEventModel(modelKey, new AxContextSchemas(), new AxKeyInformation(keyInfoKey),
71                 new AxEvents(eventsKey))));
72         assertFalse(model.equals(new AxEventModel(modelKey, new AxContextSchemas(schemasKey), new AxKeyInformation(),
73                 new AxEvents(eventsKey))));
74         assertFalse(model.equals(new AxEventModel(modelKey, new AxContextSchemas(schemasKey),
75                 new AxKeyInformation(keyInfoKey), new AxEvents())));
76         assertTrue(model.equals(new AxEventModel(modelKey, new AxContextSchemas(schemasKey),
77                 new AxKeyInformation(keyInfoKey), new AxEvents(eventsKey))));
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 AxEventModel(modelKey, new AxContextSchemas(),
83                 new AxKeyInformation(keyInfoKey), new AxEvents(eventsKey))));
84         assertNotEquals(0, model.compareTo(new AxEventModel(modelKey, new AxContextSchemas(schemasKey),
85                 new AxKeyInformation(), new AxEvents(eventsKey))));
86         assertNotEquals(0, model.compareTo(new AxEventModel(modelKey, new AxContextSchemas(schemasKey),
87                 new AxKeyInformation(keyInfoKey), new AxEvents())));
88         assertEquals(0, model.compareTo(new AxEventModel(modelKey, new AxContextSchemas(schemasKey),
89                 new AxKeyInformation(keyInfoKey), new AxEvents(eventsKey))));
90     }
91 }