@Test
public void updateValidationTest()
throws IOException
{
RepositoryGroupResource resource = new RepositoryGroupResource();
resource.setId("updateValidationTest");
resource.setName("updateValidationTest");
resource.setFormat("maven2");
resource.setProvider("maven2");
RepositoryGroupMemberRepository member = new RepositoryGroupMemberRepository();
member.setId("nexus-test-harness-repo");
resource.addRepository(member);
resource = this.messageUtil.createGroup(resource);
Response response = null;
String responseText = null;
// no groups
resource.getRepositories().clear();
response = this.messageUtil.sendMessage(Method.PUT, resource);
responseText = response.getEntity().getText();
Assert.assertTrue("Group should have been updated: " + response.getStatus()
+ "\n" + responseText, response.getStatus().isSuccess());
resource.addRepository(member);
// missing Id
resource.setId(null);
response = this.messageUtil.sendMessage(Method.PUT, resource, "updateValidationTest");
responseText = response.getEntity().getText();
Assert.assertFalse("Group should not have been udpated: " + response.getStatus() + "\n" + responseText,
response.getStatus().isSuccess());
Assert.assertTrue("Response text did not contain an error message. Status: " + response.getStatus()
+ "\nResponse Text:\n " + responseText,
responseText.contains("<errors>"));
resource.setId("updateValidationTest");
// missing name
resource.setName(null);
response = this.messageUtil.sendMessage(Method.PUT, resource);
responseText = response.getEntity().getText();
Assert.assertTrue("Group should have been udpated: " + response.getStatus()
+ "\n" + responseText, response.getStatus().isSuccess());
Assert.assertEquals("Group Name did not default to the Id", this.messageUtil.getGroup(resource.getId()).getName(),
resource.getId());
}