diff options
Diffstat (limited to 'vid-app-common/src/test/java/org/onap/vid/controllers')
15 files changed, 0 insertions, 2516 deletions
diff --git a/vid-app-common/src/test/java/org/onap/vid/controllers/AaiControllerTest.java b/vid-app-common/src/test/java/org/onap/vid/controllers/AaiControllerTest.java deleted file mode 100644 index 2a398b361..000000000 --- a/vid-app-common/src/test/java/org/onap/vid/controllers/AaiControllerTest.java +++ /dev/null @@ -1,440 +0,0 @@ -package org.onap.vid.controllers; - -import javax.servlet.http.HttpServletRequest; - -import org.json.simple.JSONObject; -import org.junit.Test; -import org.onap.vid.aai.AaiResponse; -import org.onap.vid.aai.model.AaiGetOperationalEnvironments.OperationalEnvironmentList; -import org.onap.vid.controllers.AaiController; -import org.onap.vid.model.VersionByInvariantIdsRequest; -import org.springframework.http.ResponseEntity; -import org.springframework.web.servlet.ModelAndView; -import java.util.*; -import org.junit.Assert; - -public class AaiControllerTest { - - private AaiController createTestSubject() { - return new AaiController(); - } - - @Test - public void testWelcome() throws Exception { - AaiController testSubject; - HttpServletRequest request = null; - ModelAndView result; - - // default test - testSubject = createTestSubject(); - result = testSubject.welcome(request); - } - - @Test - public void testGetTargetProvStatus() throws Exception { - AaiController testSubject; - ResponseEntity<String> result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getTargetProvStatus(); - } - - @Test - public void testViewEditGetTenantsFromServiceType() throws Exception { - AaiController testSubject; - HttpServletRequest request = null; - String globalCustomerId = ""; - String serviceType = ""; - ResponseEntity<String> result; - - // default test - testSubject = createTestSubject(); - result = testSubject.viewEditGetTenantsFromServiceType(request, globalCustomerId, serviceType); - } - - - - - - @Test - public void testGetAicZones() throws Exception { - AaiController testSubject; - HttpServletRequest request = null; - ResponseEntity<String> result; - - // default test - try { - testSubject = createTestSubject(); - result = testSubject.getAicZones(request); - } catch (Exception e) { - } - } - - @Test - public void testGetAicZoneForPnf() throws Exception { - AaiController testSubject; - String globalCustomerId = ""; - String serviceType = ""; - String serviceId = ""; - HttpServletRequest request = null; - ResponseEntity<String> result; - - // default test - try { - testSubject = createTestSubject(); - result = testSubject.getAicZoneForPnf(globalCustomerId, serviceType, serviceId, request); - } catch (Exception e) { - } - } - - @Test - public void testGetUserID() throws Exception { - AaiController testSubject; - HttpServletRequest request = null; - ResponseEntity<String> result; - - // default test - try { - testSubject = createTestSubject(); - result = testSubject.getUserID(request); - } catch (Exception e) { - } - } - - @Test - public void testDoGetServices() throws Exception { - AaiController testSubject; - HttpServletRequest request = null; - ResponseEntity<String> result; - - // default test - try { - testSubject = createTestSubject(); - result = testSubject.doGetServices(request); - } catch (Exception e) { - } - } - - @Test - public void testGetVersionByInvariantId() throws Exception { - AaiController testSubject; - HttpServletRequest request = null; - VersionByInvariantIdsRequest versions = null; - ResponseEntity<String> result; - - // default test - try { - testSubject = createTestSubject(); - result = testSubject.getVersionByInvariantId(request, versions); - } catch (Exception e) { - } - } - - // @Test - // public void testAaiResponseToResponseEntity() throws Exception { - // AaiController testSubject;AaiResponse aaiResponseData = null; - // ResponseEntity<String> result; - // - // // default test - // } - - @Test - public void testDoGetServiceInstance() throws Exception { - AaiController testSubject; - String serviceInstanceId = ""; - String serviceInstanceType = ""; - ResponseEntity<String> result; - - // default test - try { - testSubject = createTestSubject(); - result = testSubject.doGetServiceInstance(serviceInstanceId, serviceInstanceType); - } catch (Exception e) { - } - } - - @Test - public void testDoGetServices_1() throws Exception { - AaiController testSubject; - String globalCustomerId = ""; - String serviceSubscriptionId = ""; - ResponseEntity<String> result; - - // default test - try { - testSubject = createTestSubject(); - result = testSubject.doGetServices(globalCustomerId, serviceSubscriptionId); - } catch (Exception e) { - } - } - - @Test - public void testDoGetSubscriberList() throws Exception { - AaiController testSubject; - HttpServletRequest request = null; - String fullSet = ""; - ResponseEntity<String> result; - - // default test - try { - testSubject = createTestSubject(); - result = testSubject.doGetSubscriberList(request, fullSet); - } catch (Exception e) { - } - } - - @Test - public void testGetOperationalEnvironments() throws Exception { - AaiController testSubject; - String operationalEnvironmentType = ""; - String operationalEnvironmentStatus = ""; - AaiResponse<OperationalEnvironmentList> result; - - // default test - try { - testSubject = createTestSubject(); - result = testSubject.getOperationalEnvironments(operationalEnvironmentType, operationalEnvironmentStatus); - } catch (Exception e) { - } - } - - @Test - public void testGetFullSubscriberList() throws Exception { - AaiController testSubject; - HttpServletRequest request = null; - ResponseEntity<String> result; - - // default test - try { - testSubject = createTestSubject(); - result = testSubject.getFullSubscriberList(request); - } catch (Exception e) { - } - } - - @Test - public void testGetVnfDataByGlobalIdAndServiceType() throws Exception { - AaiController testSubject; - HttpServletRequest request = null; - String globalCustomerId = ""; - String serviceType = ""; - ResponseEntity<String> result; - - // default test - try { - testSubject = createTestSubject(); - result = testSubject.getVnfDataByGlobalIdAndServiceType(request, globalCustomerId, serviceType); - } catch (Exception e) { - } - } - - @Test - public void testDoRefreshSubscriberList() throws Exception { - AaiController testSubject; - ResponseEntity<String> result; - - // default test - try { - testSubject = createTestSubject(); - result = testSubject.doRefreshSubscriberList(); - } catch (Exception e) { - } - } - - @Test - public void testDoRefreshFullSubscriberList() throws Exception { - AaiController testSubject; - ResponseEntity<String> result; - - // default test - try { - testSubject = createTestSubject(); - result = testSubject.doRefreshFullSubscriberList(); - } catch (Exception e) { - } - } - - @Test - public void testGetSubscriberDetails() throws Exception { - AaiController testSubject; - HttpServletRequest request = null; - String subscriberId = ""; - ResponseEntity<String> result; - - // default test - try { - testSubject = createTestSubject(); - result = testSubject.GetSubscriberDetails(request, subscriberId); - } catch (Exception e) { - } - } - - @Test - public void testSearchServiceInstances() throws Exception { - AaiController testSubject; - HttpServletRequest request = null; - String subscriberId = ""; - String instanceIdentifier = ""; - List<String> projects = null; - List<String> owningEntities = null; - ResponseEntity<String> result; - - // default test - try { - testSubject = createTestSubject(); - result = testSubject.SearchServiceInstances(request, subscriberId, instanceIdentifier, projects, - owningEntities); - } catch (Exception e) { - } - } - - @Test - public void testViewEditGetComponentList() throws Exception { - AaiController testSubject; - String namedQueryId = ""; - String globalCustomerId = ""; - String serviceType = ""; - String serviceInstance = ""; - ResponseEntity<String> result; - - // default test - try { - testSubject = createTestSubject(); - result = testSubject.viewEditGetComponentList(namedQueryId, globalCustomerId, serviceType, serviceInstance); - } catch (Exception e) { - } - } - - @Test - public void testGetVnfData() throws Exception { - AaiController testSubject; - String globalCustomerId = ""; - String serviceType = ""; - String serviceInstanceId = ""; - AaiResponse<String> result; - - // default test - try { - testSubject = createTestSubject(); - result = testSubject.getVnfData(globalCustomerId, serviceType, serviceInstanceId); - } catch (Exception e) { - } - } - - @Test - public void testViewEditGetComponentList_1() throws Exception { - AaiController testSubject; - String namedQueryId = ""; - String globalCustomerId = ""; - String serviceType = ""; - ResponseEntity<String> result; - - // default test - try { - testSubject = createTestSubject(); - result = testSubject.viewEditGetComponentList(namedQueryId, globalCustomerId, serviceType); - } catch (Exception e) { - } - } - - @Test - public void testGetNodeTemplateInstances() throws Exception { - AaiController testSubject; - String globalCustomerId = ""; - String serviceType = ""; - String modelVersionId = ""; - String modelInvariantId = ""; - String cloudRegion = ""; - ResponseEntity<String> result; - - // default test - try { - testSubject = createTestSubject(); - result = testSubject.getNodeTemplateInstances(globalCustomerId, serviceType, modelVersionId, - modelInvariantId, cloudRegion); - } catch (Exception e) { - } - } - - @Test - public void testGetByUri() throws Exception { - AaiController testSubject; - HttpServletRequest request = null; - ResponseEntity<String> result; - - // default test - try { - testSubject = createTestSubject(); - result = testSubject.getByUri(request); - } catch (Exception e) { - } - } - - @Test - public void testGetSpecificConfiguration() throws Exception { - AaiController testSubject; - String configurationId = ""; - ResponseEntity<String> result; - - // default test - try { - testSubject = createTestSubject(); - result = testSubject.getSpecificConfiguration(configurationId); - } catch (Exception e) { - } - } - - @Test - public void testGetServiceInstanceAssociatedPnfs() throws Exception { - AaiController testSubject; - String globalCustomerId = ""; - String serviceType = ""; - String serviceInstanceId = ""; - List<String> result; - - // default test - try { - testSubject = createTestSubject(); - result = testSubject.getServiceInstanceAssociatedPnfs(globalCustomerId, serviceType, serviceInstanceId); - } catch (Exception e) { - } - } - - @Test - public void testGetSpecificPnf() throws Exception { - AaiController testSubject; - String pnfId = ""; - ResponseEntity result; - - // default test - try { - testSubject = createTestSubject(); - result = testSubject.getSpecificPnf(pnfId); - } catch (Exception e) { - } - } - - @Test - public void testGetPnfInstances() throws Exception { - AaiController testSubject; - String globalCustomerId = ""; - String serviceType = ""; - String modelVersionId = ""; - String modelInvariantId = ""; - String cloudRegion = ""; - String equipVendor = ""; - String equipModel = ""; - ResponseEntity<String> result; - - // default test - try { - testSubject = createTestSubject(); - result = testSubject.getPnfInstances(globalCustomerId, serviceType, modelVersionId, modelInvariantId, - cloudRegion, equipVendor, equipModel); - } catch (Exception e) { - } - - } - -}
\ No newline at end of file diff --git a/vid-app-common/src/test/java/org/onap/vid/controllers/ChangeManagementControllerTest.java b/vid-app-common/src/test/java/org/onap/vid/controllers/ChangeManagementControllerTest.java deleted file mode 100644 index 3c8250b26..000000000 --- a/vid-app-common/src/test/java/org/onap/vid/controllers/ChangeManagementControllerTest.java +++ /dev/null @@ -1,455 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright © 2018 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Modifications Copyright 2018 Nokia - * ================================================================================ - * 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.vid.controllers; - -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.BDDMockito.given; -import static org.mockito.BDDMockito.willThrow; -import static org.mockito.Matchers.argThat; -import static org.mockito.Matchers.isA; -import static org.onap.vid.controllers.ChangeManagementController.CHANGE_MANAGEMENT; -import static org.onap.vid.controllers.ChangeManagementController.GET_VNF_WORKFLOW_RELATION; -import static org.onap.vid.controllers.ChangeManagementController.SCHEDULER_BY_SCHEDULE_ID; -import static org.onap.vid.controllers.ChangeManagementController.VNF_WORKFLOW_RELATION; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.common.collect.ImmutableList; -import java.io.IOException; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; -import java.util.Arrays; -import java.util.Collection; -import java.util.Scanner; -import javax.ws.rs.WebApplicationException; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.tuple.ImmutablePair; -import org.apache.commons.lang3.tuple.Pair; -import org.apache.log4j.BasicConfigurator; -import org.json.simple.JSONArray; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.ArgumentMatcher; -import org.mockito.Mock; -import org.mockito.runners.MockitoJUnitRunner; -import org.onap.vid.changeManagement.GetVnfWorkflowRelationRequest; -import org.onap.vid.changeManagement.GetWorkflowsResponse; -import org.onap.vid.changeManagement.VnfDetailsWithWorkflows; -import org.onap.vid.changeManagement.VnfWorkflowRelationAllResponse; -import org.onap.vid.changeManagement.VnfWorkflowRelationResponse; -import org.onap.vid.domain.mso.InstanceIds; -import org.onap.vid.domain.mso.RequestStatus; -import org.onap.vid.exceptions.NotFoundException; -import org.onap.vid.model.ExceptionResponse; -import org.onap.vid.mso.rest.Request; -import org.onap.vid.services.ChangeManagementService; -import org.onap.vid.services.WorkflowService; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.mock.web.MockMultipartFile; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; -import org.springframework.web.multipart.MultipartFile; - -@RunWith(MockitoJUnitRunner.class) -public class ChangeManagementControllerTest { - - private static final String FILE_NAME = "file"; - private static final String GET_VNF_WORKFLOW_RELATION_URL = - "/" + CHANGE_MANAGEMENT + "/" + GET_VNF_WORKFLOW_RELATION; - private static final String WORKFLOW_URL = "/" + CHANGE_MANAGEMENT + "/workflow"; - private static final String WORKFLOW_NAME_URL = WORKFLOW_URL + "/{name}"; - private static final String MSO_URL = "/" + CHANGE_MANAGEMENT + "/mso"; - private static final String UPLOAD_CONFIG_UPDATE_FILE_URL = "/" + CHANGE_MANAGEMENT + "/uploadConfigUpdateFile"; - private static final String SCHEDULER_URL = "/" + CHANGE_MANAGEMENT + "/scheduler"; - private static final String SCHEDULER_BY_SCHEDULE_ID_URL = "/" + CHANGE_MANAGEMENT + SCHEDULER_BY_SCHEDULE_ID; - private static final String VNF_WORKFLOW_RELATION_URL = "/" + CHANGE_MANAGEMENT + "/" + VNF_WORKFLOW_RELATION; - private static final String VNFS = "vnfs"; - - private static final String FAILED_TO_GET_MSG = "Failed to get workflows for vnf"; - private static final String FAILED_TO_ADD_MSG = "Failed to add vnf to workflow relation"; - private static final String FAILED_TO_GET_ALL_MSG = "Failed to get all vnf to workflow relations"; - private static final String FAILED_TO_DELETE_MSG = "Failed to delete vnf from workflow relation"; - - private final ObjectMapper objectMapper = new ObjectMapper(); - private ChangeManagementController controller; - private MockMvc mockMvc; - @Mock - private WorkflowService workflowService; - @Mock - private ChangeManagementService changeManagementService; - @Mock - private Response mockResponse; - @Mock - private Response.StatusType statusType; - private ClassLoader classLoader = getClass().getClassLoader(); - private final String CHANGE_MANAGEMENT_REQUEST_JSON = getRequestContent("change-management-request.json"); - private final String GET_VNF_WORKFLOW_RELATION_REQUEST_JSON = getRequestContent( - "get-vnf-workflow-relation-request.json"); - private final String VNF_WORKFLOW_RELATION_REQUEST_JSON = getRequestContent("vnf-workflow-relation-request.json"); - - @Before - public void setUp() { - controller = new ChangeManagementController(workflowService, changeManagementService, objectMapper); - BasicConfigurator.configure(); - mockMvc = MockMvcBuilders.standaloneSetup(controller).build(); - } - - @Test - public void getWorkflow_shouldReturnListOfVnfs_whenServiceReturnsCorrectValue() throws Exception { - - Collection<String> givenVnfs = ImmutableList.of("vnf1", "vnf2", "vnf3"); - Collection<String> resultWorkflows = ImmutableList.of("workflow1", "workflow2"); - - given( - workflowService.getWorkflowsForVNFs(argThat(other -> CollectionUtils.isEqualCollection(givenVnfs, other)))) - .willReturn(resultWorkflows); - - mockMvc.perform(get(WORKFLOW_URL) - .param(VNFS, StringUtils.join(givenVnfs, ","))) - .andExpect(status().isOk()) - .andExpect(content().json(objectMapper.writeValueAsString(resultWorkflows))); - } - - @Test - public void getMSOChangeManagements_shouldReturnCollectionOfRequests_whenServiceReturnsCorrectValue() - throws Exception { - - Collection<Request> requests = ImmutableList.of( - createRequest("network-instance-id-1", "status-message-1"), - createRequest("network-instance-id-2", "status-message-2")); - - given(changeManagementService.getMSOChangeManagements()).willReturn(requests); - - mockMvc.perform(get(MSO_URL)) - .andExpect(status().isOk()) - .andExpect(content().json(objectMapper.writeValueAsString(requests))); - } - - @Test - public void changeManagement_shouldReturnOkResponse_whenServiceReturnsCorrectValue() throws Exception { - - String vnfName = "vnfName1"; - String jsonBody = "{'param1': 'paramparam'}"; - - given(changeManagementService.doChangeManagement( - argThat(request -> matches(request, CHANGE_MANAGEMENT_REQUEST_JSON)), eq(vnfName))) - .willReturn(ResponseEntity.ok().body(jsonBody)); - - mockMvc.perform(post(WORKFLOW_NAME_URL, vnfName) - .contentType(MediaType.APPLICATION_JSON) - .content(CHANGE_MANAGEMENT_REQUEST_JSON)) - .andExpect(status().isOk()) - .andExpect(content().json(jsonBody)); - } - - @Test - public void uploadConfigUpdateFile_shouldReturnOkResponse_whenServiceReturnsCorrectJson() throws Exception { - - String jsonString = "{'param1': 'paramparam'}"; - byte[] fileContent = "some file content".getBytes(StandardCharsets.UTF_8); - MockMultipartFile file = new MockMultipartFile(FILE_NAME, fileContent); - - given(changeManagementService - .uploadConfigUpdateFile(argThat(multipartFileMatcher(file)))) - .willReturn(jsonString); - - mockMvc.perform(MockMvcRequestBuilders - .fileUpload(UPLOAD_CONFIG_UPDATE_FILE_URL) - .file(file)) - .andExpect(status().isOk()) - .andExpect(content().json(jsonString)); - } - - @Test - public void uploadConfigUpdateFile_shouldReturnResponseStatus_whenServiceThrowsWebApplicationException() - throws Exception { - - byte[] fileContent = "some file content".getBytes(StandardCharsets.UTF_8); - MockMultipartFile file = new MockMultipartFile(FILE_NAME, fileContent); - - given(statusType.getStatusCode()).willReturn(HttpStatus.NOT_FOUND.value()); - given(mockResponse.getStatus()).willReturn(HttpStatus.NOT_FOUND.value()); - given(mockResponse.getStatusInfo()).willReturn(statusType); - - WebApplicationException exception = new WebApplicationException(mockResponse); - - willThrow(exception).given(changeManagementService) - .uploadConfigUpdateFile(argThat(multipartFileMatcher(file))); - - mockMvc.perform(MockMvcRequestBuilders - .fileUpload(UPLOAD_CONFIG_UPDATE_FILE_URL) - .file(file)) - .andExpect(status().isNotFound()) - .andExpect(content().json(objectMapper.writeValueAsString(new ExceptionResponse(exception)))); - } - - @Test - public void uploadConfigUpdateFile_shouldReturnInternalServerError_whenServiceThrowsRuntimeException() - throws Exception { - - byte[] fileContent = "some file content".getBytes(StandardCharsets.UTF_8); - MockMultipartFile file = new MockMultipartFile(FILE_NAME, fileContent); - - RuntimeException exception = new RuntimeException("runtime exception message"); - - willThrow(exception).given(changeManagementService) - .uploadConfigUpdateFile(argThat(multipartFileMatcher(file))); - - mockMvc.perform(MockMvcRequestBuilders - .fileUpload(UPLOAD_CONFIG_UPDATE_FILE_URL) - .file(file)) - .andExpect(status().isInternalServerError()) - .andExpect(content().json(objectMapper.writeValueAsString(new ExceptionResponse(exception)))); - } - - @Test - public void getSchedulerChangeManagements_shouldReturnJsonArray_whenServiceReturnsCorrectValue() throws Exception { - - JSONArray array = new JSONArray(); - array.add("element1"); - array.add("element2"); - - given(changeManagementService.getSchedulerChangeManagements()).willReturn(array); - - mockMvc.perform(get(SCHEDULER_URL)) - .andExpect(status().isOk()) - .andExpect(content().json(array.toJSONString())); - } - - @Test - public void deleteSchedule_shouldReturnOkResponse_whenServiceReturnsOkStatus() throws Exception { - - String id = "schedule-id-1"; - Pair<String, Integer> pair = new ImmutablePair<>("myString", HttpStatus.OK.value()); - - given(changeManagementService.deleteSchedule(id)).willReturn(pair); - - mockMvc.perform(delete(SCHEDULER_BY_SCHEDULE_ID_URL, id)) - .andExpect(status().isOk()); - } - - @Test - public void deleteSchedule_shouldReturnNotFoundResponse_whenServiceReturnsNotFoundStatus() throws Exception { - - String id = "schedule-id-1"; - Pair<String, Integer> pair = new ImmutablePair<>("myString", HttpStatus.NOT_FOUND.value()); - - given(changeManagementService.deleteSchedule(id)).willReturn(pair); - - mockMvc.perform(delete(SCHEDULER_BY_SCHEDULE_ID_URL, id)) - .andExpect(status().isNotFound()); - } - - @Test - public void getWorkflows_shouldReturnOkResponse_whenServiceReturnsOkStatus() throws Exception { - - ImmutableList<String> elements = ImmutableList.of("workflow1", "workflow2"); - GetWorkflowsResponse response = new GetWorkflowsResponse(); - response.setWorkflows(elements); - - given(changeManagementService - .getWorkflowsForVnf(argThat(request -> matches(request, GET_VNF_WORKFLOW_RELATION_REQUEST_JSON)))) - .willReturn(elements); - - mockMvc.perform(post(GET_VNF_WORKFLOW_RELATION_URL) - .contentType(MediaType.APPLICATION_JSON) - .content(GET_VNF_WORKFLOW_RELATION_REQUEST_JSON)) - .andExpect(status().isOk()) - .andExpect(content().json(objectMapper.writeValueAsString(response))); - } - - @Test - public void getWorkflows_shouldReturnNotFound_whenServiceThrowsNotFoundException() throws Exception { - - String errorMsg = "not found"; - VnfWorkflowRelationResponse response = new VnfWorkflowRelationResponse(ImmutableList.of(errorMsg)); - - willThrow(new NotFoundException(errorMsg)) - .given(changeManagementService) - .getWorkflowsForVnf(argThat(request -> matches(request, GET_VNF_WORKFLOW_RELATION_REQUEST_JSON))); - - mockMvc.perform(post(GET_VNF_WORKFLOW_RELATION_URL) - .contentType(MediaType.APPLICATION_JSON) - .content(GET_VNF_WORKFLOW_RELATION_REQUEST_JSON)) - .andExpect(status().isNotFound()) - .andExpect(content().json(objectMapper.writeValueAsString(response))); - } - - @Test - public void getWorkflows_shouldReturnInternalServerError_whenServiceThrowsRuntimeException() throws Exception { - - VnfWorkflowRelationResponse response = new VnfWorkflowRelationResponse(ImmutableList.of(FAILED_TO_GET_MSG)); - - willThrow(new RuntimeException("runtime exception message")) - .given(changeManagementService).getWorkflowsForVnf(isA(GetVnfWorkflowRelationRequest.class)); - - mockMvc.perform(post(GET_VNF_WORKFLOW_RELATION_URL) - .contentType(MediaType.APPLICATION_JSON) - .content(VNF_WORKFLOW_RELATION_REQUEST_JSON)) - .andExpect(status().isInternalServerError()) - .andExpect(content().json(objectMapper.writeValueAsString(response))); - } - - @Test - public void createWorkflowRelation_shouldReturnOkResponse_whenServiceReturnsOkStatus() throws Exception { - - VnfWorkflowRelationResponse response = new VnfWorkflowRelationResponse(); - - given(changeManagementService - .addVnfWorkflowRelation(argThat(request -> matches(request, VNF_WORKFLOW_RELATION_REQUEST_JSON)))) - .willReturn(response); - - mockMvc.perform(post(VNF_WORKFLOW_RELATION_URL) - .contentType(MediaType.APPLICATION_JSON) - .content(VNF_WORKFLOW_RELATION_REQUEST_JSON)) - .andExpect(status().isOk()) - .andExpect(content().json(objectMapper.writeValueAsString(response))); - } - - @Test - public void createWorkflowRelation_shouldReturnInternalServerError_whenServiceThrowsException() throws Exception { - - VnfWorkflowRelationResponse response = new VnfWorkflowRelationResponse(ImmutableList.of(FAILED_TO_ADD_MSG)); - - willThrow(new RuntimeException("runtime exception message")) - .given(changeManagementService).addVnfWorkflowRelation(argThat(request -> matches(request, - VNF_WORKFLOW_RELATION_REQUEST_JSON))); - - mockMvc.perform(post(VNF_WORKFLOW_RELATION_URL) - .contentType(MediaType.APPLICATION_JSON) - .content(VNF_WORKFLOW_RELATION_REQUEST_JSON)) - .andExpect(status().isInternalServerError()) - .andExpect(content().json(objectMapper.writeValueAsString(response))); - } - - @Test - public void getAllWorkflowRelation_shouldReturnOkResponse_whenServiceReturnsOkStatus() throws Exception { - - VnfDetailsWithWorkflows workflows = new VnfDetailsWithWorkflows(); - workflows.setWorkflows(ImmutableList.of("workflow1", "workflow2")); - VnfWorkflowRelationAllResponse response = new VnfWorkflowRelationAllResponse(ImmutableList.of(workflows)); - - given(changeManagementService.getAllVnfWorkflowRelations()).willReturn(response); - - mockMvc.perform(get(VNF_WORKFLOW_RELATION_URL)) - .andExpect(status().isOk()) - .andExpect(content().json(objectMapper.writeValueAsString(response))); - } - - @Test - public void getAllWorkflowRelation_shouldReturnInternalServerError_whenServiceThrowsRuntimeException() - throws Exception { - - VnfWorkflowRelationResponse response = new VnfWorkflowRelationResponse(ImmutableList.of(FAILED_TO_GET_ALL_MSG)); - - willThrow(new RuntimeException("runtime exception message")) - .given(changeManagementService).getAllVnfWorkflowRelations(); - - mockMvc.perform(get(VNF_WORKFLOW_RELATION_URL)) - .andExpect(status().isInternalServerError()) - .andExpect(content().json(objectMapper.writeValueAsString(response))); - } - - @Test - public void deleteWorkflowRelation_shouldReturnOkResponse_whenServiceReturnsOkStatus() throws Exception { - VnfWorkflowRelationResponse response = new VnfWorkflowRelationResponse(ImmutableList.of("abc")); - - given(changeManagementService.deleteVnfWorkflowRelation(argThat(request -> matches(request, - VNF_WORKFLOW_RELATION_REQUEST_JSON)))) - .willReturn(response); - - mockMvc.perform(delete(VNF_WORKFLOW_RELATION_URL) - .contentType(MediaType.APPLICATION_JSON) - .content(VNF_WORKFLOW_RELATION_REQUEST_JSON)) - .andExpect(status().isOk()) - .andExpect(content().json(objectMapper.writeValueAsString(response))); - } - - @Test - public void deleteWorkflowRelation_shouldReturnInternalServerError_whenServiceThrowsRuntimeException() - throws Exception { - VnfWorkflowRelationResponse response = new VnfWorkflowRelationResponse(ImmutableList.of(FAILED_TO_DELETE_MSG)); - - willThrow(new RuntimeException("runtime exception message")) - .given(changeManagementService).deleteVnfWorkflowRelation(argThat(request -> matches(request, - VNF_WORKFLOW_RELATION_REQUEST_JSON))); - - mockMvc.perform(delete(VNF_WORKFLOW_RELATION_URL) - .contentType(MediaType.APPLICATION_JSON) - .content(VNF_WORKFLOW_RELATION_REQUEST_JSON)) - .andExpect(status().isInternalServerError()) - .andExpect(content().json(objectMapper.writeValueAsString(response))); - } - - private <T> boolean matches(T request, String expectedJson) { - try { - return objectMapper.writeValueAsString(request).equals(expectedJson); - } catch (JsonProcessingException e) { - System.out.println("Exception occurred: " + e.getMessage()); - } - return false; - } - - private ArgumentMatcher<MultipartFile> multipartFileMatcher(MultipartFile otherFile) { - return other -> { - try { - return other.getName().equals(otherFile.getName()) - && other.getSize() == otherFile.getSize() - && Arrays.equals(other.getBytes(), otherFile.getBytes()); - } catch (IOException e) { - System.out.println("IOException occurred: " + e.getMessage()); - } - return false; - }; - } - - private Request createRequest(String networkInstanceId, String statusMessage) { - Request req = new Request(); - InstanceIds instanceIds = new InstanceIds(); - instanceIds.setNetworkInstanceId(networkInstanceId); - - RequestStatus requestStatus = new RequestStatus(); - requestStatus.setStatusMessage(statusMessage); - - req.setInstanceIds(instanceIds); - req.setRequestStatus(requestStatus); - - return req; - } - - private String getRequestContent(String filename) { - InputStream inputStream = classLoader.getResourceAsStream(filename); - return new Scanner(inputStream).useDelimiter("\\A").next().replaceAll("\\s+", ""); - } -}
\ No newline at end of file diff --git a/vid-app-common/src/test/java/org/onap/vid/controllers/HealthCheckControllerTest.java b/vid-app-common/src/test/java/org/onap/vid/controllers/HealthCheckControllerTest.java deleted file mode 100644 index 4894f35ea..000000000 --- a/vid-app-common/src/test/java/org/onap/vid/controllers/HealthCheckControllerTest.java +++ /dev/null @@ -1,101 +0,0 @@ -package org.onap.vid.controllers; - -import org.apache.log4j.BasicConfigurator; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; -import org.onap.vid.dao.FnAppDoaImpl; -import org.springframework.http.MediaType; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; - -import java.sql.SQLException; - -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.BDDMockito.given; -import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR; -import static org.springframework.http.HttpStatus.OK; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -@RunWith(MockitoJUnitRunner.class) -public class HealthCheckControllerTest { - - private static final String ERROR_MESSAGE = "error message"; - private HealthCheckController testSubject; - private MockMvc mockMvc; - - @Mock - private FnAppDoaImpl fnAppDoa; - - @Before - public void setUp() { - testSubject = new HealthCheckController(fnAppDoa); - BasicConfigurator.configure(); - mockMvc = MockMvcBuilders.standaloneSetup(testSubject).build(); - } - - @Test - public void getHealthCheckStatusForIDNS_shouldReturnSuccess_whenNoExceptionIsThrown() throws Exception { - databaseConnectionEstablished(); - mockMvc.perform(get("/healthCheck") - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.statusCode").value(OK.value())) - .andExpect(jsonPath("$.detailedMsg").value("health check succeeded")); - } - - @Test - public void getHealthCheckStatusForIDNS_shouldReturnErrorCode_whenExceptionIsThrown() throws Exception { - databaseNotAccessible(); - mockMvc.perform(get("/healthCheck") - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.statusCode").value(INTERNAL_SERVER_ERROR.value())) - .andExpect(jsonPath("$.detailedMsg").value("health check failed: " + ERROR_MESSAGE)); - } - - @Test - public void getHealthCheck_shouldReturnSuccess_whenNoExceptionIsThrown() throws Exception { - databaseConnectionEstablished(); - mockMvc.perform(get("/rest/healthCheck/{User-Agent}/{X-ECOMP-RequestID}", "userAgent", "requestId") - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.statusCode").value(OK.value())) - .andExpect(jsonPath("$.detailedMsg").value("health check succeeded")) - .andExpect(jsonPath("$.date").isString()); - } - - @Test - public void getHealthCheck_shouldReturnErrorCode_whenExceptionIsThrown() throws Exception { - databaseNotAccessible(); - mockMvc.perform(get("/rest/healthCheck/{User-Agent}/{X-ECOMP-RequestID}", "userAgent", "requestId") - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.statusCode").value(INTERNAL_SERVER_ERROR.value())) - .andExpect(jsonPath("$.detailedMsg").value("health check failed: " + ERROR_MESSAGE)); - } - - @Test - public void getCommitInfo_shouldReturnCommitData_whenCorrectPropertiesFileExists() throws Exception { - mockMvc.perform(get("/commitInfo") - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(jsonPath("$.commitId").value("123")) - .andExpect(jsonPath("$.commitMessageShort").value("Test short commit message")) - .andExpect(jsonPath("$.commitTime").value("1999-09-12T13:48:55+0200")); - } - - private void databaseConnectionEstablished() throws SQLException { - given(fnAppDoa.getProfileCount(anyString(), anyString(), anyString())) - .willReturn(0); - } - - private void databaseNotAccessible() throws SQLException { - given(fnAppDoa.getProfileCount(anyString(), anyString(), anyString())) - .willThrow(new SQLException(ERROR_MESSAGE)); - } -}
\ No newline at end of file diff --git a/vid-app-common/src/test/java/org/onap/vid/controllers/LocalWebConfig.java b/vid-app-common/src/test/java/org/onap/vid/controllers/LocalWebConfig.java deleted file mode 100644 index 59fed3343..000000000 --- a/vid-app-common/src/test/java/org/onap/vid/controllers/LocalWebConfig.java +++ /dev/null @@ -1,70 +0,0 @@ -package org.onap.vid.controllers; - -import com.fasterxml.jackson.databind.ObjectMapper; -import org.apache.commons.io.IOUtils; -import org.json.JSONObject; -import org.json.JSONTokener; -import org.onap.vid.aai.AaiClient; -import org.onap.vid.aai.AaiClientInterface; -import org.onap.vid.asdc.AsdcClient; -import org.onap.vid.asdc.local.LocalAsdcClient; -import org.onap.vid.asdc.parser.ToscaParserImpl2; -import org.onap.vid.controllers.VidController; -import org.onap.vid.services.AaiService; -import org.onap.vid.services.AaiServiceImpl; -import org.onap.vid.services.VidService; -import org.onap.vid.services.VidServiceImpl; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import java.io.IOException; -import java.io.InputStream; - -@Configuration -public class LocalWebConfig { - - /** - * Gets the object mapper. - * - * @return the object mapper - */ - @Bean - public ObjectMapper getObjectMapper() { - return new ObjectMapper(); - } - - - @Bean - public VidService vidService(AsdcClient asdcClient) { - return new VidServiceImpl(asdcClient, null); - } - - @Bean - public AaiService getAaiService() { - return new AaiServiceImpl(); - } - - @Bean - public AaiClientInterface getAaiClientInterface() { - return new AaiClient(null,null); - } - - @Bean - public AsdcClient asdcClient() throws IOException { - - - final InputStream asdcServicesFile = VidController.class.getClassLoader().getResourceAsStream("sdcservices.json"); - - final JSONTokener jsonTokener = new JSONTokener(IOUtils.toString(asdcServicesFile)); - final JSONObject sdcServicesCatalog = new JSONObject(jsonTokener); - - return new LocalAsdcClient.Builder().catalog(sdcServicesCatalog).build(); - - } - - @Bean - public ToscaParserImpl2 getToscaParser() { - return new ToscaParserImpl2(); - } - -} diff --git a/vid-app-common/src/test/java/org/onap/vid/controllers/LoggerControllerTest.java b/vid-app-common/src/test/java/org/onap/vid/controllers/LoggerControllerTest.java deleted file mode 100644 index 5a3002aba..000000000 --- a/vid-app-common/src/test/java/org/onap/vid/controllers/LoggerControllerTest.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.onap.vid.controllers; - -import static org.junit.Assert.*; -import java.util.*; -import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.NotAuthorizedException; - -import org.junit.Assert; -import org.junit.Test; -import org.onap.vid.model.ExceptionResponse; - - -public class LoggerControllerTest { - - private LoggerController createTestSubject() { - return new LoggerController(); - } - - /*@Test - public void testGetLog() throws Exception { - LoggerController testSubject; - String loggerName = ""; - HttpServletRequest request = null; - Integer limit = 0; - String result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getLog(loggerName, request, limit); - }*/ - - - @Test - public void testNotAuthorizedHandler() throws Exception { - LoggerController testSubject; - NotAuthorizedException e = null; - String result; - - // default test - testSubject = createTestSubject(); - result = testSubject.notAuthorizedHandler(e); - } - - /*@Test - public void testIoExceptionHandler() throws Exception { - LoggerController testSubject; - Exception e = null; - ExceptionResponse result; - - // default test - testSubject = createTestSubject(); - result = testSubject.ioExceptionHandler(e); - }*/ -}
\ No newline at end of file diff --git a/vid-app-common/src/test/java/org/onap/vid/controllers/MaintenanceControllerTest.java b/vid-app-common/src/test/java/org/onap/vid/controllers/MaintenanceControllerTest.java deleted file mode 100644 index 3a9d88f07..000000000 --- a/vid-app-common/src/test/java/org/onap/vid/controllers/MaintenanceControllerTest.java +++ /dev/null @@ -1,339 +0,0 @@ -package org.onap.vid.controllers; - -/*- - * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Copyright © 2018 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Modifications Copyright 2018 Nokia - * ================================================================================ - * 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========================================================= - */ - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import org.apache.log4j.BasicConfigurator; -import org.codehaus.jackson.map.ObjectMapper; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.ArgumentMatcher; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; -import org.onap.vid.category.AddCategoryOptionResponse; -import org.onap.vid.category.AddCategoryOptionsRequest; -import org.onap.vid.category.CategoryParameterOptionRep; -import org.onap.vid.category.CategoryParametersResponse; -import org.onap.vid.model.CategoryParameter; -import org.onap.vid.model.CategoryParameterOption; -import org.onap.vid.services.CategoryParameterService; -import org.onap.vid.services.CategoryParameterServiceImpl; -import org.springframework.http.MediaType; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.ResultActions; -import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; -import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; - -import javax.ws.rs.ForbiddenException; -import java.util.Collections; -import java.util.function.BiFunction; - -import static org.mockito.ArgumentMatchers.argThat; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.BDDMockito.*; -import static org.mockito.Mockito.times; -import static org.onap.vid.model.CategoryParameter.Family.PARAMETER_STANDARDIZATION; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -@RunWith(MockitoJUnitRunner.class) -public class MaintenanceControllerTest { - - final private String MAINTENANCE_CATEGORY_PATH = "/maintenance/category_parameter"; - final private String CATEGORY_PARAMETER_PATH = MAINTENANCE_CATEGORY_PATH + "/{name}"; - final private String DELETE_CATEGORY_PATH = "/maintenance/delete_category_parameter/{name}"; - - @Mock - private CategoryParameterService service; - private MaintenanceController maintenanceController; - private MockMvc mockMvc; - private ObjectMapper objectMapper; - - @Before - public void setUp() { - maintenanceController = new MaintenanceController(service); - BasicConfigurator.configure(); - mockMvc = MockMvcBuilders.standaloneSetup(maintenanceController).build(); - objectMapper = new ObjectMapper(); - } - - @Test - public void addCategoryOptions_shouldReturnMultiStatus_whenErrorsExist() throws Exception { - String categoryName = "catName1"; - AddCategoryOptionsRequest req = new AddCategoryOptionsRequest(); - req.options = ImmutableList.of("first option", "second option"); - AddCategoryOptionResponse addCategoryOptionResponse = new AddCategoryOptionResponse( - ImmutableList.of("error one", "error two")); - - given(service.createCategoryParameterOptions(eq(categoryName), argThat(requestMatcher(req)))) - .willReturn(addCategoryOptionResponse); - - prepareRequestExpectations(MockMvcRequestBuilders::post, CATEGORY_PARAMETER_PATH, categoryName, - objectMapper.writeValueAsString(req)) - .andExpect(status().isMultiStatus()) - .andExpect( - content().json(objectMapper - .writeValueAsString(addCategoryOptionResponse))); - } - - @Test - public void addCategoryOptions_shouldReturnOk_whenNoErrorsExist() throws Exception { - String categoryName = "catName2"; - AddCategoryOptionsRequest req = new AddCategoryOptionsRequest(); - req.options = ImmutableList.of("first option", "second option", "third option"); - AddCategoryOptionResponse addCategoryOptionResponse = new AddCategoryOptionResponse(Collections.emptyList()); - - given(service.createCategoryParameterOptions(eq(categoryName), argThat(requestMatcher(req)))) - .willReturn(addCategoryOptionResponse); - prepareRequestExpectations(MockMvcRequestBuilders::post, CATEGORY_PARAMETER_PATH, categoryName, - objectMapper.writeValueAsString(req)) - .andExpect(status().isOk()) - .andExpect(content().json( - objectMapper.writeValueAsString(addCategoryOptionResponse))); - } - - @Test - public void addCategoryOptions_shouldReturnNotFound_whenUnfoundedCategoryExceptionIsThrown() throws Exception { - String unfoundedMsg = "unfounded category exception message"; - String categoryName = "catName3"; - AddCategoryOptionsRequest req = new AddCategoryOptionsRequest(); - req.options = ImmutableList.of("first option"); - - given(service.createCategoryParameterOptions(eq(categoryName), argThat(requestMatcher(req)))) - .willThrow(new CategoryParameterServiceImpl.UnfoundedCategoryException(unfoundedMsg)); - - prepareRequestExpectations(MockMvcRequestBuilders::post, CATEGORY_PARAMETER_PATH, categoryName, - objectMapper.writeValueAsString(req)) - .andExpect(status().isNotFound()) - .andExpect(content().json( - objectMapper.writeValueAsString(new AddCategoryOptionResponse(ImmutableList.of(unfoundedMsg))))); - } - - @Test - public void addCategoryOptions_shouldReturnInternalServerError_whenExceptionIsThrown() throws Exception { - String categoryName = "catName13"; - AddCategoryOptionsRequest req = new AddCategoryOptionsRequest(); - req.options = ImmutableList.of("option second", "first option"); - - given(service.createCategoryParameterOptions(eq(categoryName), argThat(requestMatcher(req)))) - .willThrow(new RuntimeException()); - - prepareRequestExpectations(MockMvcRequestBuilders::post, CATEGORY_PARAMETER_PATH, categoryName, - objectMapper.writeValueAsString(req)) - .andExpect(status().isInternalServerError()); - } - - @Test - public void updateNameForOption_shouldReturnMultiStatus_whenErrorsExist() throws Exception { - String categoryName = "catName4"; - CategoryParameterOptionRep categoryParameterOptionRep = new CategoryParameterOptionRep("id1", "name1"); - AddCategoryOptionResponse addCategoryOptionResponse = new AddCategoryOptionResponse( - ImmutableList.of("error one", "error two")); - - given(service - .updateCategoryParameterOption(eq(categoryName), argThat(requestMatcher(categoryParameterOptionRep)))) - .willReturn(addCategoryOptionResponse); - - prepareRequestExpectations(MockMvcRequestBuilders::put, CATEGORY_PARAMETER_PATH, categoryName, - objectMapper.writeValueAsString(categoryParameterOptionRep)) - .andExpect(status().isMultiStatus()) - .andExpect( - content().json(objectMapper - .writeValueAsString(addCategoryOptionResponse))); - } - - @Test - public void updateNameForOption_shouldReturnOk_whenNoErrorsExist() throws Exception { - String categoryName = "catName5"; - CategoryParameterOptionRep categoryParameterOptionRep = new CategoryParameterOptionRep("id2", "name2"); - AddCategoryOptionResponse addCategoryOptionResponse = new AddCategoryOptionResponse(Collections.emptyList()); - - given(service - .updateCategoryParameterOption(eq(categoryName), argThat(requestMatcher(categoryParameterOptionRep)))) - .willReturn(addCategoryOptionResponse); - prepareRequestExpectations(MockMvcRequestBuilders::put, CATEGORY_PARAMETER_PATH, categoryName, - objectMapper.writeValueAsString(categoryParameterOptionRep)) - .andExpect(status().isOk()) - .andExpect(content().json( - objectMapper.writeValueAsString(addCategoryOptionResponse))); - } - - @Test - public void updateNameForOption_shouldReturnForbidden_whenForbiddenExceptionIsThrown() throws Exception { - String categoryName = "catName6"; - CategoryParameterOptionRep categoryParameterOptionRep = new CategoryParameterOptionRep("id3", "name3"); - - given(service - .updateCategoryParameterOption(eq(categoryName), argThat(requestMatcher(categoryParameterOptionRep)))) - .willThrow(new ForbiddenException()); - prepareRequestExpectations(MockMvcRequestBuilders::put, CATEGORY_PARAMETER_PATH, categoryName, - objectMapper.writeValueAsString(categoryParameterOptionRep)) - .andExpect(status().isForbidden()) - .andExpect(content().json( - objectMapper - .writeValueAsString(new AddCategoryOptionResponse(ImmutableList.of("HTTP 403 Forbidden"))))); - } - - @Test - public void updateNameForOption_shouldReturnNotFound_whenUnfoundedIsThrown() throws Exception { - String unfoundedOptionMsg = "unfounded category option exception message"; - String categoryName = "catName7"; - CategoryParameterOptionRep categoryParameterOptionRep = new CategoryParameterOptionRep("id4", "name4"); - - given(service - .updateCategoryParameterOption(eq(categoryName), argThat(requestMatcher(categoryParameterOptionRep)))) - .willThrow(new CategoryParameterServiceImpl.UnfoundedCategoryOptionException(unfoundedOptionMsg)); - - prepareRequestExpectations(MockMvcRequestBuilders::put, CATEGORY_PARAMETER_PATH, categoryName, - objectMapper.writeValueAsString(categoryParameterOptionRep)) - .andExpect(status().isNotFound()) - .andExpect(content().json( - objectMapper.writeValueAsString(new AddCategoryOptionResponse(ImmutableList.of(unfoundedOptionMsg))))); - } - - @Test - public void updateNameForOption_shouldReturnConflict_whenAlreadyExistOptionNameIsThrown() throws Exception { - String conflictMsg = "already exists option name exception message"; - String categoryName = "catName8"; - CategoryParameterOptionRep categoryParameterOptionRep = new CategoryParameterOptionRep("id5", "name5"); - - given(service - .updateCategoryParameterOption(eq(categoryName), argThat(requestMatcher(categoryParameterOptionRep)))) - .willThrow(new CategoryParameterServiceImpl.AlreadyExistOptionNameException(conflictMsg)); - - prepareRequestExpectations(MockMvcRequestBuilders::put, CATEGORY_PARAMETER_PATH, categoryName, - objectMapper.writeValueAsString(categoryParameterOptionRep)) - .andExpect(status().isConflict()) - .andExpect(content().json( - objectMapper.writeValueAsString(new AddCategoryOptionResponse(ImmutableList.of(conflictMsg))))); - } - - @Test - public void updateNameForOption_shouldReturnInternalServerError_whenExceptionIsThrown() throws Exception { - String categoryName = "catName18"; - CategoryParameterOptionRep categoryParameterOptionRep = new CategoryParameterOptionRep("id6", "name6"); - - given(service - .updateCategoryParameterOption(eq(categoryName), argThat(requestMatcher(categoryParameterOptionRep)))) - .willThrow(new RuntimeException()); - - prepareRequestExpectations(MockMvcRequestBuilders::put, CATEGORY_PARAMETER_PATH, categoryName, - objectMapper.writeValueAsString(categoryParameterOptionRep)) - .andExpect(status().isInternalServerError()); - } - - @Test - public void getCategoryParameter_shouldReturnExistingMap() throws Exception { - CategoryParametersResponse categoryParametersResponse = - new CategoryParametersResponse( - ImmutableMap.of( - "key1", ImmutableList.of( - new CategoryParameterOptionRep("testId", "testName")))); - - given(service.getCategoryParameters(PARAMETER_STANDARDIZATION)) - .willReturn(categoryParametersResponse); - - mockMvc.perform(get(MAINTENANCE_CATEGORY_PATH) - .param("familyName", "PARAMETER_STANDARDIZATION") - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(content().json(objectMapper.writeValueAsString(categoryParametersResponse))); - } - - @Test - public void getCategoryParameter_shouldReturnInternalServerError_whenExceptionIsThrown() throws Exception { - given(service.getCategoryParameters(PARAMETER_STANDARDIZATION)) - .willThrow(new RuntimeException()); - - mockMvc.perform(get(MAINTENANCE_CATEGORY_PATH) - .param("familyName", "PARAMETER_STANDARDIZATION") - .accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isInternalServerError()); - } - - @Test - public void deleteCategoryOption_shouldReturnOk_whenNoExceptionIsThrown() throws Exception { - String categoryName = "catName9"; - CategoryParameterOption categoryParameterOption = new CategoryParameterOption("id1", "name1", - new CategoryParameter()); - - prepareRequestExpectations(MockMvcRequestBuilders::delete, DELETE_CATEGORY_PATH, categoryName, - objectMapper.writeValueAsString(categoryParameterOption)) - .andExpect(status().isOk()); - - then(service).should(times(1)) - .deleteCategoryOption(eq(categoryName), argThat(requestMatcher(categoryParameterOption))); - } - - @Test - public void deleteCategoryOption_shouldReturnNotFound_whenUnfoundedExceptionIsThrown() throws Exception { - String unfoundedMsg = "unfounded category exception message"; - String categoryName = "catName10"; - CategoryParameterOption categoryParameterOption = new CategoryParameterOption("id2", "name2", - new CategoryParameter()); - - willThrow(new CategoryParameterServiceImpl.UnfoundedCategoryException(unfoundedMsg)) - .given(service).deleteCategoryOption(eq(categoryName), argThat(requestMatcher(categoryParameterOption))); - - prepareRequestExpectations(MockMvcRequestBuilders::delete, DELETE_CATEGORY_PATH, categoryName, - objectMapper.writeValueAsString(categoryParameterOption)) - .andExpect(status().isNotFound()) - .andExpect(content().json( - objectMapper.writeValueAsString(new AddCategoryOptionResponse(ImmutableList.of(unfoundedMsg))))); - } - - @Test - public void deleteCategoryOption_shouldReturnInternalServerError_whenExceptionIsThrown() throws Exception { - String categoryName = "catName19"; - CategoryParameterOption categoryParameterOption = new CategoryParameterOption("id3", "name3", - new CategoryParameter()); - - willThrow(new RuntimeException()).given(service) - .deleteCategoryOption(eq(categoryName), argThat(requestMatcher(categoryParameterOption))); - - prepareRequestExpectations(MockMvcRequestBuilders::delete, DELETE_CATEGORY_PATH, categoryName, - objectMapper.writeValueAsString(categoryParameterOption)) - .andExpect(status().isInternalServerError()); - } - - private <T> ArgumentMatcher<T> requestMatcher(T t) { - return new ArgumentMatcher<T>() { - @Override - public boolean matches(Object o) { - return t.equals(o); - } - }; - } - - private ResultActions prepareRequestExpectations( - BiFunction<String, String, MockHttpServletRequestBuilder> httpMethod, - String path, String name, String jsonContent) throws Exception { - return mockMvc.perform(httpMethod.apply(path, name) - .contentType(MediaType.APPLICATION_JSON) - .content(jsonContent)); - } -}
\ No newline at end of file diff --git a/vid-app-common/src/test/java/org/onap/vid/controllers/MsoControllerNewTest.java b/vid-app-common/src/test/java/org/onap/vid/controllers/MsoControllerNewTest.java deleted file mode 100644 index d1e09ce8d..000000000 --- a/vid-app-common/src/test/java/org/onap/vid/controllers/MsoControllerNewTest.java +++ /dev/null @@ -1,391 +0,0 @@ -package org.onap.vid.controllers; - -import static org.junit.Assert.*; - -import javax.servlet.http.HttpServletRequest; - -import org.junit.Test; -import org.onap.vid.mso.MsoBusinessLogicImpl; -import org.onap.vid.mso.rest.RequestDetails; -import org.onap.vid.mso.rest.RequestDetailsWrapper; -import org.springframework.http.ResponseEntity; - -public class MsoControllerNewTest { - - private MsoController createTestSubject() { - try { - return new MsoController(new MsoBusinessLogicImpl(null,null)); - } catch (Exception e) { - return null; - } - } - - @Test - public void testCreateSvcInstance() throws Exception { - MsoController testSubject; - HttpServletRequest request = null; - RequestDetails mso_request = null; - ResponseEntity<String> result; - - // default test - try { - testSubject = createTestSubject(); - result = testSubject.createSvcInstance(request, mso_request); - } catch (Exception e) { - } - } - - @Test - public void testCreateVnf() throws Exception { - MsoController testSubject; - String serviceInstanceId = ""; - HttpServletRequest request = null; - RequestDetails mso_request = null; - ResponseEntity<String> result; - - // default test - try { - testSubject = createTestSubject(); - result = testSubject.createVnf(serviceInstanceId, request, mso_request); - } catch (Exception e) { - } - } - - @Test - public void testCreateNwInstance() throws Exception { - MsoController testSubject; - String serviceInstanceId = ""; - HttpServletRequest request = null; - RequestDetails mso_request = null; - ResponseEntity<String> result; - - // default test - try { - testSubject = createTestSubject(); - result = testSubject.createNwInstance(serviceInstanceId, request, mso_request); - } catch (Exception e) { - } - } - - @Test - public void testCreateVolumeGroupInstance() throws Exception { - MsoController testSubject; - String serviceInstanceId = ""; - String vnfInstanceId = ""; - HttpServletRequest request = null; - RequestDetails mso_request = null; - ResponseEntity<String> result; - - // default test - try { - testSubject = createTestSubject(); - result = testSubject.createVolumeGroupInstance(serviceInstanceId, vnfInstanceId, request, mso_request); - } catch (Exception e) { - } - } - - @Test - public void testCreateVfModuleInstance() throws Exception { - MsoController testSubject; - String serviceInstanceId = ""; - String vnfInstanceId = ""; - HttpServletRequest request = null; - RequestDetails mso_request = null; - ResponseEntity<String> result; - - // default test - try { - testSubject = createTestSubject(); - result = testSubject.createVfModuleInstance(serviceInstanceId, vnfInstanceId, request, mso_request); - } catch (Exception e) { - } - } - - @Test - public void testCreateConfigurationInstance() throws Exception { - MsoController testSubject; - String serviceInstanceId = ""; - HttpServletRequest request = null; - RequestDetailsWrapper mso_request = null; - ResponseEntity<String> result; - - // default test - try { - testSubject = createTestSubject(); - result = testSubject.createConfigurationInstance(serviceInstanceId, request, mso_request); - } catch (Exception e) { - } - } - - @Test - public void testDeleteSvcInstance() throws Exception { - MsoController testSubject; - String serviceInstanceId = ""; - HttpServletRequest request = null; - RequestDetails mso_request = null; - String result; - - // default test - try { - testSubject = createTestSubject(); - result = testSubject.deleteSvcInstance(serviceInstanceId, request, mso_request, ""); - } catch (Exception e) { - } - } - - @Test - public void testDeleteVnf() throws Exception { - MsoController testSubject; - String serviceInstanceId = ""; - String vnfInstanceId = ""; - HttpServletRequest request = null; - RequestDetails mso_request = null; - ResponseEntity<String> result; - - // default test - try { - testSubject = createTestSubject(); - result = testSubject.deleteVnf(serviceInstanceId, vnfInstanceId, request, mso_request); - } catch (Exception e) { - } - } - - @Test - public void testDeleteConfiguration() throws Exception { - MsoController testSubject; - String serviceInstanceId = ""; - String configurationId = ""; - RequestDetailsWrapper mso_request = null; - ResponseEntity<String> result; - - // default test - try { - testSubject = createTestSubject(); - result = testSubject.deleteConfiguration(serviceInstanceId, configurationId, mso_request); - } catch (Exception e) { - } - } - - @Test - public void testActivateConfiguration() throws Exception { - MsoController testSubject; - String serviceInstanceId = ""; - String configurationId = ""; - RequestDetails mso_request = null; - ResponseEntity<String> result; - - // default test - try { - testSubject = createTestSubject(); - result = testSubject.activateConfiguration(serviceInstanceId, configurationId, mso_request); - } catch (Exception e) { - } - } - - @Test - public void testDeactivateConfiguration() throws Exception { - MsoController testSubject; - String serviceInstanceId = ""; - String configurationId = ""; - RequestDetails mso_request = null; - ResponseEntity<String> result; - - // default test - try { - testSubject = createTestSubject(); - result = testSubject.deactivateConfiguration(serviceInstanceId, configurationId, mso_request); - } catch (Exception e) { - } - } - - @Test - public void testDisablePortOnConfiguration() throws Exception { - MsoController testSubject; - String serviceInstanceId = ""; - String configurationId = ""; - RequestDetails mso_request = null; - ResponseEntity<String> result; - - // default test - try { - testSubject = createTestSubject(); - result = testSubject.disablePortOnConfiguration(serviceInstanceId, configurationId, mso_request); - } catch (Exception e) { - } - } - - @Test - public void testEnablePortOnConfiguration() throws Exception { - MsoController testSubject; - String serviceInstanceId = ""; - String configurationId = ""; - RequestDetails mso_request = null; - ResponseEntity<String> result; - - // default test - try { - testSubject = createTestSubject(); - result = testSubject.enablePortOnConfiguration(serviceInstanceId, configurationId, mso_request); - } catch (Exception e) { - } - } - - @Test - public void testDeleteVfModule() throws Exception { - MsoController testSubject; - String serviceInstanceId = ""; - String vnfInstanceId = ""; - String vfModuleId = ""; - HttpServletRequest request = null; - RequestDetails mso_request = null; - ResponseEntity<String> result; - - // default test - try { - testSubject = createTestSubject(); - result = testSubject.deleteVfModule(serviceInstanceId, vnfInstanceId, vfModuleId, request, mso_request); - } catch (Exception e) { - } - } - - @Test - public void testDeleteVolumeGroupInstance() throws Exception { - MsoController testSubject; - String serviceInstanceId = ""; - String vnfInstanceId = ""; - String volumeGroupId = ""; - HttpServletRequest request = null; - RequestDetails mso_request = null; - ResponseEntity<String> result; - - // default test - try { - testSubject = createTestSubject(); - result = testSubject.deleteVolumeGroupInstance(serviceInstanceId, vnfInstanceId, volumeGroupId, request, - mso_request); - } catch (Exception e) { - } - } - - @Test - public void testDeleteNwInstance() throws Exception { - MsoController testSubject; - String serviceInstanceId = ""; - String networkInstanceId = ""; - HttpServletRequest request = null; - RequestDetails mso_request = null; - ResponseEntity<String> result; - - // default test - try { - testSubject = createTestSubject(); - result = testSubject.deleteNwInstance(serviceInstanceId, networkInstanceId, request, mso_request); - } catch (Exception e) { - } - } - - @Test - public void testGetOrchestrationRequest() throws Exception { - MsoController testSubject; - String requestId = ""; - HttpServletRequest request = null; - ResponseEntity<String> result; - - // default test - try { - testSubject = createTestSubject(); - result = testSubject.getOrchestrationRequest(requestId, request); - } catch (Exception e) { - } - } - - @Test - public void testGetOrchestrationRequests() throws Exception { - MsoController testSubject; - String filterString = ""; - HttpServletRequest request = null; - ResponseEntity<String> result; - - // default test - try { - testSubject = createTestSubject(); - result = testSubject.getOrchestrationRequests(filterString, request); - } catch (Exception e) { - } - } - - @Test - public void testActivateServiceInstance() throws Exception { - MsoController testSubject; - String serviceInstanceId = ""; - RequestDetails requestDetails = null; - ResponseEntity<String> result; - - // default test - try { - testSubject = createTestSubject(); - result = testSubject.activateServiceInstance(serviceInstanceId, requestDetails); - } catch (Exception e) { - } - } - - @Test - public void testDeactivateServiceInstance() throws Exception { - MsoController testSubject; - String serviceInstanceId = ""; - RequestDetails requestDetails = null; - ResponseEntity<String> result; - - // default test - try { - testSubject = createTestSubject(); - result = testSubject.deactivateServiceInstance(serviceInstanceId, requestDetails); - } catch (Exception e) { - } - } - - @Test - public void testManualTaskComplete() throws Exception { - MsoController testSubject; - String taskId = ""; - RequestDetails requestDetails = null; - ResponseEntity<String> result; - - // default test - try { - testSubject = createTestSubject(); - result = testSubject.manualTaskComplete(taskId, requestDetails); - } catch (Exception e) { - } - } - - @Test - public void testRemoveRelationshipFromServiceInstance() throws Exception { - MsoController testSubject; - String serviceInstanceId = ""; - RequestDetails requestDetails = null; - ResponseEntity<String> result; - - // default test - try { - testSubject = createTestSubject(); - result = testSubject.removeRelationshipFromServiceInstance(serviceInstanceId, requestDetails); - } catch (Exception e) { - } - } - - @Test - public void testAddRelationshipToServiceInstance() throws Exception { - MsoController testSubject; - String serviceInstanceId = ""; - RequestDetails requestDetails = null; - ResponseEntity<String> result; - - // default test - try { - testSubject = createTestSubject(); - result = testSubject.addRelationshipToServiceInstance(serviceInstanceId, requestDetails); - } catch (Exception e) { - } - } -} diff --git a/vid-app-common/src/test/java/org/onap/vid/controllers/MsoControllerTest.java b/vid-app-common/src/test/java/org/onap/vid/controllers/MsoControllerTest.java deleted file mode 100644 index 0d1559548..000000000 --- a/vid-app-common/src/test/java/org/onap/vid/controllers/MsoControllerTest.java +++ /dev/null @@ -1,109 +0,0 @@ -package org.onap.vid.controllers; - -import org.apache.commons.lang.StringEscapeUtils; -import org.onap.portalsdk.core.util.SystemProperties; -import org.onap.vid.controllers.MsoConfig; -import org.onap.vid.controllers.MsoController; -import org.onap.vid.domain.mso.RequestInfo; -import org.onap.vid.factories.MsoRequestFactory; -import org.onap.vid.mso.rest.Request; -import org.onap.vid.mso.rest.RequestDetails; -import org.onap.vid.mso.rest.Task; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.ResponseEntity; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; -import org.springframework.test.context.web.WebAppConfiguration; -import org.testng.Assert; -import org.testng.Assert.*; -import org.testng.annotations.Test; - -import java.util.List; - - -@WebAppConfiguration -@ContextConfiguration(classes = {SystemProperties.class, MsoConfig.class}) -public class MsoControllerTest extends AbstractTestNGSpringContextTests { - - @Autowired - MsoRequestFactory msoRequestFactory; - - @Test(enabled = false) - public void testInstanceCreationNew() throws Exception { - - RequestDetails requestDetails = msoRequestFactory.createMsoRequest("msoRequest.json"); - MsoController msoController = new MsoController(null); - //TODO: make ths test to really test something - //ResponseEntity<String> responseEntityNew = msoController.createSvcInstanceNew(null, requestDetails); - ResponseEntity<String> responseEntity = msoController.createSvcInstance(null, requestDetails); - //Assert.assertEquals(responseEntityNew, responseEntity); - - } - - @Test(enabled = false) - public void testInstanceCreationLocalWithRest() throws Exception { - - RequestDetails requestDetails = msoRequestFactory.createMsoRequest("msoRequest.json"); - MsoController msoController = new MsoController(null); - ResponseEntity<String> responseEntityNew = msoController.createSvcInstance(null, requestDetails); - //TODO: make ths test to really test something -// ResponseEntity<String> responseEntityRest = msoController.createSvcInstanceNewRest(null, requestDetails); -// -// Assert.assertEquals(responseEntityNew.getBody(), responseEntityRest.getBody()); - - } - - @Test(enabled = false) - public void testInstanceCreation() throws Exception { - - RequestDetails requestDetails = msoRequestFactory.createMsoRequest("msoRequest.json"); - MsoController msoController = new MsoController(null); - ResponseEntity<String> responseEntity = msoController.createSvcInstance(null, requestDetails); - - - Assert.assertEquals(responseEntity.getBody(), "{ \"status\": 200, \"entity\": {\n" + - " \"requestReferences\": {\n" + - " \"instanceId\": \"ba00de9b-3c3e-4b0a-a1ad-0c5489e711fb\",\n" + - " \"requestId\": \"311cc766-b673-4a50-b9c5-471f68914586\"\n" + - " }\n" + - "}}"); - - } - - @Test(enabled = false) - public void testGetOrchestrationRequestsForDashboard() throws Exception { - MsoController msoController = new MsoController(null); - List<Request> orchestrationRequestsForDashboard = msoController.getOrchestrationRequestsForDashboard(); - - Assert.assertEquals(orchestrationRequestsForDashboard.size(), 2); - } - - @Test(enabled = false) - public void testGetManualTasksByRequestId() throws Exception { - MsoController msoController = new MsoController(null); - List<Task> orchestrationRequestsForDashboard = msoController.getManualTasksByRequestId("za1234d1-5a33-55df-13ab-12abad84e335"); - - Assert. assertEquals(orchestrationRequestsForDashboard.get(0).getTaskId(), "daf4dd84-b77a-42da-a051-3239b7a9392c"); - } - - - public void testCompleteManualTask() throws Exception { // TODO not done yet - RequestInfo requestInfo = new RequestInfo(); - requestInfo.setResponseValue("rollback"); - requestInfo.setRequestorId("abc"); - requestInfo.setSource("VID"); - RequestDetails requestDetails = new RequestDetails(); - requestDetails.setRequestInfo(requestInfo); - MsoController msoController = new MsoController(null); - ResponseEntity<String> responseEntity = msoController.manualTaskComplete("daf4dd84-b77a-42da-a051-3239b7a9392c", requestDetails); - String assertString = "{ \\\"status\\\": 200, \\\"entity\\\": {\\n\" +\n" + - " \" \\\"taskRequestReference\\\": {\\n\" +\n" + - " \" \\\"taskId\\\": \\\"daf4dd84-b77a-42da-a051-3239b7a9392c\\\"\\n\" +\n" + - " \" }\\n\" +\n" + - " \"}\\n\" +\n" + - " \"}"; - Assert.assertEquals(responseEntity.getBody(), StringEscapeUtils.unescapeJava(assertString)); - } - - -} diff --git a/vid-app-common/src/test/java/org/onap/vid/controllers/PolicyControllerTest.java b/vid-app-common/src/test/java/org/onap/vid/controllers/PolicyControllerTest.java deleted file mode 100644 index 33bed45ec..000000000 --- a/vid-app-common/src/test/java/org/onap/vid/controllers/PolicyControllerTest.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.onap.vid.controllers; - -import javax.servlet.http.HttpServletRequest; - -import org.json.simple.JSONObject; -import org.junit.Test; -import org.onap.vid.policy.PolicyResponseWrapper; -import org.springframework.http.ResponseEntity; - -public class PolicyControllerTest { - - private PolicyController createTestSubject() { - return new PolicyController(); - } - - @Test - public void testGetPolicyInfo() throws Exception { - PolicyController testSubject; - HttpServletRequest request = null; - JSONObject policy_request = null; - ResponseEntity<String> result; - - // default test - try { - testSubject = createTestSubject(); - result = testSubject.getPolicyInfo(request, policy_request); - }catch(Exception e){} - } - -}
\ No newline at end of file diff --git a/vid-app-common/src/test/java/org/onap/vid/controllers/PromiseEcompRequestIdFilterTest.java b/vid-app-common/src/test/java/org/onap/vid/controllers/PromiseEcompRequestIdFilterTest.java deleted file mode 100644 index f17403955..000000000 --- a/vid-app-common/src/test/java/org/onap/vid/controllers/PromiseEcompRequestIdFilterTest.java +++ /dev/null @@ -1,169 +0,0 @@ -package org.onap.vid.controllers; - -import com.google.common.collect.ImmutableMap; -import org.mockito.ArgumentCaptor; -import org.mockito.Mockito; -import org.mockito.stubbing.Answer; -import org.onap.portalsdk.core.web.support.UserUtils; -import org.onap.vid.controller.filter.PromiseEcompRequestIdFilter; -import org.springframework.mock.web.MockHttpServletResponse; -import org.testng.annotations.Test; - -import javax.servlet.FilterChain; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.util.*; -import java.util.function.Function; - -import static org.apache.commons.lang3.StringUtils.equalsIgnoreCase; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.argThat; -import static org.onap.portalsdk.core.util.SystemProperties.ECOMP_REQUEST_ID; - -@Test -public class PromiseEcompRequestIdFilterTest { - - private final String anotherHeader = "ANDREI_RUBLEV"; - private final String anotherValue = "foo value"; - private final String mixedCaseHeader = "x-ecomp-REQUESTID"; - - @Test - public void givenRequestIdHeader_headerValueNotChanged() throws IOException, ServletException { - - final String someTxId = "863850e2-8545-4efd-94b8-afba5f52b3d5"; - - final ImmutableMap<String, String> incomingRequestHeaders = ImmutableMap.of( - anotherHeader, anotherValue, - ECOMP_REQUEST_ID, someTxId - ); - - buildRequestThenRunThroughFilterAndAssertResultRequestHeaders(incomingRequestHeaders, specificTxId(someTxId)); - } - - @Test - public void givenMixedCaseRequestIdHeader_headerValueNotChanged() throws IOException, ServletException { - - final String someTxId = "729bbd8d-b0c2-4809-a794-dcccd9cda2c0"; - - final ImmutableMap<String, String> incomingRequestHeaders = ImmutableMap.of( - mixedCaseHeader, someTxId, - anotherHeader, anotherValue - ); - - buildRequestThenRunThroughFilterAndAssertResultRequestHeaders(incomingRequestHeaders, specificTxId(someTxId)); - } - - @Test - public void givenNoRequestIdHeader_headerValueWasGenerated() throws IOException, ServletException { - - final ImmutableMap<String, String> incomingRequestHeaders = ImmutableMap.of( - anotherHeader, anotherValue - ); - - buildRequestThenRunThroughFilterAndAssertResultRequestHeaders(incomingRequestHeaders, UserUtils::getRequestId); - } - - - private void buildRequestThenRunThroughFilterAndAssertResultRequestHeaders( - ImmutableMap<String, String> originalRequestHeaders, - Function<HttpServletRequest, String> txIdExtractor - ) throws IOException, ServletException { - HttpServletRequest servletRequest = createMockedHttpServletRequest(originalRequestHeaders); - HttpServletResponse servletResponse = createMockedHttpServletResponse(); - - final FilterChain capturingFilterChain = Mockito.mock(FilterChain.class); - - ////////////////// - // - // doFilter() is the function under test - // - new PromiseEcompRequestIdFilter().doFilter(servletRequest, servletResponse, capturingFilterChain); - // - ////////////////// - - final ServletRequest capturedServletRequest = extractCapturedServletRequest(capturingFilterChain); - final ServletResponse capturedServletResponse = extractCapturedServletResponse(capturingFilterChain); - final String expectedTxId = txIdExtractor.apply((HttpServletRequest) capturedServletRequest); - - assertRequestObjectHeaders(capturedServletRequest, expectedTxId); - assertResponseObjectHeaders(capturedServletResponse, expectedTxId); - } - - - private void assertRequestObjectHeaders(ServletRequest request, String expectedTxId) { - /* - Assert that: - - Two headers are in place - - Direct value extraction is as expected - - UserUtils.getRequestId() returns correct and valid value - */ - final HttpServletRequest httpServletRequest = (HttpServletRequest) request; - - assertThat(Collections.list(httpServletRequest.getHeaderNames()), - containsInAnyOrder(equalToIgnoringCase(ECOMP_REQUEST_ID), equalToIgnoringCase(anotherHeader))); - - assertThat(httpServletRequest.getHeader(anotherHeader), is(anotherValue)); - - assertThat(httpServletRequest.getHeader(ECOMP_REQUEST_ID), is(expectedTxId)); - assertThat(httpServletRequest.getHeader(mixedCaseHeader), is(expectedTxId)); - - assertThat(UserUtils.getRequestId(httpServletRequest), is(expectedTxId)); - assertThat(UserUtils.getRequestId(httpServletRequest), is(not(emptyOrNullString()))); - } - - private void assertResponseObjectHeaders(ServletResponse response, String txId) { - final String REQUEST_ID_HEADER_NAME_IN_RESPONSE = mixedCaseHeader + "-echo"; - final HttpServletResponse httpServletResponse = (HttpServletResponse) response; - - assertThat("header " + REQUEST_ID_HEADER_NAME_IN_RESPONSE.toLowerCase() + " in response must be provided", - httpServletResponse.getHeader(REQUEST_ID_HEADER_NAME_IN_RESPONSE), is(txId)); - } - - - - private HttpServletRequest createMockedHttpServletRequest(Map<String, String> requestHeaders) { - HttpServletRequest servletRequest = Mockito.mock(HttpServletRequest.class); - requestHeaders.forEach((k, v) -> { - Mockito.when(servletRequest.getHeader(argThat(s -> equalsIgnoreCase(s, k)))).thenReturn(v); - Mockito.when(servletRequest.getHeaders(argThat(s -> equalsIgnoreCase(s, k)))).then(returnEnumerationAnswer(v)); - }); - Mockito.when(servletRequest.getHeaderNames()).then(returnEnumerationAnswer(requestHeaders.keySet())); - return servletRequest; - } - - private HttpServletResponse createMockedHttpServletResponse() { - return new MockHttpServletResponse(); - } - - private static Answer<Enumeration<String>> returnEnumerationAnswer(String ... items) { - return returnEnumerationAnswer(Arrays.asList(items)); - } - - private static Answer<Enumeration<String>> returnEnumerationAnswer(Collection<String> items) { - return invocation -> Collections.enumeration(items); - } - - private Function<HttpServletRequest, String> specificTxId(String someTxId) { - return r -> someTxId; - } - - private ServletRequest extractCapturedServletRequest(FilterChain capturingFilterChain) throws IOException, ServletException { - ArgumentCaptor<ServletRequest> captor = ArgumentCaptor.forClass(ServletRequest.class); - Mockito.verify(capturingFilterChain).doFilter(captor.capture(), any()); - return captor.getValue(); - } - - private ServletResponse extractCapturedServletResponse(FilterChain capturingFilterChain) throws IOException, ServletException { - ArgumentCaptor<ServletResponse> captor = ArgumentCaptor.forClass(ServletResponse.class); - Mockito.verify(capturingFilterChain).doFilter(any(), captor.capture()); - return captor.getValue(); - } - -} diff --git a/vid-app-common/src/test/java/org/onap/vid/controllers/PropertyControllerTest.java b/vid-app-common/src/test/java/org/onap/vid/controllers/PropertyControllerTest.java deleted file mode 100644 index b4a6a8f96..000000000 --- a/vid-app-common/src/test/java/org/onap/vid/controllers/PropertyControllerTest.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.onap.vid.controllers; - -import javax.servlet.http.HttpServletRequest; - -import org.junit.Test; -import org.onap.vid.controllers.PropertyController; -import org.springframework.http.ResponseEntity; -import org.springframework.web.servlet.ModelAndView; - -public class PropertyControllerTest { - - private PropertyController createTestSubject() { - return new PropertyController(); - } - - @Test - public void testWelcome() throws Exception { - PropertyController testSubject; - HttpServletRequest request = null; - ModelAndView result; - - // default test - testSubject = createTestSubject(); - result = testSubject.welcome(request); - } - - - @Test - public void testGetProperty() throws Exception { - PropertyController testSubject; - String name = ""; - String defaultvalue = ""; - HttpServletRequest request = null; - ResponseEntity<String> result; - - // default test - testSubject = createTestSubject(); - result = testSubject.getProperty(name, defaultvalue, request); - } -}
\ No newline at end of file diff --git a/vid-app-common/src/test/java/org/onap/vid/controllers/RoleGeneratorControllerTest.java b/vid-app-common/src/test/java/org/onap/vid/controllers/RoleGeneratorControllerTest.java deleted file mode 100644 index 11ab2fccc..000000000 --- a/vid-app-common/src/test/java/org/onap/vid/controllers/RoleGeneratorControllerTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.onap.vid.controllers; - -import org.junit.Test; -import org.springframework.http.ResponseEntity; - -public class RoleGeneratorControllerTest { - - private RoleGeneratorController createTestSubject() { - return new RoleGeneratorController(); - } - - @Test - public void testGenerateRoleScript() throws Exception { - RoleGeneratorController testSubject; - boolean firstRun = false; - ResponseEntity<String> result; - - // default test - try { - testSubject = createTestSubject(); - result = testSubject.generateRoleScript(firstRun); - } catch (Exception e) { - - } - } -}
\ No newline at end of file diff --git a/vid-app-common/src/test/java/org/onap/vid/controllers/ToscaParserMockHelper.java b/vid-app-common/src/test/java/org/onap/vid/controllers/ToscaParserMockHelper.java deleted file mode 100644 index 317c8e505..000000000 --- a/vid-app-common/src/test/java/org/onap/vid/controllers/ToscaParserMockHelper.java +++ /dev/null @@ -1,42 +0,0 @@ -package org.onap.vid.controllers; - -import org.onap.vid.model.NewServiceModel; - -/** - * Created by moriya1 on 04/07/2017. - */ -public class ToscaParserMockHelper { - - private String uuid; - private String filePath; - private NewServiceModel newServiceModel; - - public ToscaParserMockHelper(String uuid, String filePath) { - this.uuid = uuid; - this.filePath = filePath; - } - - public String getUuid() { - return uuid; - } - - public void setUuid(String uuid) { - this.uuid = uuid; - } - - public String getFilePath() { - return filePath; - } - - public void setFilePath(String filePath) { - this.filePath = filePath; - } - - public NewServiceModel getNewServiceModel() { - return newServiceModel; - } - - public void setNewServiceModel(NewServiceModel newServiceModel) { - this.newServiceModel = newServiceModel; - } -} diff --git a/vid-app-common/src/test/java/org/onap/vid/controllers/VidControllerTest.java b/vid-app-common/src/test/java/org/onap/vid/controllers/VidControllerTest.java deleted file mode 100644 index 198680afc..000000000 --- a/vid-app-common/src/test/java/org/onap/vid/controllers/VidControllerTest.java +++ /dev/null @@ -1,204 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * VID - * ================================================================================ - * Modifications Copyright 2018 Nokia - * ================================================================================ - * 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.vid.controllers; - - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import org.apache.log4j.BasicConfigurator; -import org.codehaus.jackson.map.ObjectMapper; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.ArgumentCaptor; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; -import org.onap.vid.asdc.AsdcCatalogException; -import org.onap.vid.asdc.beans.SecureServices; -import org.onap.vid.asdc.beans.Service; -import org.onap.vid.asdc.beans.ServiceBuilder; -import org.onap.vid.model.*; -import org.onap.vid.model.PombaInstance.PombaRequest; -import org.onap.vid.model.PombaInstance.ServiceInstance; -import org.onap.vid.roles.RoleProvider; -import org.onap.vid.services.AaiService; -import org.onap.vid.services.PombaService; -import org.onap.vid.services.VidService; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.setup.MockMvcBuilders; - -import javax.ws.rs.core.MediaType; -import java.util.List; -import java.util.Map; -import java.util.UUID; -import java.util.stream.IntStream; - -import static java.util.stream.Collectors.toMap; -import static org.assertj.core.api.Assertions.assertThat; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.nullValue; -import static org.hamcrest.Matchers.not; -import static org.mockito.BDDMockito.given; -import static org.mockito.BDDMockito.then; -import static org.mockito.Mockito.times; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; - -@RunWith(MockitoJUnitRunner.class) -public class VidControllerTest { - - public static final String REST_MODELS_SERVICES = "/rest/models/services"; - public static final String REST_MODELS_SERVICES_UUID = "/rest/models/services/{uuid}"; - public static final String REST_MODELS_RESET = "/rest/models/reset"; - public static final String REST_MODELS_SERVICES_VERIFY_SERVICE = "/rest/models/services/verifyService"; - @Mock - private VidService vidService; - @Mock - private AaiService aaiService; - @Mock - private RoleProvider roleProvider; - @Mock - private PombaService pombaService; - - private VidController vidController; - private MockMvc mockMvc; - private ObjectMapper objectMapper; - - private String uuid1; - private String uuid2; - private String uuid3; - - @Before - public void setUp() { - vidController = new VidController(vidService, aaiService, roleProvider, pombaService); - BasicConfigurator.configure(); - mockMvc = MockMvcBuilders.standaloneSetup(vidController).build(); - objectMapper = new ObjectMapper(); - - uuid1 = UUID.randomUUID().toString(); - uuid2 = UUID.randomUUID().toString(); - uuid3 = UUID.randomUUID().toString(); - } - - @Test - public void getServices_shouldReturnService_whenServiceExists() throws Exception { - List<Service> services = ImmutableList.of(createService(uuid1, 1), createService(uuid2, 2), createService(uuid3, 3)); - - given(aaiService.getServicesByDistributionStatus()).willReturn(services); - - SecureServices secureServices = new SecureServices(); - secureServices.setServices(services); - secureServices.setReadOnly(false); - - mockMvc.perform(get(REST_MODELS_SERVICES) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(content().json(objectMapper.writeValueAsString(secureServices))); - } - - @Test - public void getService_shouldReturnService_whenNoExceptionIsThrown() throws Exception { - ServiceModel model = expectedServiceModel(uuid1); - - given(vidService.getService(uuid1)).willReturn(model); - - mockMvc.perform(get(REST_MODELS_SERVICES_UUID, uuid1) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()) - .andExpect(content().json(objectMapper.writeValueAsString(model))); - } - - @Test - public void getService_shouldThrow_whenAsdcCatalogExceptionIsThrown() throws Exception { - String testUuid = UUID.randomUUID().toString(); - - given(vidService.getService(testUuid)).willThrow(new AsdcCatalogException("error msg")); - - mockMvc.perform(get(REST_MODELS_SERVICES_UUID, testUuid) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isServiceUnavailable()); - } - - @Test - public void invalidateServiceModelCache_shouldReturnAccepted() throws Exception { - mockMvc.perform(post(REST_MODELS_RESET) - .contentType(MediaType.APPLICATION_JSON)) - .andExpect(status().isAccepted()); - - then(vidService).should(times(1)).invalidateServiceCache(); - } - - @Test - public void verifyServiceInstance_shouldReturnOk() throws Exception { - PombaRequest pombaRequest = new PombaRequest(); - pombaRequest.serviceInstanceList = ImmutableList.of(new ServiceInstance()); - - mockMvc.perform(post(REST_MODELS_SERVICES_VERIFY_SERVICE) - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(pombaRequest))) - .andExpect(status().isOk()); - - ArgumentCaptor<PombaRequest> argumentCaptor = ArgumentCaptor.forClass(PombaRequest.class); - then(pombaService).should(times(1)).verify(argumentCaptor.capture()); - - assertThat(pombaRequest).isEqualToComparingFieldByFieldRecursively(argumentCaptor.getValue()); - } - - private ServiceModel expectedServiceModel(String uuid) { - final ServiceModel serviceModel = getModelsByUuid().get(uuid); - Assert.assertThat(serviceModel, is(not(nullValue()))); - return serviceModel; - } - - private Service createService(String uuid, int i) { - return new ServiceBuilder().setUuid(uuid).setInvariantUUID("invariantUUID" + i) - .setCategory("category" + i).setVersion("version" + i).setName("name" + i) - .setDistributionStatus("distStatus" + i).setToscaModelURL("toscaModelUrl" + i).build(); - } - - private ServiceModel createServiceModel(int i) { - ServiceModel model = new ServiceModel(); - - model.setCollectionResource(ImmutableMap.of("resKey" + i, new CR())); - model.setNetworks(ImmutableMap.of("network" + i, new Network())); - model.setPnfs(ImmutableMap.of("pnf" + i, new Node())); - model.setServiceProxies(ImmutableMap.of("servProxy" + i, new ServiceProxy())); - model.setVfModules(ImmutableMap.of("vfmod" + i, new VfModule())); - model.setVnfs(ImmutableMap.of("vnf" + i, new VNF())); - model.setVolumeGroups(ImmutableMap.of("volgroup" + i, new VolumeGroup())); - model.setService(new org.onap.vid.model.Service()); - return model; - } - - private Map<String, ServiceModel> getModelsByUuid() { - ServiceModel serviceModel1 = createServiceModel(1); - ServiceModel serviceModel2 = createServiceModel(2); - ServiceModel serviceModel3 = createServiceModel(3); - - List<ServiceModel> pseudoServiceModels = ImmutableList.of(serviceModel1, serviceModel2, serviceModel3); - List<String> uuids = ImmutableList.of(uuid1, uuid2, uuid3); - return IntStream.range(0, pseudoServiceModels.size()).boxed() - .collect(toMap(i -> uuids.get(i), i -> pseudoServiceModels.get(i))); - } -}
\ No newline at end of file diff --git a/vid-app-common/src/test/java/org/onap/vid/controllers/ViewEditSubControllerTest.java b/vid-app-common/src/test/java/org/onap/vid/controllers/ViewEditSubControllerTest.java deleted file mode 100644 index 7d61f98f9..000000000 --- a/vid-app-common/src/test/java/org/onap/vid/controllers/ViewEditSubControllerTest.java +++ /dev/null @@ -1,46 +0,0 @@ -package org.onap.vid.controllers; -//package org.onap.vid.controller; -// -//import javax.servlet.http.HttpServletRequest; -// -//import org.junit.Test; -//import org.springframework.web.servlet.ModelAndView; -// -//public class ViewEditSubControllerTest { -// -// private ViewEditSubController createTestSubject() { -// return new ViewEditSubController(); -// } -// -// @Test -// public void testWelcome() throws Exception { -// ViewEditSubController testSubject; -// HttpServletRequest request = null; -// ModelAndView result; -// -// // default test -// testSubject = createTestSubject(); -// result = testSubject.welcome(request); -// } -// -// -// @Test -// public void testGetViewName() throws Exception { -// ViewEditSubController testSubject; -// String result; -// -// // default test -// testSubject = createTestSubject(); -// result = testSubject.getViewName(); -// } -// -// @Test -// public void testSetViewName() throws Exception { -// ViewEditSubController testSubject; -// String viewName = ""; -// -// // default test -// testSubject = createTestSubject(); -// testSubject.setViewName(viewName); -// } -//}
\ No newline at end of file |