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