2 * ============LICENSE_START====================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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====================================================
21 package org.onap.aaf.misc.env.jaxb;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertTrue;
25 import static org.mockito.MockitoAnnotations.initMocks;
27 import java.io.InputStream;
28 import java.io.StringReader;
30 import javax.xml.bind.JAXBException;
31 import javax.xml.validation.Schema;
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.mockito.Mock;
36 import org.mockito.Mockito;
37 import org.onap.aaf.misc.env.APIException;
38 import org.onap.aaf.misc.env.Env;
39 import org.onap.aaf.misc.env.LogTarget;
40 import org.onap.aaf.misc.env.TimeTaken;
42 public class JU_JAXBObjectifierTest {
53 TimeTaken tt,ttObjectify;
60 tt=Mockito.mock(TimeTaken.class);
61 Mockito.doReturn(tt).when(env).start("JAXB Unmarshal", Env.XML);
62 Mockito.doNothing().when(tt).done();
63 logT = Mockito.mock(LogTarget.class);
64 Mockito.doReturn(logT).when(env).debug();
68 public void testObjectify() {
69 JAXBObjectifier<?> bdfObj = null;
71 bdfObj = new JAXBObjectifier( schema, new Class[] {this.getClass()});
72 bdfObj = new JAXBObjectifier(jumar);
73 Mockito.doReturn(this.getClass()).when(jumar).unmarshal(logT, "test");
74 bdfObj.objectify(env, "test");
75 } catch (APIException e) {
76 assertTrue(e.getMessage().contains("Test Exception"));
77 } catch (JAXBException e) {
78 // TODO Auto-generated catch block
85 public void testObjectifyException() {
86 JAXBObjectifier<?> bdfObj = null;
88 bdfObj = new JAXBObjectifier(jumar);
89 Mockito.doThrow(new JAXBException("Test Exception")).when(jumar).unmarshal(logT, "test");
90 bdfObj.objectify(env, "test");
91 } catch (APIException e) {
92 assertTrue(e.getMessage().contains("Test Exception"));
93 } catch (JAXBException e) {
94 // TODO Auto-generated catch block
101 public void testObjectifyRdr() {
102 JAXBObjectifier<?> bdfObj = null;
104 bdfObj = new JAXBObjectifier(new Class[] {this.getClass()});
105 bdfObj = new JAXBObjectifier(jumar);
106 Mockito.doReturn(this.getClass()).when(jumar).unmarshal(logT, Mockito.mock(StringReader.class));
107 bdfObj.objectify(env, Mockito.mock(StringReader.class));
108 } catch (APIException e) {
109 assertTrue(e.getMessage().contains("Test Exception"));
110 } catch (JAXBException e) {
111 // TODO Auto-generated catch block
118 public void testObjectifyRdrException() {
119 JAXBObjectifier<?> bdfObj = null;
121 bdfObj = new JAXBObjectifier(jumar);
122 StringReader sr = Mockito.mock(StringReader.class);
123 Mockito.doThrow(new JAXBException("Test Exception")).when(jumar).unmarshal(logT, sr);
124 bdfObj.objectify(env, sr);
125 } catch (APIException e) {
126 assertTrue(e.getMessage().contains("Test Exception"));
127 } catch (JAXBException e) {
128 // TODO Auto-generated catch block
135 public void testObjectifyIs() {
136 JAXBObjectifier<?> bdfObj = null;
138 bdfObj = new JAXBObjectifier(jumar);
139 Mockito.doReturn(this.getClass()).when(jumar).unmarshal(logT, Mockito.mock(InputStream.class));
140 bdfObj.objectify(env, Mockito.mock(InputStream.class));
141 } catch (APIException e) {
142 assertTrue(e.getMessage().contains("Test Exception"));
143 } catch (JAXBException e) {
144 // TODO Auto-generated catch block
151 public void testObjectifyIsException() {
152 JAXBObjectifier<?> bdfObj = null;
154 bdfObj = new JAXBObjectifier(jumar);
155 InputStream sr = Mockito.mock(InputStream.class);
156 Mockito.doThrow(new JAXBException("Test Exception")).when(jumar).unmarshal(logT, sr);
157 bdfObj.objectify(env, sr);
158 } catch (APIException e) {
159 assertTrue(e.getMessage().contains("Test Exception"));
160 } catch (JAXBException e) {
161 // TODO Auto-generated catch block
168 public void testEmptyMethods() {
169 JAXBObjectifier<?> bdfObj = null;
171 bdfObj = new JAXBObjectifier(jumar);
172 bdfObj.servicePrestart(env);
173 bdfObj.threadPrestart(env);
174 bdfObj.threadDestroy(env);
175 bdfObj.serviceDestroy(env);
177 } catch (APIException e) {
178 assertTrue(e.getMessage().contains("Test Exception"));
184 public void testNewInstance() {
185 JAXBObjectifier<?> bdfObj = null;
187 bdfObj = new JAXBObjectifier(jumar);
188 Object retVal = bdfObj.newInstance();
189 Mockito.doThrow(new IllegalAccessException("Test Exception")).when(jumar).newInstance();
191 } catch (IllegalAccessException e) {
192 assertEquals("Test Exception", e.getLocalizedMessage());
193 } catch (APIException e) {
194 assertTrue(e.getMessage().contains("Test Exception"));
195 } catch (InstantiationException e) {
196 // TODO Auto-generated catch block
202 public void testNewInstanceException() {
203 JAXBObjectifier<?> bdfObj = null;
205 bdfObj = new JAXBObjectifier(jumar);
206 Mockito.doThrow(new IllegalAccessException("Test Exception")).when(jumar).newInstance();
207 Object retVal = bdfObj.newInstance();
208 } catch (IllegalAccessException e) {
209 assertEquals("Test Exception", e.getLocalizedMessage());
210 } catch (APIException e) {
211 assertTrue(e.getMessage().contains("Test Exception"));
212 } catch (InstantiationException e) {
213 // TODO Auto-generated catch block