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;
29 import java.io.PrintStream;
31 import org.onap.aaf.cadi.PropAccess;
32 import org.onap.aaf.cadi.config.Get;
36 private String defaultVal = "some default value";
38 private ByteArrayOutputStream outStream;
44 outStream = new ByteArrayOutputStream();
45 System.setOut(new PrintStream(outStream));
49 public void tearDown() {
50 System.setOut(System.out);
54 public void beanTest() {
56 tb.setProperty1("prop1");
58 Get.Bean testBean = new Get.Bean(tb);
59 assertThat(testBean.get("property1", defaultVal, true), is("prop1"));
60 assertThat(testBean.get("property2", defaultVal, true), is(defaultVal));
61 assertThat(testBean.get("thrower", defaultVal, true), is(defaultVal));
65 public void nullTest() {
66 assertThat(Get.NULL.get("name", defaultVal, true), is(defaultVal));
70 public void accessTest() {
73 PropAccess access = new PropAccess();
74 access.setProperty("tag", "value");
75 Get.AccessGet accessGet = new Get.AccessGet(access);
77 assertThat(accessGet.get("tag", defaultVal, true), is("value"));
78 output = outStream.toString().split(" ", 2)[1];
79 assertThat(output, is("INIT [cadi] tag is set to value\n"));
83 assertThat(accessGet.get("not a real tag", defaultVal, true), is(defaultVal));
84 output = outStream.toString().split(" ", 2)[1];
85 assertThat(output, is("INIT [cadi] not a real tag is set to " + defaultVal + "\n"));
89 assertThat(accessGet.get("not a real tag", null, true), is(nullValue()));
90 output = outStream.toString().split(" ", 2)[1];
91 assertThat(output, is("INIT [cadi] not a real tag is not set\n"));
95 assertThat(accessGet.get("tag", defaultVal, false), is("value"));
96 assertThat(outStream.toString(), is(""));
99 public class TestBean implements java.io.Serializable {
101 private static final long serialVersionUID = 1L;
102 private String property1 = null;
103 private String property2 = null;
104 @SuppressWarnings("unused")
105 private String thrower = null;
107 public TestBean() { }
108 public String getProperty1() { return property1; }
109 public void setProperty1(final String value) { this.property1 = value; }
110 public String getProperty2() { return property2; }
111 public void setProperty2(final String value) { this.property2 = value; }
112 public String getThrower() throws Exception { throw new Exception(); }
113 public void setThrower(final String value) { this.thrower = value; }