@Test
  public void getPipelineTemplateAsXmlPartial_shouldEnforceAdminPermissions() throws Exception {
    String md5 = setUpPipelineGroupsWithAdminPermissions();

    controller.getBuildAsXmlPartial("go", "stage", 0, md5, response);
    assertThat(response.getStatus(), is(SC_UNAUTHORIZED));
    assertThat(
        response.getContentAsString(),
        is("User 'ram' does not have permissions to administer pipeline group 'studios'"));

    controller.getBuildAsXmlPartial("bcg", "stage", 0, md5, response);
    assertThat(response.getStatus(), is(SC_OK));
  }
  @Test
  public void shouldGetBuildAsPartialXml() throws Exception {
    configHelper.addPipeline("pipeline", "stage", "build1", "build2");

    String md5 = goConfigDao.md5OfConfigFile();

    controller.getBuildAsXmlPartial("pipeline", "stage", 1, null, response);
    assertValidContentAndStatus(SC_OK, "text/xml", "<job name=\"build2\" />");
    assertThat(response.getHeader(XmlAction.X_CRUISE_CONFIG_MD5), is(md5));
  }
  @Test
  public void shouldReturnConflictIfGetRequestUsesIncorrectConfigMD5() throws Exception {
    String oldMd5 = goConfigDao.md5OfConfigFile();

    configHelper.addPipeline("pipeline", "stage", "build1", "build2");

    String newMd5 = goConfigDao.md5OfConfigFile();

    controller.getBuildAsXmlPartial("pipeline", "stage", 1, oldMd5, response);
    assertValidContentAndStatus(
        SC_CONFLICT, RESPONSE_CHARSET, ConfigFileHasChangedException.CONFIG_CHANGED_PLEASE_REFRESH);
    assertThat(response.getHeader(XmlAction.X_CRUISE_CONFIG_MD5), is(newMd5));
  }
 @Test
 public void shouldGetErrorMessageWhenPipelineDoesNotExistAndGettingBuild() throws Exception {
   configHelper.addPipeline("pipeline", "stage", "build1");
   controller.getBuildAsXmlPartial("unknown", "stage", 0, null, response);
   assertValidContentAndStatus(SC_NOT_FOUND, RESPONSE_CHARSET, "Pipeline 'unknown' not found.");
 }
 @Test
 public void shouldGetErrorMessageWhenBuildDoesNotExist() throws Exception {
   configHelper.addPipeline("pipeline", "stage", "build1");
   controller.getBuildAsXmlPartial("pipeline", "stage", 1, null, response);
   assertValidContentAndStatus(SC_NOT_FOUND, RESPONSE_CHARSET, "Build does not exist.");
 }