Removed Dependency: httpclient
[holmes/rule-management.git] / rulemgt / src / test / java / org / onap / holmes / rulemgt / bolt / enginebolt / EngineServiceTest.java
1 /**\r
2  * Copyright 2017 - 2021 ZTE Corporation.\r
3  * <p>\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
7  * <p>\r
8  * http://www.apache.org/licenses/LICENSE-2.0\r
9  * <p>\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
15  */\r
16 \r
17 \r
18 package org.onap.holmes.rulemgt.bolt.enginebolt;\r
19 \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
29 \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
36 \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
41 \r
42     private EngineService engineService = new EngineService();\r
43     ;\r
44 \r
45     @Before\r
46     public void setUp() throws Exception {\r
47         System.setProperty("ENABLE_ENCRYPT", "false");\r
48     }\r
49 \r
50     @Test\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
56         replayAll();\r
57         assertThat(engineService.delete("test", "127.0.0.1"), is(true));\r
58         verifyAll();\r
59     }\r
60 \r
61     @Test\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
67 \r
68         CorrelationCheckRule4Engine correlationCheckRule4Engine = new CorrelationCheckRule4Engine();\r
69         correlationCheckRule4Engine.setContent("{\"package\":\"test\"}");\r
70 \r
71         replayAll();\r
72         assertThat(engineService.check(correlationCheckRule4Engine, "127.0.0.1"), is(true));\r
73         verifyAll();\r
74     }\r
75 \r
76     @Test\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
82 \r
83         CorrelationDeployRule4Engine correlationDeployRule4Engine = new CorrelationDeployRule4Engine();\r
84         correlationDeployRule4Engine.setContent("{\"package\":\"test\"}");\r
85 \r
86         replayAll();\r
87         assertThat(engineService.deploy(correlationDeployRule4Engine, "127.0.0.1"), equalTo("true"));\r
88         verifyAll();\r
89     }\r
90 }