Merge "Sonar Fix: X509ChainWithIssuer.java"
[aaf/authz.git] / auth / auth-batch / src / test / java / org / onap / aaf / auth / 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.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.dao.cass.FutureDAO;
38 import org.onap.aaf.auth.env.AuthzTrans;
39 import org.onap.aaf.auth.helpers.Creator;
40 import org.onap.aaf.auth.helpers.Future;
41 import org.onap.aaf.auth.helpers.creators.RowCreator;
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;
47
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;
52
53 public class JU_Future {
54
55         Future future;
56         Date start;
57         Date expires;
58         ByteBuffer bBuff;
59
60         @Before
61         public void setUp() {
62                 UUID id = new UUID(0, 0);
63                 start = new Date();
64                 expires = new Date();
65                 future = new Future(id, "Re-Validate Ownership for AAF Namespace '\'test\'test", "target", start, expires,
66                                 bBuff);
67         }
68
69         @Test
70         public void testId() {
71                 Assert.assertTrue(future.id() instanceof UUID);
72         }
73
74         @Test
75         public void testMemo() {
76                 Assert.assertEquals("Re-Validate Ownership for AAF Namespace '\'test\'test", future.memo());
77         }
78
79         @Test
80         public void testStart() {
81                 Assert.assertTrue(future.start() instanceof Date);
82         }
83
84         @Test
85         public void testExpires() {
86                 Assert.assertTrue(future.expires() instanceof Date);
87         }
88
89         @Test
90         public void testTarget() {
91                 Assert.assertEquals("target", future.target());
92         }
93
94         @Test
95         public void testExpunge() {
96                 future.expunge();
97         }
98
99         @Test
100         public void testCompareTo() {
101                 future.compareTo(null);
102                 future.compareTo(future);
103         }
104
105         @Test
106         public void testResetLocalData() {
107                 Future.resetLocalData();
108         }
109
110         @Test
111         public void testSizeForDeletion() {
112                 Assert.assertEquals(0, Future.sizeForDeletion());
113         }
114
115         @Test
116         public void testPendingDelete() {
117                 Assert.assertEquals(false, Future.pendingDelete(future));
118         }
119
120         @Test
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();
131                 rows.add(row);
132
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);
139
140                 Future.load(trans, session, creator);
141         }
142
143         @Test
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");
147         }
148
149         @Test
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");
153         }
154
155         @Test
156         public void testDelayedDeleteWithDryRun() {
157                 AuthzTrans trans = mock(AuthzTrans.class);
158                 LogTarget target = mock(LogTarget.class);
159
160                 when(trans.info()).thenReturn(target);
161
162                 assertEquals(Result.ok().status, future.delayedDelete(trans, null, true, "text").status);
163         }
164
165         @Test
166         public void testDelayedDeleteNonDryRun() {
167                 AuthzTrans trans = mock(AuthzTrans.class);
168                 LogTarget target = mock(LogTarget.class);
169                 FutureDAO fd = mock(FutureDAO.class);
170
171                 when(trans.info()).thenReturn(target);
172                 when(fd.delete(any(AuthzTrans.class), any(FutureDAO.Data.class), any(Boolean.class))).thenReturn(Result.ok());
173
174                 assertEquals(Result.ok().status, future.delayedDelete(trans, fd, false, "text").status);
175         }
176
177 }