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.createMock;
\r
37 import static org.powermock.api.easymock.PowerMock.*;
\r
39 @RunWith(PowerMockRunner.class)
\r
40 public class EngineWrapperTest {
\r
43 public ExpectedException thrown = ExpectedException.none();
\r
45 private EngineWrapper engineWrapper = new EngineWrapper();
\r
47 private EngineService mockedEngineService;
\r
50 public void before() {
\r
51 mockedEngineService = createMock(EngineService.class);
\r
52 Whitebox.setInternalState(engineWrapper, "engineService", mockedEngineService);
\r
56 public void after() {
\r
61 public void deployEngine_fail() throws Exception {
\r
62 thrown.expect(CorrelationException.class);
\r
63 thrown.expectMessage("Failed to deploy the rule!");
\r
65 expect(mockedEngineService.deploy(anyObject(CorrelationDeployRule4Engine.class),
\r
66 anyObject(String.class))).andReturn(null);
\r
70 engineWrapper.deployEngine(new CorrelationDeployRule4Engine(), "127.0.0.1");
\r
76 public void deployEngine_parse_content_exception() throws Exception {
\r
77 thrown.expect(CorrelationException.class);
\r
78 thrown.expectMessage(
\r
79 "Failed to parse the value returned by the engine management service.");
\r
80 expect(mockedEngineService.deploy(anyObject(CorrelationDeployRule4Engine.class),
\r
81 anyObject(String.class))).andReturn("");
\r
85 engineWrapper.deployEngine(new CorrelationDeployRule4Engine(), "127.0.0.1");
\r
91 public void deployEngine_success() throws Exception {
\r
92 String content = "{\"packageName\":\"test\"}";
\r
93 expect(mockedEngineService.deploy(anyObject(CorrelationDeployRule4Engine.class),
\r
94 anyObject(String.class))).andReturn(content);
\r
98 String result = engineWrapper.deployEngine(new CorrelationDeployRule4Engine(), "127.0.0.1");
\r
100 assertThat(result, equalTo("test"));
\r
105 public void deleteRuleFromEngine_fail() throws Exception {
\r
106 thrown.expect(CorrelationException.class);
\r
107 thrown.expectMessage("Failed to delete the rule!");
\r
109 expect(mockedEngineService.delete(anyObject(String.class),
\r
110 anyObject(String.class)))
\r
115 engineWrapper.deleteRuleFromEngine("", "127.0.0.1");
\r
121 public void deleteRuleFromEngine_success() throws Exception {
\r
122 expect(mockedEngineService.delete(anyObject(String.class),
\r
123 anyObject(String.class)))
\r
128 boolean result = engineWrapper.deleteRuleFromEngine("", "127.0.0.1");
\r
130 assertThat(result, equalTo(true));
\r
134 public void checkRuleFromEngine_fail() throws Exception {
\r
135 thrown.expect(CorrelationException.class);
\r
136 thrown.expectMessage("Failed to verify the rule. The contents of the rule are invalid.");
\r
139 mockedEngineService.check(anyObject(CorrelationCheckRule4Engine.class),
\r
140 anyObject(String.class))).andReturn(false);
\r
143 engineWrapper.checkRuleFromEngine(new CorrelationCheckRule4Engine(), "127.0.0.1");
\r
149 public void checkRuleFromEngine_success() throws Exception {
\r
150 expect(mockedEngineService.check(anyObject(CorrelationCheckRule4Engine.class),anyString())).andReturn(true);
\r
154 boolean result = engineWrapper.checkRuleFromEngine(new CorrelationCheckRule4Engine(), "127.0.0.1");
\r
156 assertThat(result, is(true));
\r