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====================================================
22 package org.onap.aaf.misc.env.jaxb;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertTrue;
26 import static org.mockito.MockitoAnnotations.initMocks;
28 import java.io.InputStream;
29 import java.io.OutputStream;
30 import java.io.StringWriter;
32 import javax.xml.bind.JAXBException;
33 import javax.xml.namespace.QName;
35 import org.junit.Before;
36 import org.junit.Test;
37 import org.mockito.Mock;
38 import org.mockito.Mockito;
39 import org.onap.aaf.misc.env.APIException;
40 import org.onap.aaf.misc.env.Env;
41 import org.onap.aaf.misc.env.LogTarget;
42 import org.onap.aaf.misc.env.TimeTaken;
44 public class JU_JAXBStringifierTest {
55 TimeTaken tt,ttstringify;
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();
70 public void teststringify() {
71 JAXBStringifier<JAXBmar> bdfObj = null;
73 bdfObj = new JAXBStringifier<JAXBmar>( qname, new Class[] {this.getClass()});
74 bdfObj = new JAXBStringifier<JAXBmar>(jumar);
75 Mockito.doReturn(this.getClass()).when(jumar).marshal(logT, jumar, Mockito.mock(StringWriter.class), true);
76 bdfObj.stringify(env, jumar, true);
77 } catch (APIException e) {
78 assertTrue(e.getMessage().contains("Test Exception"));
79 } catch (JAXBException e) {
80 // TODO Auto-generated catch block
87 public void teststringifyWriter() {
88 JAXBStringifier<JAXBmar> bdfObj = null;
90 bdfObj = new JAXBStringifier<JAXBmar>(new Class[] {this.getClass()});
91 bdfObj = new JAXBStringifier<JAXBmar>(jumar);
92 Mockito.doReturn(this.getClass()).when(jumar).marshal(logT, jumar, Mockito.mock(StringWriter.class), true);
93 bdfObj.stringify(env, jumar, Mockito.mock(StringWriter.class), true);
94 } catch (APIException e) {
95 assertTrue(e.getMessage().contains("Test Exception"));
96 } catch (JAXBException e) {
97 // TODO Auto-generated catch block
104 public void teststringifyWriterException() {
105 JAXBStringifier<JAXBmar> bdfObj = null;
107 bdfObj = new JAXBStringifier<JAXBmar>(jumar);
108 StringWriter sr = Mockito.mock(StringWriter.class);
109 Mockito.doThrow(new JAXBException("Test Exception")).when(jumar).marshal(logT, jumar, sr, true);
110 bdfObj.stringify(env, jumar, sr, true);
111 } catch (APIException e) {
112 assertTrue(e.getMessage().contains("Test Exception"));
113 } catch (JAXBException e) {
114 // TODO Auto-generated catch block
121 public void teststringifyOs() {
122 JAXBStringifier<JAXBmar> bdfObj = null;
124 bdfObj = new JAXBStringifier<JAXBmar>(jumar);
125 Mockito.doReturn(this.getClass()).when(jumar).marshal(logT, jumar, Mockito.mock(OutputStream.class), true);
126 bdfObj.stringify(env, jumar, Mockito.mock(OutputStream.class), true);
127 } catch (APIException e) {
128 assertTrue(e.getMessage().contains("Test Exception"));
129 } catch (JAXBException e) {
130 // TODO Auto-generated catch block
137 public void teststringifyOsException() {
138 JAXBStringifier<JAXBmar> bdfObj = null;
140 bdfObj = new JAXBStringifier<JAXBmar>(jumar);
141 OutputStream os = Mockito.mock(OutputStream.class);
142 Mockito.doThrow(new JAXBException("Test Exception")).when(jumar).marshal(logT, jumar, os, true);
143 bdfObj.stringify(env, jumar, os, true);
144 } catch (APIException e) {
145 assertTrue(e.getMessage().contains("Test Exception"));
146 } catch (JAXBException e) {
147 // TODO Auto-generated catch block
154 public void testEmptyMethods() {
155 JAXBStringifier<JAXBmar> bdfObj = null;
157 bdfObj = new JAXBStringifier<JAXBmar>(jumar);
158 bdfObj.servicePrestart(env);
159 bdfObj.threadPrestart(env);
160 bdfObj.threadDestroy(env);
161 bdfObj.serviceDestroy(env);
163 } catch (APIException e) {
164 assertTrue(e.getMessage().contains("Test Exception"));
170 public void testPretty() {
171 JAXBStringifier<JAXBmar> bdfObj = null;
172 bdfObj = new JAXBStringifier<JAXBmar>(jumar);
173 Mockito.doReturn(jumar).when(jumar).pretty(true);
174 Object retVal = bdfObj.pretty(true);
175 assertTrue(retVal instanceof JAXBStringifier);
179 public void testNewInstanceException() {
180 JAXBStringifier<JAXBmar> bdfObj = null;
181 bdfObj = new JAXBStringifier<JAXBmar>(jumar);
182 Mockito.doReturn(jumar).when(jumar).asFragment(true);
183 Object retVal = bdfObj.asFragment(true);
184 assertTrue(retVal instanceof JAXBStringifier);