Improve Batches
[aaf/authz.git] / cadi / core / src / test / java / org / onap / aaf / cadi / config / test / JU_GetAccess.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.File;
30 import java.io.IOException;
31 import java.io.PrintStream;
32
33 import org.onap.aaf.cadi.PropAccess;
34 import org.onap.aaf.cadi.config.Get;
35 import org.onap.aaf.cadi.config.GetAccess;
36
37 public class JU_GetAccess {
38
39     private String defaultVal = "some default value";
40
41     private ByteArrayOutputStream outStream;
42
43     private PropAccess access;
44     private Get.AccessGet accessGet;
45     private File file;
46     private String filePath;
47
48     @Before
49     public void setup() throws IOException {
50         outStream = new ByteArrayOutputStream();
51         System.setOut(new PrintStream(outStream));
52
53         file = File.createTempFile("GetAccess_test", "");
54         filePath = file.getAbsolutePath();
55
56         access = new PropAccess();
57         access.setProperty("cadi_prop_files", filePath);
58         accessGet = new Get.AccessGet(access);
59
60     }
61
62     @After
63     public void tearDown() {
64         System.setOut(System.out);
65
66         file.delete();
67     }
68
69     @Test
70     public void constructorTest() {
71         String output;
72
73         @SuppressWarnings("unused")
74         GetAccess getAccess = new GetAccess(accessGet);
75         String[] lines = outStream.toString().split(System.lineSeparator());
76         assertThat(lines.length, is(6));
77         output = lines[0].split(" ", 2)[1];
78
79     }
80
81     @Test
82     public void getPropertyTest1() {
83         GetAccess getAccess = new GetAccess(accessGet);
84
85         getAccess.setProperty("tag", "value");
86         assertThat(getAccess.getProperty("tag", defaultVal), is("value"));
87         assertThat(getAccess.getProperty("not_a_tag", defaultVal), is(defaultVal));
88     }
89
90     @Test
91     public void getPropertyTest2() {
92         GetAccess getAccess = new GetAccess(accessGet);
93
94         getAccess.setProperty("tag", "value");
95         assertThat(getAccess.getProperty("tag"), is("value"));
96         assertThat(getAccess.getProperty("not_a_tag"), is(nullValue()));
97     }
98
99     @Test
100     public void getTest() {
101         GetAccess getAccess = new GetAccess(accessGet);
102         assertThat((Get.AccessGet)getAccess.get(), is(accessGet));
103     }
104
105 }