diff options
Diffstat (limited to 'adapters/mso-requests-db-adapter/src')
7 files changed, 248 insertions, 13 deletions
diff --git a/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/application/MSORequestDBApplication.java b/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/application/MSORequestDBApplication.java index 21582a1e5f..700a371375 100644 --- a/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/application/MSORequestDBApplication.java +++ b/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/application/MSORequestDBApplication.java @@ -4,6 +4,8 @@ * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright (C) 2018 IBM. + * ================================================================================ * 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 @@ -67,4 +69,6 @@ public class MSORequestDBApplication { .withDefaultLockAtMostFor(Duration.ofMinutes(10)) .build(); } + + } diff --git a/adapters/mso-requests-db-adapter/src/main/resources/application-local.yaml b/adapters/mso-requests-db-adapter/src/main/resources/application-local.yaml index 414c552619..41b72ba08f 100644 --- a/adapters/mso-requests-db-adapter/src/main/resources/application-local.yaml +++ b/adapters/mso-requests-db-adapter/src/main/resources/application-local.yaml @@ -12,10 +12,9 @@ mso: endpoint: http://localhost:8081 logPath: logs site-name: localSite - adapters: - requestDb: - auth: Basic YnBlbDptc28tZGItMTUwNyE= - endpoint: http://localhost:8081 + infra-requests: + archived: + period: 180 spring: datasource: url: jdbc:mariadb://localhost:3306/requestdb @@ -50,6 +49,6 @@ management: flyway: baseline-on-migrate: false url: jdbc:mariadb://localhost:3306/requestdb - user: mso - password: mso123 + user: catalog + password: catalog123
\ No newline at end of file diff --git a/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/ArchiveInfraRequestsSchedulerTest.java b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/ArchiveInfraRequestsSchedulerTest.java index 54debac36f..f05a301caa 100644 --- a/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/ArchiveInfraRequestsSchedulerTest.java +++ b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/ArchiveInfraRequestsSchedulerTest.java @@ -28,6 +28,7 @@ import java.util.Calendar; import java.util.Date; import java.util.List; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.onap.so.adapters.requestsdb.application.MSORequestDBApplication; @@ -61,6 +62,7 @@ public class ArchiveInfraRequestsSchedulerTest { private int archivedPeriod; @Test + @Transactional public void testArchiveInfraRequests() { String requestId1 = "requestId1"; String requestId2 = "requestId2"; @@ -85,7 +87,8 @@ public class ArchiveInfraRequestsSchedulerTest { assertEquals(requestId2, archivedRepo.findOne(requestId2).getRequestId()); } - @Test + @Test + @Ignore public void testInfraRequestsScheduledTask() { Date currentDate= new Date(); Calendar calendar = Calendar.getInstance(); diff --git a/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/adapters/MSORequestDBImplTest.java b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/adapters/MSORequestDBImplTest.java index 03fd0622fa..571a2c053f 100644 --- a/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/adapters/MSORequestDBImplTest.java +++ b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/adapters/MSORequestDBImplTest.java @@ -87,7 +87,7 @@ public class MSORequestDBImplTest { jaxWsProxyFactory.setServiceClass(MsoRequestsDbAdapter.class); jaxWsProxyFactory.setAddress("http://localhost:" + port + "/services/RequestsDbAdapter"); jaxWsProxyFactory.setUsername("bpel"); - jaxWsProxyFactory.setPassword("password1$"); + jaxWsProxyFactory.setPassword("mso-db-1507!"); dbAdapter = (MsoRequestsDbAdapter) jaxWsProxyFactory.create(); } diff --git a/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/client/RequestDbClientPortChanger.java b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/client/RequestDbClientPortChanger.java new file mode 100644 index 0000000000..bd15396c03 --- /dev/null +++ b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/client/RequestDbClientPortChanger.java @@ -0,0 +1,41 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.adapters.requestsdb.client; + + +import org.onap.so.db.request.client.RequestsDbClient; +import org.springframework.stereotype.Component; +import java.net.URI; +@Component +public class RequestDbClientPortChanger extends RequestsDbClient { + private int port; + + public void setPort(int port) { + this.port = port; + } + + @Override + public URI getUri(String uri) { + uri = uri.replace("8081", String.valueOf(port)); + return URI.create(uri); + } +} + diff --git a/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/client/RequestsDbClientTest.java b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/client/RequestsDbClientTest.java new file mode 100644 index 0000000000..f1269f412b --- /dev/null +++ b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/client/RequestsDbClientTest.java @@ -0,0 +1,192 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.adapters.requestsdb.client; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.so.adapters.requestsdb.application.MSORequestDBApplication; +import org.onap.so.db.request.beans.InfraActiveRequests; +import org.onap.so.db.request.beans.OperationStatus; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.embedded.LocalServerPort; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; +import java.util.List; +import java.util.UUID; +import java.util.Map; +import java.util.HashMap; +import java.util.ArrayList; + +import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThat; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = MSORequestDBApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@ActiveProfiles("test") +public class RequestsDbClientTest { + + @Autowired + private RequestDbClientPortChanger requestsDbClient; + + private InfraActiveRequests infraActiveRequests; + + @LocalServerPort + private int port; + + @Before + public void setup() { + requestsDbClient.setPort(port); + + infraActiveRequests = new InfraActiveRequests(); + infraActiveRequests.setRequestId(UUID.randomUUID().toString()); + infraActiveRequests.setOperationalEnvId(UUID.randomUUID().toString()); + infraActiveRequests.setServiceInstanceId(UUID.randomUUID().toString()); + infraActiveRequests.setServiceInstanceName("serviceInstanceNameTest"); + infraActiveRequests.setVnfId(UUID.randomUUID().toString()); + infraActiveRequests.setVnfName("vnfInstanceNameTest"); + infraActiveRequests.setVfModuleId(UUID.randomUUID().toString()); + infraActiveRequests.setVfModuleName("vfModuleInstanceNameTest"); + infraActiveRequests.setVolumeGroupId(UUID.randomUUID().toString()); + infraActiveRequests.setVolumeGroupName("volumeGroupInstanceNameTest"); + infraActiveRequests.setNetworkId(UUID.randomUUID().toString()); + infraActiveRequests.setNetworkName("networkInstanceNameTest"); + infraActiveRequests.setConfigurationId(UUID.randomUUID().toString()); + infraActiveRequests.setConfigurationName("configurationInstanceNameTest"); + infraActiveRequests.setAicCloudRegion("1"); + infraActiveRequests.setTenantId(UUID.randomUUID().toString()); + infraActiveRequests.setRequestScope("operationalEnvironment"); + infraActiveRequests.setRequestorId(UUID.randomUUID().toString()); + infraActiveRequests.setSource("sourceTest"); + infraActiveRequests.setOperationalEnvName(UUID.randomUUID().toString()); + infraActiveRequests.setRequestStatus("IN_PROGRESS"); + infraActiveRequests.setAction("create"); + infraActiveRequests.setRequestAction("someaction"); + requestsDbClient.save(infraActiveRequests); + } + + private void verifyOperationStatus(OperationStatus request,OperationStatus response){ + assertThat(request, sameBeanAs(response).ignoring("operateAt").ignoring("finishedAt")); + } + + private void verifyInfraActiveRequests(InfraActiveRequests infraActiveRequestsResponse) { + assertThat(infraActiveRequestsResponse, sameBeanAs(infraActiveRequests).ignoring("modifyTime").ignoring("log")); + } + + @Test + public void getCloudOrchestrationFiltersFromInfraActiveTest() { + Map<String, String> requestMap = new HashMap<>(); + requestMap.put("operationalEnvironmentId", infraActiveRequests.getOperationalEnvId()); + requestMap.put("operationalEnvironmentName", infraActiveRequests.getOperationalEnvName()); + requestMap.put("resourceType", "operationalEnvironment"); + + List<InfraActiveRequests> iarr = requestsDbClient.getCloudOrchestrationFiltersFromInfraActive(requestMap); + + assertEquals(1, iarr.size()); + InfraActiveRequests infraActiveRequestsResponse = iarr.get(0); + verifyInfraActiveRequests(infraActiveRequestsResponse); + } + + + @Test + public void checkVnfIdStatusTest() { + InfraActiveRequests infraActiveRequestsResponse = requestsDbClient.checkVnfIdStatus(infraActiveRequests.getOperationalEnvId()); + verifyInfraActiveRequests(infraActiveRequestsResponse); + assertNull(requestsDbClient.checkVnfIdStatus(UUID.randomUUID().toString())); + } + + @Test + public void checkInstanceNameDuplicateTest() { + InfraActiveRequests infraActiveRequestsResponse = requestsDbClient.checkInstanceNameDuplicate(null,infraActiveRequests.getOperationalEnvName(),infraActiveRequests.getRequestScope()); + + verifyInfraActiveRequests(infraActiveRequestsResponse); + } + + @Test + public void checkInstanceNameDuplicateViaTest() { + Map<String, String> requestMap = new HashMap<>(); + requestMap.put("operationalEnvironmentId", infraActiveRequests.getOperationalEnvId()); + + InfraActiveRequests infraActiveRequestsResponse = requestsDbClient.checkInstanceNameDuplicate((HashMap<String, String>)requestMap,null,infraActiveRequests.getRequestScope()); + + verifyInfraActiveRequests(infraActiveRequestsResponse); + } + + @Test + public void getOrchestrationFiltersFromInfraActiveTest() { + Map<String, List<String>> requestMap = new HashMap<>(); + List<String> values = new ArrayList<>(); + values.add("EQUALS"); + values.add(infraActiveRequests.getServiceInstanceId()); + requestMap.put("serviceInstanceId", values); + + values = new ArrayList<>(); + values.add("EQUALS"); + values.add(infraActiveRequests.getServiceInstanceName()); + requestMap.put("serviceInstanceName", values); + + List<InfraActiveRequests> iaar = requestsDbClient.getOrchestrationFiltersFromInfraActive(requestMap); + + assertEquals(1, iaar.size()); + InfraActiveRequests infraActiveRequestsResponse = iaar.get(0); + + verifyInfraActiveRequests(infraActiveRequestsResponse); + values = new ArrayList<>(); + values.add("EQUALS"); + values.add(UUID.randomUUID().toString()); + requestMap.put("serviceInstanceName", values); + requestsDbClient.getOrchestrationFiltersFromInfraActive(requestMap); + } + + @Test + public void getInfraActiveRequestbyRequestIdTest(){ + InfraActiveRequests infraActiveRequestsResponse = requestsDbClient.getInfraActiveRequestbyRequestId(infraActiveRequests.getRequestId()); + verifyInfraActiveRequests(infraActiveRequestsResponse); + infraActiveRequestsResponse = requestsDbClient.getInfraActiveRequestbyRequestId(infraActiveRequests.getRequestId()); + + assertNull(requestsDbClient.getInfraActiveRequestbyRequestId(UUID.randomUUID().toString())); + } + + + @Test + public void getOneByServiceIdAndOperationIdTest(){ + OperationStatus operationStatus = new OperationStatus(); + operationStatus.setProgress("IN_PROGRESS"); + operationStatus.setResult("FAILED"); + operationStatus.setServiceId(UUID.randomUUID().toString()); + operationStatus.setOperationContent("operation-content"); + operationStatus.setOperation("operation"); + operationStatus.setOperationId(UUID.randomUUID().toString()); + operationStatus.setReason("reason-test"); + operationStatus.setUserId(UUID.randomUUID().toString()); + operationStatus.setServiceName("test-service"); + requestsDbClient.save(operationStatus); + + OperationStatus operationStatusResponse = requestsDbClient.getOneByServiceIdAndOperationId(operationStatus.getServiceId(),operationStatus.getOperationId()); + + verifyOperationStatus(operationStatus,operationStatusResponse); + + assertNull(requestsDbClient.getOneByServiceIdAndOperationId(UUID.randomUUID().toString(),operationStatus.getOperationId())); + } +} diff --git a/adapters/mso-requests-db-adapter/src/test/resources/application-test.yaml b/adapters/mso-requests-db-adapter/src/test/resources/application-test.yaml index 812fd232b4..35b3ec9360 100644 --- a/adapters/mso-requests-db-adapter/src/test/resources/application-test.yaml +++ b/adapters/mso-requests-db-adapter/src/test/resources/application-test.yaml @@ -10,7 +10,7 @@ ssl-enable: false mso: adapters: requestDb: - auth: Basic YnBlbDpwYXNzd29yZDEk + auth: Basic YnBlbDptc28tZGItMTUwNyE= endpoint: http://localhost:8081 logPath: logs site-name: localSite @@ -35,10 +35,6 @@ spring: database-platform: org.hibernate.dialect.MySQL5InnoDBDialect security: usercredentials: - - - username: bpel - password: '$2a$10$Fh9ffgPw2vnmsghsRD3ZauBL1aKXebigbq3BB1RPWtE62UDILsjke' - role: BPEL-Client - username: bpel password: '$2a$12$1xyutEZNfjGewIZRfKaE8eZE99f5sYFUmmM80BobI65KNjmcK0JuO' |