72d671f87ff57eaf8d07f0d1520fe3e913170c24
[policy/apex-pdp.git] / core / core-protocols / src / test / java / org / onap / policy / apex / core / protocols / engdep / messages / EngineServiceInfoResponseTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 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.core.protocols.engdep.messages;
23
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertFalse;
26 import static org.junit.Assert.assertNotNull;
27 import static org.junit.Assert.assertTrue;
28
29 import java.util.ArrayList;
30 import java.util.List;
31
32 import org.junit.Test;
33 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
34
35 /**
36  * Test the start engine message.
37  */
38 public class EngineServiceInfoResponseTest {
39
40     @Test
41     public void test() {
42         AxArtifactKey targetKey = new AxArtifactKey("Target:0.0.1");
43         GetEngineServiceInfo request = new GetEngineServiceInfo(targetKey);
44         
45         EngineServiceInfoResponse response = new EngineServiceInfoResponse(targetKey, true, request);
46         assertNotNull(response);
47         response = new EngineServiceInfoResponse(targetKey, true, "Response Data", request);
48         assertNotNull(response);
49         assertEquals("Response Data", response.getMessageData());
50         
51         AxArtifactKey apexModelKey = new AxArtifactKey("Model:0.0.1");
52         response.setApexModelKey(apexModelKey);
53         assertEquals(apexModelKey, response.getApexModelKey());
54         
55         AxArtifactKey engineServiceKey = new AxArtifactKey("EngineService:0.0.1");
56         response.setEngineServiceKey(engineServiceKey);;
57         assertEquals(engineServiceKey, response.getEngineServiceKey());
58         
59         List<AxArtifactKey> engineKeyArrayList = new ArrayList<>();
60         AxArtifactKey engineKey = new AxArtifactKey("Engine:0.0.1");
61         engineKeyArrayList.add(engineKey);
62         response.setEngineKeyArray(engineKeyArrayList);
63         assertEquals(engineKeyArrayList.get(0), response.getEngineKeyArray()[0]);
64         
65         response = new EngineServiceInfoResponse(null, false, null);
66         assertTrue(response.hashCode() != 0);
67         response.setApexModelKey(apexModelKey);
68         assertTrue(response.hashCode() != 0);
69         response.setApexModelKey(null);
70         response.setEngineServiceKey(engineServiceKey);;
71         assertTrue(response.hashCode() != 0);
72         response.setEngineServiceKey(null);
73         response.setEngineKeyArray(engineKeyArrayList);
74         assertTrue(response.hashCode() != 0);
75         response.setEngineKeyArray(null);
76         
77         assertTrue(response.equals(response));
78         assertFalse(response.equals(null));
79         assertFalse(response.equals((Object)new StartEngine(new AxArtifactKey())));
80
81         response = new EngineServiceInfoResponse(null, false, null);
82         EngineServiceInfoResponse otherResponse = new EngineServiceInfoResponse(null, false, null);
83
84         response.setApexModelKey(apexModelKey);
85         assertFalse(response.equals(otherResponse));
86         otherResponse.setApexModelKey(apexModelKey);
87         assertTrue(response.equals(otherResponse));
88         response.setApexModelKey(null);
89         assertFalse(response.equals(otherResponse));
90         otherResponse.setApexModelKey(null);
91         assertTrue(response.equals(otherResponse));
92
93         response.setEngineServiceKey(engineServiceKey);
94         assertFalse(response.equals(otherResponse));
95         otherResponse.setEngineServiceKey(engineServiceKey);
96         assertTrue(response.equals(otherResponse));
97         response.setEngineServiceKey(null);
98         assertFalse(response.equals(otherResponse));
99         otherResponse.setEngineServiceKey(null);
100         assertTrue(response.equals(otherResponse));
101
102         response.setEngineKeyArray(engineKeyArrayList);
103         assertFalse(response.equals(otherResponse));
104         otherResponse.setEngineKeyArray(engineKeyArrayList);
105         assertTrue(response.equals(otherResponse));
106         response.setEngineKeyArray(null);
107         assertFalse(response.equals(otherResponse));
108         otherResponse.setEngineKeyArray(null);
109         assertTrue(response.equals(otherResponse));
110
111     }
112 }