Improve coverage of cadi-aaf
[aaf/authz.git] / cadi / aaf / src / test / java / org / onap / aaf / cadi / cm / test / JU_CmAgent.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.cadi.cm.test;
24
25 import java.io.ByteArrayInputStream;
26 import java.io.File;
27
28 import org.junit.After;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.onap.aaf.cadi.cm.CmAgent;
32
33 public class JU_CmAgent {
34
35         private static final String resourceDirString = "src/test/resources";
36         private static final String aafDir = resourceDirString + "/aaf";
37
38         private ByteArrayInputStream inStream;
39
40         @Before
41         public void setup() {
42                 System.setProperty("user.home", aafDir);
43
44                 // Simulate user input
45                 inStream = new ByteArrayInputStream("test\nhttp://example.com\nhttp://example.com".getBytes());
46                 System.setIn(inStream);
47         }
48
49         @After
50         public void tearDown() {
51                 recursiveDelete(new File(aafDir));
52         }
53
54         @Test
55         public void test() {
56                 String[] args;
57                 args = new String[] {
58                                 "-login",
59                                 "-noexit",
60                 };
61                 CmAgent.main(args);
62
63                 inStream.reset();
64                 args = new String[] {
65                                 "noexit=true",
66                 };
67                 CmAgent.main(args);
68
69                 inStream.reset();
70                 args = new String[] {
71                                 "place",
72                 };
73                 CmAgent.main(args);
74
75                 inStream.reset();
76                 args = new String[] {
77                                 "create"
78                 };
79                 CmAgent.main(args);
80
81                 inStream.reset();
82                 args = new String[] {
83                                 "read"
84                 };
85                 CmAgent.main(args);
86
87                 inStream.reset();
88                 args = new String[] {
89                                 "copy"
90                 };
91                 CmAgent.main(args);
92
93                 inStream.reset();
94                 args = new String[] {
95                                 "update"
96                 };
97                 CmAgent.main(args);
98
99                 inStream.reset();
100                 args = new String[] {
101                                 "delete"
102                 };
103                 CmAgent.main(args);
104
105                 inStream.reset();
106                 args = new String[] {
107                                 "showpass"
108                 };
109                 CmAgent.main(args);
110
111         }
112
113         private void recursiveDelete(File file) {
114                 for (File f : file.listFiles()) {
115                         if (f.isDirectory()) {
116                                 recursiveDelete(f);
117                         }
118                         f.delete();
119                 }
120                 file.delete();
121         }
122
123 }