Search in sources :

Example 1 with JobIdsRequestModel

use of com.synopsys.integration.alert.common.rest.model.JobIdsRequestModel in project hub-alert by blackducksoftware.

the class JobConfigActionsTest method validateJobsByIdForbiddenTest.

@Test
public void validateJobsByIdForbiddenTest() {
    JobIdsRequestModel jobIdsRequestModel = new JobIdsRequestModel(List.of(jobId));
    Mockito.when(mockedAuthorizationManager.anyReadPermission(Mockito.any())).thenReturn(false);
    ActionResponse<List<JobFieldStatuses>> actionResponse = defaultJobConfigActions.validateJobsById(jobIdsRequestModel);
    assertTrue(actionResponse.isError());
    assertEquals(HttpStatus.FORBIDDEN, actionResponse.getHttpStatus());
    assertFalse(actionResponse.hasContent());
}
Also used : JobIdsRequestModel(com.synopsys.integration.alert.common.rest.model.JobIdsRequestModel) List(java.util.List) Test(org.junit.jupiter.api.Test)

Example 2 with JobIdsRequestModel

use of com.synopsys.integration.alert.common.rest.model.JobIdsRequestModel in project hub-alert by blackducksoftware.

the class JobConfigActionsTest method validateJobsByIdEmptyListTest.

@Test
public void validateJobsByIdEmptyListTest() {
    JobIdsRequestModel jobIdsRequestModel = new JobIdsRequestModel(List.of());
    Mockito.when(mockedAuthorizationManager.anyReadPermission(Mockito.any())).thenReturn(true);
    ActionResponse<List<JobFieldStatuses>> actionResponse = defaultJobConfigActions.validateJobsById(jobIdsRequestModel);
    assertTrue(actionResponse.isSuccessful());
    assertEquals(HttpStatus.OK, actionResponse.getHttpStatus());
    assertTrue(actionResponse.hasContent());
}
Also used : JobIdsRequestModel(com.synopsys.integration.alert.common.rest.model.JobIdsRequestModel) List(java.util.List) Test(org.junit.jupiter.api.Test)

Example 3 with JobIdsRequestModel

use of com.synopsys.integration.alert.common.rest.model.JobIdsRequestModel in project hub-alert by blackducksoftware.

the class JobConfigControllerTestIT method testGetValidationResultsForJobs.

@Test
@WithMockUser(roles = AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)
public void testGetValidationResultsForJobs() throws Exception {
    final String urlPath = REQUEST_URL + "/validateJobsById";
    DistributionJobModel distributionJobModel = createAndSaveMockDistributionJob(-1L);
    JobIdsRequestModel jobIdsRequestModel = new JobIdsRequestModel(List.of(distributionJobModel.getJobId()));
    MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post(urlPath).with(SecurityMockMvcRequestPostProcessors.user("admin").roles(AlertIntegrationTestConstants.ROLE_ALERT_ADMIN)).with(SecurityMockMvcRequestPostProcessors.csrf()).content(gson.toJson(jobIdsRequestModel)).contentType(MEDIA_TYPE);
    mockMvc.perform(request).andExpect(MockMvcResultMatchers.status().isOk());
}
Also used : JobIdsRequestModel(com.synopsys.integration.alert.common.rest.model.JobIdsRequestModel) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) DistributionJobModel(com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test) DatabaseConfiguredFieldTest(com.synopsys.integration.alert.util.DatabaseConfiguredFieldTest)

Example 4 with JobIdsRequestModel

use of com.synopsys.integration.alert.common.rest.model.JobIdsRequestModel in project hub-alert by blackducksoftware.

the class JobConfigActionsTest method validateJobsByIdTest.

@Test
public void validateJobsByIdTest() throws Exception {
    JobIdsRequestModel jobIdsRequestModel = new JobIdsRequestModel(List.of(jobId));
    Mockito.when(mockedAuthorizationManager.anyReadPermission(Mockito.any())).thenReturn(true);
    Mockito.when(mockedConfigurationFieldModelConverter.convertToFieldModel(Mockito.any())).thenReturn(fieldModel);
    Mockito.when(mockedFieldModelProcessor.performAfterReadAction(Mockito.eq(fieldModel))).thenReturn(fieldModel);
    ActionResponse<List<JobFieldStatuses>> actionResponse = defaultJobConfigActions.validateJobsById(jobIdsRequestModel);
    assertTrue(actionResponse.isSuccessful());
    assertEquals(HttpStatus.OK, actionResponse.getHttpStatus());
    assertTrue(actionResponse.hasContent());
}
Also used : JobIdsRequestModel(com.synopsys.integration.alert.common.rest.model.JobIdsRequestModel) List(java.util.List) Test(org.junit.jupiter.api.Test)

Aggregations

JobIdsRequestModel (com.synopsys.integration.alert.common.rest.model.JobIdsRequestModel)4 Test (org.junit.jupiter.api.Test)4 List (java.util.List)3 DistributionJobModel (com.synopsys.integration.alert.common.persistence.model.job.DistributionJobModel)1 DatabaseConfiguredFieldTest (com.synopsys.integration.alert.util.DatabaseConfiguredFieldTest)1 WithMockUser (org.springframework.security.test.context.support.WithMockUser)1 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)1