byte[] r1content = "R1 content".getBytes();
r1.setContent(r1content);
r1.setDescription("this is a resource to edit comment");
registry.put("/c101/c11/r1", r1);
Comment c1 = new Comment();
c1.setResourcePath("/c10/c11/r1");
c1.setText("This is default comment ");
c1.setUser("admin");
String commentPath = registry.addComment("/c101/c11/r1", c1);
Comment[] comments = registry.getComments("/c101/c11/r1");
boolean commentFound = false;
for (Comment comment : comments) {
if (comment.getText().equals(c1.getText())) {
commentFound = true;
// //System.out.println(comment.getText());
// //System.out.println(comment.getResourcePath());
// //System.out.println(comment.getUser());
// //System.out.println(comment.getTime());
// //System.out.println("\n");
//break;
}
}
assertTrue("comment:" + c1.getText() +
" is not associated with the artifact /c101/c11/r1", commentFound);
try {
Resource commentsResource = registry.get("/c101/c11/r1;comments");
assertTrue("Comment resource should be a directory.",
commentsResource instanceof Collection);
comments = (Comment[]) commentsResource.getContent();
List commentTexts = new ArrayList();
for (Comment comment : comments) {
Resource commentResource = registry.get(comment.getPath());
commentTexts.add(commentResource.getContent());
}
assertTrue(c1.getText() + " is not associated for resource /c101/c11/r1.",
commentTexts.contains(c1.getText()));
registry.editComment(comments[0].getPath(), "This is the edited comment");
comments = registry.getComments("/c101/c11/r1");
// System.out.println(comments);
Resource resource = registry.get(comments[0].getPath());
assertEquals("This is the edited comment", resource.getContent());
} catch (RegistryException e) {
e.printStackTrace();
fail("Failed to get comments form URL:/c101/c11/r1;comments");
}
/*Edit comment goes here*/
String editedCommentString = "This is the edited comment";
registry.editComment(commentPath, editedCommentString);
Comment[] comments1 = registry.getComments("/c101/c11/r1");
boolean editedCommentFound = false;
boolean defaultCommentFound = true;
for (Comment comment : comments1) {
if (comment.getText().equals(editedCommentString)) {
editedCommentFound = true;
} else if (comment.getText().equals(c1.getText())) {
defaultCommentFound = false;
// //System.out.println(comment.getText());
// //System.out.println(comment.getResourcePath());
// //System.out.println(comment.getUser());
// //System.out.println(comment.getTime());