0c21bda34e66c5bb48e9a6fbe28c4d03a15b81c8
[aaf/authz.git] / misc / env / src / test / java / org / onap / aaf / misc / env / JU_BaseDataFactory.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.assertTrue;
24 import static org.mockito.MockitoAnnotations.initMocks;
25
26 import org.junit.Before;
27 import org.junit.Test;
28 import org.mockito.Mockito;
29 import org.onap.aaf.misc.env.impl.EnvFactory;
30
31 public class JU_BaseDataFactory {
32
33         @Before
34         public void setUp() throws Exception {
35                 initMocks(this);
36         }
37         
38         @Test
39         public void testGenSchemaException() {
40                 Store env = Mockito.mock(Store.class);
41                 Mockito.doReturn("testdir").when(env).get(null, EnvFactory.DEFAULT_SCHEMA_DIR);
42                 try {
43                         BaseDataFactory.genSchema(env, new String[] {});
44                 } catch (APIException e) {
45                         assertTrue(e.getLocalizedMessage().contains("does not exist.  You can set this with"));
46                 }
47         }
48         
49         @Test
50         public void testGenSchemaXsdException() {
51                 Store env = Mockito.mock(Store.class);
52                 Mockito.doReturn(System.getProperty("user.dir")).when(env).get(null, EnvFactory.DEFAULT_SCHEMA_DIR);
53                 String[] schemaFIles = new String[] {"../auth-client/src/main/xsd/aaf_2_0.xsd"};
54                 try {
55                         BaseDataFactory.genSchema(env, schemaFIles);
56                 } catch (APIException e) {
57                         assertTrue(e.getLocalizedMessage().contains("for schema validation"));
58                 }
59         }
60         
61         @Test
62         public void testGenSchemaNoException() {
63                 Store env = Mockito.mock(Store.class);
64                 Mockito.doReturn(System.getProperty("user.dir")).when(env).get(null, EnvFactory.DEFAULT_SCHEMA_DIR);
65                 String[] schemaFIles = new String[] {"../../auth-client/src/main/xsd/aaf_2_0.xsd"};
66                 try {
67                         BaseDataFactory.genSchema(env, schemaFIles);
68                 } catch (APIException e) {
69                         e.printStackTrace();
70                 }
71         }
72         
73         @Test
74         public void testGetQName() {
75                 String[] schemaFIles = new String[] {"../../auth-client/src/main/xsd/aaf_2_0.xsd"};
76                 try {
77                         BaseDataFactory.getQName(Api.class);
78                 } catch (APIException e) {
79                         assertTrue(e.getLocalizedMessage().contains("package-info does not have an XmlSchema annotation"));
80                 }
81         }
82 }