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.Date;
31 import java.util.List;
32 import java.util.UUID;
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.onap.aaf.auth.batch.helpers.Approval;
37 import org.onap.aaf.auth.batch.helpers.creators.RowCreator;
38 import org.onap.aaf.auth.dao.cass.ApprovalDAO;
39 import org.onap.aaf.auth.env.AuthzTrans;
40 import org.onap.aaf.auth.layer.Result;
41 import org.onap.aaf.misc.env.LogTarget;
43 import junit.framework.Assert;
45 public class JU_Approval {
55 ticket = new UUID(0, 0);
58 approval = new Approval(id, ticket, "approver", date, "user", "memo", "operation", "status", "type", 100l);
62 public void testRoleFromMemo() {
63 Assert.assertNull(approval.roleFromMemo(null));
64 Assert.assertEquals(".admin",
65 approval.roleFromMemo("Re-Validate as Administrator for AAF Namespace '\'test\'test"));
66 Assert.assertEquals(".owner", approval.roleFromMemo("Re-Validate Ownership for AAF Namespace '\'test\'test"));
67 Assert.assertEquals("", approval.roleFromMemo("Re-Approval in Role '\'test\'test"));
71 public void testExpunge() {
76 public void testGetLast_notified() {
77 Assert.assertTrue(approval.getLast_notified() instanceof Date);
81 public void testSetLastNotified() {
82 approval.setLastNotified(date);
86 public void testGetStatus() {
87 Assert.assertEquals("status", approval.getStatus());
91 public void testSetStatus() {
92 approval.setStatus("status");
96 public void testGetId() {
97 Assert.assertTrue(approval.getId() instanceof UUID);
101 public void testGetTicket() {
102 Assert.assertTrue(approval.getTicket() instanceof UUID);
106 public void testGetMemo() {
107 Assert.assertEquals("memo", approval.getMemo());
111 public void testGetOperation() {
112 Assert.assertEquals("operation", approval.getOperation());
116 public void testGetType() {
117 Assert.assertEquals("type", approval.getType());
121 public void testLapsed() {
126 public void testGetRole() {
127 Assert.assertNull(approval.getRole());
131 public void testToString() {
132 Assert.assertEquals("user memo", approval.toString());
136 public void testResetLocalData() {
137 approval.resetLocalData();
141 public void testPendingDelete() {
142 Assert.assertFalse(approval.pendingDelete(approval));
146 public void testUpdateNonDryRun() {
147 approval = new Approval(id, ticket, "approver", date, "user", "memo", "operation", "status", "type", 100l);
148 AuthzTrans trans = mock(AuthzTrans.class);
149 ApprovalDAO dao = mock(ApprovalDAO.class);
150 LogTarget target = mock(LogTarget.class);
152 when(trans.info()).thenReturn(target);
154 approval.update(trans, dao, false);
158 public void testUpdateDryRun() {
159 approval = new Approval(id, ticket, "approver", date, "user", "memo", "operation", "status", "type", 100l);
160 AuthzTrans trans = mock(AuthzTrans.class);
161 ApprovalDAO dao = mock(ApprovalDAO.class);
162 LogTarget target = mock(LogTarget.class);
164 when(trans.info()).thenReturn(target);
166 approval.update(trans, dao, true);
170 public void testDelayDeleteDryRun() {
171 approval = new Approval(id, ticket, "approver", date, "user", "memo", "operation", "status", "type", 100l);
172 AuthzTrans trans = mock(AuthzTrans.class);
173 ApprovalDAO dao = mock(ApprovalDAO.class);
174 LogTarget target = mock(LogTarget.class);
176 when(trans.info()).thenReturn(target);
178 List<Approval> list = new ArrayList<Approval>();
180 Approval.delayDelete(trans, dao, true, list, "text");
184 public void testDelayDeleteNonDryRun() {
185 approval = new Approval(id, ticket, "approver", date, "user", "memo", "operation", "status", "type", 100l);
186 AuthzTrans trans = mock(AuthzTrans.class);
187 ApprovalDAO dao = mock(ApprovalDAO.class);
188 LogTarget target = mock(LogTarget.class);
190 when(trans.info()).thenReturn(target);
191 Result<Void> rv = Result.ok();
192 when(dao.delete(any(AuthzTrans.class), any(ApprovalDAO.Data.class), any(Boolean.class))).thenReturn(rv);
194 List<Approval> list = new ArrayList<Approval>();
196 Approval.delayDelete(trans, dao, false, list, "text");
200 public void testDelayDeleteResultNotOk() {
201 approval = new Approval(id, ticket, "approver", date, "user", "memo", "operation", "status", "type", 100l);
202 AuthzTrans trans = mock(AuthzTrans.class);
203 ApprovalDAO dao = mock(ApprovalDAO.class);
204 LogTarget target = mock(LogTarget.class);
206 when(trans.info()).thenReturn(target);
207 Result<Void> rv = Result.err(new Exception());
208 when(dao.delete(any(AuthzTrans.class), any(ApprovalDAO.Data.class), any(Boolean.class))).thenReturn(rv);
210 List<Approval> list = new ArrayList<Approval>();
212 Approval.delayDelete(trans, dao, false, list, "text");
216 public void testv2() {
217 Approval.v2_0_17.create(RowCreator.getRow());
220 "select id,ticket,approver,last_notified,user,memo,operation,status,type,WRITETIME(status) from authz.approval",
221 Approval.v2_0_17.select());