Search in sources :

Example 6 with ProjectMetaData

use of com.mercedesbenz.sechub.domain.administration.project.ProjectJsonInput.ProjectMetaData in project sechub by mercedes-benz.

the class ProjectUpdateAdministrationRestControllerMockTest method when_validator_marks_no_errors___calling_update_project_metadata_calls_update_service_and_returns_http_200.

@Test
public void when_validator_marks_no_errors___calling_update_project_metadata_calls_update_service_and_returns_http_200() throws Exception {
    /* execute + test @formatter:off */
    this.mockMvc.perform(post(https(PORT_USED).buildUpdateProjectMetaData(projectId)).contentType(MediaType.APPLICATION_JSON_VALUE).content("{\"metaData\":{\"key1\":\"value1\",\"key2\":\"value2\"}}")).andExpect(status().isOk());
    ProjectMetaData metaData = new ProjectMetaData();
    metaData.getMetaDataMap().put("key1", "value1");
    metaData.getMetaDataMap().put("key2", "value2");
    verify(mockedProjectUpdateMetaDataService).updateProjectMetaData(projectId, metaData);
/* @formatter:on */
}
Also used : ProjectMetaData(com.mercedesbenz.sechub.domain.administration.project.ProjectJsonInput.ProjectMetaData) Test(org.junit.Test) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)

Example 7 with ProjectMetaData

use of com.mercedesbenz.sechub.domain.administration.project.ProjectJsonInput.ProjectMetaData in project sechub by mercedes-benz.

the class ProjectUpdateMetaDataServiceTest method project_found__but_metadata_empty_updates_with_empty_list.

@Test
public void project_found__but_metadata_empty_updates_with_empty_list() {
    /* prepare */
    when(repository.findById(projectId)).thenReturn(Optional.of(project));
    ProjectMetaData emptyMetaData = new ProjectMetaData();
    List<ProjectMetaDataEntity> emptyMetaDataEntryList = Collections.emptyList();
    /* execute */
    serviceToTest.updateProjectMetaData(projectId, emptyMetaData);
    /* test */
    verify(metaDataRepository).deleteAll(metaData);
    verify(metaDataRepository).saveAll(emptyMetaDataEntryList);
}
Also used : ProjectMetaData(com.mercedesbenz.sechub.domain.administration.project.ProjectJsonInput.ProjectMetaData) Test(org.junit.Test)

Example 8 with ProjectMetaData

use of com.mercedesbenz.sechub.domain.administration.project.ProjectJsonInput.ProjectMetaData in project sechub by mercedes-benz.

the class ProjectUpdateMetaDataServiceTest method project_found__and_2_metadata_entries_updated.

@Test
public void project_found__and_2_metadata_entries_updated() throws Exception {
    /* prepare */
    when(repository.findById(projectId)).thenReturn(Optional.of(project));
    ProjectMetaData newMetaData = new ProjectMetaData();
    newMetaData.getMetaDataMap().put("key3", "value3");
    newMetaData.getMetaDataMap().put("key4", "value4");
    List<ProjectMetaDataEntity> newMetaDataEntryList = Arrays.asList(new ProjectMetaDataEntity(projectId, "key3", "value3"), new ProjectMetaDataEntity(projectId, "key4", "value4"));
    /* execute */
    serviceToTest.updateProjectMetaData(projectId, newMetaData);
    /* test */
    verify(metaDataRepository).deleteAll(metaData);
    verify(metaDataRepository).saveAll(newMetaDataEntryList);
}
Also used : ProjectMetaData(com.mercedesbenz.sechub.domain.administration.project.ProjectJsonInput.ProjectMetaData) Test(org.junit.Test)

Example 9 with ProjectMetaData

use of com.mercedesbenz.sechub.domain.administration.project.ProjectJsonInput.ProjectMetaData in project sechub by mercedes-benz.

the class ProjectUpdateAdministrationRestController method updateProjectMetaData.

@UseCaseUpdateProjectMetaData(@Step(number = 1, name = "Rest call", description = "MetaData will be updated", needsRestDoc = true))
@RequestMapping(path = AdministrationAPIConstants.API_UPDATE_PROJECT_METADATA, method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE })
public void updateProjectMetaData(@Validated @RequestBody ProjectJsonInput input, @PathVariable(name = "projectId") String projectId) {
    /* @formatter:on */
    Optional<ProjectMetaData> projectMetaData = input.getMetaData();
    if (!projectMetaData.isPresent()) {
        return;
    }
    ProjectMetaData metaData = projectMetaData.get();
    updateProjectMetaDataService.updateProjectMetaData(projectId, metaData);
}
Also used : ProjectMetaData(com.mercedesbenz.sechub.domain.administration.project.ProjectJsonInput.ProjectMetaData) UseCaseUpdateProjectMetaData(com.mercedesbenz.sechub.sharedkernel.usecases.admin.project.UseCaseUpdateProjectMetaData) UseCaseUpdateProjectMetaData(com.mercedesbenz.sechub.sharedkernel.usecases.admin.project.UseCaseUpdateProjectMetaData) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ProjectMetaData (com.mercedesbenz.sechub.domain.administration.project.ProjectJsonInput.ProjectMetaData)9 Test (org.junit.Test)6 URI (java.net.URI)3 UseCaseAdminCreatesProject (com.mercedesbenz.sechub.sharedkernel.usecases.admin.project.UseCaseAdminCreatesProject)2 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ProjectWhiteList (com.mercedesbenz.sechub.domain.administration.project.ProjectJsonInput.ProjectWhiteList)1 User (com.mercedesbenz.sechub.domain.administration.user.User)1 UserRepository (com.mercedesbenz.sechub.domain.administration.user.UserRepository)1 RoleConstants (com.mercedesbenz.sechub.sharedkernel.RoleConstants)1 Step (com.mercedesbenz.sechub.sharedkernel.Step)1 UserContextService (com.mercedesbenz.sechub.sharedkernel.UserContextService)1 AlreadyExistsException (com.mercedesbenz.sechub.sharedkernel.error.AlreadyExistsException)1 NotFoundException (com.mercedesbenz.sechub.sharedkernel.error.NotFoundException)1 DomainMessage (com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage)1 DomainMessageFactory (com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessageFactory)1 DomainMessageService (com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessageService)1 IsSendingAsyncMessage (com.mercedesbenz.sechub.sharedkernel.messaging.IsSendingAsyncMessage)1 MessageDataKeys (com.mercedesbenz.sechub.sharedkernel.messaging.MessageDataKeys)1 MessageID (com.mercedesbenz.sechub.sharedkernel.messaging.MessageID)1