eef1a87b7f695f592bad08568392ee351f4d7596
[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_COMPONENT, "aaf_com:1.1");
77                 Server serverMock = mock(Server.class);
78                 JettyServiceStarter<AuthzEnv, AuthzTrans> jssMock = mock(JettyServiceStarter.class);
79                 aafFs = new AAF_FS(aEnv);
80                 aEnv.access().setProperty(Config.AAF_LOCATE_URL, "aaf_loc:ate.url");
81                 aafFs = new AAF_FS(aEnv);
82         }
83
84         @Test
85         public void testRegistrants() throws CadiException, LocatorException {
86                 int port = 8008;
87                 aEnv.access().setProperty(Config.AAF_URL, "www.google.com");
88                 aEnv.access().setProperty(Config.CADI_LATITUDE, "38.550674");
89                 aEnv.access().setProperty(Config.CADI_LONGITUDE, "-90.146942");
90                 aEnv.access().setProperty(Config.AAF_LOCATE_URL, "testLocateUrl");
91                 aEnv.access().setProperty(Config.HOSTNAME, "testHost");
92
93                 // Doesn't work within Jenkins
94                 Registrant<AuthzEnv>[] registrants = aafFs.registrants(port);
95                 assertNotNull(registrants);
96         }
97
98         @Test
99         public void testFilters() throws CadiException, LocatorException {
100                 aafFs.filters();
101         }
102
103         @Test
104         public void testMain() {
105                 System.setProperty("cadi_exitOnFailure", "false");
106
107                 String[] strArr = { "aaf_component=aaf_com:po.nent" };
108                 try {
109                         AAF_FS.main(strArr); // Timeout caused in Jenkins but not in local
110                 } catch (Exception e) {
111                         // Failure expected until we understand how code is.
112                 }
113         }
114
115         @After
116         public void cleanUp() {
117                 for (File f : d.listFiles()) {
118                         f.delete();
119                 }
120                 d.delete();
121                 System.setErr(System.err);
122                 System.setOut(System.out);
123         }
124
125 }