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;
30 import org.junit.Test;
31 import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
34 * Test the deployment web socket client.
36 public class EngineServiceFacadeTest {
38 public void testEngineServiceFacade() throws Exception {
39 EngineServiceFacade facade = new EngineServiceFacade("localhost", 51273);
41 facade.setDeploymentClient(new DummyDeploymentClient("localhost", 51273));
43 // First init should fail
46 assertNull(facade.getKey());
47 assertNull(facade.getApexModelKey());
48 assertNull(facade.getEngineKeyArray());
51 facade.deployModel("src/test/resources/models/SamplePolicyModelJAVASCRIPT.json", false, false);
52 fail("test should throw an exception here");
53 } catch (final Exception ade) {
54 assertEquals("cound not deploy apex model, deployer is not initialized", ade.getMessage());
57 // Second init should work
60 assertEquals("EngineService:0.0.1", facade.getKey().getId());
61 assertEquals("Model:0.0.1", facade.getApexModelKey().getId());
62 assertEquals("Engine:0.0.1", facade.getEngineKeyArray()[0].getId());
65 facade.deployModel("src/test/resources/models/NonExistantModel.json", false, false);
66 fail("test should throw an exception here");
67 } catch (final Exception ade) {
68 assertEquals("cound not create apex model, could not read from file "
69 + "src/test/resources/models/NonExistantModel.json", ade.getMessage());
73 facade.deployModel("src/test/resources/models/JunkModel.json", false, false);
74 fail("test should throw an exception here");
75 } catch (final Exception ade) {
76 assertEquals("could not deploy apex model from src/test/resources/models/JunkModel.json", ade.getMessage());
79 InputStream badStream = new ByteArrayInputStream("".getBytes());
81 facade.deployModel("MyModel", badStream, false, false);
82 fail("test should throw an exception here");
83 } catch (final Exception ade) {
84 assertEquals("format of input for Apex concept is neither JSON nor XML", ade.getMessage());
87 InputStream closedStream = new ByteArrayInputStream("".getBytes());
90 facade.deployModel("MyModel", closedStream, false, false);
91 fail("test should throw an exception here");
92 } catch (final Exception ade) {
93 assertEquals("format of input for Apex concept is neither JSON nor XML", ade.getMessage());
97 facade.deployModel("src/test/resources/models/SmallModel.json", false, false);
98 fail("test should throw an exception here");
99 } catch (final Exception ade) {
100 assertEquals("could not deploy apex model from src/test/resources/models/SmallModel.json",
105 facade.deployModel("src/test/resources/models/SmallModel.json", false, false);
106 } catch (final Exception ade) {
107 fail("test should not throw an exception here");
111 facade.startEngine(facade.getEngineKeyArray()[0]);
112 fail("test should throw an exception here");
113 } catch (final Exception ade) {
114 assertEquals("failed response Operation failed received from serverlocalhost:51273", ade.getMessage());
118 facade.startEngine(facade.getEngineKeyArray()[0]);
119 } catch (final Exception ade) {
120 fail("test should not throw an exception here");
124 facade.stopEngine(facade.getEngineKeyArray()[0]);
125 fail("test should throw an exception here");
126 } catch (final Exception ade) {
127 assertEquals("failed response Operation failed received from serverlocalhost:51273", ade.getMessage());
131 facade.stopEngine(facade.getEngineKeyArray()[0]);
132 } catch (final Exception ade) {
133 fail("test should not throw an exception here");
137 facade.startPerioidicEvents(facade.getEngineKeyArray()[0], 1000);
138 fail("test should throw an exception here");
139 } catch (final Exception ade) {
140 assertEquals("failed response Operation failed received from serverlocalhost:51273", ade.getMessage());
144 facade.startPerioidicEvents(facade.getEngineKeyArray()[0], 1000);
145 } catch (final Exception ade) {
146 fail("test should not throw an exception here");
150 facade.stopPerioidicEvents(facade.getEngineKeyArray()[0]);
151 fail("test should throw an exception here");
152 } catch (final Exception ade) {
153 assertEquals("failed response Operation failed received from serverlocalhost:51273", ade.getMessage());
157 facade.stopPerioidicEvents(facade.getEngineKeyArray()[0]);
158 } catch (final Exception ade) {
159 fail("test should not throw an exception here");
163 facade.getEngineStatus(facade.getEngineKeyArray()[0]);
164 fail("test should throw an exception here");
165 } catch (final Exception ade) {
166 assertEquals("failed response Operation failed received from serverlocalhost:51273", ade.getMessage());
170 facade.getEngineStatus(facade.getEngineKeyArray()[0]);
171 } catch (final Exception ade) {
172 fail("test should not throw an exception here");
176 facade.getEngineInfo(facade.getEngineKeyArray()[0]);
177 fail("test should throw an exception here");
178 } catch (final Exception ade) {
179 assertEquals("failed response Operation failed received from serverlocalhost:51273", ade.getMessage());
183 facade.getEngineInfo(facade.getEngineKeyArray()[0]);
184 } catch (final Exception ade) {
185 fail("test should not throw an exception here");
189 facade.getEngineStatus(new AxArtifactKey("ReturnBadMessage", "0.0.1"));
190 fail("test should throw an exception here");
191 } catch (final Exception ade) {
192 assertEquals("response received from server is of incorrect type "
193 + "org.onap.policy.apex.core.protocols.engdep.messages.GetEngineStatus, should be of type "
194 + "org.onap.policy.apex.core.protocols.engdep.messages.Response", ade.getMessage());
198 facade.getEngineStatus(new AxArtifactKey("ReturnBadResponse", "0.0.1"));
199 fail("test should throw an exception here");
200 } catch (final Exception ade) {
201 assertEquals("response received is not correct response to sent message GET_ENGINE_STATUS",
206 facade.getEngineStatus(new AxArtifactKey("DoNotRespond", "0.0.1"));
207 fail("test should throw an exception here");
208 } catch (final Exception ade) {
209 assertEquals("no response received to sent message GET_ENGINE_STATUS", ade.getMessage());