79a3dd5334f4d8a581f8476818b0e1bfce7bb409
[aaf/authz.git] / auth / auth-cmd / src / test / java / org / onap / aaf / auth / cmd / test / JU_BaseCmd.java
1 /*******************************************************************************
2  * ============LICENSE_START====================================================
3  * * org.onap.aaf
4  * * ===========================================================================
5  * * Copyright © 2017 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.cmd.test;
23
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertTrue;
26 import static org.junit.Assert.fail;
27
28 import java.io.IOException;
29 import java.security.GeneralSecurityException;
30 import java.util.Date;
31 import java.util.GregorianCalendar;
32
33 import javax.xml.datatype.DatatypeConfigurationException;
34 import javax.xml.datatype.DatatypeFactory;
35 import javax.xml.datatype.XMLGregorianCalendar;
36
37 import org.junit.BeforeClass;
38 import org.junit.Test;
39 import org.junit.runner.RunWith;
40 import org.mockito.runners.MockitoJUnitRunner;
41 import org.onap.aaf.auth.cmd.AAFcli;
42 import org.onap.aaf.auth.cmd.BaseCmd;
43 import org.onap.aaf.cadi.CadiException;
44 import org.onap.aaf.cadi.LocatorException;
45 import org.onap.aaf.cadi.client.Future;
46 import org.onap.aaf.misc.env.APIException;
47
48 import aaf.v2_0.History;
49
50 @RunWith(MockitoJUnitRunner.class)
51 public class JU_BaseCmd {
52
53         private static AAFcli cli;
54         private static BaseCmd bCmd;
55
56         @BeforeClass
57         public static void setUp() throws APIException, LocatorException, GeneralSecurityException, IOException, CadiException {
58                 cli = JU_AAFCli.getAAfCli();
59                 bCmd = new BaseCmd<>(cli, "testString");
60         }
61
62         @Test
63         public void exec() throws CadiException, APIException, LocatorException {
64                 assertEquals(bCmd._exec(4, "add", "del", "reset", "extend"), 0);
65
66         }
67         
68         @Test
69         public void exec1() throws CadiException, APIException, LocatorException {
70                 assertEquals(bCmd._exec(0, "add", "del", "reset", "extend"), 0);
71
72         }
73
74         @Test
75         public void activity() throws DatatypeConfigurationException {
76                 boolean noError = true;
77                 History history = new History();
78                 History.Item item = new History.Item();
79                 item.setTarget("target");
80                 item.setUser("user");
81                 item.setMemo("memo");
82
83                 GregorianCalendar c = new GregorianCalendar();
84                 c.setTime(new Date());
85                 XMLGregorianCalendar date = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
86                 item.setTimestamp(date);
87                 history.getItem().add(item);
88                 try {
89                         bCmd.activity(history, "history");
90                 } catch (Exception e) {
91                         noError = false;
92                 }
93                 assertEquals(noError, true);
94
95         }
96
97         @Test
98         public void activity1() throws DatatypeConfigurationException {
99                 boolean noError = true;
100                 History history = new History();
101                 History.Item item = new History.Item();
102                 item.setTarget("target");
103                 item.setUser("user");
104                 item.setMemo("memo");
105
106                 GregorianCalendar c = new GregorianCalendar();
107                 c.setTime(new Date());
108                 XMLGregorianCalendar date = DatatypeFactory.newInstance().newXMLGregorianCalendar(c);
109                 item.setTimestamp(date);
110                 history.getItem().add(item);
111                 try {
112                         bCmd.activity(history, "1[]");
113                 } catch (Exception e) {
114                         noError = false;
115                 }
116                 assertEquals(noError, true);
117
118         }
119
120 }