2 * ============LICENSE_START====================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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====================================================
22 package org.onap.aaf.auth.fs.test;
24 import static org.junit.Assert.assertNotNull;
25 import static org.mockito.Mockito.mock;
27 import java.io.ByteArrayOutputStream;
29 import java.io.IOException;
30 import java.io.PrintStream;
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;
46 public class JU_AAF_FS {
53 private static final String testDir = "src/test/resources/logs";
54 private ByteArrayOutputStream outStream;
55 private ByteArrayOutputStream errStream;
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);
68 fService = new File(d + "/fs-serviceTEST.log");
69 fService.createNewFile();
70 fEtc = new File(d + "/org.osaaf.aaf.log4j.props");
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);
86 public void testRegistrants() throws CadiException, LocatorException {
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");
94 // Doesn't work within Jenkins
95 Registrant<AuthzEnv>[] registrants = aafFs.registrants(port);
96 assertNotNull(registrants);
100 public void testFilters() throws CadiException, LocatorException {
105 public void testMain() {
106 System.setProperty("cadi_exitOnFailure", "false");
108 String[] strArr = { "aaf_component=aaf_com:po.nent" };
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.
117 public void cleanUp() {
118 for (File f : d.listFiles()) {
122 System.setErr(System.err);
123 System.setOut(System.out);