--- /dev/null
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+package org.onap.aaf.misc.env;\r
+\r
+import static org.junit.Assert.assertEquals;\r
+\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+\r
+public class JU_APIExceptionTest {\r
+\r
+ private static final String EXCEPTION_MESSAGE = "New API Exception for test";\r
+\r
+ @Before\r
+ public void setUp() throws Exception {\r
+ }\r
+\r
+ @Test\r
+ public void testNewAPIExceptionWithMessage() {\r
+ APIException exception = new APIException(EXCEPTION_MESSAGE);\r
+\r
+ assertEquals(exception.getMessage(), EXCEPTION_MESSAGE);\r
+ }\r
+\r
+ @Test\r
+ public void testNewAPIExceptionCreatedWithMessageAndThrowable() {\r
+ Throwable throwable = new Throwable();\r
+ APIException exception = new APIException(EXCEPTION_MESSAGE, throwable);\r
+\r
+ assertEquals(exception.getMessage(), EXCEPTION_MESSAGE);\r
+ assertEquals(exception.getCause(), throwable);\r
+ }\r
+\r
+ @Test\r
+ public void testNewAPIExceptionCreatedWithThrowable() {\r
+ Throwable throwable = new Throwable();\r
+ APIException exception = new APIException(throwable);\r
+\r
+ assertEquals(exception.getCause(), throwable);\r
+ }\r
+\r
+ @Test\r
+ public void testPayloadSetter() {\r
+ Throwable throwable = new Throwable();\r
+ Object payload = new Object();\r
+\r
+ APIException exception = new APIException(throwable);\r
+\r
+ exception.setPayload(payload);\r
+\r
+ assertEquals(exception.getPayload(), payload);\r
+ }\r
+}\r
--- /dev/null
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+package org.onap.aaf.misc.env;\r
+\r
+import static org.junit.Assert.assertEquals;\r
+import static org.mockito.Mockito.when;\r
+\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.junit.runner.RunWith;\r
+import org.mockito.Mock;\r
+import org.mockito.runners.MockitoJUnitRunner;\r
+import org.onap.aaf.misc.env.impl.BasicTrans;\r
+\r
+@RunWith(MockitoJUnitRunner.class)\r
+public class JU_BasicTransTest {\r
+\r
+ BasicTrans trans = null;\r
+\r
+ @Mock\r
+ private EnvJAXB env;\r
+\r
+ @Mock\r
+ private TimeTaken timeTaken;\r
+\r
+ @Before\r
+ public void setUp() throws Exception {\r
+ trans = new BasicTrans(env);\r
+ }\r
+\r
+ @Test\r
+ public void testSlot() {\r
+ Slot slot = new Slot(1, "XML");\r
+ when(env.slot("XML")).thenReturn(slot);\r
+\r
+ Slot outputSlot = trans.slot("XML");\r
+ Object[] state = new Object[2];\r
+\r
+ slot.put(state, "JSON");\r
+\r
+ assertEquals(slot.get(state), "JSON");\r
+ assertEquals(slot.getKey(), outputSlot.getKey());\r
+ assertEquals(slot.toString(), outputSlot.toString());\r
+ }\r
+\r
+ @Test\r
+ public void testGetStaticSlot() {\r
+ StaticSlot staticSlot = new StaticSlot(1, "XML");\r
+ when(env.get(staticSlot)).thenReturn(staticSlot.toString());\r
+\r
+ assertEquals(staticSlot.toString(), trans.get(staticSlot));\r
+ }\r
+\r
+ @Test\r
+ public void testGetStaticSlotWithT() {\r
+ StaticSlot staticSlot = new StaticSlot(1, "XML");\r
+ when(env.get(staticSlot, "XML")).thenReturn(staticSlot.getKey());\r
+\r
+ assertEquals(staticSlot.getKey(), trans.get(staticSlot, "XML"));\r
+ }\r
+\r
+ @Test\r
+ public void testSetProperty() {\r
+ String tag = "tag";\r
+ String value = "value";\r
+ String defltValue = "diffValue";\r
+ when(env.setProperty(tag, value)).thenReturn(value);\r
+ when(env.getProperty(tag)).thenReturn(value);\r
+ when(env.getProperty(tag, defltValue)).thenReturn(defltValue);\r
+\r
+ assertEquals(value, trans.setProperty(tag, value));\r
+ assertEquals(value, trans.getProperty(tag));\r
+ assertEquals(defltValue, trans.getProperty(tag, defltValue));\r
+ }\r
+\r
+ @Test\r
+ public void testDecryptor() {\r
+ when(env.decryptor()).thenReturn(Decryptor.NULL);\r
+\r
+ assertEquals(Decryptor.NULL, trans.decryptor());\r
+ assertEquals("tag", trans.decryptor().decrypt("tag"));\r
+ }\r
+\r
+ @Test\r
+ public void testEncryptor() {\r
+ when(env.encryptor()).thenReturn(Encryptor.NULL);\r
+\r
+ assertEquals(Encryptor.NULL, trans.encryptor());\r
+ assertEquals("tag", trans.encryptor().encrypt("tag"));\r
+ }\r
+}\r
--- /dev/null
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+package org.onap.aaf.misc.env.impl;\r
+\r
+import static org.junit.Assert.assertEquals;\r
+import static org.junit.Assert.assertTrue;\r
+\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.onap.aaf.misc.env.EnvJAXB;\r
+import org.onap.aaf.misc.env.TransCreate;\r
+import org.onap.aaf.misc.env.TransJAXB;\r
+\r
+public class JU_EnvFactoryTest {\r
+\r
+ @Before\r
+ public void setUp() throws Exception {\r
+ }\r
+\r
+ @Test\r
+ public void testSingleton() {\r
+ BasicEnv singleton = EnvFactory.singleton();\r
+\r
+ assertEquals(EnvFactory.singleton, singleton);\r
+ }\r
+\r
+ @Test\r
+ public void testSetSingleton() {\r
+ String[] str = { "argument1" };\r
+ BasicEnv env = new BasicEnv("tag", str);\r
+ EnvFactory.setSingleton(env);\r
+\r
+ assertEquals(EnvFactory.singleton(), env);\r
+ }\r
+\r
+ @Test\r
+ public void testNewTrans() {\r
+ TransJAXB newTrans = EnvFactory.newTrans();\r
+\r
+ assertTrue(newTrans instanceof BasicTrans);\r
+ }\r
+\r
+ @Test\r
+ public void testNewTransEnvJAXB() {\r
+ EnvJAXB env = new BasicEnv("");\r
+\r
+ TransJAXB trans = EnvFactory.newTrans(env);\r
+\r
+ assertTrue(trans instanceof BasicTrans);\r
+ }\r
+\r
+ @Test\r
+ public void testTransCreator() {\r
+ TransCreate<TransJAXB> transCreator = EnvFactory.transCreator();\r
+\r
+ TransJAXB newTrans = transCreator.newTrans();\r
+\r
+ assertTrue(newTrans instanceof BasicTrans);\r
+ }\r
+\r
+}\r
--- /dev/null
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+package org.onap.aaf.misc.env.jaxb;\r
+\r
+import static org.junit.Assert.assertEquals;\r
+import static org.junit.Assert.assertTrue;\r
+import static org.mockito.Mockito.mock;\r
+import static org.mockito.Mockito.verify;\r
+import static org.mockito.Mockito.when;\r
+\r
+import java.io.ByteArrayInputStream;\r
+import java.io.IOException;\r
+import java.io.OutputStream;\r
+import java.io.Writer;\r
+\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.mockito.Mock;\r
+import org.onap.aaf.misc.env.APIException;\r
+import org.onap.aaf.misc.env.Env;\r
+import org.onap.aaf.misc.env.EnvJAXB;\r
+import org.onap.aaf.misc.env.IOStringifier;\r
+import org.onap.aaf.misc.env.old.Objectifier;\r
+import org.onap.aaf.misc.env.old.Stringifier;\r
+\r
+public class JU_JAXBDataTest {\r
+\r
+ @Mock\r
+ private Objectifier<String> objfr;\r
+\r
+ private String object = "Text";\r
+\r
+ @Mock\r
+ private Stringifier<String> strfr;\r
+\r
+ @Mock\r
+ private IOStringifier<String> ioStrfr;\r
+\r
+ @Mock\r
+ private JAXBDF<String> df;\r
+\r
+ @Mock\r
+ private Env env;\r
+\r
+ @Mock\r
+ private Class<String> typeClass;\r
+\r
+ @Mock\r
+ private OutputStream os;\r
+\r
+ @Mock\r
+ private Writer writer;\r
+\r
+ @Mock\r
+ private EnvJAXB env1;\r
+\r
+ @Before\r
+ public void setUp() throws Exception {\r
+ writer = mock(Writer.class);\r
+ os = mock(OutputStream.class);\r
+ strfr = mock(Stringifier.class);\r
+ ioStrfr = mock(IOStringifier.class);\r
+ objfr = mock(Objectifier.class);\r
+ env1 = mock(EnvJAXB.class);\r
+ }\r
+\r
+ @Test\r
+ public void testJAXBDataEnv() throws APIException, IOException {\r
+ JAXBData<String> jaxb = new JAXBData<String>(env, df, strfr, objfr, object, typeClass);\r
+\r
+ when(objfr.objectify(env, object)).thenReturn("String1");\r
+\r
+ jaxb.to(os);\r
+ jaxb.to(writer);\r
+\r
+ verify(writer).write(object);\r
+ verify(os).write(object.getBytes());\r
+\r
+ assertEquals(jaxb.asString(), object);\r
+ assertEquals(jaxb.asString(null), object);\r
+ assertEquals(jaxb.toString(), object);\r
+ assertEquals(jaxb.getTypeClass(), typeClass);\r
+ assertEquals(jaxb.out(null), jaxb);\r
+ assertEquals(jaxb.in(null), jaxb);\r
+ assertTrue(jaxb.getInputStream() instanceof ByteArrayInputStream);\r
+ assertEquals(jaxb.asObject(), "String1");\r
+ assertEquals(jaxb.asObject(env1), "String1");\r
+ assertEquals(jaxb.toString(), object);\r
+ }\r
+\r
+ @Test\r
+ public void testJAXBDataEnvForObjectifier() throws APIException, IOException {\r
+ JAXBData<String> jaxb = new JAXBData<String>(env, df, strfr, objfr, object, typeClass);\r
+\r
+ when(objfr.objectify(env1, object)).thenReturn("String1");\r
+\r
+ assertEquals(jaxb.asObject(env1), "String1");\r
+ }\r
+\r
+ @Test\r
+ public void testJAXBDataEnvWithObject() throws APIException, IOException {\r
+ JAXBData<String> jaxb = new JAXBData<String>(env, df, strfr, objfr, object);\r
+\r
+ when(strfr.stringify(env, object, new boolean[] { false, false })).thenReturn(object);\r
+\r
+ jaxb.to(os);\r
+\r
+ verify(os).write(object.getBytes());\r
+\r
+ assertEquals(jaxb.asString(), object);\r
+ assertEquals(jaxb.asString(null), object);\r
+ assertEquals(jaxb.toString(), object);\r
+ }\r
+\r
+ @Test\r
+ public void testJAXBDataEnvForWriter() throws APIException, IOException {\r
+ JAXBData<String> jaxb = new JAXBData<String>(env, df, strfr, objfr, object);\r
+\r
+ when(strfr.stringify(env, object, new boolean[] { false, false })).thenReturn(object);\r
+\r
+ jaxb.to(writer);\r
+\r
+ verify(writer).write(object);\r
+\r
+ assertEquals(jaxb.asString(), object);\r
+ assertEquals(jaxb.asString(null), object);\r
+ assertEquals(jaxb.toString(), object);\r
+ assertEquals(jaxb.asObject(), object);\r
+ assertEquals(jaxb.asObject(null), object);\r
+ }\r
+\r
+ @Test\r
+ public void testAsStringWithNullString() throws APIException, IOException {\r
+ JAXBData<String> jaxb = new JAXBData<String>(env, df, strfr, objfr, object);\r
+\r
+ when(strfr.stringify(env, object, new boolean[] { false, false })).thenReturn(object);\r
+\r
+ assertEquals(jaxb.asString(), object);\r
+ }\r
+\r
+ @Test\r
+ public void testAsStringWithNullStringWithEnv() throws APIException, IOException {\r
+ JAXBData<String> jaxb = new JAXBData<String>(env, df, strfr, objfr, object);\r
+\r
+ when(strfr.stringify(env1, object)).thenReturn(object);\r
+\r
+ assertEquals(jaxb.asString(env1), object);\r
+ }\r
+\r
+ @Test\r
+ public void testToWithIOStrifier() throws APIException, IOException {\r
+ JAXBData<String> jaxb = new JAXBData<String>(env, df, strfr, objfr, object);\r
+\r
+ jaxb.option(0);\r
+\r
+ when(strfr.stringify(env1, object)).thenReturn(object);\r
+ when(strfr.stringify(env, object, new boolean[] { false, false })).thenReturn(object);\r
+\r
+ assertTrue(jaxb.getInputStream() instanceof ByteArrayInputStream);\r
+ assertEquals(jaxb.asString(env1), object);\r
+ }\r
+}\r
--- /dev/null
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+package org.onap.aaf.misc.env.util;\r
+\r
+import static org.mockito.Mockito.mock;\r
+import static org.mockito.Mockito.never;\r
+import static org.mockito.Mockito.only;\r
+import static org.mockito.Mockito.verify;\r
+\r
+import java.io.IOException;\r
+import java.io.OutputStream;\r
+\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.mockito.Mock;\r
+\r
+public class JU_DoubleOutputStreamTest {\r
+\r
+ @Mock\r
+ private OutputStream stream1;\r
+\r
+ @Mock\r
+ private OutputStream stream2;\r
+\r
+ private DoubleOutputStream doubleOutputStream;\r
+\r
+ @Before\r
+ public void setup() {\r
+ stream1 = mock(OutputStream.class);\r
+ stream2 = mock(OutputStream.class);\r
+ }\r
+\r
+ @Test\r
+ public void testWriteInt() throws IOException {\r
+ doubleOutputStream = new DoubleOutputStream(stream1, true, stream2, true);\r
+\r
+ doubleOutputStream.write(123);\r
+\r
+ verify(stream1, only()).write(123);\r
+ verify(stream2, only()).write(123);\r
+ }\r
+\r
+ @Test\r
+ public void testWriteByteArray() throws IOException {\r
+ doubleOutputStream = new DoubleOutputStream(stream1, true, stream2, true);\r
+\r
+ byte[] bytes = { 1, 2, 3, 4 };\r
+\r
+ doubleOutputStream.write(bytes);\r
+\r
+ verify(stream1, only()).write(bytes);\r
+ verify(stream2, only()).write(bytes);\r
+\r
+ }\r
+\r
+ @Test\r
+ public void testWriteByteArrayWithOffset() throws IOException {\r
+ doubleOutputStream = new DoubleOutputStream(stream1, true, stream2, true);\r
+\r
+ byte[] bytes = { 1, 2, 3, 4 };\r
+\r
+ doubleOutputStream.write(bytes, 1, 3);\r
+ verify(stream1, only()).write(bytes, 1, 3);\r
+ verify(stream2, only()).write(bytes, 1, 3);\r
+ }\r
+\r
+ @Test\r
+ public void testFlush() throws IOException {\r
+ doubleOutputStream = new DoubleOutputStream(stream1, true, stream2, true);\r
+\r
+ doubleOutputStream.flush();\r
+\r
+ verify(stream1, only()).flush();\r
+ verify(stream2, only()).flush();\r
+ }\r
+\r
+ @Test\r
+ public void testClose() throws IOException {\r
+ doubleOutputStream = new DoubleOutputStream(stream1, true, stream2, false);\r
+\r
+ doubleOutputStream.close();\r
+\r
+ verify(stream1, only()).close();\r
+ verify(stream2, never()).close();\r
+ }\r
+}\r
--- /dev/null
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+package org.onap.aaf.misc.env.util;\r
+\r
+import static org.junit.Assert.assertEquals;\r
+import static org.mockito.Mockito.mock;\r
+import static org.mockito.Mockito.times;\r
+import static org.mockito.Mockito.verify;\r
+\r
+import java.io.IOException;\r
+import java.io.OutputStream;\r
+import java.io.Writer;\r
+\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.mockito.Mock;\r
+\r
+public class JU_IndentPrintWriterTest {\r
+\r
+ @Mock\r
+ private OutputStream stream;\r
+\r
+ @Mock\r
+ private Writer writer;\r
+\r
+ @Before\r
+ public void setUp() throws Exception {\r
+ stream = mock(OutputStream.class);\r
+ writer = mock(Writer.class);\r
+ }\r
+\r
+ @Test\r
+ public void testWriteInt() throws IOException {\r
+ IndentPrintWriter indentWriter = new IndentPrintWriter(writer);\r
+\r
+ indentWriter.write(123);\r
+\r
+ verify(writer).write(123);\r
+\r
+ assertEquals(indentWriter.getIndent(), 0);\r
+ }\r
+\r
+ @Test\r
+ public void testWriteIntWithNewLineCharacter() throws IOException {\r
+ IndentPrintWriter indentWriter = new IndentPrintWriter(writer);\r
+\r
+ indentWriter.setIndent(12);\r
+\r
+ indentWriter.println();\r
+\r
+ indentWriter.write("123", 1, 2);\r
+\r
+ verify(writer).write('\n');\r
+ verify(writer).write('2');\r
+ verify(writer).write('3');\r
+ assertEquals(indentWriter.getIndent(), 12);\r
+ }\r
+\r
+ @Test\r
+ public void testWriteString() throws IOException {\r
+ IndentPrintWriter indentWriter = new IndentPrintWriter(writer);\r
+\r
+ indentWriter.inc();\r
+\r
+ indentWriter.write("123");\r
+\r
+ verify(writer).write('1');\r
+ verify(writer).write('2');\r
+ verify(writer).write('3');\r
+ assertEquals(indentWriter.getIndent(), 1);\r
+ }\r
+\r
+ @Test\r
+ public void testSetIndent() throws IOException {\r
+ IndentPrintWriter indentWriter = new IndentPrintWriter(stream);\r
+\r
+ indentWriter.setIndent(12);\r
+ indentWriter.dec();\r
+\r
+ assertEquals(indentWriter.getIndent(), 11);\r
+ }\r
+\r
+ @Test\r
+ public void testToCol() throws IOException {\r
+ IndentPrintWriter indentWriter = new IndentPrintWriter(writer);\r
+\r
+ indentWriter.toCol(5);\r
+ char[] chars = { 'a', 'b', 'c' };\r
+ indentWriter.write(chars, 1, 2);\r
+\r
+ verify(writer, times(5)).write(' ');\r
+ verify(writer).write('c');\r
+ verify(writer).write('b');\r
+ }\r
+}
\ No newline at end of file
--- /dev/null
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+package org.onap.aaf.misc.env.util;\r
+\r
+import static org.junit.Assert.assertEquals;\r
+import static org.junit.Assert.assertNotNull;\r
+import static org.junit.Assert.fail;\r
+\r
+import java.io.IOException;\r
+\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+\r
+public class JU_StringBuilderOutputStreamTest {\r
+\r
+ StringBuilderOutputStream streamBuilder;\r
+\r
+ StringBuilder builder = new StringBuilder();\r
+\r
+ @Before\r
+ public void setUp() throws Exception {\r
+ streamBuilder = new StringBuilderOutputStream(builder);\r
+ }\r
+\r
+ @Test\r
+ public void testWriteIntAndReset() {\r
+ streamBuilder.write(123);\r
+\r
+ assertEquals("123", streamBuilder.toString());\r
+ streamBuilder.reset();\r
+ assertEquals("", streamBuilder.toString());\r
+ }\r
+\r
+ @Test\r
+ public void testWriteByteArrayWithoutException() throws IOException {\r
+ byte[] bytes = { 1, 2, 3, 4 };\r
+ streamBuilder.write(bytes);\r
+ assertEquals(4, streamBuilder.getBuffer().length());\r
+\r
+ streamBuilder.write(bytes, 1, 2);\r
+ assertEquals(6, streamBuilder.getBuffer().length());\r
+\r
+ streamBuilder.write(bytes, 1, 0);\r
+ assertEquals(6, streamBuilder.getBuffer().length());\r
+\r
+ streamBuilder.append(bytes[0]);\r
+ assertEquals(7, streamBuilder.getBuffer().length());\r
+ }\r
+\r
+ @Test\r
+ public void testWriteByteArrayWithIndexOutOfBoundException() {\r
+ byte[] bytes = { 1, 2, 3, 4 };\r
+\r
+ try {\r
+ streamBuilder.write(bytes, -1, 2);\r
+ fail("This is supposed to throw IndexOutOfBounds Excetpion");\r
+ } catch (IndexOutOfBoundsException e) {\r
+ } catch (Exception e) {\r
+ fail("This should throw only IndexOutOfBounds Exception");\r
+ }\r
+ assertEquals(0, streamBuilder.getBuffer().length());\r
+\r
+ }\r
+\r
+ @Test\r
+ public void testDefaultConstructor() throws IOException {\r
+ StringBuilderOutputStream stream = new StringBuilderOutputStream();\r
+\r
+ assertNotNull(stream.getBuffer());\r
+ stream.close();\r
+ }\r
+\r
+ @Test\r
+ public void testConstructorWithPositiveDefaultCapacity() throws IOException {\r
+ StringBuilderOutputStream stream = new StringBuilderOutputStream(10);\r
+\r
+ assertNotNull(stream.getBuffer());\r
+ assertEquals(10, stream.getBuffer().capacity());\r
+ stream.close();\r
+ }\r
+\r
+ @Test\r
+ public void testConstructorWithNegativeCapacityException() {\r
+ try {\r
+ StringBuilderOutputStream stream = new StringBuilderOutputStream(-1);\r
+ fail("This should throw IllegalArgumentException");\r
+ } catch (IllegalArgumentException e) {\r
+ } catch (Exception e) {\r
+ fail("This should throw only IllegalArgumentException");\r
+ }\r
+ }\r
+\r
+ @Test\r
+ public void testWriteString() {\r
+ streamBuilder.write("1234");\r
+\r
+ assertEquals("1234", streamBuilder.toString());\r
+\r
+ streamBuilder.write("1234", 1, 2);\r
+ assertEquals("12342", streamBuilder.toString());\r
+ }\r
+\r
+ @Test\r
+ public void testAppendCharSequence() {\r
+ streamBuilder.append("1234");\r
+ assertEquals("1234", streamBuilder.toString());\r
+\r
+ streamBuilder.append(null);\r
+ assertEquals("1234null", streamBuilder.toString());\r
+\r
+ streamBuilder.append("1234", 1, 2);\r
+ assertEquals("1234null2", streamBuilder.toString());\r
+\r
+ streamBuilder.append(null, 1, 2);\r
+ assertEquals("1234null2u", streamBuilder.toString());\r
+ }\r
+}\r
--- /dev/null
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+package org.onap.aaf.misc.env.util;\r
+\r
+import static org.junit.Assert.assertEquals;\r
+import static org.junit.Assert.assertNotNull;\r
+import static org.junit.Assert.fail;\r
+\r
+import java.io.IOException;\r
+\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+\r
+public class JU_StringBuilderWriterTest {\r
+\r
+ StringBuilderWriter streamWriter;\r
+\r
+ StringBuilder builder = new StringBuilder();\r
+\r
+ @Before\r
+ public void setUp() throws Exception {\r
+ streamWriter = new StringBuilderWriter(builder);\r
+ }\r
+\r
+ @Test\r
+ public void testWriteIntAndReset() {\r
+ streamWriter.write(1);\r
+\r
+ assertEquals(1, streamWriter.getBuffer().length());\r
+ streamWriter.reset();\r
+ assertEquals("", streamWriter.toString());\r
+ }\r
+\r
+ @Test\r
+ public void testWriteByteArrayWithoutException() throws IOException {\r
+ char[] bytes = { 1, 2, 3, 4 };\r
+ streamWriter.write(bytes);\r
+ assertEquals(4, streamWriter.getBuffer().length());\r
+\r
+ streamWriter.write(bytes, 1, 2);\r
+ assertEquals(6, streamWriter.getBuffer().length());\r
+\r
+ streamWriter.write(bytes, 1, 0);\r
+ assertEquals(6, streamWriter.getBuffer().length());\r
+\r
+ streamWriter.append(bytes[0]);\r
+ assertEquals(7, streamWriter.getBuffer().length());\r
+ }\r
+\r
+ @Test\r
+ public void testWriteByteArrayWithIndexOutOfBoundException() {\r
+ char[] bytes = { 1, 2, 3, 4 };\r
+\r
+ try {\r
+ streamWriter.write(bytes, -1, 2);\r
+ fail("This is supposed to throw IndexOutOfBounds Excetpion");\r
+ } catch (IndexOutOfBoundsException e) {\r
+ } catch (Exception e) {\r
+ fail("This should throw only IndexOutOfBounds Exception");\r
+ }\r
+ assertEquals(0, streamWriter.getBuffer().length());\r
+\r
+ }\r
+\r
+ @Test\r
+ public void testDefaultConstructor() throws IOException {\r
+ StringBuilderWriter stream = new StringBuilderWriter();\r
+\r
+ assertNotNull(stream.getBuffer());\r
+ stream.close();\r
+ }\r
+\r
+ @Test\r
+ public void testConstructorWithPositiveDefaultCapacity() throws IOException {\r
+ StringBuilderWriter stream = new StringBuilderWriter(10);\r
+\r
+ assertNotNull(stream.getBuffer());\r
+ assertEquals(10, stream.getBuffer().capacity());\r
+ stream.close();\r
+ }\r
+\r
+ @Test\r
+ public void testConstructorWithNegativeCapacityException() {\r
+ try {\r
+ StringBuilderWriter stream = new StringBuilderWriter(-1);\r
+ fail("This should throw IllegalArgumentException");\r
+ } catch (IllegalArgumentException e) {\r
+ } catch (Exception e) {\r
+ fail("This should throw only IllegalArgumentException");\r
+ }\r
+ }\r
+\r
+ @Test\r
+ public void testWriteString() {\r
+ streamWriter.write("1234");\r
+\r
+ assertEquals("1234", streamWriter.toString());\r
+\r
+ streamWriter.write("1234", 1, 2);\r
+ assertEquals("123423", streamWriter.toString());\r
+ }\r
+\r
+ @Test\r
+ public void testAppendCharSequence() {\r
+ streamWriter.append("1234");\r
+ assertEquals("1234", streamWriter.toString());\r
+\r
+ streamWriter.append(null);\r
+ assertEquals("1234null", streamWriter.toString());\r
+\r
+ streamWriter.append("1234", 1, 2);\r
+ assertEquals("1234null2", streamWriter.toString());\r
+\r
+ streamWriter.append(null, 1, 2);\r
+ assertEquals("1234null2u", streamWriter.toString());\r
+ }\r
+}\r
-/**
- * ============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.util.test;
-
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertFalse;
-
-import org.junit.Test;
-import org.onap.aaf.misc.env.util.IPValidator;
-
-public class JU_IPValidator {
-
- @Test
- public void test() {
- assertTrue(IPValidator.ipv4("10.10.10.10"));
- assertTrue(IPValidator.ipv4("127.0.0.0"));
- assertFalse(IPValidator.ipv4("10"));
- assertFalse(IPValidator.ipv4("10.10.10"));
- assertFalse(IPValidator.ipv4("10.10.10."));
- assertFalse(IPValidator.ipv4("10.10.10.10."));
- assertFalse(IPValidator.ipv4("10.10.10.10.10"));
- assertFalse(IPValidator.ipv4("something10.10.10.10"));
- assertTrue(IPValidator.ipv4("0.10.10.10"));
- assertTrue(IPValidator.ipv4("0.0.0.0"));
- assertTrue(IPValidator.ipv4("0.10.10.10"));
- assertFalse(IPValidator.ipv4("011.255.255.255"));
- assertFalse(IPValidator.ipv4("255.01.255.255"));
- assertFalse(IPValidator.ipv4("255.255.255.256"));
- assertFalse(IPValidator.ipv4("255.299.255.255"));
-
-
- assertTrue(IPValidator.ipv6("0000:0000:0000:0000:0000:0000:0000:0000"));
- assertTrue(IPValidator.ipv6("0:0:0:0:0:0:0:0"));
- assertTrue(IPValidator.ipv6("2001:08DB:0000:0000:0023:F422:FE3B:AC10"));
- assertTrue(IPValidator.ipv6("2001:8DB:0:0:23:F422:FE3B:AC10"));
- assertTrue(IPValidator.ipv6("2001:8DB::23:F422:FE3B:AC10"));
- assertTrue(IPValidator.ipv6("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"));
- assertTrue(IPValidator.ipv6("FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF"));
- assertFalse(IPValidator.ipv6("2001:8DB::23:G422:FE3B:AC10"));
- assertFalse(IPValidator.ipv6("2001:8DB::23:G422:FE3B:AC10"));
- // more than one Double Colons
- assertFalse(IPValidator.ipv6("0000:0000:0000::0000::0000"));
- assertFalse(IPValidator.ipv6("2001:8DB::23:G422:FE3B:AC10:FFFF"));
-
-
-
- assertTrue(IPValidator.ip("2001:08DB:0000:0000:0023:F422:FE3B:AC10"));
- assertTrue(IPValidator.ip("192.168.7.2"));
- }
-
-}
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+\r
+package org.onap.aaf.misc.env.util.test;\r
+\r
+import static org.junit.Assert.assertFalse;\r
+import static org.junit.Assert.assertTrue;\r
+\r
+import org.junit.Test;\r
+import org.onap.aaf.misc.env.util.IPValidator;\r
+\r
+public class JU_IPValidator {\r
+\r
+ @Test\r
+ public void test() {\r
+ assertTrue(IPValidator.ipv4("10.10.10.10"));\r
+ assertTrue(IPValidator.ipv4("127.0.0.0"));\r
+ assertFalse(IPValidator.ipv4("10"));\r
+ assertFalse(IPValidator.ipv4("10.10.10"));\r
+ assertFalse(IPValidator.ipv4("10.10.10."));\r
+ assertFalse(IPValidator.ipv4("10.10.10.10."));\r
+ assertFalse(IPValidator.ipv4("10.10.10.10.10"));\r
+ assertFalse(IPValidator.ipv4("something10.10.10.10"));\r
+ assertTrue(IPValidator.ipv4("0.10.10.10"));\r
+ assertTrue(IPValidator.ipv4("0.0.0.0"));\r
+ assertTrue(IPValidator.ipv4("0.10.10.10"));\r
+ assertFalse(IPValidator.ipv4("011.255.255.255"));\r
+ assertFalse(IPValidator.ipv4("255.01.255.255"));\r
+ assertFalse(IPValidator.ipv4("255.255.255.256"));\r
+ assertFalse(IPValidator.ipv4("255.299.255.255"));\r
+\r
+ assertTrue(IPValidator.ipv6("0000:0000:0000:0000:0000:0000:0000:0000"));\r
+ assertTrue(IPValidator.ipv6("0:0:0:0:0:0:0:0"));\r
+ assertTrue(IPValidator.ipv6("2001:08DB:0000:0000:0023:F422:FE3B:AC10"));\r
+ assertTrue(IPValidator.ipv6("2001:8DB:0:0:23:F422:FE3B:AC10"));\r
+ assertTrue(IPValidator.ipv6("2001:8DB::23:F422:FE3B:AC10"));\r
+ assertTrue(IPValidator.ipv6("ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff"));\r
+ assertTrue(IPValidator.ipv6("FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF"));\r
+ assertFalse(IPValidator.ipv6("2001:8DB::23:G422:FE3B:AC10"));\r
+ assertFalse(IPValidator.ipv6("2001:8DB::23:G422:FE3B:AC10"));\r
+ // more than one Double Colons\r
+ assertFalse(IPValidator.ipv6("0000:0000:0000::0000::0000"));\r
+ assertFalse(IPValidator.ipv6("2001:8DB::23:G422:FE3B:AC10:FFFF"));\r
+\r
+ assertTrue(IPValidator.ip("2001:08DB:0000:0000:0023:F422:FE3B:AC10"));\r
+ assertTrue(IPValidator.ip("192.168.7.2"));\r
+ }\r
+\r
+}\r
--- /dev/null
+/**\r
+ * ============LICENSE_START====================================================\r
+ * org.onap.aaf\r
+ * ===========================================================================\r
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.\r
+ * ===========================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END====================================================\r
+ *\r
+ */\r
+package org.onap.aaf.misc.env.util.test;\r
+\r
+import static org.junit.Assert.assertEquals;\r
+\r
+import org.junit.Before;\r
+import org.junit.Test;\r
+import org.onap.aaf.misc.env.APIException;\r
+import org.onap.aaf.misc.env.LogTarget;\r
+import org.onap.aaf.misc.env.util.Pool;\r
+\r
+public class JU_PoolTest {\r
+\r
+ @Before\r
+ public void setUp() throws Exception {\r
+ }\r
+\r
+ @Test\r
+ public void test() {\r
+ Pool pool = new Pool<Integer>(new Pool.Creator<Integer>() {\r
+\r
+ Integer content = 0;\r
+\r
+ @Override\r
+ public Integer create() throws APIException {\r
+ return content++;\r
+ }\r
+\r
+ @Override\r
+ public void destroy(Integer t) {\r
+\r
+ }\r
+\r
+ @Override\r
+ public boolean isValid(Integer t) {\r
+ return t == content;\r
+ }\r
+\r
+ @Override\r
+ public void reuse(Integer t) {\r
+ content = t;\r
+ }\r
+ });\r
+ try {\r
+ // pool.drain();\r
+ assertEquals("Should return intial value", 0, pool.get().content);\r
+ // pooled.toss();\r
+ pool.prime(LogTarget.SYSOUT, 23);\r
+ assertEquals("Should Return 23 as added at last prime", 23, pool.get(LogTarget.SYSOUT).content);\r
+ pool.prime(LogTarget.SYSERR, 13);\r
+ assertEquals("Should add another 13 from SysErr and remove 1", 35, pool.get(LogTarget.SYSERR).content);\r
+ assertEquals("Create a new creator with create method", 1, pool.get().content);\r
+ assertEquals("Create a new creator with create method", 2, pool.get().content);\r
+ assertEquals("Should remove last from pool", 34, pool.get(LogTarget.SYSOUT).content);\r
+\r
+ pool.drain();\r
+ assertEquals("Should remove last from pool", 17, pool.get(LogTarget.SYSOUT).content);\r
+ } catch (APIException e) {\r
+ }\r
+ }\r
+\r
+}\r