1 /*******************************************************************************
3 * * ===========================================================================
4 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
5 * * ===========================================================================
6 * * Licensed under the Apache License, Version 2.0 (the "License");
7 * * you may not use this file except in compliance with the License.
8 * * You may obtain a copy of the License at
10 * * http://www.apache.org/licenses/LICENSE-2.0
12 * * Unless required by applicable law or agreed to in writing, software
13 * * distributed under the License is distributed on an "AS IS" BASIS,
14 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * * See the License for the specific language governing permissions and
16 * * limitations under the License.
17 * * ============LICENSE_END====================================================
20 ******************************************************************************/
22 package org.onap.aaf.cadi.config.test;
24 import static org.junit.Assert.*;
25 import static org.hamcrest.CoreMatchers.*;
28 import java.io.ByteArrayOutputStream;
30 import java.io.IOException;
31 import java.io.PrintStream;
33 import org.onap.aaf.cadi.PropAccess;
34 import org.onap.aaf.cadi.config.Get;
35 import org.onap.aaf.cadi.config.GetAccess;
37 public class JU_GetAccess {
39 private String defaultVal = "some default value";
41 private ByteArrayOutputStream outStream;
43 private PropAccess access;
44 private Get.AccessGet accessGet;
46 private String filePath;
49 public void setup() throws IOException {
50 outStream = new ByteArrayOutputStream();
51 System.setOut(new PrintStream(outStream));
53 file = File.createTempFile("GetAccess_test", "");
54 filePath = file.getAbsolutePath();
56 access = new PropAccess();
57 access.setProperty("cadi_prop_files", filePath);
58 accessGet = new Get.AccessGet(access);
63 public void tearDown() {
64 System.setOut(System.out);
70 public void constructorTest() {
73 @SuppressWarnings("unused")
74 GetAccess getAccess = new GetAccess(accessGet);
75 String[] lines = outStream.toString().split("\n");
76 assertThat(lines.length, is(2));
77 output = lines[0].split(" ", 2)[1];
78 assertThat(output, is("INIT [cadi] cadi_prop_files is set to " + filePath));
79 output = lines[1].split(" ", 2)[1];
80 assertThat(output, is("INIT [cadi] Loading CADI Properties from " + filePath));
84 public void getPropertyTest1() {
85 GetAccess getAccess = new GetAccess(accessGet);
87 getAccess.setProperty("tag", "value");
88 assertThat(getAccess.getProperty("tag", defaultVal), is("value"));
89 assertThat(getAccess.getProperty("not_a_tag", defaultVal), is(defaultVal));
93 public void getPropertyTest2() {
94 GetAccess getAccess = new GetAccess(accessGet);
96 getAccess.setProperty("tag", "value");
97 assertThat(getAccess.getProperty("tag"), is("value"));
98 assertThat(getAccess.getProperty("not_a_tag"), is(nullValue()));
102 public void getTest() {
103 GetAccess getAccess = new GetAccess(accessGet);
104 assertThat((Get.AccessGet)getAccess.get(), is(accessGet));