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(".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"));
68 public void testExpunge() {
73 // public void testGetLast_notified() {
74 // Assert.assertTrue(approval.getLast_notified() instanceof Date);
78 // public void testSetLastNotified() {
79 // approval.setLastNotified(date);
83 public void testGetStatus() {
84 Assert.assertEquals("status", approval.getStatus());
88 public void testSetStatus() {
89 approval.setStatus("status");
93 public void testGetId() {
94 Assert.assertTrue(approval.getId() instanceof UUID);
98 public void testGetTicket() {
99 Assert.assertTrue(approval.getTicket() instanceof UUID);
103 public void testGetMemo() {
104 Assert.assertEquals("memo", approval.getMemo());
108 public void testGetOperation() {
109 Assert.assertEquals("operation", approval.getOperation());
113 public void testGetType() {
114 Assert.assertEquals("type", approval.getType());
118 public void testLapsed() {
123 public void testGetRole() {
124 Assert.assertNull(approval.getRole());
128 public void testToString() {
129 Assert.assertEquals("user memo", approval.toString());
133 public void testResetLocalData() {
134 approval.resetLocalData();
138 public void testPendingDelete() {
139 Assert.assertFalse(approval.pendingDelete(approval));
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);
149 when(trans.info()).thenReturn(target);
151 // approval.update(trans, dao, false);
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);
161 when(trans.info()).thenReturn(target);
163 // approval.update(trans, dao, true);
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);
173 when(trans.info()).thenReturn(target);
175 List<Approval> list = new ArrayList<Approval>();
177 Approval.delayDelete(trans, dao, true, list, "text");
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);
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);
191 List<Approval> list = new ArrayList<Approval>();
193 Approval.delayDelete(trans, dao, false, list, "text");
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);
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);
207 List<Approval> list = new ArrayList<Approval>();
209 Approval.delayDelete(trans, dao, false, list, "text");