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
18 package org.onap.holmes.rulemgt.bolt.enginebolt;
\r
20 import org.junit.Before;
\r
21 import org.junit.Test;
\r
22 import org.junit.runner.RunWith;
\r
23 import org.onap.holmes.common.utils.JerseyClient;
\r
24 import org.onap.holmes.rulemgt.bean.request.CorrelationCheckRule4Engine;
\r
25 import org.onap.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine;
\r
26 import org.powermock.core.classloader.annotations.PrepareForTest;
\r
27 import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
\r
28 import org.powermock.modules.junit4.PowerMockRunner;
\r
30 import static org.easymock.EasyMock.*;
\r
31 import static org.hamcrest.Matchers.equalTo;
\r
32 import static org.hamcrest.core.Is.is;
\r
33 import static org.junit.Assert.assertThat;
\r
34 import static org.powermock.api.easymock.PowerMock.createMock;
\r
35 import static org.powermock.api.easymock.PowerMock.*;
\r
37 @RunWith(PowerMockRunner.class)
\r
38 @PrepareForTest(EngineService.class)
\r
39 @SuppressStaticInitializationFor({"org.onap.holmes.common.utils.JerseyClient"})
\r
40 public class EngineServiceTest {
\r
42 private EngineService engineService = new EngineService();
\r
46 public void setUp() throws Exception {
\r
47 System.setProperty("ENABLE_ENCRYPT", "false");
\r
51 public void delete() throws Exception {
\r
52 JerseyClient client = createMock(JerseyClient.class);
\r
53 expectNew(JerseyClient.class).andReturn(client);
\r
54 expect(client.path(anyString())).andReturn(client);
\r
55 expect(client.delete(anyString())).andReturn("true");
\r
57 assertThat(engineService.delete("test", "127.0.0.1"), is(true));
\r
62 public void check() throws Exception {
\r
63 JerseyClient client = createMock(JerseyClient.class);
\r
64 expectNew(JerseyClient.class).andReturn(client);
\r
65 expect(client.header(anyString(), anyString())).andReturn(client);
\r
66 expect(client.post(anyString(), anyObject())).andReturn("true");
\r
68 CorrelationCheckRule4Engine correlationCheckRule4Engine = new CorrelationCheckRule4Engine();
\r
69 correlationCheckRule4Engine.setContent("{\"package\":\"test\"}");
\r
72 assertThat(engineService.check(correlationCheckRule4Engine, "127.0.0.1"), is(true));
\r
77 public void deploy() throws Exception {
\r
78 JerseyClient client = createMock(JerseyClient.class);
\r
79 expectNew(JerseyClient.class).andReturn(client);
\r
80 expect(client.header(anyString(), anyString())).andReturn(client);
\r
81 expect(client.put(anyString(), anyObject())).andReturn("true");
\r
83 CorrelationDeployRule4Engine correlationDeployRule4Engine = new CorrelationDeployRule4Engine();
\r
84 correlationDeployRule4Engine.setContent("{\"package\":\"test\"}");
\r
87 assertThat(engineService.deploy(correlationDeployRule4Engine, "127.0.0.1"), equalTo("true"));
\r