db48345ca92447fb5afba018616c00335d6a3ada
[aaf/authz.git] / misc / env / src / test / java / org / onap / aaf / misc / env / JU_StoreImplTest.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
4  * ===========================================================================
5  * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6  * ===========================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END====================================================
19  *
20  */
21 package org.onap.aaf.misc.env;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNull;
25 import static org.junit.Assert.assertSame;
26 import static org.junit.Assert.assertTrue;
27 import static org.mockito.MockitoAnnotations.initMocks;
28
29 import java.io.File;
30 import java.util.List;
31 import java.util.Properties;
32
33 import javax.xml.namespace.QName;
34
35 import org.junit.Before;
36 import org.junit.Test;
37 import org.junit.runner.RunWith;
38 import org.mockito.Mock;
39 import org.mockito.Mockito;
40 import org.mockito.runners.MockitoJUnitRunner;
41
42 @RunWith(MockitoJUnitRunner.class) 
43 public class JU_StoreImplTest {
44         
45         @Mock
46         QName qname;
47         
48         @Mock
49         Env env;
50         
51         TimeTaken tt,ttstringify;
52         
53         LogTarget logT;
54         
55         @Before
56         public void setUp() {
57                 initMocks(this);
58                 tt=Mockito.mock(TimeTaken.class);
59         Mockito.doReturn(tt).when(env).start("JAXB Marshal", Env.XML);
60                 Mockito.doNothing().when(tt).done();
61                 logT = Mockito.mock(LogTarget.class);
62                 Mockito.doReturn(logT).when(env).debug();
63         }
64
65         @Test
66     public void testPropsFromArgs() {
67                 StoreImpl bdfObj = new StoreImpl();
68                 bdfObj = new StoreImpl("");
69                 bdfObj.propsFromArgs(null, new String[] {"test"});
70                 bdfObj.propsFromArgs("test", new String[] {"test","te=st","test=1"});
71         
72     }
73         
74         @Test
75     public void testMorePropsConstructor() {
76                 Properties props = Mockito.mock(Properties.class);
77                 new StoreImpl(null,props);
78                 StoreImpl bdfObj = new StoreImpl("test",props);
79     }
80         
81         @Test
82     public void testMorePropsFileNOtExists() {
83                 Properties props = Mockito.mock(Properties.class);
84                 Mockito.doReturn("test").when(props).getProperty("test");
85                 StoreImpl bdfObj = new StoreImpl("test",props);
86     }
87         
88         @Test
89     public void testMorePropsExists() {
90                 Properties props = Mockito.mock(Properties.class);
91                 Mockito.doReturn(System.getProperty("user.dir")+"/src/test/java/org/onap/aaf/misc/env/JU_StoreImplTest.java").when(props).getProperty("test");
92                 StoreImpl bdfObj = new StoreImpl("test",props);
93     }
94         
95         @Test
96     public void testNewTransState() {
97                 StoreImpl bdfObj = new StoreImpl(null, new String[] {});
98                 bdfObj.newTransState();
99         }
100         
101         @Test
102     public void testSlot() {
103                 StoreImpl bdfObj = new StoreImpl("test", new String[] {});
104                 Slot slot = bdfObj.slot(null);
105                 assertEquals(slot.toString(),"=0");
106                 slot = bdfObj.slot("test");
107                 assertEquals(slot.toString(),"test=1");
108         }
109         
110         @Test
111         public void testExistingSlot() {
112                 StoreImpl bdfObj = new StoreImpl("test", new String[] {"test","test=1"});
113                 Slot retVal = bdfObj.existingSlot("test");
114                 assertNull(retVal);
115         }
116         
117         @Test
118         public void testExistingSlotNames() {
119                 StoreImpl bdfObj = new StoreImpl("test", new String[] {"test","test=1"});
120                 List<String> retVal = bdfObj.existingSlotNames();
121                 assertTrue(retVal.size()==0);
122         }
123         
124         @Test
125         public void testGet() {
126                 StoreImpl bdfObj = new StoreImpl("test", new String[] {"test","test=1"});
127                 Object retVal = bdfObj.get(new StaticSlot(1,"test"),qname);
128                 assertTrue(retVal instanceof QName);
129         }
130         
131         @Test
132         public void testGetSlot() {
133                 StoreImpl bdfObj = new StoreImpl("test", new String[] {"test","test=1"});
134                 Object retVal = bdfObj.get(new StaticSlot(1,"test"));
135                 assertNull(retVal);
136         }
137         
138         @Test
139         public void testExistingStaticSlotNames() {
140                 StoreImpl bdfObj = new StoreImpl("test", new String[] {"test","test=1"});
141                 List<String> retVal = bdfObj.existingStaticSlotNames();
142                 assertTrue(retVal.size()==1);
143         }
144 }