From c4fe01668d4472c978ca220bdfff9c8e15bc8027 Mon Sep 17 00:00:00 2001 From: rajeevme Date: Wed, 26 Feb 2020 17:48:18 +0530 Subject: [AAI-2531] | Update springboot to 2.1.12.RELEASE Issue-ID: AAI-2531 Change-Id: I5cd738c8786753c4ecbfc4cb23a051978466e256 Signed-off-by: rajeevme --- .../sync/CrossEntityReferenceSynchronizerTest.java | 3 +- .../ElasticSearchOperationExceptionTest.java | 40 ++++++++ .../org/onap/aai/sparky/security/EcompSsoTest.java | 5 +- .../config/PortalAuthenticationConfigTest.java | 36 +++++++ .../sync/task/PerformGizmoRetrievalTest.java | 66 ++++++++++++ .../sparky/synchronizer/GizmoEntitySummarizer.java | 6 +- .../java/org/onap/aai/sparky/util/BaseMatcher.java | 40 ++++++++ .../org/onap/aai/sparky/util/ConfigHelperTest.java | 31 +++++- .../onap/aai/sparky/util/EncryptConvertorTest.java | 70 +++++++++++++ .../org/onap/aai/sparky/util/EncryptorTest.java | 50 +++++++++ .../onap/aai/sparky/util/RawByteHelperTest.java | 112 +++++++++++++++++++++ .../org/onap/aai/sparky/util/RestletUtilsTest.java | 93 +++++++++++++++++ .../util/StringCollectionContainsMatcher.java | 39 ++++--- .../BaseVisualizationContextTest.java | 3 +- .../services/BaseVisualizationContextTest.java | 4 +- .../src/test/resources/configHelperTest.properties | 3 + .../test/resources/oxm-reader/oxm-reader-bean.xml | 5 +- 17 files changed, 579 insertions(+), 27 deletions(-) create mode 100644 sparkybe-onap-service/src/test/java/org/onap/aai/sparky/dal/exception/ElasticSearchOperationExceptionTest.java create mode 100644 sparkybe-onap-service/src/test/java/org/onap/aai/sparky/security/portal/config/PortalAuthenticationConfigTest.java create mode 100644 sparkybe-onap-service/src/test/java/org/onap/aai/sparky/sync/task/PerformGizmoRetrievalTest.java create mode 100644 sparkybe-onap-service/src/test/java/org/onap/aai/sparky/util/BaseMatcher.java create mode 100644 sparkybe-onap-service/src/test/java/org/onap/aai/sparky/util/EncryptConvertorTest.java create mode 100644 sparkybe-onap-service/src/test/java/org/onap/aai/sparky/util/EncryptorTest.java create mode 100644 sparkybe-onap-service/src/test/java/org/onap/aai/sparky/util/RawByteHelperTest.java create mode 100644 sparkybe-onap-service/src/test/java/org/onap/aai/sparky/util/RestletUtilsTest.java create mode 100644 sparkybe-onap-service/src/test/resources/configHelperTest.properties (limited to 'sparkybe-onap-service/src') diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/crossentityreference/sync/CrossEntityReferenceSynchronizerTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/crossentityreference/sync/CrossEntityReferenceSynchronizerTest.java index 876db5d..9529143 100644 --- a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/crossentityreference/sync/CrossEntityReferenceSynchronizerTest.java +++ b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/crossentityreference/sync/CrossEntityReferenceSynchronizerTest.java @@ -34,6 +34,7 @@ import java.util.Set; import org.hamcrest.Matcher; import org.junit.Before; import org.junit.Test; +import org.mockito.ArgumentMatcher; import org.mockito.Matchers; import org.mockito.Mockito; import org.onap.aai.restclient.client.OperationResult; @@ -211,7 +212,7 @@ public class CrossEntityReferenceSynchronizerTest { } - private Matcher> listContainsValue(String expectedValue) { + private ArgumentMatcher> listContainsValue(String expectedValue) { return new StringCollectionContainsMatcher(expectedValue); } diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/dal/exception/ElasticSearchOperationExceptionTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/dal/exception/ElasticSearchOperationExceptionTest.java new file mode 100644 index 0000000..8c7e60d --- /dev/null +++ b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/dal/exception/ElasticSearchOperationExceptionTest.java @@ -0,0 +1,40 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2018 Amdocs + * ================================================================================ + * 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.aai.sparky.dal.exception; + +import org.junit.Test; +import static org.junit.Assert.assertNotNull; +/** + * The Class ElasticSearchOperationException. + */ +public class ElasticSearchOperationExceptionTest extends Exception { + + @Test + public void elasticSearchOperationExceptionMultiArgsTest() { + new ElasticSearchOperationException("message", new Exception()); + } + + @Test + public void elasticSearchOperationExceptionSingleArgTest() { + new ElasticSearchOperationException("message"); + } + +} diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/security/EcompSsoTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/security/EcompSsoTest.java index 42ea4a5..9a39cf3 100644 --- a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/security/EcompSsoTest.java +++ b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/security/EcompSsoTest.java @@ -72,5 +72,8 @@ public class EcompSsoTest { assertNull(EcompSso.getCookie(request, testCookieName + "3")); } - + @Test + public void validateEcompSso() { + EcompSso.validateEcompSso(Mockito.mock(HttpServletRequest.class)); + } } diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/security/portal/config/PortalAuthenticationConfigTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/security/portal/config/PortalAuthenticationConfigTest.java new file mode 100644 index 0000000..395aa37 --- /dev/null +++ b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/security/portal/config/PortalAuthenticationConfigTest.java @@ -0,0 +1,36 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2018 Amdocs + * ================================================================================ + * 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.aai.sparky.security.portal.config; + + + +import org.junit.Test; +import static org.junit.Assert.assertNotNull; + +/** + * Provides Portal authentication configuration. + */ +public class PortalAuthenticationConfigTest { + @Test + public void testGetTestPortalAuthenticationConfig() { + assertNotNull(PortalAuthenticationConfig.getInstance()); + } +} \ No newline at end of file diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/sync/task/PerformGizmoRetrievalTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/sync/task/PerformGizmoRetrievalTest.java new file mode 100644 index 0000000..908bc22 --- /dev/null +++ b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/sync/task/PerformGizmoRetrievalTest.java @@ -0,0 +1,66 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2018 Amdocs + * ================================================================================ + * 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.aai.sparky.sync.task; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.onap.aai.cl.api.Logger; +import org.onap.aai.cl.eelf.LoggerFactory; +import org.onap.aai.restclient.client.OperationResult; +import org.onap.aai.sparky.dal.GizmoAdapter; +import org.onap.aai.sparky.dal.NetworkTransaction; +import org.onap.aai.sparky.logging.AaiUiMsgs; +import org.slf4j.MDC; + +import java.util.Map; +import java.util.function.Supplier; + +/* + * Consider abstraction the tasks into common elemnts, because most of them repeat a generic call + * flow pattern + */ + +/** + * The Class PerformActiveInventoryRetrieval. + */ +public class PerformGizmoRetrievalTest { + + + private NetworkTransaction txn; + private GizmoAdapter gizmoAdapter; + PerformGizmoRetrieval performGizmoRetrieval; + + @Before + public void init(){ + txn = Mockito.mock(NetworkTransaction.class); + gizmoAdapter = Mockito.mock(GizmoAdapter.class); + performGizmoRetrieval = new PerformGizmoRetrieval(txn,gizmoAdapter); + } + /* (non-Javadoc) + * @see java.util.function.Supplier#get() + */ + @Test + public void get() { + performGizmoRetrieval.get(); + } + +} diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/synchronizer/GizmoEntitySummarizer.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/synchronizer/GizmoEntitySummarizer.java index 4b86bb5..6669dbc 100644 --- a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/synchronizer/GizmoEntitySummarizer.java +++ b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/synchronizer/GizmoEntitySummarizer.java @@ -37,10 +37,10 @@ import org.onap.aai.cl.api.Logger; import org.onap.aai.cl.eelf.LoggerFactory; import org.onap.aai.restclient.client.OperationResult; import org.onap.aai.restclient.enums.RestAuthenticationMode; -import org.onap.aai.setup.SchemaVersion; import org.onap.aai.sparky.config.oxm.OxmModelLoader; import org.onap.aai.sparky.dal.GizmoAdapter; import org.onap.aai.sparky.dal.exception.ElasticSearchOperationException; +import org.onap.aai.sparky.dal.exception.ElasticSearchOperationExceptionTest; import org.onap.aai.sparky.dal.rest.RestClientConstructionException; import org.onap.aai.sparky.dal.rest.config.RestEndpointConfig; import org.onap.aai.sparky.logging.AaiUiMsgs; @@ -66,7 +66,7 @@ public class GizmoEntitySummarizer { */ public GizmoEntitySummarizer() - throws ElasticSearchOperationException, IOException, RestClientConstructionException { + throws ElasticSearchOperationExceptionTest, IOException, RestClientConstructionException, ElasticSearchOperationException { OxmModelAndProcessorHelper.API_VERSION_OVERRIDE = "v11"; @@ -240,7 +240,7 @@ public class GizmoEntitySummarizer { } public static void main(String[] args) - throws ElasticSearchOperationException, IOException, RestClientConstructionException { + throws ElasticSearchOperationExceptionTest, IOException, RestClientConstructionException, ElasticSearchOperationException { System.setProperty("CONFIG_HOME", "X:\\2018_dev\\OSEAAI\\gizmo_integration\\onap_sparky-be\\appconfig-local\\"); GizmoEntitySummarizer gizmoSummarizer = new GizmoEntitySummarizer(); diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/util/BaseMatcher.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/util/BaseMatcher.java new file mode 100644 index 0000000..2abf360 --- /dev/null +++ b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/util/BaseMatcher.java @@ -0,0 +1,40 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2018 Amdocs + * ================================================================================ + * 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.aai.sparky.util; + + +import org.hamcrest.Description; +import org.hamcrest.SelfDescribing; +import org.hamcrest.StringDescription; +import org.mockito.ArgumentMatcher; + +public abstract class BaseMatcher implements ArgumentMatcher, SelfDescribing { + public BaseMatcher() { + } + + @Override + public void describeTo(Description var1){ + } + + public String toString() { + return StringDescription.toString(this); + } +} diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/util/ConfigHelperTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/util/ConfigHelperTest.java index 61bf5c2..2d4a365 100644 --- a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/util/ConfigHelperTest.java +++ b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/util/ConfigHelperTest.java @@ -23,12 +23,15 @@ package org.onap.aai.sparky.util; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; - +import static org.hamcrest.MatcherAssert.assertThat; +import java.io.File; +import java.io.IOException; +import java.nio.file.FileSystems; import java.util.Properties; import org.junit.Before; import org.junit.Test; - +import static org.junit.Assert.assertEquals; public class ConfigHelperTest { private ConfigHelper configHelper; @@ -45,11 +48,33 @@ public class ConfigHelperTest { @Test public void updateValues() throws Exception { - assertNotNull(configHelper.getConfigWithPrefix("aai-ui", props)); assertFalse(configHelper.isEssDevModeEnabled()); assertNotNull(configHelper.getFilepath("sparky-aaui", false)); } + @Test + public void getFileContents() { + File file = new File(getClass().getClassLoader().getResource("configHelperTest.properties").getFile()); + try { + assertNotNull(ConfigHelper.getFileContents(file.getAbsolutePath())); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Test + public void loadConfig() throws Exception { + String separator = FileSystems.getDefault().getSeparator(); + assertEquals(3, ConfigHelper.loadConfig("target"+separator+"test-classes"+separator+"configHelperTest.properties").size()); + } + + @Test + public void propertyFetch() throws Exception { + Properties p=new Properties(); + p.setProperty("key1","value1"); + assertEquals(ConfigHelper.propertyFetch(p,"key1","value2"),"value1"); + assertEquals(ConfigHelper.propertyFetch(p,"key2","value2"),"value2"); + } } diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/util/EncryptConvertorTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/util/EncryptConvertorTest.java new file mode 100644 index 0000000..fb25b4b --- /dev/null +++ b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/util/EncryptConvertorTest.java @@ -0,0 +1,70 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2018 Amdocs + * ================================================================================ + * 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.aai.sparky.util; + +import org.junit.Test; + +import java.util.Arrays; + +import static org.junit.Assert.assertEquals; +/** + * The Class EncryptConvertor. + */ +public class EncryptConvertorTest { + + @Test + public void toHexStringTestString() { + assertEquals(EncryptConvertor.toHexString("abcd"),"61626364"); + } + + @Test + public void toHexStringTestByteArray() { + assertEquals(EncryptConvertor.toHexString("abcd".getBytes()),"61626364"); + } + + @Test + public void stringFromHexTestString() throws Exception { + assertEquals(EncryptConvertor.stringFromHex("61626364"),"abcd"); + } + + @Test + public void stringFromHexTestCharArray() throws Exception { + assertEquals(EncryptConvertor.stringFromHex("61626364".toCharArray()),"abcd"); + } + + @Test + public void bytesFromHexTestCharArray() throws Exception { + byte[] buf = {97, 98, 99, 100}; + assertEquals(Arrays.toString(EncryptConvertor.bytesFromHex("61626364")), Arrays.toString(buf)); + } + + @Test + public void bytesFromHex() throws Exception { + byte[] buf = {97, 98, 99, 100}; + assertEquals(Arrays.toString(EncryptConvertor.bytesFromHex("61626364".toCharArray())), Arrays.toString(buf)); + } + + @Test + public void fromHexDigit() throws Exception { + assertEquals(EncryptConvertor.fromHexDigit('a',2), 10); + } + +} diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/util/EncryptorTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/util/EncryptorTest.java new file mode 100644 index 0000000..10fbd6f --- /dev/null +++ b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/util/EncryptorTest.java @@ -0,0 +1,50 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2018 Amdocs + * ================================================================================ + * 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.aai.sparky.util; + + +import org.junit.Before; +import org.junit.Test; + + +import static org.junit.Assert.*; + +/** + * The Class Encryptor. + */ +public class EncryptorTest { + + Encryptor encryptor; + @Before + public void init(){ + encryptor = new Encryptor(); + } + + @Test + public void encryptTest() { + assertEquals("OBF:1t331y0o1u2e1uvk1u3m1y0s1wui1qaz1qc31wtw1y0y1u1o1uum1u2w1y121t33",encryptor.encryptValue("encryptThisValue")); + } + + @Test + public void decryptTest() { + assertEquals("encryptThisValue",encryptor.decryptValue("OBF:1t331y0o1u2e1uvk1u3m1y0s1wui1qaz1qc31wtw1y0y1u1o1uum1u2w1y121t33")); + } +} diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/util/RawByteHelperTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/util/RawByteHelperTest.java new file mode 100644 index 0000000..c44de6f --- /dev/null +++ b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/util/RawByteHelperTest.java @@ -0,0 +1,112 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2018 Amdocs + * ================================================================================ + * 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.aai.sparky.util; + +import org.junit.Test; +import static org.junit.Assert.assertEquals; +/** + * The Class RawByteHelper. + */ +public class RawByteHelperTest { + + @Test + public void testDumpBytes() { + String str = "abcd"; + assertEquals(RawByteHelper.dumpBytes(str.getBytes()),"61 62 63 64 "); + + } + + // if you're trying to figure out why or's w/ FF's see: + @Test + public void testBytesToInt() { + byte one = 0, two = 0, three = 1, four = 1; + assertEquals(RawByteHelper.bytesToInt(one, two, three,four),257); + } + + @Test + public void testBytesToShort() { + byte a = 1; + byte b = 0; + assertEquals(RawByteHelper.bytesToShort(a, b), (short)256); + } + + // short helper functions + @Test + public void testFirstByteShort() { + short num1 = 123; + short num2 = 321; + assertEquals(RawByteHelper.firstByte(num1),(short)0); + assertEquals(RawByteHelper.firstByte(num2),(short)1); + } + + @Test + public void testFirstByteInt() { + int num1 = 123; + assertEquals(RawByteHelper.firstByte(num1),(byte)0); + } + + @Test + public void testSecondByteShort() { + short num1 = 123; + short num2 = 321; + assertEquals(RawByteHelper.secondByte(num1),(byte)num1); + assertEquals(RawByteHelper.secondByte(num2),(byte)65); + } + + @Test + public void testSecondByteInt() { + int num1 = 123; + int num2 = -123; + assertEquals(RawByteHelper.secondByte(num1),(byte)0); + assertEquals(RawByteHelper.secondByte(num2),(byte)-1); + } + + @Test + public void thirdByte() { + int num1 = 123; + int num2 = -123; + assertEquals(RawByteHelper.thirdByte(num1),(byte)0); + assertEquals(RawByteHelper.thirdByte(num2),(byte)-1); + } + @Test + public void fourthByte() { + int num1 = 123; + int num2 = 321; + assertEquals(RawByteHelper.fourthByte(num1),(byte)123); + assertEquals(RawByteHelper.fourthByte(num2),(byte)65); + } + @Test + public void intToByte() { + int num1 = 123; + int num2 = 321; + assertEquals(RawByteHelper.intToByte(num1),(byte)123); + assertEquals(RawByteHelper.intToByte(num2),(byte)65); + } + @Test + public void intToShort() { + int num1 = 123; + int num2 = 321; + assertEquals(RawByteHelper.intToByte(num1),(short)123); + assertEquals(RawByteHelper.intToByte(num2),(short)65); + } + +} + diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/util/RestletUtilsTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/util/RestletUtilsTest.java new file mode 100644 index 0000000..92d17e9 --- /dev/null +++ b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/util/RestletUtilsTest.java @@ -0,0 +1,93 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2018 Amdocs + * ================================================================================ + * 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.aai.sparky.util; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.aai.cl.api.Logger; +import org.onap.aai.sparky.search.SearchServiceAdapter; +import org.restlet.Response; +import org.restlet.Server; +import org.restlet.engine.adapter.Call; +import org.restlet.engine.adapter.HttpResponse; +import org.restlet.ext.servlet.internal.ServletCall; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertEquals; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +@RunWith(MockitoJUnitRunner.class) +public class RestletUtilsTest { + + static final String EMPTY_STRING = ""; + RestletUtils restletUtils; + + @Before + public void init() { + restletUtils = new RestletUtils(); + } + + @Test + public void testConvertRestletResponseToHttpServletResponse() { + Response restletResponse = Mockito.mock(HttpResponse.class); + Call call = new ServletCall(Mockito.mock(Server.class),Mockito.mock(HttpServletRequest.class),Mockito.mock(HttpServletResponse.class)); + Mockito.when(((HttpResponse)restletResponse).getHttpCall()).thenReturn((ServletCall)call); + restletUtils.convertRestletResponseToHttpServletResponse(restletResponse); + } + + @Test + public void testExecutePostQueryNullCheck() { + Logger logger = Mockito.mock(Logger.class); + Response response = Mockito.mock(Response.class); + SearchServiceAdapter search = Mockito.mock(SearchServiceAdapter.class); + String requestUrl = EMPTY_STRING; + String requestJsonPayload = EMPTY_STRING; + try{ + restletUtils.executePostQuery(logger,search,response,requestUrl,requestJsonPayload); + }catch (NullPointerException e){ + //expected + } + } + + @Test + public void testHandleRestletErrors() { + Logger logger = Mockito.mock(Logger.class); + Response response = Mockito.mock(Response.class); + Exception exc = Mockito.mock(Exception.class); + String errorMsg = ""; + restletUtils.handleRestletErrors(logger,errorMsg,exc,response); + } + + @Test + public void testSetRestletResponse() { + Logger logger = Mockito.mock(Logger.class); + Response response = Mockito.mock(Response.class); + Exception exc = Mockito.mock(Exception.class); + boolean isError = true; + int responseCode =200; + String payload = ""; + restletUtils.setRestletResponse(logger,false,responseCode,response,payload); + } +} diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/util/StringCollectionContainsMatcher.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/util/StringCollectionContainsMatcher.java index cf20436..b101901 100644 --- a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/util/StringCollectionContainsMatcher.java +++ b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/util/StringCollectionContainsMatcher.java @@ -21,11 +21,10 @@ package org.onap.aai.sparky.util; -import java.util.List; - -import org.hamcrest.BaseMatcher; import org.hamcrest.Description; +import java.util.List; + public class StringCollectionContainsMatcher extends BaseMatcher> { private String valueToCheck; @@ -34,27 +33,37 @@ public class StringCollectionContainsMatcher extends BaseMatcher> { public StringCollectionContainsMatcher(String valToCheck) { this.valueToCheck = valToCheck; } - + + @Override + public void describeTo(Description arg0) { + // TODO Auto-generated method stub + } + @Override + public boolean matches(List argumentList) { + for ( String listItem : argumentList ) { + + if ( listItem.contains(valueToCheck)) { + return true; + } + } + + return false; + } + + /*@Override public boolean matches(Object arg0) { @SuppressWarnings("unchecked") List argumentList = (List) arg0; - + for ( String listItem : argumentList ) { - + if ( listItem.contains(valueToCheck)) { return true; } } - - return false; - } - @Override - public void describeTo(Description arg0) { - // TODO Auto-generated method stub - - } - + return false; + }*/ } diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/BaseVisualizationContextTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/BaseVisualizationContextTest.java index 1de7263..543326c 100644 --- a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/BaseVisualizationContextTest.java +++ b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/BaseVisualizationContextTest.java @@ -41,6 +41,7 @@ import org.hamcrest.Matcher; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.ArgumentMatcher; import org.mockito.Matchers; import org.mockito.Mockito; import org.onap.aai.cl.api.Logger; @@ -116,7 +117,7 @@ public class BaseVisualizationContextTest { } - private Matcher> listContainsValue(String expectedValue) { + private ArgumentMatcher> listContainsValue(String expectedValue) { return new StringCollectionContainsMatcher(expectedValue); } diff --git a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/services/BaseVisualizationContextTest.java b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/services/BaseVisualizationContextTest.java index 5bff7f4..d5e98a9 100644 --- a/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/services/BaseVisualizationContextTest.java +++ b/sparkybe-onap-service/src/test/java/org/onap/aai/sparky/viewandinspect/services/BaseVisualizationContextTest.java @@ -41,6 +41,7 @@ import org.hamcrest.Matcher; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.ArgumentMatcher; import org.mockito.Matchers; import org.mockito.Mockito; import org.onap.aai.cl.api.Logger; @@ -116,11 +117,10 @@ public class BaseVisualizationContextTest { } - private Matcher> listContainsValue(String expectedValue) { + private ArgumentMatcher> listContainsValue(String expectedValue) { return new StringCollectionContainsMatcher(expectedValue); } - @Test public void validateBasicConstruction() throws Exception { diff --git a/sparkybe-onap-service/src/test/resources/configHelperTest.properties b/sparkybe-onap-service/src/test/resources/configHelperTest.properties new file mode 100644 index 0000000..e92b77a --- /dev/null +++ b/sparkybe-onap-service/src/test/resources/configHelperTest.properties @@ -0,0 +1,3 @@ +prefix.key1=value1 +prefix.key2=value2 +prefix.key3=value3 \ No newline at end of file diff --git a/sparkybe-onap-service/src/test/resources/oxm-reader/oxm-reader-bean.xml b/sparkybe-onap-service/src/test/resources/oxm-reader/oxm-reader-bean.xml index 76e5f17..caceee6 100644 --- a/sparkybe-onap-service/src/test/resources/oxm-reader/oxm-reader-bean.xml +++ b/sparkybe-onap-service/src/test/resources/oxm-reader/oxm-reader-bean.xml @@ -40,8 +40,11 @@ - + + + + -- cgit 1.2.3-korg