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.OutputStream;
29 import java.io.StringWriter;
31 import javax.xml.bind.JAXBException;
32 import javax.xml.namespace.QName;
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.mockito.Mock;
37 import org.mockito.Mockito;
38 import org.onap.aaf.misc.env.APIException;
39 import org.onap.aaf.misc.env.Env;
40 import org.onap.aaf.misc.env.LogTarget;
41 import org.onap.aaf.misc.env.TimeTaken;
43 public class JU_JAXBStringifierTest {
54 TimeTaken tt,ttstringify;
61 tt=Mockito.mock(TimeTaken.class);
62 Mockito.doReturn(tt).when(env).start("JAXB Marshal", Env.XML);
63 Mockito.doNothing().when(tt).done();
64 logT = Mockito.mock(LogTarget.class);
65 Mockito.doReturn(logT).when(env).debug();
69 public void teststringify() {
70 JAXBStringifier<JAXBmar> bdfObj = null;
72 bdfObj = new JAXBStringifier<JAXBmar>( qname, new Class[] {this.getClass()});
73 bdfObj = new JAXBStringifier<JAXBmar>(jumar);
74 Mockito.doReturn(this.getClass()).when(jumar).marshal(logT, jumar, Mockito.mock(StringWriter.class), true);
75 bdfObj.stringify(env, jumar, true);
76 } catch (APIException e) {
77 assertTrue(e.getMessage().contains("Test Exception"));
78 } catch (JAXBException e) {
79 // TODO Auto-generated catch block
86 public void teststringifyWriter() {
87 JAXBStringifier<JAXBmar> bdfObj = null;
89 bdfObj = new JAXBStringifier<JAXBmar>(new Class[] {this.getClass()});
90 bdfObj = new JAXBStringifier<JAXBmar>(jumar);
91 Mockito.doReturn(this.getClass()).when(jumar).marshal(logT, jumar, Mockito.mock(StringWriter.class), true);
92 bdfObj.stringify(env, jumar, Mockito.mock(StringWriter.class), true);
93 } catch (APIException e) {
94 assertTrue(e.getMessage().contains("Test Exception"));
95 } catch (JAXBException e) {
96 // TODO Auto-generated catch block
103 public void teststringifyWriterException() {
104 JAXBStringifier<JAXBmar> bdfObj = null;
106 bdfObj = new JAXBStringifier<JAXBmar>(jumar);
107 StringWriter sr = Mockito.mock(StringWriter.class);
108 Mockito.doThrow(new JAXBException("Test Exception")).when(jumar).marshal(logT, jumar, sr, true);
109 bdfObj.stringify(env, jumar, sr, true);
110 } catch (APIException e) {
111 assertTrue(e.getMessage().contains("Test Exception"));
112 } catch (JAXBException e) {
113 // TODO Auto-generated catch block
120 public void teststringifyOs() {
121 JAXBStringifier<JAXBmar> bdfObj = null;
123 bdfObj = new JAXBStringifier<JAXBmar>(jumar);
124 Mockito.doReturn(this.getClass()).when(jumar).marshal(logT, jumar, Mockito.mock(OutputStream.class), true);
125 bdfObj.stringify(env, jumar, Mockito.mock(OutputStream.class), true);
126 } catch (APIException e) {
127 assertTrue(e.getMessage().contains("Test Exception"));
128 } catch (JAXBException e) {
129 // TODO Auto-generated catch block
136 public void teststringifyOsException() {
137 JAXBStringifier<JAXBmar> bdfObj = null;
139 bdfObj = new JAXBStringifier<JAXBmar>(jumar);
140 OutputStream os = Mockito.mock(OutputStream.class);
141 Mockito.doThrow(new JAXBException("Test Exception")).when(jumar).marshal(logT, jumar, os, true);
142 bdfObj.stringify(env, jumar, os, true);
143 } catch (APIException e) {
144 assertTrue(e.getMessage().contains("Test Exception"));
145 } catch (JAXBException e) {
146 // TODO Auto-generated catch block
153 public void testEmptyMethods() {
154 JAXBStringifier<JAXBmar> bdfObj = null;
156 bdfObj = new JAXBStringifier<JAXBmar>(jumar);
157 bdfObj.servicePrestart(env);
158 bdfObj.threadPrestart(env);
159 bdfObj.threadDestroy(env);
160 bdfObj.serviceDestroy(env);
162 } catch (APIException e) {
163 assertTrue(e.getMessage().contains("Test Exception"));
169 public void testPretty() {
170 JAXBStringifier<JAXBmar> bdfObj = null;
171 bdfObj = new JAXBStringifier<JAXBmar>(jumar);
172 Mockito.doReturn(jumar).when(jumar).pretty(true);
173 Object retVal = bdfObj.pretty(true);
174 assertTrue(retVal instanceof JAXBStringifier);
178 public void testNewInstanceException() {
179 JAXBStringifier<JAXBmar> bdfObj = null;
180 bdfObj = new JAXBStringifier<JAXBmar>(jumar);
181 Mockito.doReturn(jumar).when(jumar).asFragment(true);
182 Object retVal = bdfObj.asFragment(true);
183 assertTrue(retVal instanceof JAXBStringifier);