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

    controller.postStageAsXmlPartial("go", 0, NEW_STAGE, md5, response);
    assertThat(response.getStatus(), is(SC_UNAUTHORIZED));

    controller.postStageAsXmlPartial("bcg", 0, NEW_STAGE, md5, response);
    assertThat(response.getStatus(), is(SC_OK));
  }
 @Test
 public void shouldPostStageAsPartialXml() throws Exception {
   configHelper.addPipeline("pipeline", "stage", "build1", "build2");
   String newXml = NEW_STAGE;
   String md5 = goConfigDao.md5OfConfigFile();
   ModelAndView mav = controller.postStageAsXmlPartial("pipeline", 0, newXml, md5, response);
   assertThat(response.getStatus(), is(SC_OK));
   assertThat(response.getContentType(), is(RESPONSE_CHARSET_JSON));
   Map json = (Map) mav.getModel().get("json");
   new JsonTester(json).shouldContain("{ 'result' : 'Stage changed successfully.' }");
 }
 @Test
 public void shouldReturnXmlAndErrorMessageWhenInvalidPostOfStageAsPartialXml() throws Exception {
   configHelper.addPipeline("pipeline", "stage", "build1", "build2");
   String md5 = goConfigDao.md5OfConfigFile();
   ModelAndView mav = controller.postStageAsXmlPartial("pipeline", 4, NEW_STAGE, md5, response);
   assertThat(response.getStatus(), is(SC_NOT_FOUND));
   assertThat(response.getContentType(), is(RESPONSE_CHARSET_JSON));
   Map<String, Object> json = (Map) mav.getModel().get("json");
   Map<String, Object> jsonMap = new LinkedHashMap<>();
   jsonMap.put("result", "Stage does not exist.");
   jsonMap.put("originalContent", NEW_STAGE);
   assertThat(json, is(jsonMap));
 }
 @Test
 public void shouldReturnXmlAndErrorMessageWhenPostOfStageAsInvalidPartialXml() throws Exception {
   configHelper.addPipeline("pipeline", "stage", "build1", "build2");
   String badXml = "<;askldjfa;dsklfja;sdjas;lkdf";
   String md5 = goConfigDao.md5OfConfigFile();
   ModelAndView mav = controller.postStageAsXmlPartial("pipeline", 0, badXml, md5, response);
   assertThat(response.getStatus(), is(SC_CONFLICT));
   assertThat(response.getContentType(), is(RESPONSE_CHARSET_JSON));
   Map json = (Map) mav.getModel().get("json");
   new JsonTester(json)
       .shouldContain(
           "{ 'result' : 'Error on line 1 of document  : The markup in the document preceding the root element must be well-formed. Nested exception: The markup in the document preceding the root element must be well-formed.',"
               + "  'originalContent' : '"
               + badXml
               + "' }");
 }