2 * ============LICENSE_START====================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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====================================================
22 package org.onap.aaf.auth.batch.helpers.test;
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;
29 import java.util.ArrayList;
30 import java.util.List;
31 import java.util.UUID;
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;
41 import junit.framework.Assert;
43 public class JU_Approval {
53 ticket = new UUID(0, 0);
55 approval = new Approval(id, ticket, "approver","user", "memo", "operation", "status", "type", 100l);
59 public void testRoleFromMemo() {
60 Assert.assertNull(Approval.roleFromMemo(null));
61 Assert.assertEquals("org.onap.ns.admin",
62 Approval.roleFromMemo(Approval.RE_VALIDATE_ADMIN + "org.onap.ns]"));
63 Assert.assertEquals("org.onap.ns.owner", Approval.roleFromMemo(Approval.RE_VALIDATE_OWNER + "org.onap.ns]"));
64 Assert.assertEquals("org.onap.ns.member", Approval.roleFromMemo(Approval.RE_APPROVAL_IN_ROLE
65 + "bob] + [org.onap.ns.member] - Expires 2018-12-25"));
69 public void testExpunge() {
74 // public void testGetLast_notified() {
75 // Assert.assertTrue(approval.getLast_notified() instanceof Date);
79 // public void testSetLastNotified() {
80 // approval.setLastNotified(date);
84 public void testGetStatus() {
85 Assert.assertEquals("status", approval.getStatus());
89 public void testSetStatus() {
90 approval.setStatus("status");
94 public void testGetId() {
95 Assert.assertTrue(approval.getId() instanceof UUID);
99 public void testGetTicket() {
100 Assert.assertTrue(approval.getTicket() instanceof UUID);
104 public void testGetMemo() {
105 Assert.assertEquals("memo", approval.getMemo());
109 public void testGetOperation() {
110 Assert.assertEquals("operation", approval.getOperation());
114 public void testGetType() {
115 Assert.assertEquals("type", approval.getType());
119 public void testLapsed() {
124 public void testGetRole() {
125 Assert.assertNull(approval.getRole());
129 public void testToString() {
130 Assert.assertEquals("user memo", approval.toString());
134 public void testResetLocalData() {
135 approval.resetLocalData();
139 public void testPendingDelete() {
140 Assert.assertFalse(approval.pendingDelete(approval));
144 public void testUpdateNonDryRun() {
145 approval = new Approval(id, ticket, "approver", "user", "memo", "operation", "status", "type", 100l);
146 AuthzTrans trans = mock(AuthzTrans.class);
147 ApprovalDAO dao = mock(ApprovalDAO.class);
148 LogTarget target = mock(LogTarget.class);
150 when(trans.info()).thenReturn(target);
152 // approval.update(trans, dao, false);
156 public void testUpdateDryRun() {
157 approval = new Approval(id, ticket, "approver", "user", "memo", "operation", "status", "type", 100l);
158 AuthzTrans trans = mock(AuthzTrans.class);
159 ApprovalDAO dao = mock(ApprovalDAO.class);
160 LogTarget target = mock(LogTarget.class);
162 when(trans.info()).thenReturn(target);
164 // approval.update(trans, dao, true);
168 public void testDelayDeleteDryRun() {
169 approval = new Approval(id, ticket, "approver", "user", "memo", "operation", "status", "type", 100l);
170 AuthzTrans trans = mock(AuthzTrans.class);
171 ApprovalDAO dao = mock(ApprovalDAO.class);
172 LogTarget target = mock(LogTarget.class);
174 when(trans.info()).thenReturn(target);
176 List<Approval> list = new ArrayList<Approval>();
178 Approval.delayDelete(trans, dao, true, list, "text");
182 public void testDelayDeleteNonDryRun() {
183 approval = new Approval(id, ticket, "approver", "user", "memo", "operation", "status", "type", 100l);
184 AuthzTrans trans = mock(AuthzTrans.class);
185 ApprovalDAO dao = mock(ApprovalDAO.class);
186 LogTarget target = mock(LogTarget.class);
188 when(trans.info()).thenReturn(target);
189 Result<Void> rv = Result.ok();
190 when(dao.delete(any(AuthzTrans.class), any(ApprovalDAO.Data.class), any(Boolean.class))).thenReturn(rv);
192 List<Approval> list = new ArrayList<Approval>();
194 Approval.delayDelete(trans, dao, false, list, "text");
198 public void testDelayDeleteResultNotOk() {
199 approval = new Approval(id, ticket, "approver", "user", "memo", "operation", "status", "type", 100l);
200 AuthzTrans trans = mock(AuthzTrans.class);
201 ApprovalDAO dao = mock(ApprovalDAO.class);
202 LogTarget target = mock(LogTarget.class);
204 when(trans.info()).thenReturn(target);
205 Result<Void> rv = Result.err(new Exception());
206 when(dao.delete(any(AuthzTrans.class), any(ApprovalDAO.Data.class), any(Boolean.class))).thenReturn(rv);
208 List<Approval> list = new ArrayList<Approval>();
210 Approval.delayDelete(trans, dao, false, list, "text");