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