diff options
Diffstat (limited to 'adapters')
9 files changed, 103 insertions, 96 deletions
diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/lcm/extclients/AbstractServiceProviderConfiguration.java b/adapters/etsi-sol003-adapter/etsi-sol003-adapter-common/src/main/java/org/onap/so/adapters/etsi/sol003/adapter/common/configuration/AbstractServiceProviderConfiguration.java index b9ce641096..6161fa60f9 100644 --- a/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/lcm/extclients/AbstractServiceProviderConfiguration.java +++ b/adapters/etsi-sol003-adapter/etsi-sol003-adapter-common/src/main/java/org/onap/so/adapters/etsi/sol003/adapter/common/configuration/AbstractServiceProviderConfiguration.java @@ -1,27 +1,25 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. + * Copyright (C) 2020 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.adapters.etsisol003adapter.lcm.extclients; +package org.onap.so.adapters.etsi.sol003.adapter.common.configuration; import java.util.Iterator; -import org.onap.so.adapters.etsisol003adapter.lcm.v1.JSON; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.http.converter.json.GsonHttpMessageConverter; import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; @@ -33,6 +31,7 @@ import com.google.gson.Gson; * that will be useful to some such classes. * * @author gareth.roper@est.tech + * @author Waqas Ikram (waqas.ikram@est.tech) */ public abstract class AbstractServiceProviderConfiguration { @@ -43,7 +42,9 @@ public abstract class AbstractServiceProviderConfiguration { iterator.remove(); } } - final Gson gson = new JSON().getGson(); - restTemplate.getMessageConverters().add(new GsonHttpMessageConverter(gson)); + restTemplate.getMessageConverters().add(new GsonHttpMessageConverter(getGson())); } + + protected abstract Gson getGson(); + } diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/lcm/extclients/vnfm/VnfmServiceProviderConfiguration.java b/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/lcm/extclients/vnfm/VnfmServiceProviderConfiguration.java index e35dafb4ea..da727b395a 100644 --- a/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/lcm/extclients/vnfm/VnfmServiceProviderConfiguration.java +++ b/adapters/etsi-sol003-adapter/etsi-sol003-lcm/etsi-sol003-lcm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/lcm/extclients/vnfm/VnfmServiceProviderConfiguration.java @@ -39,7 +39,8 @@ import org.apache.http.impl.client.HttpClients; import org.apache.http.ssl.SSLContextBuilder; import org.onap.aai.domain.yang.EsrSystemInfo; import org.onap.aai.domain.yang.EsrVnfm; -import org.onap.so.adapters.etsisol003adapter.lcm.extclients.AbstractServiceProviderConfiguration; +import org.onap.so.adapters.etsi.sol003.adapter.common.configuration.AbstractServiceProviderConfiguration; +import org.onap.so.adapters.etsisol003adapter.lcm.v1.JSON; import org.onap.so.configuration.rest.BasicHttpHeadersProvider; import org.onap.so.rest.service.HttpRestServiceProvider; import org.onap.so.rest.service.HttpRestServiceProviderImpl; @@ -55,6 +56,7 @@ import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.security.oauth2.client.OAuth2RestTemplate; import org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails; import org.springframework.web.client.RestTemplate; +import com.google.gson.Gson; /** * Configures the HttpRestServiceProvider for REST call to a VNFM. @@ -151,4 +153,9 @@ public class VnfmServiceProviderConfiguration extends AbstractServiceProviderCon } } + @Override + protected Gson getGson() { + return new JSON().getGson(); + } + } diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/extclients/AbstractServiceProviderConfiguration.java b/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/extclients/AbstractServiceProviderConfiguration.java deleted file mode 100644 index f9da6981c8..0000000000 --- a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/extclients/AbstractServiceProviderConfiguration.java +++ /dev/null @@ -1,56 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * Copyright (C) 2019 Nordix Foundation. - * ================================================================================ - * 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.adapters.etsisol003adapter.pkgm.extclients; - -import java.time.LocalDateTime; -import java.util.Iterator; -import org.onap.so.adapters.etsisol003adapter.pkgm.JSON; -import org.onap.so.adapters.etsisol003adapter.pkgm.rest.EtsiSubscriptionNotificationController; -import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.http.converter.json.GsonHttpMessageConverter; -import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; -import org.springframework.web.client.RestTemplate; -import org.threeten.bp.OffsetDateTime; -import com.google.gson.Gson; - -/** - * A base class that can be extended by classes for configuring HttpRestServiceProvider classes. Provides common methods - * that will be useful to some such classes. - * - * @author gareth.roper@est.tech - */ -public abstract class AbstractServiceProviderConfiguration { - private final JSON.OffsetDateTimeTypeAdapter offsetDateTimeTypeAdapter = new JSON.OffsetDateTimeTypeAdapter(); - - public void setGsonMessageConverter(final RestTemplate restTemplate) { - final Iterator<HttpMessageConverter<?>> iterator = restTemplate.getMessageConverters().iterator(); - while (iterator.hasNext()) { - if (iterator.next() instanceof MappingJackson2HttpMessageConverter) { - iterator.remove(); - } - } - final Gson gson = JSON.createGson().registerTypeAdapter(OffsetDateTime.class, offsetDateTimeTypeAdapter) - .registerTypeAdapter(LocalDateTime.class, - new EtsiSubscriptionNotificationController.LocalDateTimeTypeAdapter()) - .create(); - restTemplate.getMessageConverters().add(new GsonHttpMessageConverter(gson)); - } -} diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/extclients/etsicatalog/EtsiCatalogServiceProviderConfiguration.java b/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/extclients/etsicatalog/EtsiCatalogServiceProviderConfiguration.java index 5caeebe53d..1ff3672df9 100644 --- a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/extclients/etsicatalog/EtsiCatalogServiceProviderConfiguration.java +++ b/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/extclients/etsicatalog/EtsiCatalogServiceProviderConfiguration.java @@ -25,7 +25,6 @@ import java.security.KeyManagementException; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; import java.security.cert.CertificateException; -import java.util.Iterator; import java.util.concurrent.TimeUnit; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.SSLContext; @@ -40,7 +39,7 @@ import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.apache.http.ssl.SSLContextBuilder; import org.onap.logging.filter.spring.SpringClientPayloadFilter; -import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.AbstractServiceProviderConfiguration; +import org.onap.so.adapters.etsi.sol003.adapter.common.configuration.AbstractServiceProviderConfiguration; import org.onap.so.configuration.rest.BasicHttpHeadersProvider; import org.onap.so.configuration.rest.HttpClientConnectionConfiguration; import org.onap.so.logging.jaxrs.filter.SOSpringClientFilter; @@ -56,12 +55,8 @@ import org.springframework.context.annotation.Configuration; import org.springframework.core.io.Resource; import org.springframework.http.client.BufferingClientHttpRequestFactory; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; -import org.springframework.http.converter.HttpMessageConverter; -import org.springframework.http.converter.json.GsonHttpMessageConverter; -import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.web.client.RestTemplate; import com.google.gson.Gson; -import com.google.gson.GsonBuilder; /** * Configures the HttpRestServiceProvider to make REST calls to the ETSI Catalog Manager @@ -173,15 +168,9 @@ public class EtsiCatalogServiceProviderConfiguration extends AbstractServiceProv } - public void setGsonMessageConverter(final RestTemplate restTemplate) { - final Iterator<HttpMessageConverter<?>> iterator = restTemplate.getMessageConverters().iterator(); - while (iterator.hasNext()) { - if (iterator.next() instanceof MappingJackson2HttpMessageConverter) { - iterator.remove(); - } - } - final Gson gson = new GsonBuilder().create(); - restTemplate.getMessageConverters().add(new GsonHttpMessageConverter(gson)); + @Override + protected Gson getGson() { + return new JSON().getGson(); } } diff --git a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/extclients/vnfm/VnfmHttpServiceProviderConfiguration.java b/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/extclients/vnfm/VnfmHttpServiceProviderConfiguration.java index 568c3df48b..22bbef9c01 100644 --- a/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/extclients/vnfm/VnfmHttpServiceProviderConfiguration.java +++ b/adapters/etsi-sol003-adapter/etsi-sol003-pkgm/etsi-sol003-pkgm-adapter/src/main/java/org/onap/so/adapters/etsisol003adapter/pkgm/extclients/vnfm/VnfmHttpServiceProviderConfiguration.java @@ -20,7 +20,11 @@ package org.onap.so.adapters.etsisol003adapter.pkgm.extclients.vnfm; import static org.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE; -import org.onap.so.adapters.etsisol003adapter.pkgm.extclients.AbstractServiceProviderConfiguration; +import java.time.LocalDateTime; +import java.time.OffsetDateTime; +import org.onap.so.adapters.etsi.sol003.adapter.common.configuration.AbstractServiceProviderConfiguration; +import org.onap.so.adapters.etsisol003adapter.pkgm.JSON; +import org.onap.so.adapters.etsisol003adapter.pkgm.rest.EtsiSubscriptionNotificationController; import org.onap.so.configuration.rest.BasicHttpHeadersProvider; import org.onap.so.rest.service.HttpRestServiceProvider; import org.onap.so.rest.service.HttpRestServiceProviderImpl; @@ -29,6 +33,7 @@ import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.client.RestTemplate; +import com.google.gson.Gson; /** * @author Waqas Ikram (waqas.ikram@est.tech) @@ -36,6 +41,8 @@ import org.springframework.web.client.RestTemplate; */ @Configuration public class VnfmHttpServiceProviderConfiguration extends AbstractServiceProviderConfiguration { + private final JSON.OffsetDateTimeTypeAdapter offsetDateTimeTypeAdapter = new JSON.OffsetDateTimeTypeAdapter(); + public static final String VNFM_ADAPTER_HTTP_SERVICE_PROVIDER_BEAN = "vnfmAdapterHttpServiceProvider"; @Bean @@ -46,4 +53,12 @@ public class VnfmHttpServiceProviderConfiguration extends AbstractServiceProvide return new HttpRestServiceProviderImpl(restTemplate, new BasicHttpHeadersProvider().getHttpHeaders()); } + @Override + protected Gson getGson() { + return JSON.createGson().registerTypeAdapter(OffsetDateTime.class, offsetDateTimeTypeAdapter) + .registerTypeAdapter(LocalDateTime.class, + new EtsiSubscriptionNotificationController.LocalDateTimeTypeAdapter()) + .create(); + } + } diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/audit/AbstractAuditService.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/audit/AbstractAuditService.java index 2f7155bffc..8cdd37d43f 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/audit/AbstractAuditService.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/audit/AbstractAuditService.java @@ -21,7 +21,6 @@ package org.onap.so.adapters.tasks.audit; -import java.util.Optional; import org.onap.so.objects.audit.AAIObjectAudit; import org.onap.so.objects.audit.AAIObjectAuditList; import org.onap.so.utils.ExternalTaskUtils; @@ -37,8 +36,6 @@ public abstract class AbstractAuditService extends ExternalTaskUtils { private static final Logger logger = LoggerFactory.getLogger(AbstractAuditService.class); - - protected static final String UNABLE_TO_FIND_ALL_V_SERVERS_AND_L_INTERACES_IN_A_AI = "Unable to find all VServers and L-Interaces in A&AI"; @@ -52,29 +49,27 @@ public abstract class AbstractAuditService extends ExternalTaskUtils { } /** - * @param auditHeatStackFailed * @param auditList * @return */ - protected boolean didCreateAuditFail(Optional<AAIObjectAuditList> auditList) { - if (auditList.get().getAuditList() != null && !auditList.get().getAuditList().isEmpty()) { + protected boolean didCreateAuditFail(AAIObjectAuditList auditList) { + if (isAuditListNotNullAndNotEmpty(auditList)) { if (logger.isInfoEnabled()) { - logger.info("Audit Results: {}", auditList.get().toString()); + logger.info("Audit Results: {}", auditList.toString()); } - return auditList.get().getAuditList().stream().filter(auditObject -> !auditObject.isDoesObjectExist()) - .findFirst().map(v -> true).orElse(false); + return auditList.getAuditList().stream().filter(auditObject -> !auditObject.isDoesObjectExist()).findFirst() + .map(v -> true).orElse(false); } else { return false; } } /** - * @param auditHeatStackFailed * @param auditList * @return */ protected boolean didDeleteAuditFail(AAIObjectAuditList auditList) { - if (auditList.getAuditList() != null && !auditList.getAuditList().isEmpty()) { + if (isAuditListNotNullAndNotEmpty(auditList)) { if (logger.isInfoEnabled()) { logger.info("Audit Results: {}", auditList.toString()); } @@ -84,4 +79,9 @@ public abstract class AbstractAuditService extends ExternalTaskUtils { return false; } } + + private boolean isAuditListNotNullAndNotEmpty(AAIObjectAuditList auditList) { + return auditList != null && auditList.getAuditList() != null && !auditList.getAuditList().isEmpty(); + } + } diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/audit/AuditCreateStackService.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/audit/AuditCreateStackService.java index 010475c87a..c06460c386 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/audit/AuditCreateStackService.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/tasks/audit/AuditCreateStackService.java @@ -67,7 +67,7 @@ public class AuditCreateStackService extends AbstractAuditService { auditListOpt.get().setHeatStackName(auditInventory.getHeatStackName()); GraphInventoryCommonObjectMapperProvider objectMapper = new GraphInventoryCommonObjectMapperProvider(); variables.put("auditInventoryResult", objectMapper.getMapper().writeValueAsString(auditListOpt.get())); - success = !didCreateAuditFail(auditListOpt); + success = !didCreateAuditFail(auditListOpt.get()); } } catch (Exception e) { logger.error("Error during audit of stack", e); diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/audit/AbstractAuditServiceTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/audit/AbstractAuditServiceTest.java new file mode 100644 index 0000000000..c70e60e9d3 --- /dev/null +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/audit/AbstractAuditServiceTest.java @@ -0,0 +1,51 @@ +package org.onap.so.adapters.tasks.audit; + +import org.junit.Test; +import org.onap.so.objects.audit.AAIObjectAudit; +import org.onap.so.objects.audit.AAIObjectAuditList; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class AbstractAuditServiceTest extends AbstractAuditService { + + private AAIObjectAuditList getAuditListWithObjectWithExistenceStateOf(boolean existenceState) { + AAIObjectAudit auditObject = new AAIObjectAudit(); + AAIObjectAuditList auditList = new AAIObjectAuditList(); + + auditObject.setDoesObjectExist(existenceState); + auditList.getAuditList().add(auditObject); + + return auditList; + } + + @Test + public void didCreateAuditFail_shouldReturnFalse_whenGivenNull() { + assertFalse(didCreateAuditFail(null)); + } + + @Test + public void didCreateAuditFail_shouldReturnTrue_whenGivenNotExistingObject() { + assertTrue(didCreateAuditFail(getAuditListWithObjectWithExistenceStateOf(false))); + } + + @Test + public void didCreateAuditFail_shouldReturnFalse_whenGivenExistingObject() { + assertFalse(didCreateAuditFail(getAuditListWithObjectWithExistenceStateOf(true))); + } + + @Test + public void didDeleteAuditFail_shouldReturnFalse_whenGivenNull() { + assertFalse(didDeleteAuditFail(null)); + } + + @Test + public void didDeleteAuditFail_shouldReturnTrue_whenGivenExistingObject() { + assertTrue(didDeleteAuditFail(getAuditListWithObjectWithExistenceStateOf(true))); + } + + @Test + public void didDeleteAuditFail_shouldReturnFalse_whenGivenNotExistingObject() { + assertFalse(didDeleteAuditFail(getAuditListWithObjectWithExistenceStateOf(false))); + } + +} diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/audit/AuditStackServiceDataTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/audit/AuditStackServiceDataTest.java index a10ab4b7df..78dbcd94c2 100644 --- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/audit/AuditStackServiceDataTest.java +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/tasks/audit/AuditStackServiceDataTest.java @@ -179,13 +179,13 @@ public class AuditStackServiceDataTest extends AuditCreateStackService { @Test public void determineAuditResult_Test() throws Exception { - boolean actual = auditStackService.didCreateAuditFail(auditListOptSuccess); + boolean actual = auditStackService.didCreateAuditFail(auditListOptSuccess.get()); assertEquals(false, actual); } @Test public void determineAuditResult_Failure_Test() throws Exception { - boolean actual = auditStackService.didCreateAuditFail(auditListOptFailure); + boolean actual = auditStackService.didCreateAuditFail(auditListOptFailure.get()); assertEquals(true, actual); } } |