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