a7ac8de9ad153db3bbde0aa6964fe0e0e03e001b
[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.PowerMockIgnore;
37 import org.powermock.core.classloader.annotations.PrepareForTest;
38 import org.powermock.modules.junit4.PowerMockRunner;
39
40 import com.att.ajsc.beans.PropertiesMapBean;
41 import org.onap.dmaap.dmf.mr.CambriaApiException;
42 import org.onap.dmaap.dmf.mr.beans.DMaaPContext;
43 import org.onap.dmaap.dmf.mr.service.EventsService;
44 import org.onap.dmaap.dmf.mr.service.TransactionService;
45 import com.att.nsa.configs.ConfigDbException;
46 import com.att.nsa.security.ReadWriteSecuredResource.AccessDeniedException;
47 import com.att.aft.dme2.internal.jettison.json.JSONException;
48 import org.powermock.api.mockito.PowerMockito;
49
50 @RunWith(PowerMockRunner.class)
51 @PowerMockIgnore("jdk.internal.reflect.*")
52 @PrepareForTest({ PropertiesMapBean.class })
53 public class TransactionRestServiceTest {
54
55         @InjectMocks
56         TransactionRestService transactionRestService;
57
58         @Mock
59         private TransactionService transactionService;
60
61         @Mock
62         DMaaPContext dmaapContext;
63
64         @Before
65         public void setUp() throws Exception {
66                 MockitoAnnotations.initMocks(this);
67         }
68
69         @After
70         public void tearDown() throws Exception {
71
72         }
73
74         @Test
75         public void testGetAllTransactionObjs() throws CambriaApiException {
76
77                 transactionRestService.getAllTransactionObjs();
78                 assertTrue(true);
79
80         }
81
82         @Test
83         public void testGetTransactionObj() throws CambriaApiException {
84
85                 transactionRestService.getTransactionObj("transactionId");
86                 assertTrue(true);
87
88         }
89
90         @Test
91         public void testGetAllTransactionObjsError() throws CambriaApiException {
92
93                 try {
94                         PowerMockito.doThrow(new IOException()).when(transactionService).getAllTransactionObjs(dmaapContext);
95                 } catch (ConfigDbException | IOException e) {
96                         assertTrue(false);
97                 }
98
99                 try {
100                         transactionRestService.getAllTransactionObjs();
101                 } catch (CambriaApiException e) {
102                         assertTrue(true);
103                 }
104
105         }
106
107         @Test
108         public void testGetTransactionObjError() {
109
110                 try {
111                         PowerMockito.doThrow(new IOException()).when(transactionService).getTransactionObj(dmaapContext,
112                                         "transactionId");
113                 } catch (ConfigDbException | JSONException | IOException e) {
114                         assertTrue(false);
115                 }
116
117                 try {
118                         transactionRestService.getTransactionObj("transactionId");
119                 } catch (CambriaApiException e) {
120                         assertTrue(true);
121                 }
122
123         }
124
125 }