Search in sources :

Example 1 with PipelineGroupNotFoundException

use of com.thoughtworks.go.config.exceptions.PipelineGroupNotFoundException in project gocd by gocd.

the class PipelineConfigsServiceTest method shouldThrowExceptionWhenTheGroupIsNotFound_onGetXml.

@Test
public void shouldThrowExceptionWhenTheGroupIsNotFound_onGetXml() {
    String groupName = "non-existent-group_name";
    Localizer localizer = mock(Localizer.class);
    when(localizer.localize("PIPELINE_GROUP_NOT_FOUND", groupName)).thenReturn("Not found");
    when(securityService.isUserAdminOfGroup(validUser.getUsername(), groupName)).thenThrow(new PipelineGroupNotFoundException());
    service.getXml(groupName, validUser, result);
    assertThat(result.httpCode(), is(404));
    assertThat(result.isSuccessful(), is(false));
    assertThat(result.message(localizer), is("Not found"));
    verify(securityService, times(1)).isUserAdminOfGroup(validUser.getUsername(), groupName);
    verify(goConfigService, never()).getConfigForEditing();
}
Also used : Localizer(com.thoughtworks.go.i18n.Localizer) PipelineGroupNotFoundException(com.thoughtworks.go.config.exceptions.PipelineGroupNotFoundException) Test(org.junit.Test)

Example 2 with PipelineGroupNotFoundException

use of com.thoughtworks.go.config.exceptions.PipelineGroupNotFoundException in project gocd by gocd.

the class PipelineConfigsServiceTest method shouldReturnUnsuccessfulResultWhenTheGroupIsNotFound_onUpdateXml.

@Test
public void shouldReturnUnsuccessfulResultWhenTheGroupIsNotFound_onUpdateXml() throws Exception {
    String groupName = "non-existent-group_name";
    Localizer localizer = mock(Localizer.class);
    when(localizer.localize("PIPELINE_GROUP_NOT_FOUND", groupName)).thenReturn("Not found");
    when(securityService.isUserAdminOfGroup(validUser.getUsername(), groupName)).thenThrow(new PipelineGroupNotFoundException());
    when(goConfigService.configFileMd5()).thenReturn("md5");
    GoConfigOperationalResponse<PipelineConfigs> actual = service.updateXml(groupName, "", "md5", validUser, result);
    PipelineConfigs configs = actual.getConfigElement();
    GoConfigValidity validity = actual.getValidity();
    assertThat(configs, is(nullValue()));
    assertThat(result.httpCode(), is(404));
    assertThat(result.isSuccessful(), is(false));
    assertThat(result.message(localizer), is("Not found"));
    assertThat(validity.isValid(), is(true));
    verify(securityService, times(1)).isUserAdminOfGroup(validUser.getUsername(), groupName);
}
Also used : Localizer(com.thoughtworks.go.i18n.Localizer) PipelineGroupNotFoundException(com.thoughtworks.go.config.exceptions.PipelineGroupNotFoundException) GoConfigValidity(com.thoughtworks.go.config.validation.GoConfigValidity) Test(org.junit.Test)

Aggregations

PipelineGroupNotFoundException (com.thoughtworks.go.config.exceptions.PipelineGroupNotFoundException)2 Localizer (com.thoughtworks.go.i18n.Localizer)2 Test (org.junit.Test)2 GoConfigValidity (com.thoughtworks.go.config.validation.GoConfigValidity)1