aboutsummaryrefslogtreecommitdiffstats
path: root/adapters/mso-requests-db-adapter/src/test/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'adapters/mso-requests-db-adapter/src/test/java/org')
-rw-r--r--adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/ArchiveInfraRequestsSchedulerTest.java106
-rw-r--r--adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/adapters/HealthCheckHandlerTest.java73
-rw-r--r--adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/adapters/MSORequestDBImplTest.java460
-rw-r--r--adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/application/EmbeddedMariaDbConfig.java102
-rw-r--r--adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/exceptions/MsoRequestsDbExceptionBeanTest.java (renamed from adapters/mso-requests-db-adapter/src/test/java/org/openecomp/mso/adapters/requestsdb/exceptions/MsoRequestsDbExceptionBeanTest.java)2
-rw-r--r--adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/exceptions/MsoRequestsDbExceptionTest.java (renamed from adapters/mso-requests-db-adapter/src/test/java/org/openecomp/mso/adapters/requestsdb/exceptions/MsoRequestsDbExceptionTest.java)4
-rw-r--r--adapters/mso-requests-db-adapter/src/test/java/org/openecomp/mso/adapters/requestsdb/HealthCheckHandlerTest.java67
-rw-r--r--adapters/mso-requests-db-adapter/src/test/java/org/openecomp/mso/adapters/requestsdb/MsoRequestsDbAdapterImplTest.java74
8 files changed, 744 insertions, 144 deletions
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
new file mode 100644
index 0000000000..54debac36f
--- /dev/null
+++ b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/ArchiveInfraRequestsSchedulerTest.java
@@ -0,0 +1,106 @@
+/*-
+ * ============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;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+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.data.repository.ArchivedInfraRequestsRepository;
+import org.onap.so.db.request.data.repository.InfraActiveRequestsRepository;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.data.domain.PageRequest;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.transaction.annotation.Transactional;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = MSORequestDBApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+@ActiveProfiles("test")
+@Transactional
+public class ArchiveInfraRequestsSchedulerTest {
+
+ @Autowired
+ private ArchiveInfraRequestsScheduler scheduler;
+
+ @Autowired
+ private InfraActiveRequestsRepository iarRepo;
+
+ @Autowired
+ private ArchivedInfraRequestsRepository archivedRepo;
+
+ @Value("${mso.infra-requests.archived.period}")
+ private int archivedPeriod;
+
+ @Test
+ public void testArchiveInfraRequests() {
+ String requestId1 = "requestId1";
+ String requestId2 = "requestId2";
+
+ InfraActiveRequests iar1 = new InfraActiveRequests();
+ iar1.setRequestId(requestId1);
+ iar1.setAction("action1");
+
+ InfraActiveRequests iar2 = new InfraActiveRequests();
+ iar2.setRequestId(requestId2);
+ iar2.setAction("action2");
+
+ List<InfraActiveRequests> requests = new ArrayList<>();
+ requests.add(iar1);
+ requests.add(iar2);
+ iarRepo.save(requests);
+
+ scheduler.archiveInfraRequests(requests);
+
+ assertEquals(2, archivedRepo.count());
+ assertEquals(requestId1, archivedRepo.findOne(requestId1).getRequestId());
+ assertEquals(requestId2, archivedRepo.findOne(requestId2).getRequestId());
+ }
+
+ @Test
+ public void testInfraRequestsScheduledTask() {
+ Date currentDate= new Date();
+ Calendar calendar = Calendar.getInstance();
+ calendar.setTime(currentDate);
+ calendar.add(Calendar.DATE, -archivedPeriod);
+ Date archivingDate = calendar.getTime();
+
+ List<InfraActiveRequests> requests = iarRepo.findByEndTimeLessThan(archivingDate, new PageRequest(0, 100));
+ List<InfraActiveRequests> requests2 = iarRepo.findByStartTimeLessThanAndEndTime(archivingDate, null, new PageRequest(0, 100));
+
+ int total = requests.size() + requests2.size();
+
+ scheduler.infraRequestsScheduledTask();
+
+ assertTrue(archivedRepo.count() >= total);
+ assertTrue(iarRepo.count() < total);
+ }
+}
diff --git a/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/adapters/HealthCheckHandlerTest.java b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/adapters/HealthCheckHandlerTest.java
new file mode 100644
index 0000000000..005eba0ec2
--- /dev/null
+++ b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/adapters/HealthCheckHandlerTest.java
@@ -0,0 +1,73 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 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.adapters;
+
+import static org.junit.Assert.*;
+
+
+
+import javax.ws.rs.core.Response;
+
+import org.json.JSONException;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.onap.so.adapters.requestsdb.application.MSORequestDBApplication;
+
+import org.springframework.boot.context.embedded.LocalServerPort;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.boot.test.web.client.TestRestTemplate;
+import org.springframework.http.HttpEntity;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.ResponseEntity;
+import org.springframework.test.context.ActiveProfiles;
+import org.springframework.test.context.junit4.SpringRunner;
+
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = MSORequestDBApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+@ActiveProfiles("test")
+public class HealthCheckHandlerTest {
+
+ @LocalServerPort
+ private int port;
+
+ TestRestTemplate restTemplate = new TestRestTemplate();
+
+ HttpHeaders headers = new HttpHeaders();
+
+
+ @Test
+ public void testHealthcheck() throws JSONException {
+
+ HttpEntity<String> entity = new HttpEntity<String>(null, headers);
+
+ ResponseEntity<String> response = restTemplate.exchange(
+ createURLWithPort("/manage/health"),
+ HttpMethod.GET, entity, String.class);
+
+ assertEquals(Response.Status.OK.getStatusCode(),response.getStatusCode().value());
+ }
+
+ private String createURLWithPort(String uri) {
+ return "http://localhost:" + port + uri;
+ }
+}
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
new file mode 100644
index 0000000000..4d00421e6c
--- /dev/null
+++ b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/adapters/MSORequestDBImplTest.java
@@ -0,0 +1,460 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP - SO
+ * ================================================================================
+ * Copyright (C) 2017 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.adapters;
+
+import static com.shazam.shazamcrest.MatcherAssert.assertThat;
+import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.onap.so.adapters.requestsdb.MsoRequestsDbAdapter;
+import org.onap.so.adapters.requestsdb.RequestStatusType;
+import org.onap.so.adapters.requestsdb.application.MSORequestDBApplication;
+import org.onap.so.adapters.requestsdb.exceptions.MsoRequestsDbException;
+import org.onap.so.db.request.beans.InfraActiveRequests;
+import org.onap.so.db.request.beans.OperationStatus;
+import org.onap.so.db.request.beans.ResourceOperationStatus;
+import org.onap.so.db.request.data.repository.OperationStatusRepository;
+import org.onap.so.db.request.data.repository.ResourceOperationStatusRepository;
+import org.onap.so.requestsdb.RequestsDbConstant;
+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;
+
+@RunWith(SpringRunner.class)
+@SpringBootTest(classes = MSORequestDBApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
+@ActiveProfiles("test")
+public class MSORequestDBImplTest {
+
+ @LocalServerPort
+ private int port;
+
+ @Autowired
+ private MsoRequestsDbAdapter dbAdapter;
+
+ @Autowired
+ private OperationStatusRepository operationStatusRepository;
+
+ @Autowired
+ private ResourceOperationStatusRepository resourceOperationStatusRepo;
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ public InfraActiveRequests setupTestEntities() {
+ return buildTestRequest();
+ }
+
+ private InfraActiveRequests buildTestRequest() {
+ InfraActiveRequests testRequest= new InfraActiveRequests();
+ testRequest.setRequestId("00032ab7-3fb3-42e5-965d-8ea592502017");
+ testRequest.setClientRequestId("00032ab7-3fb3-42e5-965d-8ea592502016");
+ testRequest.setRequestStatus("COMPLETE");
+ testRequest.setStatusMessage("Vf Module has been deleted successfully.");
+ testRequest.setProgress((long) 100);
+ testRequest.setSource("VID");
+ testRequest.setTenantId("6accefef3cb442ff9e644d589fb04107");
+ testRequest.setServiceInstanceId("e3b5744d-2ad1-4cdd-8390-c999a38829bc");
+ testRequest.setRequestAction("deleteInstance");
+ testRequest.setRequestScope("vfModule");
+ testRequest.setAction("deleteInstance");
+ testRequest.setAicCloudRegion("mtn6");
+ testRequest.setLastModifiedBy("BPMN");
+ testRequest.setVfModuleId("c7d527b1-7a91-49fd-b97d-1c8c0f4a7992");
+ testRequest.setVfModuleModelName("vSAMP10aDEV::base::module-0");
+ testRequest.setVnfId("b92f60c8-8de3-46c1-8dc1-e4390ac2b005");
+
+ return testRequest;
+ }
+
+
+
+
+ @Test
+ public void getByRequestId() throws MsoRequestsDbException {
+ InfraActiveRequests testRequest = setupTestEntities();
+ // Given
+ String requestId = "00032ab7-3fb3-42e5-965d-8ea592502017";
+
+ // When
+ InfraActiveRequests infraRequest = dbAdapter.getInfraRequest(requestId);
+ if(infraRequest ==null)
+ fail("Null infraRequest");
+
+ // Then
+ assertThat(infraRequest, sameBeanAs(testRequest).ignoring("requestBody").ignoring("endTime").ignoring("startTime").ignoring("modifyTime"));
+ }
+
+
+ @Test
+ public void getByInvalidRequestId() throws MsoRequestsDbException {
+ // Given
+ String requestId = "invalidRequestId";
+
+ try {
+ dbAdapter.getInfraRequest(requestId);
+ fail("Expected MsoRequestsDbException to be thrown");
+ } catch (MsoRequestsDbException e) {
+ assertEquals(e.getMessage(),"Error retrieving MSO Infra Requests DB for Request ID invalidRequestId");
+ } catch (Exception e) {
+ fail("Expected MsoRequestsDbException to be thrown, unknown exception thrown");
+ }
+ }
+
+ @Test
+ public void getByClientRequestId() throws MsoRequestsDbException {
+ InfraActiveRequests testRequest = setupTestEntities();
+ // Given
+ String clientRequestId = "00032ab7-3fb3-42e5-965d-8ea592502016";
+
+ // When
+ InfraActiveRequests infraRequest = dbAdapter.getInfraRequest(clientRequestId);
+ if(infraRequest ==null)
+ fail("Null infraRequest");
+
+ // Then
+ assertThat(infraRequest, sameBeanAs(testRequest).ignoring("requestBody").ignoring("endTime").ignoring("startTime").ignoring("modifyTime"));
+ }
+
+
+ @Test
+ public void updateInfraRequest() throws MsoRequestsDbException {
+ InfraActiveRequests testRequest = setupTestEntities();
+ // Given
+ String clientRequestId = "00032ab7-3fb3-42e5-965d-8ea592502016";
+
+
+ // When
+ String lastModifiedBy = "UNIT TEST";
+ String statusMessage = "TESTING THE UDPATES";
+ String progress = "50";
+ String vnfOutputs = "VNF OUTPUTS";
+ String networkId = "New NetworkID";
+ String vnfId = "NEWVNFID";
+ String volumeGroupId = "NewVolumeGroupId";
+ String serviceInstanceName = "NewServiceInstanceName";
+ String configurationId = "NewConfigurationId";
+ String configurationName = "NewConfigurationName";
+ String vfModuleName = "VFModuleName";
+ RequestStatusType requestStatus = RequestStatusType.COMPLETE ;
+ String responseBody = "NewResponseBody";
+ String vfModuleId = "NEW VF MODULEID";
+ String serviceInstanceId = " new serv ind";
+
+
+ testRequest.setVolumeGroupId(volumeGroupId);
+ testRequest.setServiceInstanceName(serviceInstanceName);
+ testRequest.setConfigurationId(configurationId);
+ testRequest.setConfigurationName(configurationName);
+ testRequest.setNetworkId(networkId);
+ testRequest.setResponseBody(responseBody);
+ testRequest.setStatusMessage(statusMessage);
+ testRequest.setProgress((long) 50);
+ testRequest.setServiceInstanceId(lastModifiedBy);
+ testRequest.setLastModifiedBy(lastModifiedBy);
+ testRequest.setVfModuleId(vfModuleId);
+ testRequest.setVfModuleName(vfModuleName);
+ testRequest.setVnfId(vnfId);
+ testRequest.setServiceInstanceId(serviceInstanceId);
+ testRequest.setVfModuleName(vfModuleName);
+ testRequest.setVnfOutputs(vnfOutputs);
+
+
+ dbAdapter.updateInfraRequest ( testRequest.getRequestId(),
+ lastModifiedBy,
+ statusMessage,
+ responseBody,
+ requestStatus,
+ progress,
+ vnfOutputs,
+ serviceInstanceId,
+ networkId,
+ vnfId,
+ vfModuleId,
+ volumeGroupId,
+ serviceInstanceName,
+ configurationId,
+ configurationName,
+ vfModuleName);
+ InfraActiveRequests infraRequest = dbAdapter.getInfraRequest(clientRequestId);
+ // Then
+ assertThat(infraRequest, sameBeanAs(testRequest).ignoring("requestBody").ignoring("endTime").ignoring("startTime").ignoring("modifyTime"));
+ }
+
+ @Test
+ public void UpdateByInvalidRequestId() throws MsoRequestsDbException {
+ // Given
+ String requestId = "invalidRequestId";
+
+ try {
+ dbAdapter.updateInfraRequest ( requestId,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null);
+ fail("Expected MsoRequestsDbException to be thrown");
+ } catch (MsoRequestsDbException e) {
+ assertEquals(e.getMessage(),"Error retrieving MSO Infra Requests DB for Request ID invalidRequestId");
+ } catch (Exception e) {
+ fail("Expected MsoRequestsDbException to be thrown, unknown exception thrown");
+ }
+ }
+
+
+ @Test
+ public void updateInfraRequestNulls() throws MsoRequestsDbException {
+ InfraActiveRequests testRequest = setupTestEntities();
+ // Given
+ String clientRequestId = "00032ab7-3fb3-42e5-965d-8ea592502016";
+
+ // When
+ dbAdapter.updateInfraRequest ( testRequest.getRequestId(),
+ testRequest.getLastModifiedBy(),
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null,
+ null);
+ InfraActiveRequests infraRequest = dbAdapter.getInfraRequest(clientRequestId);
+ // Then
+ assertThat(infraRequest, sameBeanAs(testRequest).ignoring("requestBody").ignoring("endTime").ignoring("startTime").ignoring("modifyTime"));
+ }
+
+ @Test
+ public void getSiteStatusNotDisabled() throws MsoRequestsDbException {
+ setupTestEntities();
+ // Given
+ String siteName = "siteName";
+
+ // When
+ boolean siteDisabled = dbAdapter.getSiteStatus(siteName);
+
+ // Then
+ assertEquals(siteDisabled, true);
+ }
+
+ @Test
+ public void getSiteStatusDisabled() throws MsoRequestsDbException {
+ setupTestEntities();
+ // Given
+ String siteName = "testSite";
+
+ // When
+ boolean siteDisabled = dbAdapter.getSiteStatus(siteName);
+
+ // Then
+ assertEquals(siteDisabled, false);
+ }
+
+ @Test
+ public void updateServiceOperation() throws MsoRequestsDbException{
+ String serviceId = "serviceid";
+ String operationId = "operationid";
+ String serviceName = "servicename";
+ String operation = "newOperationType";
+ String userId = "NewUserId";
+ String result = "NewResult";
+ String operationContent = "newOperationContent";
+ String progress = "Newprogress";
+ String reason = "NewReason";
+
+ OperationStatus updatedOperationStatus = new OperationStatus();
+
+
+
+ updatedOperationStatus.setServiceId(serviceId);
+ updatedOperationStatus.setServiceName(serviceName);
+ updatedOperationStatus.setOperationId(operationId);
+ updatedOperationStatus.setOperation(operation);
+ updatedOperationStatus.setUserId(userId);
+ updatedOperationStatus.setResult(result);
+ updatedOperationStatus.setProgress(progress);
+ updatedOperationStatus.setReason(reason);
+ updatedOperationStatus.setOperationContent(operationContent);
+
+ dbAdapter.updateServiceOperationStatus(serviceId, operationId, operation, userId,
+ result, operationContent, progress, reason);
+ OperationStatus dbOpStatus = operationStatusRepository.findOneByServiceIdAndOperationId(serviceId,operationId);
+ assertThat(dbOpStatus, sameBeanAs(updatedOperationStatus).ignoring("operateAt").ignoring("finishedAt"));
+ }
+
+
+ @Test
+ public void updateServiceOperation_Not_Found() throws MsoRequestsDbException{
+ String serviceId = "badserviceId";
+ String operationId = "operationid";
+ String operation = "newOperationType";
+ String userId = "NewUserId";
+ String result = "NewResult";
+ String operationContent = "newOperationContent";
+ String progress = "Newprogress";
+ String reason = "NewReason";
+
+ OperationStatus updatedOperationStatus = new OperationStatus();
+
+
+
+ updatedOperationStatus.setServiceId(serviceId);
+ updatedOperationStatus.setOperationId(operationId);
+ updatedOperationStatus.setOperation(operation);
+ updatedOperationStatus.setUserId(userId);
+ updatedOperationStatus.setResult(result);
+ updatedOperationStatus.setProgress(progress);
+ updatedOperationStatus.setReason(reason);
+ updatedOperationStatus.setOperationContent(operationContent);
+
+ thrown.expect(MsoRequestsDbException.class);
+ thrown.expectMessage("Unable to retrieve OperationStatus Object ServiceId: " + serviceId + " operationId: " + operationId);
+
+ dbAdapter.updateServiceOperationStatus(serviceId, operationId, operation, userId,
+ result, operationContent, progress, reason);
+
+ }
+
+ @Test
+ public void initResourceOperationStatus() throws MsoRequestsDbException{
+ String resourceTemplateUUIDs = "template1:template2:template3:";
+ String serviceId = "serviceId";
+ String operationId = "operationId";
+ String operationType = "operationType";
+
+ ResourceOperationStatus resource1 = new ResourceOperationStatus();
+ resource1.setOperationId(operationId);
+ resource1.setServiceId(serviceId);
+ resource1.setResourceTemplateUUID("template1");
+ resource1.setOperType(operationType);
+ resource1.setStatus(RequestsDbConstant.Status.PROCESSING);
+ resource1.setStatusDescription("Waiting for start");
+
+ ResourceOperationStatus resource2 = new ResourceOperationStatus();
+ resource2.setOperationId(operationId);
+ resource2.setServiceId(serviceId);
+ resource2.setResourceTemplateUUID("template2");
+ resource2.setOperType(operationType);
+ resource2.setStatus(RequestsDbConstant.Status.PROCESSING);
+ resource2.setStatusDescription("Waiting for start");
+
+ ResourceOperationStatus resource3 = new ResourceOperationStatus();
+ resource3.setOperationId(operationId);
+ resource3.setServiceId(serviceId);
+ resource3.setResourceTemplateUUID("template3");
+ resource3.setOperType(operationType);
+ resource3.setStatus(RequestsDbConstant.Status.PROCESSING);
+ resource3.setStatusDescription("Waiting for start");
+
+ List<ResourceOperationStatus> expectedResult = new ArrayList<ResourceOperationStatus>();
+ expectedResult.add(resource1);
+ expectedResult.add(resource2);
+ expectedResult.add(resource3);
+
+ dbAdapter.initResourceOperationStatus(serviceId, operationId, operationType,resourceTemplateUUIDs);
+ List<ResourceOperationStatus> testList = resourceOperationStatusRepo.findByServiceIdAndOperationId(serviceId,operationId);
+ assertThat(testList, sameBeanAs(expectedResult));
+ }
+
+ @Test
+ public void getResourceOperationStatus() throws MsoRequestsDbException{
+ String resourceTemplateUUIDs = "template1";
+ String serviceId = "serviceId";
+ String operationId = "operationId";
+ String operationType = "operationType";
+
+ ResourceOperationStatus resource1 = new ResourceOperationStatus();
+ resource1.setOperationId(operationId);
+ resource1.setServiceId(serviceId);
+ resource1.setResourceTemplateUUID("template1");
+ resource1.setOperType(operationType);
+ resource1.setStatus(RequestsDbConstant.Status.PROCESSING);
+ resource1.setStatusDescription("Waiting for start");
+
+
+ dbAdapter.initResourceOperationStatus(serviceId, operationId, operationType,resourceTemplateUUIDs);
+
+ ResourceOperationStatus actualResource = dbAdapter.getResourceOperationStatus(serviceId, operationId,"template1");
+ assertThat(actualResource, sameBeanAs(resource1));
+ }
+
+ @Test
+ public void updateResourceOperationStatus() throws MsoRequestsDbException{
+ String resourceTemplateUUID = "template1";
+ String serviceId = "serviceId";
+ String operationId = "operationId";
+ String operationType = "operationType";
+ String resourceInstanceID = "resourceInstanceID";
+ String jobId = "jobId";
+ String status = RequestsDbConstant.Status.FINISHED;
+ String progress = "50";
+ String errorCode = "errorCode";
+ String statusDescription = "statusDescription";
+
+
+ ResourceOperationStatus expectedResource = new ResourceOperationStatus();
+ expectedResource.setOperationId(operationId);
+ expectedResource.setServiceId(serviceId);
+ expectedResource.setResourceTemplateUUID(resourceTemplateUUID);
+ expectedResource.setOperType(operationType);
+ expectedResource.setJobId(jobId);
+ expectedResource.setErrorCode(errorCode);
+ expectedResource.setStatus(RequestsDbConstant.Status.FINISHED);
+ expectedResource.setStatusDescription(statusDescription);
+ expectedResource.setProgress(progress);
+ expectedResource.setResourceInstanceID(resourceInstanceID);
+
+
+ dbAdapter.updateResourceOperationStatus(serviceId, operationId, resourceTemplateUUID,
+ operationType, resourceInstanceID, jobId, status, progress,
+ errorCode, statusDescription);
+
+ ResourceOperationStatus actualResource = dbAdapter.getResourceOperationStatus(serviceId, operationId,"template1");
+ assertThat(actualResource, sameBeanAs(expectedResource));
+ }
+
+
+} \ No newline at end of file
diff --git a/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/application/EmbeddedMariaDbConfig.java b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/application/EmbeddedMariaDbConfig.java
new file mode 100644
index 0000000000..cd07f6757f
--- /dev/null
+++ b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/application/EmbeddedMariaDbConfig.java
@@ -0,0 +1,102 @@
+/*-
+ * ============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.application;
+import ch.vorburger.exec.ManagedProcessException;
+import ch.vorburger.mariadb4j.DBConfigurationBuilder;
+import ch.vorburger.mariadb4j.springframework.MariaDB4jSpringService;
+
+import org.springframework.beans.factory.annotation.Qualifier;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
+import org.springframework.boot.context.properties.ConfigurationProperties;
+import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.context.annotation.Primary;
+import org.springframework.context.annotation.Profile;
+import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
+import org.springframework.orm.jpa.JpaTransactionManager;
+import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
+import org.springframework.transaction.PlatformTransactionManager;
+import org.springframework.transaction.annotation.EnableTransactionManagement;
+
+import javax.persistence.EntityManagerFactory;
+import javax.sql.DataSource;
+
+@Configuration
+@Profile({"test"})
+@EnableTransactionManagement
+@EnableJpaRepositories(
+ entityManagerFactoryRef = "requestEntityManagerFactory",transactionManagerRef = "requestTransactionManager",
+ basePackages = { "org.onap.so.db.request.data.repository"}
+ )
+public class EmbeddedMariaDbConfig {
+
+ @Bean
+ MariaDB4jSpringService mariaDB4jSpringService() {
+ return new MariaDB4jSpringService();
+ }
+
+ @Primary
+ @Bean(name = "requestDataSource")
+ @ConfigurationProperties(prefix = "spring.datasource")
+ DataSource dataSource(MariaDB4jSpringService mariaDB4jSpringService,
+ @Value("${mariaDB4j.databaseName}") String databaseName,
+ @Value("${spring.datasource.username}") String datasourceUsername,
+ @Value("${spring.datasource.password}") String datasourcePassword,
+ @Value("${spring.datasource.driver-class-name}") String datasourceDriver) throws ManagedProcessException {
+ //Create our database with default root user and no password
+ mariaDB4jSpringService.getDB().createDB(databaseName);
+
+ DBConfigurationBuilder config = mariaDB4jSpringService.getConfiguration();
+
+ return DataSourceBuilder
+ .create()
+ .username(datasourceUsername)
+ .password(datasourcePassword)
+ .url(config.getURL(databaseName))
+ .driverClassName(datasourceDriver)
+ .build();
+ }
+
+ @Primary
+ @Bean(name = "requestEntityManagerFactory")
+ public LocalContainerEntityManagerFactoryBean
+ entityManagerFactory(
+ EntityManagerFactoryBuilder builder,
+ @Qualifier("requestDataSource") DataSource dataSource
+ ) {
+ return builder
+ .dataSource(dataSource)
+ .packages("org.onap.so.db.request.beans")
+ .persistenceUnit("requestDB")
+ .build();
+ }
+
+ @Primary
+ @Bean(name = "requestTransactionManager")
+ public PlatformTransactionManager transactionManager(
+ @Qualifier("requestEntityManagerFactory") EntityManagerFactory
+ entityManagerFactory
+ ) {
+ return new JpaTransactionManager(entityManagerFactory);
+ }
+}
diff --git a/adapters/mso-requests-db-adapter/src/test/java/org/openecomp/mso/adapters/requestsdb/exceptions/MsoRequestsDbExceptionBeanTest.java b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/exceptions/MsoRequestsDbExceptionBeanTest.java
index 159dd91541..77821bfefd 100644
--- a/adapters/mso-requests-db-adapter/src/test/java/org/openecomp/mso/adapters/requestsdb/exceptions/MsoRequestsDbExceptionBeanTest.java
+++ b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/exceptions/MsoRequestsDbExceptionBeanTest.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.openecomp.mso.adapters.requestsdb.exceptions;
+package org.onap.so.adapters.requestsdb.exceptions;
import org.junit.Assert;
import org.junit.Before;
diff --git a/adapters/mso-requests-db-adapter/src/test/java/org/openecomp/mso/adapters/requestsdb/exceptions/MsoRequestsDbExceptionTest.java b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/exceptions/MsoRequestsDbExceptionTest.java
index b946349037..04f597f9b2 100644
--- a/adapters/mso-requests-db-adapter/src/test/java/org/openecomp/mso/adapters/requestsdb/exceptions/MsoRequestsDbExceptionTest.java
+++ b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/exceptions/MsoRequestsDbExceptionTest.java
@@ -14,10 +14,10 @@
* 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
+ * limitations under the License.
* ============LICENSE_END=========================================================
*/
-package org.openecomp.mso.adapters.requestsdb.exceptions;
+package org.onap.so.adapters.requestsdb.exceptions;
import org.junit.Assert;
import org.junit.Test;
diff --git a/adapters/mso-requests-db-adapter/src/test/java/org/openecomp/mso/adapters/requestsdb/HealthCheckHandlerTest.java b/adapters/mso-requests-db-adapter/src/test/java/org/openecomp/mso/adapters/requestsdb/HealthCheckHandlerTest.java
deleted file mode 100644
index 87e2a87138..0000000000
--- a/adapters/mso-requests-db-adapter/src/test/java/org/openecomp/mso/adapters/requestsdb/HealthCheckHandlerTest.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP - SO
- * ================================================================================
- * Copyright (C) 2018 Huawei Technologies Co., Ltd. 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.openecomp.mso.adapters.requestsdb;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.openecomp.mso.HealthCheckUtils;
-import org.openecomp.mso.logger.MsoLogger;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
-
-import javax.ws.rs.core.Response;
-
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.when;
-
-@RunWith(PowerMockRunner.class)
-@PrepareForTest(HealthCheckHandler.class)
-public class HealthCheckHandlerTest {
-
- HealthCheckHandler hcH;
-
- @Before
- public void init(){
-
- hcH = new HealthCheckHandler();
- }
-
- @Test
- public void testNoServiceResp() {
-
- HealthCheckUtils test = PowerMockito.mock(HealthCheckUtils.class);
- try {
- PowerMockito.whenNew(HealthCheckUtils.class).withNoArguments().thenReturn(test);
- when(test.siteStatusCheck(any(MsoLogger.class))).thenReturn(true);
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- Response response = hcH.healthcheck("request");
- assertEquals(503,response.getStatus());
- }
-
-}
-
-
diff --git a/adapters/mso-requests-db-adapter/src/test/java/org/openecomp/mso/adapters/requestsdb/MsoRequestsDbAdapterImplTest.java b/adapters/mso-requests-db-adapter/src/test/java/org/openecomp/mso/adapters/requestsdb/MsoRequestsDbAdapterImplTest.java
deleted file mode 100644
index 506b3bd95f..0000000000
--- a/adapters/mso-requests-db-adapter/src/test/java/org/openecomp/mso/adapters/requestsdb/MsoRequestsDbAdapterImplTest.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP - SO
- * ================================================================================
- * Copyright (C) 2018 Huawei Technologies Co., Ltd. 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.openecomp.mso.adapters.requestsdb;
-
-import org.junit.Test;
-
-public class MsoRequestsDbAdapterImplTest {
-
- // TODO: following test case is done for coverage
- // later it should be modified for proper test.
- MsoRequestsDbAdapterImpl msoRequestsDbAdapter = new MsoRequestsDbAdapterImpl();
-
- @Test(expected = NullPointerException.class)
- public void updateInfraRequest() throws Exception {
- msoRequestsDbAdapter.updateInfraRequest("test", "test",
- "test", "test", RequestStatusType.COMPLETE, "test",
- "test", "test", "test", "test",
- "test", "test", "test",
- "test", "test", "tets");
- }
-
- @Test(expected = NullPointerException.class)
- public void getInfraRequest() throws Exception {
- msoRequestsDbAdapter.getInfraRequest("test");
- }
-
- @Test(expected = NullPointerException.class)
- public void getSiteStatus() throws Exception {
- msoRequestsDbAdapter.getSiteStatus("test");
- }
-
- @Test(expected = NullPointerException.class)
- public void updateServiceOperationStatus() throws Exception {
- msoRequestsDbAdapter.updateServiceOperationStatus("test", "test",
- "test", "test", "test", "test",
- "test", "test");
- }
-
- @Test(expected = NullPointerException.class)
- public void initResourceOperationStatus() throws Exception {
- msoRequestsDbAdapter.initResourceOperationStatus("test", "test", "test", "uuid");
- }
-
- @Test(expected = NullPointerException.class)
- public void getResourceOperationStatus() throws Exception {
- msoRequestsDbAdapter.getResourceOperationStatus("test", "test", "uuid");
- }
-
- @Test(expected = NullPointerException.class)
- public void updateResourceOperationStatus() throws Exception {
- msoRequestsDbAdapter.updateResourceOperationStatus("test", "test",
- "uuid", "type", "instance-id",
- "jobid", "test", "progress", "errorcode",
- "status-desc");
- }
-
-} \ No newline at end of file