596a408f90c21c8e6a07b88ab239f9b137a3e72c
[holmes/rule-management.git] / rulemgt / src / test / java / org / openo / holmes / rulemgt / bolt / enginebolt / EngineServiceTest.java
1 /**\r
2  * Copyright 2017 ZTE Corporation.\r
3  *\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  *\r
8  *     http://www.apache.org/licenses/LICENSE-2.0\r
9  *\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.openo.holmes.rulemgt.bolt.enginebolt;\r
19 \r
20 \r
21 import org.apache.http.HttpResponse;\r
22 import org.easymock.EasyMock;\r
23 import org.junit.Before;\r
24 import org.junit.Rule;\r
25 import org.junit.Test;\r
26 import org.junit.rules.ExpectedException;\r
27 import org.openo.holmes.rulemgt.RuleAppConfig;\r
28 import org.openo.holmes.rulemgt.bean.request.CorrelationCheckRule4Engine;\r
29 import org.openo.holmes.rulemgt.bean.request.CorrelationDeployRule4Engine;\r
30 import org.powermock.api.easymock.PowerMock;\r
31 import org.powermock.modules.junit4.rule.PowerMockRule;\r
32 import org.powermock.reflect.Whitebox;\r
33 \r
34 public class EngineServiceTest {\r
35 \r
36     @Rule\r
37     public ExpectedException thrown = ExpectedException.none();\r
38     @Rule\r
39     public PowerMockRule powerMockRule = new PowerMockRule();\r
40     private EngineService engineService;\r
41     private HttpResponse httpResponseMock;\r
42     private RuleAppConfig ruleAppConfig = new RuleAppConfig();\r
43     private CorrelationDeployRule4Engine correlationDeployRule4Engine;\r
44 \r
45     @Before\r
46     public void setUp() {\r
47         engineService = new EngineService();\r
48         httpResponseMock = PowerMock.createMock(HttpResponse.class);\r
49         Whitebox.setInternalState(engineService, "ruleAppConfig", ruleAppConfig);\r
50         correlationDeployRule4Engine = new CorrelationDeployRule4Engine();\r
51         correlationDeployRule4Engine.setContent("{\"package\":\"test\"}");\r
52         correlationDeployRule4Engine.setEngineId("engine_id");\r
53     }\r
54 \r
55     @Test\r
56     public void getResponseContent_http_entity_is_null() throws Exception {\r
57         EasyMock.expect(httpResponseMock.getEntity()).andReturn(null);\r
58         PowerMock.replayAll();\r
59 \r
60         engineService.getResponseContent(httpResponseMock);\r
61 \r
62         PowerMock.verifyAll();\r
63     }\r
64 \r
65     @Test\r
66     public void delete_exception() throws Exception {\r
67         thrown.expect(Exception.class);\r
68 \r
69         engineService.delete("test");\r
70 \r
71     }\r
72 \r
73     @Test\r
74     public void deploy_exception() throws Exception {\r
75 \r
76         thrown.expect(Exception.class);\r
77 \r
78         engineService.deploy(correlationDeployRule4Engine);\r
79 \r
80     }\r
81 \r
82     @Test\r
83     public void check_normal() throws Exception {\r
84         thrown.expect(Exception.class);\r
85 \r
86         engineService.check(new CorrelationCheckRule4Engine());\r
87 \r
88     }\r
89 }