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