From dbbcde5f8a212c2cc28c8daad43422a81feee368 Mon Sep 17 00:00:00 2001 From: "waqas.ikram" Date: Tue, 12 Mar 2019 12:25:44 +0000 Subject: Fixing test folder packaging Change-Id: Id776f95fb316f14b4f493aa20f8b07636e873537 Issue-ID: SO-1335 Signed-off-by: waqas.ikram --- .../configuration/rest/CorsConfigurer.java | 9 +- .../configuration/CamundaConfigurationTest.java | 44 ++++ .../configuration/CamundaRestUrlProviderTest.java | 80 +++++++ .../HttpServiceProviderConfigurationTest.java | 70 +++++++ .../monitoring/configuration/PojoClassesTests.java | 82 ++++++++ .../database/DatabaseUrlProviderTest.java | 52 +++++ .../db/api/DatabaseServiceProviderTest.java | 107 ++++++++++ .../CamundaProcessDataServiceProviderTest.java | 232 +++++++++++++++++++++ .../so/monitoring/utils/ObjectEqualsUtilsTest.java | 71 +++++++ .../configuration/CamundaConfigurationTest.java | 44 ---- .../configuration/CamundaRestUrlProviderTest.java | 80 ------- .../HttpServiceProviderConfigurationTest.java | 70 ------- .../montoring/configuration/PojoClassesTests.java | 82 -------- .../database/DatabaseUrlProviderTest.java | 52 ----- .../db/api/DatabaseServiceProviderTest.java | 107 ---------- .../CamundaProcessDataServiceProviderTest.java | 232 --------------------- .../so/montoring/utils/ObjectEqualsUtilsTest.java | 71 ------- 17 files changed, 740 insertions(+), 745 deletions(-) create mode 100644 so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/configuration/CamundaConfigurationTest.java create mode 100644 so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/configuration/CamundaRestUrlProviderTest.java create mode 100644 so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/configuration/HttpServiceProviderConfigurationTest.java create mode 100644 so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/configuration/PojoClassesTests.java create mode 100644 so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/configuration/database/DatabaseUrlProviderTest.java create mode 100644 so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/db/api/DatabaseServiceProviderTest.java create mode 100644 so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/rest/service/CamundaProcessDataServiceProviderTest.java create mode 100644 so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/utils/ObjectEqualsUtilsTest.java delete mode 100644 so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/montoring/configuration/CamundaConfigurationTest.java delete mode 100644 so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/montoring/configuration/CamundaRestUrlProviderTest.java delete mode 100644 so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/montoring/configuration/HttpServiceProviderConfigurationTest.java delete mode 100644 so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/montoring/configuration/PojoClassesTests.java delete mode 100644 so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/montoring/configuration/database/DatabaseUrlProviderTest.java delete mode 100644 so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/montoring/db/api/DatabaseServiceProviderTest.java delete mode 100644 so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/montoring/rest/service/CamundaProcessDataServiceProviderTest.java delete mode 100644 so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/montoring/utils/ObjectEqualsUtilsTest.java (limited to 'so-monitoring') diff --git a/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/configuration/rest/CorsConfigurer.java b/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/configuration/rest/CorsConfigurer.java index 0bcf24dbd8..4d0fd443e9 100644 --- a/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/configuration/rest/CorsConfigurer.java +++ b/so-monitoring/so-monitoring-handler/src/main/java/org/onap/so/monitoring/configuration/rest/CorsConfigurer.java @@ -30,17 +30,12 @@ import org.springframework.web.filter.CorsFilter; * @author waqas.ikram@ericsson, eoin.hanan@ericsson.com */ @Configuration -public class CorsConfigurer { +public class CorsConfigurer { @Bean public CorsFilter corsFilter() { final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); - final CorsConfiguration config = new CorsConfiguration(); - config.setAllowCredentials(true); - config.addAllowedOrigin("*"); - config.addAllowedHeader("*"); - config.addAllowedMethod("*"); - source.registerCorsConfiguration("/**", config); + source.registerCorsConfiguration("/**", new CorsConfiguration().applyPermitDefaultValues()); return new CorsFilter(source); } } diff --git a/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/configuration/CamundaConfigurationTest.java b/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/configuration/CamundaConfigurationTest.java new file mode 100644 index 0000000000..fb56d841e4 --- /dev/null +++ b/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/configuration/CamundaConfigurationTest.java @@ -0,0 +1,44 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.monitoring.configuration; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.so.monitoring.configuration.camunda.CamundaConfiguration; +import org.onap.so.monitoring.configuration.camunda.CamundaRestUrlProvider; + + +/** + * @author waqas.ikram@ericsson.com + * + */ +public class CamundaConfigurationTest { + + @Test + public void test_CamundaRestURIConfiguration_ValidUrl() { + final CamundaConfiguration objUnderTest = new CamundaConfiguration(); + final CamundaRestUrlProvider provider = objUnderTest.camundaRestUrlProvider("http://localhost:8080", "default"); + assertEquals( + "http://localhost:8080/default/history/activity-instance?processInstanceId=Deadpool&sortBy=startTime&sortOrder=asc", + provider.getActivityInstanceUrl("Deadpool")); + } + +} diff --git a/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/configuration/CamundaRestUrlProviderTest.java b/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/configuration/CamundaRestUrlProviderTest.java new file mode 100644 index 0000000000..3cd8a33d77 --- /dev/null +++ b/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/configuration/CamundaRestUrlProviderTest.java @@ -0,0 +1,80 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.monitoring.configuration; + +import static org.junit.Assert.assertEquals; + +import java.util.UUID; + +import org.junit.Test; +import org.onap.so.monitoring.configuration.camunda.CamundaRestUrlProvider; + +/** + * @author waqas.ikram@ericsson.com + */ +public class CamundaRestUrlProviderTest { + private static final String DEFAULT = "default"; + private static final String CAMUNDA_REST_API_URL = "http://localhost:9080/engine-rest/engine/"; + private static final String BASE_URL = CAMUNDA_REST_API_URL + DEFAULT; + private final CamundaRestUrlProvider objUnderTest = new CamundaRestUrlProvider(CAMUNDA_REST_API_URL, DEFAULT); + private static final String ID = UUID.randomUUID().toString(); + + + @Test + public void test_GetHistoryProcessInstanceUrl() { + final String expectedUrl = BASE_URL + "/history/process-instance?variables=requestId_eq_" + ID; + final String actualUrl = objUnderTest.getHistoryProcessInstanceUrl(ID); + assertEquals(expectedUrl, actualUrl); + } + + @Test + public void test_GetProcessInstanceUrl() { + final String expectedUrl = BASE_URL + "/history/process-instance/" + ID; + final String actualUrl = objUnderTest.getSingleProcessInstanceUrl(ID); + assertEquals(expectedUrl, actualUrl); + } + + + @Test + public void test_GetProcessDefinitionUrl() { + final String expectedUrl = BASE_URL + "/process-definition/" + ID + "/xml"; + final String actualUrl = objUnderTest.getProcessDefinitionUrl(ID); + assertEquals(expectedUrl, actualUrl); + + } + + @Test + public void test_GetActivityIntanceUrl() { + final String expectedUrl = + BASE_URL + "/history/activity-instance?processInstanceId=" + ID + "&sortBy=startTime&sortOrder=asc"; + final String actualUrl = objUnderTest.getActivityInstanceUrl(ID); + assertEquals(expectedUrl, actualUrl); + + } + + @Test + public void test_GetProcessInstanceVariablesUrl() { + final String expectedUrl = BASE_URL + "/history/variable-instance?processInstanceId=" + ID; + final String actualUrl = objUnderTest.getProcessInstanceVariablesUrl(ID); + assertEquals(expectedUrl, actualUrl); + + } + +} diff --git a/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/configuration/HttpServiceProviderConfigurationTest.java b/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/configuration/HttpServiceProviderConfigurationTest.java new file mode 100644 index 0000000000..1b3e168c12 --- /dev/null +++ b/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/configuration/HttpServiceProviderConfigurationTest.java @@ -0,0 +1,70 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.monitoring.configuration; + +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; +import org.onap.so.monitoring.configuration.rest.HttpServiceProviderConfiguration; +import org.onap.so.monitoring.rest.service.HttpRestServiceProvider; +import org.springframework.web.client.RestTemplate; + +/** + * @author waqas.ikram@ericsson.com + * + */ +public class HttpServiceProviderConfigurationTest { + + private final HttpServiceProviderConfiguration objUnderTest = new HttpServiceProviderConfiguration(); + private static final String AUTHORIZATION = + "Basic YWRtaW46S3A4Yko0U1hzek0wV1hsaGFrM2VIbGNzZTJnQXc4NHZhb0dHbUp2VXkyVQ=="; + + @Test + public void test_CamundaHttpRestServiceProvider_NotNull() { + + final HttpRestServiceProvider serviceProvider = + objUnderTest.camundaHttpRestServiceProvider(new RestTemplate(), AUTHORIZATION); + + assertNotNull(serviceProvider); + } + + @Test + public void test_DatabaseHttpRestServiceProvider_NotNull() { + + final HttpRestServiceProvider serviceProvider = + objUnderTest.databaseHttpRestServiceProvider(new RestTemplate(), AUTHORIZATION); + + assertNotNull(serviceProvider); + } + + @Test + public void test_DatabaseHttpRestServiceProviderWithAuthorizationNullOrEmpty_NotNull() { + + HttpRestServiceProvider serviceProvider = + objUnderTest.databaseHttpRestServiceProvider(new RestTemplate(), null); + + assertNotNull(serviceProvider); + + serviceProvider = objUnderTest.databaseHttpRestServiceProvider(new RestTemplate(), ""); + + assertNotNull(serviceProvider); + } + +} diff --git a/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/configuration/PojoClassesTests.java b/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/configuration/PojoClassesTests.java new file mode 100644 index 0000000000..f51d4c64b1 --- /dev/null +++ b/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/configuration/PojoClassesTests.java @@ -0,0 +1,82 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.monitoring.configuration; + +import static org.junit.Assert.assertFalse; + +import java.util.Set; +import java.util.regex.Pattern; + +import org.junit.Test; +import org.onap.so.openpojo.rules.ToStringTester; +import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; +import org.springframework.core.type.filter.RegexPatternTypeFilter; + +import com.openpojo.reflection.filters.FilterPackageInfo; +import com.openpojo.validation.Validator; +import com.openpojo.validation.ValidatorBuilder; +import com.openpojo.validation.test.impl.GetterTester; +import com.openpojo.validation.test.impl.SetterTester; + +import nl.jqno.equalsverifier.EqualsVerifier; +import nl.jqno.equalsverifier.Warning; + +/** + * @author waqas.ikram@ericsson.com + */ +public class PojoClassesTests { + + @Test + public void test_camunda_module_pojo_classes() throws ClassNotFoundException { + test("org.onap.so.monitoring.camunda.model"); + assertEqualMethod("org.onap.so.monitoring.camunda.model"); + } + + @Test + public void test_so_monitoring_pojo_classes() throws ClassNotFoundException { + test("org.onap.so.monitoring.model"); + assertEqualMethod("org.onap.so.monitoring.model"); + } + + public void assertEqualMethod(final String pojoPackage) throws ClassNotFoundException { + final Set classes = getBeanDefinition(pojoPackage); + assertFalse(classes.isEmpty()); + for (final BeanDefinition bean : classes) { + final Class clazz = Class.forName(bean.getBeanClassName()); + if (!clazz.getName().endsWith("Builder")) { + EqualsVerifier.forClass(clazz).suppress(Warning.STRICT_INHERITANCE, Warning.NONFINAL_FIELDS).verify(); + } + } + } + + private Set getBeanDefinition(final String pojoPackage) { + final ClassPathScanningCandidateComponentProvider provider = + new ClassPathScanningCandidateComponentProvider(false); + provider.addIncludeFilter(new RegexPatternTypeFilter(Pattern.compile(pojoPackage + ".*"))); + return provider.findCandidateComponents(pojoPackage); + } + + private void test(final String pojoPackage) { + final Validator validator = ValidatorBuilder.create().with(new SetterTester()).with(new GetterTester()) + .with(new ToStringTester()).build(); + validator.validate(pojoPackage, new FilterPackageInfo()); + } +} diff --git a/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/configuration/database/DatabaseUrlProviderTest.java b/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/configuration/database/DatabaseUrlProviderTest.java new file mode 100644 index 0000000000..d820e9435d --- /dev/null +++ b/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/configuration/database/DatabaseUrlProviderTest.java @@ -0,0 +1,52 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.monitoring.configuration.database; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + + +/** + * @author waqas.ikram@ericsson.com + */ +public class DatabaseUrlProviderTest { + + private static final int MAX_RESULT = 1; + private static final String URL = "http://localhost:8081/infraActiveRequests/"; + private final DatabaseUrlProvider objUnderTest = new DatabaseUrlProvider(URL); + + @Test + public void test_maxResultNull() { + final long from = System.currentTimeMillis(); + final long to = System.currentTimeMillis(); + final String actualUrl = objUnderTest.getSearchUrl(from, to, null); + assertEquals(URL + "v1/getInfraActiveRequests?from=" + from + "&to=" + to, actualUrl); + } + + @Test + public void test_maxResultNotNull() { + final long from = System.currentTimeMillis(); + final long to = System.currentTimeMillis(); + final String actualUrl = objUnderTest.getSearchUrl(from, to, MAX_RESULT); + assertEquals(URL + "v1/getInfraActiveRequests?from=" + from + "&to=" + to + "&maxResult=" + MAX_RESULT, + actualUrl); + } +} diff --git a/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/db/api/DatabaseServiceProviderTest.java b/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/db/api/DatabaseServiceProviderTest.java new file mode 100644 index 0000000000..58666671a7 --- /dev/null +++ b/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/db/api/DatabaseServiceProviderTest.java @@ -0,0 +1,107 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.monitoring.db.api; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.junit.Test; +import org.onap.so.monitoring.camunda.model.SoActiveInfraRequests; +import org.onap.so.monitoring.configuration.database.DatabaseUrlProvider; +import org.onap.so.monitoring.db.service.DatabaseServiceProvider; +import org.onap.so.monitoring.db.service.DatabaseServiceProviderImpl; +import org.onap.so.monitoring.model.SoInfraRequest; +import org.onap.so.monitoring.rest.service.HttpRestServiceProvider; + +import com.google.common.base.Optional; + + +/** + * @author waqas.ikram@ericsson.com + */ +public class DatabaseServiceProviderTest { + + private final static DatabaseUrlProvider URL_PROVIDER = + new DatabaseUrlProvider("http://localhost:8081/infraActiveRequests/"); + + @Test + public void test_GetSoInfraRequest_WithEmptyFilters_EmptyList() { + final HttpRestServiceProvider mockServiceProvider = mock(HttpRestServiceProvider.class); + final String searchUrl = URL_PROVIDER.getSearchUrl(0, 0, null); + final Optional response = Optional.of(new SoActiveInfraRequests[] {}); + + when(mockServiceProvider.postHttpRequest(eq(Collections.emptyMap()), eq(searchUrl), + eq(SoActiveInfraRequests[].class))).thenReturn(response); + + final DatabaseServiceProvider objUnderTest = new DatabaseServiceProviderImpl(URL_PROVIDER, mockServiceProvider); + + assertTrue(objUnderTest.getSoInfraRequest(Collections.emptyMap(), 0, 0, null).isEmpty()); + } + + @Test + public void test_GetSoInfraRequest_OptionalAbsent_EmptyList() { + final HttpRestServiceProvider mockServiceProvider = mock(HttpRestServiceProvider.class); + final String searchUrl = URL_PROVIDER.getSearchUrl(0, 0, null); + final Optional response = Optional.absent(); + + when(mockServiceProvider.postHttpRequest(eq(Collections.emptyMap()), eq(searchUrl), + eq(SoActiveInfraRequests[].class))).thenReturn(response); + + final DatabaseServiceProvider objUnderTest = new DatabaseServiceProviderImpl(URL_PROVIDER, mockServiceProvider); + + assertTrue(objUnderTest.getSoInfraRequest(Collections.emptyMap(), 0, 0, null).isEmpty()); + } + + @Test + public void test_GetSoInfraRequest_WithFilters_InfraActiveRequestsList() { + final String searchUrl = URL_PROVIDER.getSearchUrl(0, 0, null); + final String requestID = UUID.randomUUID().toString(); + final Map filters = new HashMap<>(); + filters.put("requestId", new String[] {"EQ", requestID}); + + final SoActiveInfraRequests soActiveInfraRequests = new SoActiveInfraRequests(); + soActiveInfraRequests.setRequestId(requestID); + + final Optional response = + Optional.of(new SoActiveInfraRequests[] {soActiveInfraRequests}); + + final HttpRestServiceProvider mockServiceProvider = mock(HttpRestServiceProvider.class); + + when(mockServiceProvider.postHttpRequest(eq(filters), eq(searchUrl), eq(SoActiveInfraRequests[].class))) + .thenReturn(response); + + final DatabaseServiceProvider objUnderTest = new DatabaseServiceProviderImpl(URL_PROVIDER, mockServiceProvider); + + final List actualList = objUnderTest.getSoInfraRequest(filters, 0, 0, null); + assertFalse(actualList.isEmpty()); + assertEquals(requestID, actualList.get(0).getRequestId()); + + } +} diff --git a/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/rest/service/CamundaProcessDataServiceProviderTest.java b/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/rest/service/CamundaProcessDataServiceProviderTest.java new file mode 100644 index 0000000000..c3930df196 --- /dev/null +++ b/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/rest/service/CamundaProcessDataServiceProviderTest.java @@ -0,0 +1,232 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.monitoring.rest.service; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.util.List; +import java.util.UUID; + +import org.junit.Test; +import org.onap.so.monitoring.camunda.model.ActivityInstance; +import org.onap.so.monitoring.camunda.model.ProcessDefinition; +import org.onap.so.monitoring.camunda.model.ProcessInstance; +import org.onap.so.monitoring.camunda.model.ProcessInstanceVariable; +import org.onap.so.monitoring.configuration.camunda.CamundaRestUrlProvider; +import org.onap.so.monitoring.model.ActivityInstanceDetail; +import org.onap.so.monitoring.model.ProcessDefinitionDetail; +import org.onap.so.monitoring.model.ProcessInstanceIdDetail; +import org.onap.so.monitoring.model.ProcessInstanceVariableDetail; + +import com.google.common.base.Optional; + + +/** + * @author waqas.ikram@ericsson.com + */ +public class CamundaProcessDataServiceProviderTest { + private static final String DURATION = "1"; + private static final String FLOW_XML = ""; + private static final String NAME = "Test"; + private static final String DEFAULT = "default"; + private static final String CAMUNDA_REST_API_URL = "http://localhost:9080/engine-rest/engine/"; + + private static final String ID = UUID.randomUUID().toString(); + private static final String PROCESS_ID = UUID.randomUUID().toString(); + private static final String DEF_ID = UUID.randomUUID().toString(); + private static final String SUPER_PROCESS_ID = UUID.randomUUID().toString(); + private final HttpRestServiceProvider httpRestServiceProvider = mock(HttpRestServiceProvider.class); + private final CamundaRestUrlProvider camundaRestUrlProvider = + new CamundaRestUrlProvider(CAMUNDA_REST_API_URL, DEFAULT); + + + @Test + public void test_GetProcessInstanceDetail_EmptyResponse() { + final Optional response = Optional.absent(); + final String url = CAMUNDA_REST_API_URL + DEFAULT + "/history/process-instance?variables=requestId_eq_" + ID; + when(httpRestServiceProvider.getHttpResponse(url, ProcessInstance[].class)).thenReturn(response); + final CamundaProcessDataServiceProvider objUnderTest = + new CamundaProcessDataServiceProviderImpl(camundaRestUrlProvider, httpRestServiceProvider); + + final Optional actualResponse = objUnderTest.getProcessInstanceIdDetail(ID); + assertFalse(actualResponse.isPresent()); + } + + @Test + public void test_GetProcessInstanceDetail_NonEmptyResponseWithSuperProcessIdNull() { + final Optional response = Optional.of(getProcessInstance()); + final String url = CAMUNDA_REST_API_URL + DEFAULT + "/history/process-instance?variables=requestId_eq_" + ID; + when(httpRestServiceProvider.getHttpResponse(url, ProcessInstance[].class)).thenReturn(response); + final CamundaProcessDataServiceProvider objUnderTest = + new CamundaProcessDataServiceProviderImpl(camundaRestUrlProvider, httpRestServiceProvider); + + final Optional actualResponse = objUnderTest.getProcessInstanceIdDetail(ID); + assertTrue(actualResponse.isPresent()); + + final ProcessInstanceIdDetail actualProcessInstanceDetail = actualResponse.get(); + assertEquals(PROCESS_ID, actualProcessInstanceDetail.getProcessInstanceId()); + } + + @Test + public void test_GetProcessInstanceDetail_NonEmptyResponseWithSuperProcessIdNotNull() { + final Optional response = Optional.of(getProcessInstance(SUPER_PROCESS_ID)); + final String url = CAMUNDA_REST_API_URL + DEFAULT + "/history/process-instance?variables=requestId_eq_" + ID; + when(httpRestServiceProvider.getHttpResponse(url, ProcessInstance[].class)).thenReturn(response); + final CamundaProcessDataServiceProvider objUnderTest = + new CamundaProcessDataServiceProviderImpl(camundaRestUrlProvider, httpRestServiceProvider); + + final Optional actualResponse = objUnderTest.getProcessInstanceIdDetail(ID); + assertFalse(actualResponse.isPresent()); + + } + + @Test + public void test_GetProcessDefinition_EmptyResponse() { + final Optional response = Optional.absent(); + final String url = CAMUNDA_REST_API_URL + DEFAULT + "/process-definition/" + ID + "/xml"; + when(httpRestServiceProvider.getHttpResponse(url, ProcessDefinition.class)).thenReturn(response); + final CamundaProcessDataServiceProvider objUnderTest = + new CamundaProcessDataServiceProviderImpl(camundaRestUrlProvider, httpRestServiceProvider); + + final Optional actualResponse = objUnderTest.getProcessDefinition(ID); + assertFalse(actualResponse.isPresent()); + } + + @Test + public void test_GetProcessDefinition_NonEmptyResponse() { + final Optional response = getProcessDefinition(); + final String url = CAMUNDA_REST_API_URL + DEFAULT + "/process-definition/" + PROCESS_ID + "/xml"; + when(httpRestServiceProvider.getHttpResponse(url, ProcessDefinition.class)).thenReturn(response); + final CamundaProcessDataServiceProvider objUnderTest = + new CamundaProcessDataServiceProviderImpl(camundaRestUrlProvider, httpRestServiceProvider); + + final Optional actualResponse = objUnderTest.getProcessDefinition(PROCESS_ID); + assertTrue(actualResponse.isPresent()); + assertEquals(PROCESS_ID, actualResponse.get().getProcessDefinitionId()); + assertEquals(FLOW_XML, actualResponse.get().getProcessDefinitionXml()); + } + + @Test + public void test_GetActivityInstance_EmptyResponse() { + final Optional response = Optional.absent(); + final String url = CAMUNDA_REST_API_URL + DEFAULT + "/history/activity-instance?processInstanceId=" + PROCESS_ID + + "&sortBy=startTime&sortOrder=asc"; + when(httpRestServiceProvider.getHttpResponse(url, ActivityInstance[].class)).thenReturn(response); + final CamundaProcessDataServiceProvider objUnderTest = + new CamundaProcessDataServiceProviderImpl(camundaRestUrlProvider, httpRestServiceProvider); + + final List actualResponse = objUnderTest.getActivityInstance(PROCESS_ID); + assertTrue(actualResponse.isEmpty()); + + } + + @Test + public void test_GetActivityInstance_NonEmptyResponse() { + final Optional response = getActivityInstance(); + final String url = CAMUNDA_REST_API_URL + DEFAULT + "/history/activity-instance?processInstanceId=" + PROCESS_ID + + "&sortBy=startTime&sortOrder=asc"; + when(httpRestServiceProvider.getHttpResponse(url, ActivityInstance[].class)).thenReturn(response); + final CamundaProcessDataServiceProvider objUnderTest = + new CamundaProcessDataServiceProviderImpl(camundaRestUrlProvider, httpRestServiceProvider); + + final List actualResponse = objUnderTest.getActivityInstance(PROCESS_ID); + assertFalse(actualResponse.isEmpty()); + final ActivityInstanceDetail actualActivityInstanceDetail = actualResponse.get(0); + assertEquals(ID, actualActivityInstanceDetail.getActivityId()); + assertEquals(NAME, actualActivityInstanceDetail.getActivityName()); + assertEquals(NAME, actualActivityInstanceDetail.getActivityType()); + + } + + @Test + public void test_GetProcessInstanceVariable_EmptyResponse() { + final Optional response = Optional.absent(); + final String url = + CAMUNDA_REST_API_URL + DEFAULT + "/history/variable-instance?processInstanceId=" + PROCESS_ID; + when(httpRestServiceProvider.getHttpResponse(url, ProcessInstanceVariable[].class)).thenReturn(response); + final CamundaProcessDataServiceProvider objUnderTest = + new CamundaProcessDataServiceProviderImpl(camundaRestUrlProvider, httpRestServiceProvider); + + final List actualResponse = objUnderTest.getProcessInstanceVariable(PROCESS_ID); + assertTrue(actualResponse.isEmpty()); + + } + + @Test + public void test_GetProcessInstanceVariable_NonEmptyResponse() { + final Optional response = getProcessInstanceVariable(); + final String url = + CAMUNDA_REST_API_URL + DEFAULT + "/history/variable-instance?processInstanceId=" + PROCESS_ID; + when(httpRestServiceProvider.getHttpResponse(url, ProcessInstanceVariable[].class)).thenReturn(response); + final CamundaProcessDataServiceProvider objUnderTest = + new CamundaProcessDataServiceProviderImpl(camundaRestUrlProvider, httpRestServiceProvider); + + final List actualResponse = objUnderTest.getProcessInstanceVariable(PROCESS_ID); + assertFalse(actualResponse.isEmpty()); + final ProcessInstanceVariableDetail variableDetail = actualResponse.get(0); + assertEquals(NAME, variableDetail.getName()); + assertEquals(NAME, variableDetail.getType()); + assertEquals(NAME, variableDetail.getValue()); + + } + + private Optional getProcessInstanceVariable() { + final ProcessInstanceVariable instanceVariable = new ProcessInstanceVariable(); + instanceVariable.setName(NAME); + instanceVariable.setType(NAME); + instanceVariable.setValue(NAME); + return Optional.of(new ProcessInstanceVariable[] {instanceVariable}); + } + + private Optional getActivityInstance() { + final ActivityInstance activityInstance = new ActivityInstance(); + activityInstance.setActivityId(ID); + activityInstance.setActivityName(NAME); + activityInstance.setActivityType(NAME); + activityInstance.setDurationInMillis(DURATION); + return Optional.of(new ActivityInstance[] {activityInstance}); + } + + private Optional getProcessDefinition() { + final ProcessDefinition processDefinition = new ProcessDefinition(); + processDefinition.setId(PROCESS_ID); + processDefinition.setBpmn20Xml(FLOW_XML); + return Optional.of(processDefinition); + } + + private ProcessInstance[] getProcessInstance() { + return getProcessInstance(null); + } + + private ProcessInstance[] getProcessInstance(final String superProcessInstanceId) { + final ProcessInstance instance = new ProcessInstance(); + instance.setId(PROCESS_ID); + instance.setProcessDefinitionId(DEF_ID); + instance.setProcessDefinitionName(NAME); + instance.setSuperProcessInstanceId(superProcessInstanceId); + return new ProcessInstance[] {instance}; + } + + +} diff --git a/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/utils/ObjectEqualsUtilsTest.java b/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/utils/ObjectEqualsUtilsTest.java new file mode 100644 index 0000000000..dd363abe3a --- /dev/null +++ b/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/monitoring/utils/ObjectEqualsUtilsTest.java @@ -0,0 +1,71 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Ericsson. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.monitoring.utils; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.Arrays; +import java.util.List; + +import org.junit.Test; + + +/** + * @author waqas.ikram@ericsson.com + * + */ +public class ObjectEqualsUtilsTest { + + private static final String VALUE = "Humpty Dumpty Sat On The Wall"; + + @Test + public void test_ObjectEqualsUtils_isEqual_NullValues() { + assertTrue(ObjectEqualsUtils.isEqual(null, null)); + } + + @Test + public void test_ObjectEqualsUtils_isEqual_FirstValueNullSecondNotNull() { + assertFalse(ObjectEqualsUtils.isEqual(null, VALUE)); + } + + @Test + public void test_ObjectEqualsUtils_isEqual_FirstValueNotNullSecondNull() { + assertFalse(ObjectEqualsUtils.isEqual(VALUE, null)); + } + + @Test + public void test_ObjectEqualsUtils_isEqual_NotNullValues() { + assertTrue(ObjectEqualsUtils.isEqual(VALUE, VALUE)); + } + + @Test + public void test_ObjectEqualsUtils_isEqual_CollectionValues() { + final List firstObject = Arrays.asList(VALUE); + final List secondObject = Arrays.asList(VALUE); + assertTrue(ObjectEqualsUtils.isEqual(firstObject, secondObject)); + } + + @Test + public void test_ObjectEqualsUtils_isEqual_CollectionAndStringValues() { + final List firstObject = Arrays.asList(VALUE); + assertFalse(ObjectEqualsUtils.isEqual(firstObject, VALUE)); + } +} diff --git a/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/montoring/configuration/CamundaConfigurationTest.java b/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/montoring/configuration/CamundaConfigurationTest.java deleted file mode 100644 index fb56d841e4..0000000000 --- a/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/montoring/configuration/CamundaConfigurationTest.java +++ /dev/null @@ -1,44 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Ericsson. 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.so.monitoring.configuration; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; -import org.onap.so.monitoring.configuration.camunda.CamundaConfiguration; -import org.onap.so.monitoring.configuration.camunda.CamundaRestUrlProvider; - - -/** - * @author waqas.ikram@ericsson.com - * - */ -public class CamundaConfigurationTest { - - @Test - public void test_CamundaRestURIConfiguration_ValidUrl() { - final CamundaConfiguration objUnderTest = new CamundaConfiguration(); - final CamundaRestUrlProvider provider = objUnderTest.camundaRestUrlProvider("http://localhost:8080", "default"); - assertEquals( - "http://localhost:8080/default/history/activity-instance?processInstanceId=Deadpool&sortBy=startTime&sortOrder=asc", - provider.getActivityInstanceUrl("Deadpool")); - } - -} diff --git a/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/montoring/configuration/CamundaRestUrlProviderTest.java b/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/montoring/configuration/CamundaRestUrlProviderTest.java deleted file mode 100644 index 3cd8a33d77..0000000000 --- a/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/montoring/configuration/CamundaRestUrlProviderTest.java +++ /dev/null @@ -1,80 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Ericsson. 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.so.monitoring.configuration; - -import static org.junit.Assert.assertEquals; - -import java.util.UUID; - -import org.junit.Test; -import org.onap.so.monitoring.configuration.camunda.CamundaRestUrlProvider; - -/** - * @author waqas.ikram@ericsson.com - */ -public class CamundaRestUrlProviderTest { - private static final String DEFAULT = "default"; - private static final String CAMUNDA_REST_API_URL = "http://localhost:9080/engine-rest/engine/"; - private static final String BASE_URL = CAMUNDA_REST_API_URL + DEFAULT; - private final CamundaRestUrlProvider objUnderTest = new CamundaRestUrlProvider(CAMUNDA_REST_API_URL, DEFAULT); - private static final String ID = UUID.randomUUID().toString(); - - - @Test - public void test_GetHistoryProcessInstanceUrl() { - final String expectedUrl = BASE_URL + "/history/process-instance?variables=requestId_eq_" + ID; - final String actualUrl = objUnderTest.getHistoryProcessInstanceUrl(ID); - assertEquals(expectedUrl, actualUrl); - } - - @Test - public void test_GetProcessInstanceUrl() { - final String expectedUrl = BASE_URL + "/history/process-instance/" + ID; - final String actualUrl = objUnderTest.getSingleProcessInstanceUrl(ID); - assertEquals(expectedUrl, actualUrl); - } - - - @Test - public void test_GetProcessDefinitionUrl() { - final String expectedUrl = BASE_URL + "/process-definition/" + ID + "/xml"; - final String actualUrl = objUnderTest.getProcessDefinitionUrl(ID); - assertEquals(expectedUrl, actualUrl); - - } - - @Test - public void test_GetActivityIntanceUrl() { - final String expectedUrl = - BASE_URL + "/history/activity-instance?processInstanceId=" + ID + "&sortBy=startTime&sortOrder=asc"; - final String actualUrl = objUnderTest.getActivityInstanceUrl(ID); - assertEquals(expectedUrl, actualUrl); - - } - - @Test - public void test_GetProcessInstanceVariablesUrl() { - final String expectedUrl = BASE_URL + "/history/variable-instance?processInstanceId=" + ID; - final String actualUrl = objUnderTest.getProcessInstanceVariablesUrl(ID); - assertEquals(expectedUrl, actualUrl); - - } - -} diff --git a/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/montoring/configuration/HttpServiceProviderConfigurationTest.java b/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/montoring/configuration/HttpServiceProviderConfigurationTest.java deleted file mode 100644 index 1b3e168c12..0000000000 --- a/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/montoring/configuration/HttpServiceProviderConfigurationTest.java +++ /dev/null @@ -1,70 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Ericsson. 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.so.monitoring.configuration; - -import static org.junit.Assert.assertNotNull; - -import org.junit.Test; -import org.onap.so.monitoring.configuration.rest.HttpServiceProviderConfiguration; -import org.onap.so.monitoring.rest.service.HttpRestServiceProvider; -import org.springframework.web.client.RestTemplate; - -/** - * @author waqas.ikram@ericsson.com - * - */ -public class HttpServiceProviderConfigurationTest { - - private final HttpServiceProviderConfiguration objUnderTest = new HttpServiceProviderConfiguration(); - private static final String AUTHORIZATION = - "Basic YWRtaW46S3A4Yko0U1hzek0wV1hsaGFrM2VIbGNzZTJnQXc4NHZhb0dHbUp2VXkyVQ=="; - - @Test - public void test_CamundaHttpRestServiceProvider_NotNull() { - - final HttpRestServiceProvider serviceProvider = - objUnderTest.camundaHttpRestServiceProvider(new RestTemplate(), AUTHORIZATION); - - assertNotNull(serviceProvider); - } - - @Test - public void test_DatabaseHttpRestServiceProvider_NotNull() { - - final HttpRestServiceProvider serviceProvider = - objUnderTest.databaseHttpRestServiceProvider(new RestTemplate(), AUTHORIZATION); - - assertNotNull(serviceProvider); - } - - @Test - public void test_DatabaseHttpRestServiceProviderWithAuthorizationNullOrEmpty_NotNull() { - - HttpRestServiceProvider serviceProvider = - objUnderTest.databaseHttpRestServiceProvider(new RestTemplate(), null); - - assertNotNull(serviceProvider); - - serviceProvider = objUnderTest.databaseHttpRestServiceProvider(new RestTemplate(), ""); - - assertNotNull(serviceProvider); - } - -} diff --git a/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/montoring/configuration/PojoClassesTests.java b/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/montoring/configuration/PojoClassesTests.java deleted file mode 100644 index f51d4c64b1..0000000000 --- a/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/montoring/configuration/PojoClassesTests.java +++ /dev/null @@ -1,82 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Ericsson. 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.so.monitoring.configuration; - -import static org.junit.Assert.assertFalse; - -import java.util.Set; -import java.util.regex.Pattern; - -import org.junit.Test; -import org.onap.so.openpojo.rules.ToStringTester; -import org.springframework.beans.factory.config.BeanDefinition; -import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; -import org.springframework.core.type.filter.RegexPatternTypeFilter; - -import com.openpojo.reflection.filters.FilterPackageInfo; -import com.openpojo.validation.Validator; -import com.openpojo.validation.ValidatorBuilder; -import com.openpojo.validation.test.impl.GetterTester; -import com.openpojo.validation.test.impl.SetterTester; - -import nl.jqno.equalsverifier.EqualsVerifier; -import nl.jqno.equalsverifier.Warning; - -/** - * @author waqas.ikram@ericsson.com - */ -public class PojoClassesTests { - - @Test - public void test_camunda_module_pojo_classes() throws ClassNotFoundException { - test("org.onap.so.monitoring.camunda.model"); - assertEqualMethod("org.onap.so.monitoring.camunda.model"); - } - - @Test - public void test_so_monitoring_pojo_classes() throws ClassNotFoundException { - test("org.onap.so.monitoring.model"); - assertEqualMethod("org.onap.so.monitoring.model"); - } - - public void assertEqualMethod(final String pojoPackage) throws ClassNotFoundException { - final Set classes = getBeanDefinition(pojoPackage); - assertFalse(classes.isEmpty()); - for (final BeanDefinition bean : classes) { - final Class clazz = Class.forName(bean.getBeanClassName()); - if (!clazz.getName().endsWith("Builder")) { - EqualsVerifier.forClass(clazz).suppress(Warning.STRICT_INHERITANCE, Warning.NONFINAL_FIELDS).verify(); - } - } - } - - private Set getBeanDefinition(final String pojoPackage) { - final ClassPathScanningCandidateComponentProvider provider = - new ClassPathScanningCandidateComponentProvider(false); - provider.addIncludeFilter(new RegexPatternTypeFilter(Pattern.compile(pojoPackage + ".*"))); - return provider.findCandidateComponents(pojoPackage); - } - - private void test(final String pojoPackage) { - final Validator validator = ValidatorBuilder.create().with(new SetterTester()).with(new GetterTester()) - .with(new ToStringTester()).build(); - validator.validate(pojoPackage, new FilterPackageInfo()); - } -} diff --git a/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/montoring/configuration/database/DatabaseUrlProviderTest.java b/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/montoring/configuration/database/DatabaseUrlProviderTest.java deleted file mode 100644 index d820e9435d..0000000000 --- a/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/montoring/configuration/database/DatabaseUrlProviderTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Ericsson. 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.so.monitoring.configuration.database; - -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - - -/** - * @author waqas.ikram@ericsson.com - */ -public class DatabaseUrlProviderTest { - - private static final int MAX_RESULT = 1; - private static final String URL = "http://localhost:8081/infraActiveRequests/"; - private final DatabaseUrlProvider objUnderTest = new DatabaseUrlProvider(URL); - - @Test - public void test_maxResultNull() { - final long from = System.currentTimeMillis(); - final long to = System.currentTimeMillis(); - final String actualUrl = objUnderTest.getSearchUrl(from, to, null); - assertEquals(URL + "v1/getInfraActiveRequests?from=" + from + "&to=" + to, actualUrl); - } - - @Test - public void test_maxResultNotNull() { - final long from = System.currentTimeMillis(); - final long to = System.currentTimeMillis(); - final String actualUrl = objUnderTest.getSearchUrl(from, to, MAX_RESULT); - assertEquals(URL + "v1/getInfraActiveRequests?from=" + from + "&to=" + to + "&maxResult=" + MAX_RESULT, - actualUrl); - } -} diff --git a/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/montoring/db/api/DatabaseServiceProviderTest.java b/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/montoring/db/api/DatabaseServiceProviderTest.java deleted file mode 100644 index 58666671a7..0000000000 --- a/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/montoring/db/api/DatabaseServiceProviderTest.java +++ /dev/null @@ -1,107 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Ericsson. 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.so.monitoring.db.api; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import org.junit.Test; -import org.onap.so.monitoring.camunda.model.SoActiveInfraRequests; -import org.onap.so.monitoring.configuration.database.DatabaseUrlProvider; -import org.onap.so.monitoring.db.service.DatabaseServiceProvider; -import org.onap.so.monitoring.db.service.DatabaseServiceProviderImpl; -import org.onap.so.monitoring.model.SoInfraRequest; -import org.onap.so.monitoring.rest.service.HttpRestServiceProvider; - -import com.google.common.base.Optional; - - -/** - * @author waqas.ikram@ericsson.com - */ -public class DatabaseServiceProviderTest { - - private final static DatabaseUrlProvider URL_PROVIDER = - new DatabaseUrlProvider("http://localhost:8081/infraActiveRequests/"); - - @Test - public void test_GetSoInfraRequest_WithEmptyFilters_EmptyList() { - final HttpRestServiceProvider mockServiceProvider = mock(HttpRestServiceProvider.class); - final String searchUrl = URL_PROVIDER.getSearchUrl(0, 0, null); - final Optional response = Optional.of(new SoActiveInfraRequests[] {}); - - when(mockServiceProvider.postHttpRequest(eq(Collections.emptyMap()), eq(searchUrl), - eq(SoActiveInfraRequests[].class))).thenReturn(response); - - final DatabaseServiceProvider objUnderTest = new DatabaseServiceProviderImpl(URL_PROVIDER, mockServiceProvider); - - assertTrue(objUnderTest.getSoInfraRequest(Collections.emptyMap(), 0, 0, null).isEmpty()); - } - - @Test - public void test_GetSoInfraRequest_OptionalAbsent_EmptyList() { - final HttpRestServiceProvider mockServiceProvider = mock(HttpRestServiceProvider.class); - final String searchUrl = URL_PROVIDER.getSearchUrl(0, 0, null); - final Optional response = Optional.absent(); - - when(mockServiceProvider.postHttpRequest(eq(Collections.emptyMap()), eq(searchUrl), - eq(SoActiveInfraRequests[].class))).thenReturn(response); - - final DatabaseServiceProvider objUnderTest = new DatabaseServiceProviderImpl(URL_PROVIDER, mockServiceProvider); - - assertTrue(objUnderTest.getSoInfraRequest(Collections.emptyMap(), 0, 0, null).isEmpty()); - } - - @Test - public void test_GetSoInfraRequest_WithFilters_InfraActiveRequestsList() { - final String searchUrl = URL_PROVIDER.getSearchUrl(0, 0, null); - final String requestID = UUID.randomUUID().toString(); - final Map filters = new HashMap<>(); - filters.put("requestId", new String[] {"EQ", requestID}); - - final SoActiveInfraRequests soActiveInfraRequests = new SoActiveInfraRequests(); - soActiveInfraRequests.setRequestId(requestID); - - final Optional response = - Optional.of(new SoActiveInfraRequests[] {soActiveInfraRequests}); - - final HttpRestServiceProvider mockServiceProvider = mock(HttpRestServiceProvider.class); - - when(mockServiceProvider.postHttpRequest(eq(filters), eq(searchUrl), eq(SoActiveInfraRequests[].class))) - .thenReturn(response); - - final DatabaseServiceProvider objUnderTest = new DatabaseServiceProviderImpl(URL_PROVIDER, mockServiceProvider); - - final List actualList = objUnderTest.getSoInfraRequest(filters, 0, 0, null); - assertFalse(actualList.isEmpty()); - assertEquals(requestID, actualList.get(0).getRequestId()); - - } -} diff --git a/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/montoring/rest/service/CamundaProcessDataServiceProviderTest.java b/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/montoring/rest/service/CamundaProcessDataServiceProviderTest.java deleted file mode 100644 index c3930df196..0000000000 --- a/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/montoring/rest/service/CamundaProcessDataServiceProviderTest.java +++ /dev/null @@ -1,232 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Ericsson. 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.so.monitoring.rest.service; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.List; -import java.util.UUID; - -import org.junit.Test; -import org.onap.so.monitoring.camunda.model.ActivityInstance; -import org.onap.so.monitoring.camunda.model.ProcessDefinition; -import org.onap.so.monitoring.camunda.model.ProcessInstance; -import org.onap.so.monitoring.camunda.model.ProcessInstanceVariable; -import org.onap.so.monitoring.configuration.camunda.CamundaRestUrlProvider; -import org.onap.so.monitoring.model.ActivityInstanceDetail; -import org.onap.so.monitoring.model.ProcessDefinitionDetail; -import org.onap.so.monitoring.model.ProcessInstanceIdDetail; -import org.onap.so.monitoring.model.ProcessInstanceVariableDetail; - -import com.google.common.base.Optional; - - -/** - * @author waqas.ikram@ericsson.com - */ -public class CamundaProcessDataServiceProviderTest { - private static final String DURATION = "1"; - private static final String FLOW_XML = ""; - private static final String NAME = "Test"; - private static final String DEFAULT = "default"; - private static final String CAMUNDA_REST_API_URL = "http://localhost:9080/engine-rest/engine/"; - - private static final String ID = UUID.randomUUID().toString(); - private static final String PROCESS_ID = UUID.randomUUID().toString(); - private static final String DEF_ID = UUID.randomUUID().toString(); - private static final String SUPER_PROCESS_ID = UUID.randomUUID().toString(); - private final HttpRestServiceProvider httpRestServiceProvider = mock(HttpRestServiceProvider.class); - private final CamundaRestUrlProvider camundaRestUrlProvider = - new CamundaRestUrlProvider(CAMUNDA_REST_API_URL, DEFAULT); - - - @Test - public void test_GetProcessInstanceDetail_EmptyResponse() { - final Optional response = Optional.absent(); - final String url = CAMUNDA_REST_API_URL + DEFAULT + "/history/process-instance?variables=requestId_eq_" + ID; - when(httpRestServiceProvider.getHttpResponse(url, ProcessInstance[].class)).thenReturn(response); - final CamundaProcessDataServiceProvider objUnderTest = - new CamundaProcessDataServiceProviderImpl(camundaRestUrlProvider, httpRestServiceProvider); - - final Optional actualResponse = objUnderTest.getProcessInstanceIdDetail(ID); - assertFalse(actualResponse.isPresent()); - } - - @Test - public void test_GetProcessInstanceDetail_NonEmptyResponseWithSuperProcessIdNull() { - final Optional response = Optional.of(getProcessInstance()); - final String url = CAMUNDA_REST_API_URL + DEFAULT + "/history/process-instance?variables=requestId_eq_" + ID; - when(httpRestServiceProvider.getHttpResponse(url, ProcessInstance[].class)).thenReturn(response); - final CamundaProcessDataServiceProvider objUnderTest = - new CamundaProcessDataServiceProviderImpl(camundaRestUrlProvider, httpRestServiceProvider); - - final Optional actualResponse = objUnderTest.getProcessInstanceIdDetail(ID); - assertTrue(actualResponse.isPresent()); - - final ProcessInstanceIdDetail actualProcessInstanceDetail = actualResponse.get(); - assertEquals(PROCESS_ID, actualProcessInstanceDetail.getProcessInstanceId()); - } - - @Test - public void test_GetProcessInstanceDetail_NonEmptyResponseWithSuperProcessIdNotNull() { - final Optional response = Optional.of(getProcessInstance(SUPER_PROCESS_ID)); - final String url = CAMUNDA_REST_API_URL + DEFAULT + "/history/process-instance?variables=requestId_eq_" + ID; - when(httpRestServiceProvider.getHttpResponse(url, ProcessInstance[].class)).thenReturn(response); - final CamundaProcessDataServiceProvider objUnderTest = - new CamundaProcessDataServiceProviderImpl(camundaRestUrlProvider, httpRestServiceProvider); - - final Optional actualResponse = objUnderTest.getProcessInstanceIdDetail(ID); - assertFalse(actualResponse.isPresent()); - - } - - @Test - public void test_GetProcessDefinition_EmptyResponse() { - final Optional response = Optional.absent(); - final String url = CAMUNDA_REST_API_URL + DEFAULT + "/process-definition/" + ID + "/xml"; - when(httpRestServiceProvider.getHttpResponse(url, ProcessDefinition.class)).thenReturn(response); - final CamundaProcessDataServiceProvider objUnderTest = - new CamundaProcessDataServiceProviderImpl(camundaRestUrlProvider, httpRestServiceProvider); - - final Optional actualResponse = objUnderTest.getProcessDefinition(ID); - assertFalse(actualResponse.isPresent()); - } - - @Test - public void test_GetProcessDefinition_NonEmptyResponse() { - final Optional response = getProcessDefinition(); - final String url = CAMUNDA_REST_API_URL + DEFAULT + "/process-definition/" + PROCESS_ID + "/xml"; - when(httpRestServiceProvider.getHttpResponse(url, ProcessDefinition.class)).thenReturn(response); - final CamundaProcessDataServiceProvider objUnderTest = - new CamundaProcessDataServiceProviderImpl(camundaRestUrlProvider, httpRestServiceProvider); - - final Optional actualResponse = objUnderTest.getProcessDefinition(PROCESS_ID); - assertTrue(actualResponse.isPresent()); - assertEquals(PROCESS_ID, actualResponse.get().getProcessDefinitionId()); - assertEquals(FLOW_XML, actualResponse.get().getProcessDefinitionXml()); - } - - @Test - public void test_GetActivityInstance_EmptyResponse() { - final Optional response = Optional.absent(); - final String url = CAMUNDA_REST_API_URL + DEFAULT + "/history/activity-instance?processInstanceId=" + PROCESS_ID - + "&sortBy=startTime&sortOrder=asc"; - when(httpRestServiceProvider.getHttpResponse(url, ActivityInstance[].class)).thenReturn(response); - final CamundaProcessDataServiceProvider objUnderTest = - new CamundaProcessDataServiceProviderImpl(camundaRestUrlProvider, httpRestServiceProvider); - - final List actualResponse = objUnderTest.getActivityInstance(PROCESS_ID); - assertTrue(actualResponse.isEmpty()); - - } - - @Test - public void test_GetActivityInstance_NonEmptyResponse() { - final Optional response = getActivityInstance(); - final String url = CAMUNDA_REST_API_URL + DEFAULT + "/history/activity-instance?processInstanceId=" + PROCESS_ID - + "&sortBy=startTime&sortOrder=asc"; - when(httpRestServiceProvider.getHttpResponse(url, ActivityInstance[].class)).thenReturn(response); - final CamundaProcessDataServiceProvider objUnderTest = - new CamundaProcessDataServiceProviderImpl(camundaRestUrlProvider, httpRestServiceProvider); - - final List actualResponse = objUnderTest.getActivityInstance(PROCESS_ID); - assertFalse(actualResponse.isEmpty()); - final ActivityInstanceDetail actualActivityInstanceDetail = actualResponse.get(0); - assertEquals(ID, actualActivityInstanceDetail.getActivityId()); - assertEquals(NAME, actualActivityInstanceDetail.getActivityName()); - assertEquals(NAME, actualActivityInstanceDetail.getActivityType()); - - } - - @Test - public void test_GetProcessInstanceVariable_EmptyResponse() { - final Optional response = Optional.absent(); - final String url = - CAMUNDA_REST_API_URL + DEFAULT + "/history/variable-instance?processInstanceId=" + PROCESS_ID; - when(httpRestServiceProvider.getHttpResponse(url, ProcessInstanceVariable[].class)).thenReturn(response); - final CamundaProcessDataServiceProvider objUnderTest = - new CamundaProcessDataServiceProviderImpl(camundaRestUrlProvider, httpRestServiceProvider); - - final List actualResponse = objUnderTest.getProcessInstanceVariable(PROCESS_ID); - assertTrue(actualResponse.isEmpty()); - - } - - @Test - public void test_GetProcessInstanceVariable_NonEmptyResponse() { - final Optional response = getProcessInstanceVariable(); - final String url = - CAMUNDA_REST_API_URL + DEFAULT + "/history/variable-instance?processInstanceId=" + PROCESS_ID; - when(httpRestServiceProvider.getHttpResponse(url, ProcessInstanceVariable[].class)).thenReturn(response); - final CamundaProcessDataServiceProvider objUnderTest = - new CamundaProcessDataServiceProviderImpl(camundaRestUrlProvider, httpRestServiceProvider); - - final List actualResponse = objUnderTest.getProcessInstanceVariable(PROCESS_ID); - assertFalse(actualResponse.isEmpty()); - final ProcessInstanceVariableDetail variableDetail = actualResponse.get(0); - assertEquals(NAME, variableDetail.getName()); - assertEquals(NAME, variableDetail.getType()); - assertEquals(NAME, variableDetail.getValue()); - - } - - private Optional getProcessInstanceVariable() { - final ProcessInstanceVariable instanceVariable = new ProcessInstanceVariable(); - instanceVariable.setName(NAME); - instanceVariable.setType(NAME); - instanceVariable.setValue(NAME); - return Optional.of(new ProcessInstanceVariable[] {instanceVariable}); - } - - private Optional getActivityInstance() { - final ActivityInstance activityInstance = new ActivityInstance(); - activityInstance.setActivityId(ID); - activityInstance.setActivityName(NAME); - activityInstance.setActivityType(NAME); - activityInstance.setDurationInMillis(DURATION); - return Optional.of(new ActivityInstance[] {activityInstance}); - } - - private Optional getProcessDefinition() { - final ProcessDefinition processDefinition = new ProcessDefinition(); - processDefinition.setId(PROCESS_ID); - processDefinition.setBpmn20Xml(FLOW_XML); - return Optional.of(processDefinition); - } - - private ProcessInstance[] getProcessInstance() { - return getProcessInstance(null); - } - - private ProcessInstance[] getProcessInstance(final String superProcessInstanceId) { - final ProcessInstance instance = new ProcessInstance(); - instance.setId(PROCESS_ID); - instance.setProcessDefinitionId(DEF_ID); - instance.setProcessDefinitionName(NAME); - instance.setSuperProcessInstanceId(superProcessInstanceId); - return new ProcessInstance[] {instance}; - } - - -} diff --git a/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/montoring/utils/ObjectEqualsUtilsTest.java b/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/montoring/utils/ObjectEqualsUtilsTest.java deleted file mode 100644 index dd363abe3a..0000000000 --- a/so-monitoring/so-monitoring-handler/src/test/java/org/onap/so/montoring/utils/ObjectEqualsUtilsTest.java +++ /dev/null @@ -1,71 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2018 Ericsson. 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. - * - * SPDX-License-Identifier: Apache-2.0 - * ============LICENSE_END========================================================= - */ -package org.onap.so.monitoring.utils; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.util.Arrays; -import java.util.List; - -import org.junit.Test; - - -/** - * @author waqas.ikram@ericsson.com - * - */ -public class ObjectEqualsUtilsTest { - - private static final String VALUE = "Humpty Dumpty Sat On The Wall"; - - @Test - public void test_ObjectEqualsUtils_isEqual_NullValues() { - assertTrue(ObjectEqualsUtils.isEqual(null, null)); - } - - @Test - public void test_ObjectEqualsUtils_isEqual_FirstValueNullSecondNotNull() { - assertFalse(ObjectEqualsUtils.isEqual(null, VALUE)); - } - - @Test - public void test_ObjectEqualsUtils_isEqual_FirstValueNotNullSecondNull() { - assertFalse(ObjectEqualsUtils.isEqual(VALUE, null)); - } - - @Test - public void test_ObjectEqualsUtils_isEqual_NotNullValues() { - assertTrue(ObjectEqualsUtils.isEqual(VALUE, VALUE)); - } - - @Test - public void test_ObjectEqualsUtils_isEqual_CollectionValues() { - final List firstObject = Arrays.asList(VALUE); - final List secondObject = Arrays.asList(VALUE); - assertTrue(ObjectEqualsUtils.isEqual(firstObject, secondObject)); - } - - @Test - public void test_ObjectEqualsUtils_isEqual_CollectionAndStringValues() { - final List firstObject = Arrays.asList(VALUE); - assertFalse(ObjectEqualsUtils.isEqual(firstObject, VALUE)); - } -} -- cgit 1.2.3-korg