Improve Batches
[aaf/authz.git] / auth / auth-batch / src / test / java / org / onap / aaf / auth / batch / helpers / test / JU_Approval.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
4  * ===========================================================================
5  * Copyright (c) 2018 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
22 package org.onap.aaf.auth.batch.helpers.test;
23
24 import static org.junit.Assert.assertEquals;
25 import static org.mockito.Matchers.any;
26 import static org.mockito.Mockito.mock;
27 import static org.mockito.Mockito.when;
28
29 import java.util.ArrayList;
30 import java.util.List;
31 import java.util.UUID;
32
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.onap.aaf.auth.batch.helpers.Approval;
36 import org.onap.aaf.auth.dao.cass.ApprovalDAO;
37 import org.onap.aaf.auth.env.AuthzTrans;
38 import org.onap.aaf.auth.layer.Result;
39 import org.onap.aaf.misc.env.LogTarget;
40
41 import junit.framework.Assert;
42
43 public class JU_Approval {
44
45         Approval approval;
46         UUID id;
47         UUID ticket;
48
49
50         @Before
51         public void setUp() {
52                 id = new UUID(0, 0);
53                 ticket = new UUID(0, 0);
54
55                 approval = new Approval(id, ticket, "approver","user", "memo", "operation", "status", "type", 100l);
56         }
57
58         @Test
59         public void testRoleFromMemo() {
60                 Assert.assertNull(approval.roleFromMemo(null));
61                 Assert.assertEquals(".admin",
62                                 approval.roleFromMemo("Re-Validate as Administrator for AAF Namespace '\'test\'test"));
63                 Assert.assertEquals(".owner", approval.roleFromMemo("Re-Validate Ownership for AAF Namespace '\'test\'test"));
64                 Assert.assertEquals("", approval.roleFromMemo("Re-Approval in Role '\'test\'test"));
65         }
66
67         @Test
68         public void testExpunge() {
69                 approval.expunge();
70         }
71
72 //      @Test
73 //      public void testGetLast_notified() {
74 //              Assert.assertTrue(approval.getLast_notified() instanceof Date);
75 //      }
76 //
77 //      @Test
78 //      public void testSetLastNotified() {
79 //              approval.setLastNotified(date);
80 //      }
81
82         @Test
83         public void testGetStatus() {
84                 Assert.assertEquals("status", approval.getStatus());
85         }
86
87         @Test
88         public void testSetStatus() {
89                 approval.setStatus("status");
90         }
91
92         @Test
93         public void testGetId() {
94                 Assert.assertTrue(approval.getId() instanceof UUID);
95         }
96
97         @Test
98         public void testGetTicket() {
99                 Assert.assertTrue(approval.getTicket() instanceof UUID);
100         }
101
102         @Test
103         public void testGetMemo() {
104                 Assert.assertEquals("memo", approval.getMemo());
105         }
106
107         @Test
108         public void testGetOperation() {
109                 Assert.assertEquals("operation", approval.getOperation());
110         }
111
112         @Test
113         public void testGetType() {
114                 Assert.assertEquals("type", approval.getType());
115         }
116
117         @Test
118         public void testLapsed() {
119                 approval.lapsed();
120         }
121
122         @Test
123         public void testGetRole() {
124                 Assert.assertNull(approval.getRole());
125         }
126
127         @Test
128         public void testToString() {
129                 Assert.assertEquals("user memo", approval.toString());
130         }
131
132         @Test
133         public void testResetLocalData() {
134                 approval.resetLocalData();
135         }
136
137         @Test
138         public void testPendingDelete() {
139                 Assert.assertFalse(approval.pendingDelete(approval));
140         }
141
142         @Test
143         public void testUpdateNonDryRun() {
144                 approval = new Approval(id, ticket, "approver", "user", "memo", "operation", "status", "type", 100l);
145                 AuthzTrans trans = mock(AuthzTrans.class);
146                 ApprovalDAO dao = mock(ApprovalDAO.class);
147                 LogTarget target = mock(LogTarget.class);
148
149                 when(trans.info()).thenReturn(target);
150
151 //              approval.update(trans, dao, false);
152         }
153
154         @Test
155         public void testUpdateDryRun() {
156                 approval = new Approval(id, ticket, "approver", "user", "memo", "operation", "status", "type", 100l);
157                 AuthzTrans trans = mock(AuthzTrans.class);
158                 ApprovalDAO dao = mock(ApprovalDAO.class);
159                 LogTarget target = mock(LogTarget.class);
160
161                 when(trans.info()).thenReturn(target);
162
163 //              approval.update(trans, dao, true);
164         }
165
166         @Test
167         public void testDelayDeleteDryRun() {
168                 approval = new Approval(id, ticket, "approver", "user", "memo", "operation", "status", "type", 100l);
169                 AuthzTrans trans = mock(AuthzTrans.class);
170                 ApprovalDAO dao = mock(ApprovalDAO.class);
171                 LogTarget target = mock(LogTarget.class);
172
173                 when(trans.info()).thenReturn(target);
174
175                 List<Approval> list = new ArrayList<Approval>();
176                 list.add(approval);
177                 Approval.delayDelete(trans, dao, true, list, "text");
178         }
179
180         @Test
181         public void testDelayDeleteNonDryRun() {
182                 approval = new Approval(id, ticket, "approver", "user", "memo", "operation", "status", "type", 100l);
183                 AuthzTrans trans = mock(AuthzTrans.class);
184                 ApprovalDAO dao = mock(ApprovalDAO.class);
185                 LogTarget target = mock(LogTarget.class);
186
187                 when(trans.info()).thenReturn(target);
188                 Result<Void> rv = Result.ok();
189                 when(dao.delete(any(AuthzTrans.class), any(ApprovalDAO.Data.class), any(Boolean.class))).thenReturn(rv);
190
191                 List<Approval> list = new ArrayList<Approval>();
192                 list.add(approval);
193                 Approval.delayDelete(trans, dao, false, list, "text");
194         }
195
196         @Test
197         public void testDelayDeleteResultNotOk() {
198                 approval = new Approval(id, ticket, "approver",  "user", "memo", "operation", "status", "type", 100l);
199                 AuthzTrans trans = mock(AuthzTrans.class);
200                 ApprovalDAO dao = mock(ApprovalDAO.class);
201                 LogTarget target = mock(LogTarget.class);
202
203                 when(trans.info()).thenReturn(target);
204                 Result<Void> rv = Result.err(new Exception());
205                 when(dao.delete(any(AuthzTrans.class), any(ApprovalDAO.Data.class), any(Boolean.class))).thenReturn(rv);
206
207                 List<Approval> list = new ArrayList<Approval>();
208                 list.add(approval);
209                 Approval.delayDelete(trans, dao, false, list, "text");
210         }
211
212
213 }