2 * Copyright 2017 - 2021 ZTE Corporation.
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 package org.onap.holmes.rulemgt.bolt.enginebolt;
\r
20 import org.junit.After;
\r
21 import org.junit.Before;
\r
22 import org.junit.Rule;
\r
23 import org.junit.Test;
\r
24 import org.junit.rules.ExpectedException;
\r
25 import org.junit.runner.RunWith;
\r
26 import org.onap.holmes.common.exception.CorrelationException;
\r
27 import org.onap.holmes.rulemgt.bean.request.CorrelationCheckRule4Engine;
\r
28 import org.onap.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine;
\r
29 import org.powermock.modules.junit4.PowerMockRunner;
\r
30 import org.powermock.reflect.Whitebox;
\r
32 import static org.easymock.EasyMock.*;
\r
33 import static org.hamcrest.MatcherAssert.assertThat;
\r
34 import static org.hamcrest.Matchers.equalTo;
\r
35 import static org.hamcrest.Matchers.is;
\r
36 import static org.powermock.api.easymock.PowerMock.*;
\r
38 @RunWith(PowerMockRunner.class)
\r
39 public class EngineWrapperTest {
\r
42 public ExpectedException thrown = ExpectedException.none();
\r
44 private EngineWrapper engineWrapper = new EngineWrapper();
\r
46 private EngineService mockedEngineService;
\r
49 public void before() {
\r
50 mockedEngineService = createMock(EngineService.class);
\r
51 Whitebox.setInternalState(engineWrapper, "engineService", mockedEngineService);
\r
55 public void after() {
\r
60 public void deployEngine_fail() throws Exception {
\r
61 thrown.expect(CorrelationException.class);
\r
62 thrown.expectMessage("Failed to deploy the rule!");
\r
64 expect(mockedEngineService.deploy(anyObject(CorrelationDeployRule4Engine.class),
\r
65 anyObject(String.class))).andReturn(null);
\r
69 engineWrapper.deployEngine(new CorrelationDeployRule4Engine(), "127.0.0.1");
\r
75 public void deployEngine_parse_content_exception() throws Exception {
\r
76 thrown.expect(CorrelationException.class);
\r
77 thrown.expectMessage(
\r
78 "Failed to parse the value returned by the engine management service.");
\r
79 expect(mockedEngineService.deploy(anyObject(CorrelationDeployRule4Engine.class),
\r
80 anyObject(String.class))).andReturn("");
\r
84 engineWrapper.deployEngine(new CorrelationDeployRule4Engine(), "127.0.0.1");
\r
90 public void deployEngine_success() throws Exception {
\r
91 String content = "{\"packageName\":\"test\"}";
\r
92 expect(mockedEngineService.deploy(anyObject(CorrelationDeployRule4Engine.class),
\r
93 anyObject(String.class))).andReturn(content);
\r
97 String result = engineWrapper.deployEngine(new CorrelationDeployRule4Engine(), "127.0.0.1");
\r
99 assertThat(result, equalTo("test"));
\r
104 public void deleteRuleFromEngine_fail() throws Exception {
\r
105 thrown.expect(CorrelationException.class);
\r
106 thrown.expectMessage("Failed to delete the rule!");
\r
108 expect(mockedEngineService.delete(anyObject(String.class),
\r
109 anyObject(String.class)))
\r
114 engineWrapper.deleteRuleFromEngine("", "127.0.0.1");
\r
120 public void deleteRuleFromEngine_success() throws Exception {
\r
121 expect(mockedEngineService.delete(anyObject(String.class),
\r
122 anyObject(String.class)))
\r
127 boolean result = engineWrapper.deleteRuleFromEngine("", "127.0.0.1");
\r
129 assertThat(result, equalTo(true));
\r
133 public void checkRuleFromEngine_fail() throws Exception {
\r
134 thrown.expect(CorrelationException.class);
\r
135 thrown.expectMessage("Failed to verify the rule. The contents of the rule are invalid.");
\r
138 mockedEngineService.check(anyObject(CorrelationCheckRule4Engine.class),
\r
139 anyObject(String.class))).andReturn(false);
\r
142 engineWrapper.checkRuleFromEngine(new CorrelationCheckRule4Engine(), "127.0.0.1");
\r
148 public void checkRuleFromEngine_success() throws Exception {
\r
149 expect(mockedEngineService.check(anyObject(CorrelationCheckRule4Engine.class),anyString())).andReturn(true);
\r
153 boolean result = engineWrapper.checkRuleFromEngine(new CorrelationCheckRule4Engine(), "127.0.0.1");
\r
155 assertThat(result, is(true));
\r