X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=misc%2Fenv%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Faaf%2Fmisc%2Fenv%2Fjaxb%2FJU_JAXBStringifierTest.java;fp=misc%2Fenv%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Faaf%2Fmisc%2Fenv%2Fjaxb%2FJU_JAXBStringifierTest.java;h=7d310ae75b9e9639b2d016d906990f18563ea168;hb=7ce6d70ff56de123b483a857a77810b78b1628de;hp=0000000000000000000000000000000000000000;hpb=da120047d0da2b940947312b55da8098724e6a75;p=aaf%2Fauthz.git diff --git a/misc/env/src/test/java/org/onap/aaf/misc/env/jaxb/JU_JAXBStringifierTest.java b/misc/env/src/test/java/org/onap/aaf/misc/env/jaxb/JU_JAXBStringifierTest.java new file mode 100644 index 00000000..7d310ae7 --- /dev/null +++ b/misc/env/src/test/java/org/onap/aaf/misc/env/jaxb/JU_JAXBStringifierTest.java @@ -0,0 +1,186 @@ +/** + * ============LICENSE_START==================================================== + * org.onap.aaf + * =========================================================================== + * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved. + * =========================================================================== + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END==================================================== + * + */ +package org.onap.aaf.misc.env.jaxb; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.MockitoAnnotations.initMocks; + +import java.io.InputStream; +import java.io.OutputStream; +import java.io.StringWriter; + +import javax.xml.bind.JAXBException; +import javax.xml.namespace.QName; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.onap.aaf.misc.env.APIException; +import org.onap.aaf.misc.env.Env; +import org.onap.aaf.misc.env.LogTarget; +import org.onap.aaf.misc.env.TimeTaken; + +public class JU_JAXBStringifierTest { + + @Mock + JAXBmar jumar; + + @Mock + QName qname; + + @Mock + Env env; + + TimeTaken tt,ttstringify; + + LogTarget logT; + + @Before + public void setUp() { + initMocks(this); + tt=Mockito.mock(TimeTaken.class); + Mockito.doReturn(tt).when(env).start("JAXB Marshal", Env.XML); + Mockito.doNothing().when(tt).done(); + logT = Mockito.mock(LogTarget.class); + Mockito.doReturn(logT).when(env).debug(); + } + + @Test + public void teststringify() { + JAXBStringifier bdfObj = null; + try { + bdfObj = new JAXBStringifier( qname, new Class[] {this.getClass()}); + bdfObj = new JAXBStringifier(jumar); + Mockito.doReturn(this.getClass()).when(jumar).marshal(logT, jumar, Mockito.mock(StringWriter.class), true); + bdfObj.stringify(env, jumar, true); + } catch (APIException e) { + assertTrue(e.getMessage().contains("Test Exception")); + } catch (JAXBException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + @Test + public void teststringifyWriter() { + JAXBStringifier bdfObj = null; + try { + bdfObj = new JAXBStringifier(new Class[] {this.getClass()}); + bdfObj = new JAXBStringifier(jumar); + Mockito.doReturn(this.getClass()).when(jumar).marshal(logT, jumar, Mockito.mock(StringWriter.class), true); + bdfObj.stringify(env, jumar, Mockito.mock(StringWriter.class), true); + } catch (APIException e) { + assertTrue(e.getMessage().contains("Test Exception")); + } catch (JAXBException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + @Test + public void teststringifyWriterException() { + JAXBStringifier bdfObj = null; + try { + bdfObj = new JAXBStringifier(jumar); + StringWriter sr = Mockito.mock(StringWriter.class); + Mockito.doThrow(new JAXBException("Test Exception")).when(jumar).marshal(logT, jumar, sr, true); + bdfObj.stringify(env, jumar, sr, true); + } catch (APIException e) { + assertTrue(e.getMessage().contains("Test Exception")); + } catch (JAXBException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + @Test + public void teststringifyOs() { + JAXBStringifier bdfObj = null; + try { + bdfObj = new JAXBStringifier(jumar); + Mockito.doReturn(this.getClass()).when(jumar).marshal(logT, jumar, Mockito.mock(OutputStream.class), true); + bdfObj.stringify(env, jumar, Mockito.mock(OutputStream.class), true); + } catch (APIException e) { + assertTrue(e.getMessage().contains("Test Exception")); + } catch (JAXBException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + @Test + public void teststringifyOsException() { + JAXBStringifier bdfObj = null; + try { + bdfObj = new JAXBStringifier(jumar); + OutputStream os = Mockito.mock(OutputStream.class); + Mockito.doThrow(new JAXBException("Test Exception")).when(jumar).marshal(logT, jumar, os, true); + bdfObj.stringify(env, jumar, os, true); + } catch (APIException e) { + assertTrue(e.getMessage().contains("Test Exception")); + } catch (JAXBException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + @Test + public void testEmptyMethods() { + JAXBStringifier bdfObj = null; + try { + bdfObj = new JAXBStringifier(jumar); + bdfObj.servicePrestart(env); + bdfObj.threadPrestart(env); + bdfObj.threadDestroy(env); + bdfObj.serviceDestroy(env); + bdfObj.refresh(env); + } catch (APIException e) { + assertTrue(e.getMessage().contains("Test Exception")); + } + + } + + @Test + public void testPretty() { + JAXBStringifier bdfObj = null; + bdfObj = new JAXBStringifier(jumar); + Mockito.doReturn(jumar).when(jumar).pretty(true); + Object retVal = bdfObj.pretty(true); + assertTrue(retVal instanceof JAXBStringifier); + } + + @Test + public void testNewInstanceException() { + JAXBStringifier bdfObj = null; + bdfObj = new JAXBStringifier(jumar); + Mockito.doReturn(jumar).when(jumar).asFragment(true); + Object retVal = bdfObj.asFragment(true); + assertTrue(retVal instanceof JAXBStringifier); + + } +}