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.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.dao.cass.ApprovalDAO;
37 import org.onap.aaf.auth.env.AuthzTrans;
38 import org.onap.aaf.auth.helpers.Approval;
39 import org.onap.aaf.auth.helpers.creators.RowCreator;
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 testSizeForDeletion() {
142 approval = new Approval(id, ticket, "approver", date, "user", "memo", "operation", "status", "type", 100l);
143 Assert.assertEquals(0, approval.sizeForDeletion());
147 public void testPendingDelete() {
148 Assert.assertFalse(approval.pendingDelete(approval));
152 public void testUpdateNonDryRun() {
153 approval = new Approval(id, ticket, "approver", date, "user", "memo", "operation", "status", "type", 100l);
154 AuthzTrans trans = mock(AuthzTrans.class);
155 ApprovalDAO dao = mock(ApprovalDAO.class);
156 LogTarget target = mock(LogTarget.class);
158 when(trans.info()).thenReturn(target);
160 approval.update(trans, dao, false);
164 public void testUpdateDryRun() {
165 approval = new Approval(id, ticket, "approver", date, "user", "memo", "operation", "status", "type", 100l);
166 AuthzTrans trans = mock(AuthzTrans.class);
167 ApprovalDAO dao = mock(ApprovalDAO.class);
168 LogTarget target = mock(LogTarget.class);
170 when(trans.info()).thenReturn(target);
172 approval.update(trans, dao, true);
176 public void testDelayDeleteDryRun() {
177 approval = new Approval(id, ticket, "approver", date, "user", "memo", "operation", "status", "type", 100l);
178 AuthzTrans trans = mock(AuthzTrans.class);
179 ApprovalDAO dao = mock(ApprovalDAO.class);
180 LogTarget target = mock(LogTarget.class);
182 when(trans.info()).thenReturn(target);
184 List<Approval> list = new ArrayList<Approval>();
186 Approval.delayDelete(trans, dao, true, list, "text");
190 public void testDelayDeleteNonDryRun() {
191 approval = new Approval(id, ticket, "approver", date, "user", "memo", "operation", "status", "type", 100l);
192 AuthzTrans trans = mock(AuthzTrans.class);
193 ApprovalDAO dao = mock(ApprovalDAO.class);
194 LogTarget target = mock(LogTarget.class);
196 when(trans.info()).thenReturn(target);
197 Result<Void> rv = Result.ok();
198 when(dao.delete(any(AuthzTrans.class), any(ApprovalDAO.Data.class), any(Boolean.class))).thenReturn(rv);
200 List<Approval> list = new ArrayList<Approval>();
202 Approval.delayDelete(trans, dao, false, list, "text");
206 public void testDelayDeleteResultNotOk() {
207 approval = new Approval(id, ticket, "approver", date, "user", "memo", "operation", "status", "type", 100l);
208 AuthzTrans trans = mock(AuthzTrans.class);
209 ApprovalDAO dao = mock(ApprovalDAO.class);
210 LogTarget target = mock(LogTarget.class);
212 when(trans.info()).thenReturn(target);
213 Result<Void> rv = Result.err(new Exception());
214 when(dao.delete(any(AuthzTrans.class), any(ApprovalDAO.Data.class), any(Boolean.class))).thenReturn(rv);
216 List<Approval> list = new ArrayList<Approval>();
218 Approval.delayDelete(trans, dao, false, list, "text");
222 public void testv2() {
223 Approval.v2_0_17.create(RowCreator.getRow());
226 "select id,ticket,approver,last_notified,user,memo,operation,status,type,WRITETIME(status) from authz.approval",
227 Approval.v2_0_17.select());