Mass removal of all Tabs (Style Warnings)
[aaf/authz.git] / cadi / core / src / test / java / org / onap / aaf / cadi / config / test / JU_Get.java
1 /*******************************************************************************
2  * * org.onap.aaf
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
9  * *
10  *  *      http://www.apache.org/licenses/LICENSE-2.0
11  * *
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====================================================
18  * *
19  * *
20  ******************************************************************************/
21
22 package org.onap.aaf.cadi.config.test;
23
24 import static org.junit.Assert.*;
25 import static org.hamcrest.CoreMatchers.*;
26 import org.junit.*;
27
28 import java.io.ByteArrayOutputStream;
29 import java.io.PrintStream;
30
31 import org.onap.aaf.cadi.PropAccess;
32 import org.onap.aaf.cadi.config.Get;
33
34 public class JU_Get {
35
36     private String defaultVal = "some default value";
37
38     private ByteArrayOutputStream outStream;
39
40     private TestBean tb;
41
42     @Before
43     public void setup() {
44         outStream = new ByteArrayOutputStream();
45         System.setOut(new PrintStream(outStream));
46     }
47
48     @After
49     public void tearDown() {
50         System.setOut(System.out);
51     }
52
53     @Test
54     public void beanTest() {
55         tb = new TestBean();
56         tb.setProperty1("prop1");
57
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));
62     }
63
64     @Test
65     public void nullTest() {
66         assertThat(Get.NULL.get("name", defaultVal, true), is(defaultVal));
67     }
68
69     @Test
70     public void accessTest() {
71         String output;
72
73         PropAccess access = new PropAccess();
74         access.setProperty("tag", "value");
75         Get.AccessGet accessGet = new Get.AccessGet(access);
76
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" + System.lineSeparator()));
80
81         outStream.reset();
82
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 + System.lineSeparator()));
86
87         outStream.reset();
88
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" + System.lineSeparator()));
92
93         outStream.reset();
94
95         assertThat(accessGet.get("tag", defaultVal, false), is("value"));
96         assertThat(outStream.toString(), is(""));
97     }
98
99     public class TestBean implements java.io.Serializable {
100
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;
106
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; }
114
115     }
116 }