85d346ba7c4bf765c2e47ceed0b77fb4412bd84a
[aaf/authz.git] / auth / auth-batch / src / test / java / org / onap / aaf / auth / batch / approvalsets / JU_Pending.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.approvalsets;
23
24 import static org.junit.Assert.assertTrue;
25 import static org.mockito.MockitoAnnotations.initMocks;
26
27 import java.io.IOException;
28 import java.text.ParseException;
29 import java.util.ArrayList;
30 import java.util.Calendar;
31 import java.util.Date;
32 import java.util.List;
33
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.mockito.Mock;
37 import org.mockito.Mockito;
38 import org.onap.aaf.auth.env.AuthzTrans;
39 import org.onap.aaf.cadi.PropAccess;
40 import org.onap.aaf.cadi.util.CSV.Writer;
41 import org.onap.aaf.misc.env.APIException;
42
43 import com.datastax.driver.core.Cluster;
44
45 public class JU_Pending {
46
47     @Mock
48     AuthzTrans trans;
49     @Mock
50     Cluster cluster;
51     @Mock
52     PropAccess access;
53
54     @Mock
55     DataView dv;
56
57     @Before
58     public void setUp() throws APIException, IOException {
59         initMocks(this);
60     }
61
62     @Test
63     public void testRow() {
64         Writer approveCW = Mockito.mock(Writer.class);
65         Mockito.doNothing().when(approveCW).row(Mockito.anyString(),
66                 Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(),
67                 Mockito.anyInt());
68         Pending pendingObj = new Pending(new Date());
69         pendingObj.row(approveCW, "key");
70         Date date = null;
71         pendingObj = new Pending(date);
72     }
73
74     @Test
75     public void testInc() {
76         List<String> inpList = new ArrayList<>();
77         inpList.add("test");
78         inpList.add("test");
79         inpList.add("test");
80         inpList.add(null);
81         inpList.add("10");
82         try {
83             Pending pendingObj = new Pending(inpList);
84             pendingObj.inc();
85             assertTrue(11 == pendingObj.qty());
86
87             Pending tempPending = new Pending(inpList);
88             pendingObj.inc(tempPending);
89             assertTrue(21 == pendingObj.qty());
90
91             tempPending.earliest = new Date();
92             pendingObj.earliest = new Date();
93             pendingObj.inc(tempPending);
94
95             Calendar calendar = Calendar.getInstance();
96             calendar.add(Calendar.DAY_OF_YEAR, 1);
97             pendingObj.earliest = calendar.getTime();
98             pendingObj.inc(tempPending);
99         } catch (ParseException e) {
100             // TODO Auto-generated catch block
101             e.printStackTrace();
102         }
103     }
104
105     @Test
106     public void testEarliest() {
107         List<String> inpList = new ArrayList<>();
108         try {
109             inpList.add("test");
110             inpList.add("test");
111             inpList.add("test");
112             inpList.add("2019-01-01");
113             inpList.add("10");
114             Pending.create();
115
116             Pending pendingObj = new Pending(inpList);
117             pendingObj.earliest(null);
118
119             pendingObj.earliest = null;
120             pendingObj.earliest(new Date());
121
122             Calendar calendar = Calendar.getInstance();
123             calendar.add(Calendar.DAY_OF_YEAR, 1);
124             pendingObj.earliest(calendar.getTime());
125             assertTrue(119 == pendingObj.earliest().getYear());
126             assertTrue(pendingObj.newApprovals());
127         } catch (ParseException e) {
128             // TODO Auto-generated catch block
129             e.printStackTrace();
130         }
131     }
132
133 }