Merge "Sonar Fix: ConfigDAO.java"
[aaf/authz.git] / misc / env / src / test / java / org / onap / aaf / misc / env / jaxb / 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.jaxb;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNull;
25 import static org.junit.Assert.assertTrue;
26 import static org.mockito.MockitoAnnotations.initMocks;
27
28 import java.util.List;
29 import java.util.Properties;
30
31 import javax.xml.namespace.QName;
32
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.junit.runner.RunWith;
36 import org.mockito.Mock;
37 import org.mockito.Mockito;
38 import org.mockito.runners.MockitoJUnitRunner;
39 import org.onap.aaf.misc.env.Env;
40 import org.onap.aaf.misc.env.LogTarget;
41 import org.onap.aaf.misc.env.Slot;
42 import org.onap.aaf.misc.env.StaticSlot;
43 import org.onap.aaf.misc.env.StoreImpl;
44 import org.onap.aaf.misc.env.TimeTaken;
45
46 @RunWith(MockitoJUnitRunner.class) 
47 public class JU_StoreImplTest {
48         
49         @Mock
50         QName qname;
51         
52         @Mock
53         Env env;
54         
55         TimeTaken tt,ttstringify;
56         
57         LogTarget logT;
58         
59         @Before
60         public void setUp() {
61                 initMocks(this);
62                 tt=Mockito.mock(TimeTaken.class);
63         Mockito.doReturn(tt).when(env).start("JAXB Marshal", Env.XML);
64                 Mockito.doNothing().when(tt).done();
65                 logT = Mockito.mock(LogTarget.class);
66                 Mockito.doReturn(logT).when(env).debug();
67         }
68
69         @Test
70     public void testPropsFromArgs() {
71                 StoreImpl bdfObj = new StoreImpl();
72                 bdfObj = new StoreImpl("");
73                 bdfObj.propsFromArgs(null, new String[] {"test"});
74                 bdfObj.propsFromArgs("test", new String[] {"test","te=st","test=1"});
75         
76     }
77         
78         @Test
79     public void testMorePropsConstructor() {
80                 Properties props = Mockito.mock(Properties.class);
81                 new StoreImpl(null,props);
82                 StoreImpl bdfObj = new StoreImpl("test",props);
83     }
84         
85         @Test
86     public void testMorePropsFileNOtExists() {
87                 Properties props = Mockito.mock(Properties.class);
88                 Mockito.doReturn("test").when(props).getProperty("test");
89                 StoreImpl bdfObj = new StoreImpl("test",props);
90     }
91         
92         @Test
93     public void testMorePropsExists() {
94                 Properties props = Mockito.mock(Properties.class);
95                 Mockito.doReturn(System.getProperty("user.dir")+"/src/test/java/org/onap/aaf/misc/env/JU_StoreImplTest.java").when(props).getProperty("test");
96                 StoreImpl bdfObj = new StoreImpl("test",props);
97     }
98         
99         @Test
100     public void testNewTransState() {
101                 StoreImpl bdfObj = new StoreImpl(null, new String[] {});
102                 bdfObj.newTransState();
103         }
104         
105         @Test
106     public void testSlot() {
107                 StoreImpl bdfObj = new StoreImpl("test", new String[] {});
108                 Slot slot = bdfObj.slot(null);
109                 assertEquals(slot.toString(),"=0");
110                 slot = bdfObj.slot("test");
111                 assertEquals(slot.toString(),"test=1");
112         }
113         
114         @Test
115         public void testExistingSlot() {
116                 StoreImpl bdfObj = new StoreImpl("test", new String[] {"test","test=1"});
117                 Slot retVal = bdfObj.existingSlot("test");
118                 assertNull(retVal);
119         }
120         
121         @Test
122         public void testExistingSlotNames() {
123                 StoreImpl bdfObj = new StoreImpl("test", new String[] {"test","test=1"});
124                 List<String> retVal = bdfObj.existingSlotNames();
125                 assertTrue(retVal.size()==0);
126         }
127         
128         @Test
129         public void testGet() {
130                 StoreImpl bdfObj = new StoreImpl("test", new String[] {"test","test=1"});
131                 Object retVal = bdfObj.get(new StaticSlot(1,"test"),qname);
132                 assertTrue(retVal instanceof QName);
133         }
134         
135         @Test
136         public void testGetSlot() {
137                 StoreImpl bdfObj = new StoreImpl("test", new String[] {"test","test=1"});
138                 Object retVal = bdfObj.get(new StaticSlot(1,"test"));
139                 assertNull(retVal);
140         }
141         
142         @Test
143         public void testExistingStaticSlotNames() {
144                 StoreImpl bdfObj = new StoreImpl("test", new String[] {"test","test=1"});
145                 List<String> retVal = bdfObj.existingStaticSlotNames();
146                 assertTrue(retVal.size()==1);
147         }
148 }