Batch work and client
[aaf/authz.git] / auth / auth-batch / src / test / java / org / onap / aaf / auth / batch / helpers / test / JU_ExpireRange.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 package org.onap.aaf.auth.batch.helpers.test;
22
23 import static org.junit.Assert.*;
24
25 import java.util.GregorianCalendar;
26 import java.util.Set;
27
28 import org.junit.Test;
29 import org.onap.aaf.auth.batch.helpers.ExpireRange;
30 import org.onap.aaf.cadi.PropAccess;
31
32 public class JU_ExpireRange {
33         @Test
34         public void test() {
35                 ExpireRange expRange = new ExpireRange(new PropAccess());
36                 
37                 Set<String> names=expRange.names();
38                 assertTrue(names.contains("OneMonth"));
39                 assertTrue(names.contains("OneWeek"));
40                 assertTrue(names.contains("Delete"));
41                 assertFalse(names.contains(null));
42                 assertFalse(names.contains("bogus"));
43                 
44                 ExpireRange.Range r;
45                 GregorianCalendar gc = new GregorianCalendar();
46                 String[] all = new String[] {"ur","cred"};
47                 
48                 // Test 3 weeks prior
49                 gc.setTime(expRange.now);
50                 gc.add(GregorianCalendar.WEEK_OF_MONTH,-3);
51                 for(String rs : all) {
52                         r = expRange.getRange(rs, gc.getTime());
53                         assertNotNull(r);
54                         assertEquals("Delete",r.name());
55                         assertFalse(r.shouldContact(null));
56                 }
57                 
58                 // Test 1 week prior
59                 gc.setTime(expRange.now);
60                 gc.add(GregorianCalendar.WEEK_OF_MONTH,-1);
61                 for(String rs : all) {
62                         r = expRange.getRange(rs, gc.getTime());
63                         assertNull(r);
64                 }
65                 
66                 // Test Today
67                 r = expRange.getRange("cred", expRange.now);
68                 assertNotNull(r);
69         }
70
71 }