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.nio.ByteBuffer;
30 import java.util.ArrayList;
31 import java.util.Date;
32 import java.util.UUID;
34 import org.junit.Assert;
35 import org.junit.Before;
36 import org.junit.Test;
37 import org.onap.aaf.auth.batch.helpers.Creator;
38 import org.onap.aaf.auth.batch.helpers.Future;
39 import org.onap.aaf.auth.batch.helpers.creators.RowCreator;
40 import org.onap.aaf.auth.dao.cass.FutureDAO;
41 import org.onap.aaf.auth.env.AuthzTrans;
42 import org.onap.aaf.auth.layer.Result;
43 import org.onap.aaf.misc.env.Env;
44 import org.onap.aaf.misc.env.LogTarget;
45 import org.onap.aaf.misc.env.TimeTaken;
46 import org.onap.aaf.misc.env.Trans;
48 import com.datastax.driver.core.ResultSet;
49 import com.datastax.driver.core.Row;
50 import com.datastax.driver.core.Session;
51 import com.datastax.driver.core.SimpleStatement;
53 public class JU_Future {
62 UUID id = new UUID(0, 0);
65 future = new Future(id, "Re-Validate Ownership for AAF Namespace '\'test\'test", "target", start, expires,
70 public void testId() {
71 Assert.assertTrue(future.id() instanceof UUID);
75 public void testMemo() {
76 Assert.assertEquals("Re-Validate Ownership for AAF Namespace '\'test\'test", future.memo());
80 public void testStart() {
81 Assert.assertTrue(future.start() instanceof Date);
85 public void testExpires() {
86 Assert.assertTrue(future.expires() instanceof Date);
90 public void testTarget() {
91 Assert.assertEquals("target", future.target());
95 public void testExpunge() {
100 public void testCompareTo() {
101 future.compareTo(null);
102 future.compareTo(future);
106 public void testResetLocalData() {
107 Future.resetLocalData();
111 public void testSizeForDeletion() {
112 Assert.assertEquals(0, Future.sizeForDeletion());
116 public void testPendingDelete() {
117 Assert.assertEquals(false, Future.pendingDelete(future));
121 public void testLoad() {
122 Session session = mock(Session.class);
123 Trans trans = mock(Trans.class);
124 @SuppressWarnings("unchecked")
125 Creator<Future> creator = (Creator<Future>)mock(Creator.class);
126 LogTarget target = mock(LogTarget.class);
127 TimeTaken tt = mock(TimeTaken.class);
128 ResultSet results = mock(ResultSet.class);
129 ArrayList<Row> rows = new ArrayList<Row>();
130 Row row = RowCreator.getRow();
133 when(results.all()).thenReturn(rows);
134 when(trans.info()).thenReturn(target);
135 when(trans.start("Load Futures", Env.REMOTE)).thenReturn(tt);
136 when(trans.start("Process Futures", Env.SUB)).thenReturn(tt);
137 when(session.execute(any(SimpleStatement.class))).thenReturn(results);
138 when(creator.create(row)).thenReturn(future);
140 Future.load(trans, session, creator);
144 public void testV2() {
145 Future.v2_0_17.create(RowCreator.getRow());
146 assertEquals(Future.v2_0_17.select(), "select id,memo,target,start,expires from authz.future");
150 public void testWithConstruct() {
151 Future.withConstruct.create(RowCreator.getRow());
152 assertEquals(Future.withConstruct.select(), "select id,memo,target,start,expires,construct from authz.future");
156 public void testDelayedDeleteWithDryRun() {
157 AuthzTrans trans = mock(AuthzTrans.class);
158 LogTarget target = mock(LogTarget.class);
160 when(trans.info()).thenReturn(target);
162 assertEquals(Result.ok().status, future.delayedDelete(trans, null, true, "text").status);
166 public void testDelayedDeleteNonDryRun() {
167 AuthzTrans trans = mock(AuthzTrans.class);
168 LogTarget target = mock(LogTarget.class);
169 FutureDAO fd = mock(FutureDAO.class);
171 when(trans.info()).thenReturn(target);
172 when(fd.delete(any(AuthzTrans.class), any(FutureDAO.Data.class), any(Boolean.class))).thenReturn(Result.ok());
174 assertEquals(Result.ok().status, future.delayedDelete(trans, fd, false, "text").status);