2 * ============LICENSE_START=======================================================
3 * Copyright (C) 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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.apex.core.deployment;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNull;
25 import static org.junit.Assert.fail;
27 import java.io.ByteArrayInputStream;
28 import java.io.InputStream;
29 import org.junit.Test;
30 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
33 * Test the deployment web socket client.
35 public class EngineServiceFacadeTest {
37 public void testEngineServiceFacade() throws Exception {
38 EngineServiceFacade facade = new EngineServiceFacade("localhost", 51273);
40 facade.setDeploymentClient(new DummyDeploymentClient("localhost", 51273));
42 // First init should fail
45 assertNull(facade.getKey());
46 assertNull(facade.getApexModelKey());
47 assertNull(facade.getEngineKeyArray());
50 facade.deployModel("src/test/resources/models/SamplePolicyModelJAVASCRIPT.json", false, false);
51 fail("test should throw an exception here");
52 } catch (final Exception ade) {
53 assertEquals("cound not deploy apex model, deployer is not initialized", ade.getMessage());
56 // Second init should work
59 assertEquals("EngineService:0.0.1", facade.getKey().getId());
60 assertEquals("Model:0.0.1", facade.getApexModelKey().getId());
61 assertEquals("Engine:0.0.1", facade.getEngineKeyArray()[0].getId());
64 facade.deployModel("src/test/resources/models/NonExistantModel.json", false, false);
65 fail("test should throw an exception here");
66 } catch (final Exception ade) {
67 assertEquals("cound not create apex model, could not read from file "
68 + "src/test/resources/models/NonExistantModel.json", ade.getMessage());
72 facade.deployModel("src/test/resources/models/JunkModel.json", false, false);
73 fail("test should throw an exception here");
74 } catch (final Exception ade) {
75 assertEquals("could not deploy apex model from src/test/resources/models/JunkModel.json", ade.getMessage());
78 InputStream badStream = new ByteArrayInputStream("".getBytes());
80 facade.deployModel("MyModel", badStream, false, false);
81 fail("test should throw an exception here");
82 } catch (final Exception ade) {
83 assertEquals("format of input for Apex concept is neither JSON nor XML", ade.getMessage());
86 InputStream closedStream = new ByteArrayInputStream("".getBytes());
89 facade.deployModel("MyModel", closedStream, false, false);
90 fail("test should throw an exception here");
91 } catch (final Exception ade) {
92 assertEquals("format of input for Apex concept is neither JSON nor XML", ade.getMessage());
96 facade.deployModel("src/test/resources/models/SmallModel.json", false, false);
97 fail("test should throw an exception here");
98 } catch (final Exception ade) {
99 assertEquals("could not deploy apex model from src/test/resources/models/SmallModel.json",
104 facade.deployModel("src/test/resources/models/SmallModel.json", false, false);
105 } catch (final Exception ade) {
106 fail("test should not throw an exception here");
110 facade.startEngine(facade.getEngineKeyArray()[0]);
111 fail("test should throw an exception here");
112 } catch (final Exception ade) {
113 assertEquals("failed response Operation failed received from serverlocalhost:51273", ade.getMessage());
117 facade.startEngine(facade.getEngineKeyArray()[0]);
118 } catch (final Exception ade) {
119 fail("test should not throw an exception here");
123 facade.stopEngine(facade.getEngineKeyArray()[0]);
124 fail("test should throw an exception here");
125 } catch (final Exception ade) {
126 assertEquals("failed response Operation failed received from serverlocalhost:51273", ade.getMessage());
130 facade.stopEngine(facade.getEngineKeyArray()[0]);
131 } catch (final Exception ade) {
132 fail("test should not throw an exception here");
136 facade.startPerioidicEvents(facade.getEngineKeyArray()[0], 1000);
137 fail("test should throw an exception here");
138 } catch (final Exception ade) {
139 assertEquals("failed response Operation failed received from serverlocalhost:51273", ade.getMessage());
143 facade.startPerioidicEvents(facade.getEngineKeyArray()[0], 1000);
144 } catch (final Exception ade) {
145 fail("test should not throw an exception here");
149 facade.stopPerioidicEvents(facade.getEngineKeyArray()[0]);
150 fail("test should throw an exception here");
151 } catch (final Exception ade) {
152 assertEquals("failed response Operation failed received from serverlocalhost:51273", ade.getMessage());
156 facade.stopPerioidicEvents(facade.getEngineKeyArray()[0]);
157 } catch (final Exception ade) {
158 fail("test should not throw an exception here");
162 facade.getEngineStatus(facade.getEngineKeyArray()[0]);
163 fail("test should throw an exception here");
164 } catch (final Exception ade) {
165 assertEquals("failed response Operation failed received from serverlocalhost:51273", ade.getMessage());
169 facade.getEngineStatus(facade.getEngineKeyArray()[0]);
170 } catch (final Exception ade) {
171 fail("test should not throw an exception here");
175 facade.getEngineInfo(facade.getEngineKeyArray()[0]);
176 fail("test should throw an exception here");
177 } catch (final Exception ade) {
178 assertEquals("failed response Operation failed received from serverlocalhost:51273", ade.getMessage());
182 facade.getEngineInfo(facade.getEngineKeyArray()[0]);
183 } catch (final Exception ade) {
184 fail("test should not throw an exception here");
188 facade.getEngineStatus(new AxArtifactKey("ReturnBadMessage", "0.0.1"));
189 fail("test should throw an exception here");
190 } catch (final Exception ade) {
191 assertEquals("response received from server is of incorrect type "
192 + "org.onap.policy.apex.core.protocols.engdep.messages.GetEngineStatus, should be of type "
193 + "org.onap.policy.apex.core.protocols.engdep.messages.Response", ade.getMessage());
197 facade.getEngineStatus(new AxArtifactKey("ReturnBadResponse", "0.0.1"));
198 fail("test should throw an exception here");
199 } catch (final Exception ade) {
200 assertEquals("response received is not correct response to sent message GET_ENGINE_STATUS",
205 facade.getEngineStatus(new AxArtifactKey("DoNotRespond", "0.0.1"));
206 fail("test should throw an exception here");
207 } catch (final Exception ade) {
208 assertEquals("no response received to sent message GET_ENGINE_STATUS", ade.getMessage());