a5abb75d4e67bb8adcc5eee34ed99327726d8fd8
[dmaap/messagerouter/messageservice.git] / src / test / java / com / att / nsa / dmaap / service / TransactionRestServiceTest.java
1 /*-\r
2  * ============LICENSE_START=======================================================\r
3  * ONAP Policy Engine\r
4  * ================================================================================\r
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.\r
6  * ================================================================================\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  * \r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * \r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  * ============LICENSE_END=========================================================\r
19  */\r
20 \r
21 package com.att.nsa.dmaap.service;\r
22 \r
23 import static org.junit.Assert.*;\r
24 \r
25 import java.io.IOException;\r
26 import java.lang.reflect.InvocationTargetException;\r
27 import java.lang.reflect.Method;\r
28 \r
29 import org.junit.After;\r
30 import org.junit.Before;\r
31 import org.junit.Test;\r
32 import org.junit.runner.RunWith;\r
33 import org.mockito.InjectMocks;\r
34 import org.mockito.Mock;\r
35 import org.mockito.MockitoAnnotations;\r
36 import org.powermock.core.classloader.annotations.PrepareForTest;\r
37 import org.powermock.modules.junit4.PowerMockRunner;\r
38 \r
39 import com.att.ajsc.beans.PropertiesMapBean;\r
40 import org.onap.dmaap.dmf.mr.CambriaApiException;\r
41 import org.onap.dmaap.dmf.mr.beans.DMaaPContext;\r
42 import org.onap.dmaap.dmf.mr.service.EventsService;\r
43 import org.onap.dmaap.dmf.mr.service.TransactionService;\r
44 import com.att.nsa.configs.ConfigDbException;\r
45 import com.att.nsa.security.ReadWriteSecuredResource.AccessDeniedException;\r
46 import com.att.aft.dme2.internal.jettison.json.JSONException;\r
47 import org.powermock.api.mockito.PowerMockito;\r
48 \r
49 @RunWith(PowerMockRunner.class)\r
50 @PrepareForTest({ PropertiesMapBean.class })\r
51 public class TransactionRestServiceTest {\r
52 \r
53         @InjectMocks\r
54         TransactionRestService transactionRestService;\r
55 \r
56         @Mock\r
57         private TransactionService transactionService;\r
58 \r
59         @Mock\r
60         DMaaPContext dmaapContext;\r
61 \r
62         @Before\r
63         public void setUp() throws Exception {\r
64                 MockitoAnnotations.initMocks(this);\r
65         }\r
66 \r
67         @After\r
68         public void tearDown() throws Exception {\r
69 \r
70         }\r
71 \r
72         @Test\r
73         public void testGetAllTransactionObjs() throws CambriaApiException {\r
74 \r
75                 transactionRestService.getAllTransactionObjs();\r
76                 assertTrue(true);\r
77 \r
78         }\r
79 \r
80         @Test\r
81         public void testGetTransactionObj() throws CambriaApiException {\r
82 \r
83                 transactionRestService.getTransactionObj("transactionId");\r
84                 assertTrue(true);\r
85 \r
86         }\r
87 \r
88         @Test\r
89         public void testGetAllTransactionObjsError() throws CambriaApiException {\r
90 \r
91                 try {\r
92                         PowerMockito.doThrow(new IOException()).when(transactionService).getAllTransactionObjs(dmaapContext);\r
93                 } catch (ConfigDbException | IOException e) {\r
94                         assertTrue(false);\r
95                 }\r
96 \r
97                 try {\r
98                         transactionRestService.getAllTransactionObjs();\r
99                 } catch (CambriaApiException e) {\r
100                         assertTrue(true);\r
101                 }\r
102 \r
103         }\r
104 \r
105         @Test\r
106         public void testGetTransactionObjError() {\r
107 \r
108                 try {\r
109                         PowerMockito.doThrow(new IOException()).when(transactionService).getTransactionObj(dmaapContext,\r
110                                         "transactionId");\r
111                 } catch (ConfigDbException | JSONException | IOException e) {\r
112                         assertTrue(false);\r
113                 }\r
114 \r
115                 try {\r
116                         transactionRestService.getTransactionObj("transactionId");\r
117                 } catch (CambriaApiException e) {\r
118                         assertTrue(true);\r
119                 }\r
120 \r
121         }\r
122 \r
123 }