Remove Tabs, per Jococo
[aaf/authz.git] / auth / auth-batch / src / test / java / org / onap / aaf / auth / batch / helpers / test / JU_Future.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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====================================================
19  *
20  */
21
22 package org.onap.aaf.auth.batch.helpers.test;
23
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;
28
29 import java.nio.ByteBuffer;
30 import java.util.ArrayList;
31 import java.util.Date;
32 import java.util.UUID;
33
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.dao.cass.FutureDAO;
40 import org.onap.aaf.auth.env.AuthzTrans;
41 import org.onap.aaf.auth.layer.Result;
42 import org.onap.aaf.misc.env.Env;
43 import org.onap.aaf.misc.env.LogTarget;
44 import org.onap.aaf.misc.env.TimeTaken;
45 import org.onap.aaf.misc.env.Trans;
46
47 import com.datastax.driver.core.ResultSet;
48 import com.datastax.driver.core.Row;
49 import com.datastax.driver.core.Session;
50 import com.datastax.driver.core.SimpleStatement;
51
52 public class JU_Future {
53
54     Future future;
55     Date start;
56     Date expires;
57     ByteBuffer bBuff;
58
59     @Before
60     public void setUp() {
61         UUID id = new UUID(0, 0);
62         start = new Date();
63         expires = new Date();
64         future = new Future(id, "Re-Validate Ownership for AAF Namespace '\'test\'test", "target", start, expires,
65                 bBuff);
66     }
67
68     @Test
69     public void testId() {
70         Assert.assertTrue(future.id() instanceof UUID);
71     }
72
73     @Test
74     public void testMemo() {
75         Assert.assertEquals("Re-Validate Ownership for AAF Namespace '\'test\'test", future.memo());
76     }
77
78     @Test
79     public void testStart() {
80         Assert.assertTrue(future.start() instanceof Date);
81     }
82
83     @Test
84     public void testExpires() {
85         Assert.assertTrue(future.expires() instanceof Date);
86     }
87
88     @Test
89     public void testTarget() {
90         Assert.assertEquals("target", future.target());
91     }
92
93     @Test
94     public void testExpunge() {
95         future.expunge();
96     }
97
98     @Test
99     public void testCompareTo() {
100         future.compareTo(null);
101         future.compareTo(future);
102     }
103
104     @Test
105     public void testResetLocalData() {
106         Future.resetLocalData();
107         Assert.assertEquals(0, Future.sizeForDeletion());
108         Assert.assertEquals(false, Future.pendingDelete(future));
109     }
110
111
112     @Test
113     public void testDelayedDeleteWithDryRun() {
114         AuthzTrans trans = mock(AuthzTrans.class);
115         LogTarget target = mock(LogTarget.class);
116
117         when(trans.info()).thenReturn(target);
118
119         assertEquals(Result.ok().status, future.delayedDelete(trans, null, true, "text").status);
120     }
121
122     @Test
123     public void testDelayedDeleteNonDryRun() {
124         AuthzTrans trans = mock(AuthzTrans.class);
125         LogTarget target = mock(LogTarget.class);
126         FutureDAO fd = mock(FutureDAO.class);
127
128         when(trans.info()).thenReturn(target);
129         when(fd.delete(any(AuthzTrans.class), any(FutureDAO.Data.class), any(Boolean.class))).thenReturn(Result.ok());
130
131         assertEquals(Result.ok().status, future.delayedDelete(trans, fd, false, "text").status);
132     }
133
134 }