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