Increased coverage authfs
[aaf/authz.git] / auth / auth-fs / src / test / java / org / onap / aaf / auth / fs / test / JU_AAF_FS.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.fs.test;
23
24 import static org.junit.Assert.*;
25
26 import org.onap.aaf.auth.env.AuthzEnv;
27 import org.onap.aaf.auth.env.AuthzTrans;
28 import org.onap.aaf.auth.fs.AAF_FS;
29 import org.onap.aaf.auth.rserv.CachingFileAccess;
30 import org.onap.aaf.auth.server.JettyServiceStarter;
31 import org.onap.aaf.cadi.Access;
32 import org.onap.aaf.cadi.CadiException;
33 import org.onap.aaf.cadi.LocatorException;
34 import org.onap.aaf.cadi.config.Config;
35 import org.onap.aaf.misc.env.APIException;
36 import org.onap.aaf.misc.env.Slot;
37 import org.onap.aaf.misc.env.StaticSlot;
38 import org.eclipse.jetty.server.Server;
39 import org.junit.After;
40 import org.junit.Before;
41 import org.junit.Test;
42 import org.mockito.Mock;
43 import org.mockito.Mockito;
44 import static org.mockito.Mockito.*;
45
46 import java.io.ByteArrayOutputStream;
47 import java.io.File;
48 import java.io.IOException;
49 import java.io.PrintStream;
50
51 import org.junit.Test;
52
53 public class JU_AAF_FS {
54         AuthzEnv aEnv;
55         AAF_FS aafFs;
56         File fService;
57         File fEtc;
58         String value;
59         File d;
60         private static final String testDir = "src/test/resources/logs";
61         private ByteArrayOutputStream outStream;
62         private ByteArrayOutputStream errStream;
63         
64         
65         @Before
66         public void setUp() throws APIException, IOException, CadiException {
67                 outStream = new ByteArrayOutputStream();
68                 errStream = new ByteArrayOutputStream();
69                 System.setOut(new PrintStream(outStream));
70                 System.setErr(new PrintStream(errStream));
71                 value = System.setProperty(Config.CADI_LOGDIR, testDir);
72                 System.setProperty(Config.CADI_ETCDIR, testDir);
73                 System.out.println(ClassLoader.getSystemResource("org.osaaf.log4j.props"));
74                 d = new File(testDir);
75                 d.mkdirs();
76                 fService = new File(d +"/fs-serviceTEST.log");
77                 fService.createNewFile();
78                 fEtc = new File(d + "/org.osaaf.log4j.props");
79                 fEtc.createNewFile();
80                 
81                 aEnv = new AuthzEnv();
82                 aEnv.staticSlot("test");
83                 aEnv.access().setProperty("aaf_public_dir", "test");
84                 aEnv.access().setProperty(Config.AAF_COMPONENT, "aaf_com:1.1");
85                 Server serverMock = mock(Server.class);
86                 JettyServiceStarter<AuthzEnv,AuthzTrans> jssMock = mock(JettyServiceStarter.class);
87                 aafFs = new AAF_FS(aEnv);
88                 aEnv.access().setProperty(Config.AAF_LOCATE_URL, "aaf_loc:ate.url");
89                 aafFs = new AAF_FS(aEnv);
90         }
91         
92         @Test
93         public void testRegistrants() throws CadiException, LocatorException {
94                 int port = 8008;
95                 aEnv.access().setProperty(Config.AAF_URL, "www.google.com");
96                 aEnv.access().setProperty(Config.CADI_LATITUDE, "38.550674");
97                 aEnv.access().setProperty(Config.CADI_LONGITUDE, "-90.146942");
98                 aEnv.access().setProperty(Config.AAF_LOCATE_URL, "testLocateUrl");
99                 aEnv.access().setProperty(Config.HOSTNAME, "testHost");
100                 
101                 aafFs.registrants(port);
102         }
103         
104         @Test
105         public void testFilters() throws CadiException, LocatorException {
106                 aafFs.filters();
107         }
108         
109         @Test
110         public void testMain() {
111                 System.setProperty("cadi_exitOnFailure", "false");
112
113                 String[] strArr = {"aaf_component=aaf_com:po.nent"};
114                 try {
115                         //AAF_FS.main(strArr);                  //Timeout caused in Jenkins but not in local
116                 } catch(Exception e) {
117                         //Failure expected until we understand how code is.
118                 }
119         }
120         
121         @After
122         public void cleanUp() {
123                 for(File f : d.listFiles()) {
124                         f.delete();
125                 }
126                 d.delete();
127                 System.setErr(System.err);
128                 System.setOut(System.out);
129         }
130
131 }