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() {
72 PropAccess access = new PropAccess();
73 access.setProperty("tag", "value");
74 Get.AccessGet accessGet = new Get.AccessGet(access);
76 assertThat(accessGet.get("tag", defaultVal, true), is("value"));
79 assertThat(accessGet.get("not a real tag", defaultVal, true), is(defaultVal));
82 assertThat(accessGet.get("not a real tag", null, true), is(nullValue()));
86 assertThat(accessGet.get("tag", defaultVal, false), is("value"));
87 assertThat(outStream.toString(), is(""));
90 public class TestBean implements java.io.Serializable {
92 private static final long serialVersionUID = 1L;
93 private String property1 = null;
94 private String property2 = null;
95 @SuppressWarnings("unused")
96 private String thrower = null;
99 public String getProperty1() { return property1; }
100 public void setProperty1(final String value) { this.property1 = value; }
101 public String getProperty2() { return property2; }
102 public void setProperty2(final String value) { this.property2 = value; }
103 public String getThrower() throws Exception { throw new Exception(); }
104 public void setThrower(final String value) { this.thrower = value; }