@Test(groups = {"wso2.greg"}) public void EditComment() throws Exception { Resource r1 = registry.newResource(); 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"); 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( commentFound, "comment:" + c1.getText() + " is not associated with the artifact /c101/c11/r1"); try { Resource commentsResource = registry.get("/c101/c11/r1;comments"); assertTrue(commentsResource instanceof Collection, "Comment resource should be a directory."); comments = (Comment[]) commentsResource.getContent(); List commentTexts = new ArrayList(); for (Comment comment : comments) { Resource commentResource = registry.get(comment.getPath()); commentTexts.add(new String((byte[]) commentResource.getContent())); } assertTrue( commentTexts.contains(c1.getText()), c1.getText() + " is not associated for resource /c101/c11/r1."); 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(new String((byte[]) resource.getContent()), "This is the edited comment"); } catch (RegistryException e) { e.printStackTrace(); fail("Failed to get comments form URL:/c101/c11/r1;comments"); } /*Edit comment goes here*/ registry.editComment("/c101/c11/r1", "This is the edited comment"); }
@Test(groups = {"wso2.greg"}) public void AddCommentToCollection() throws Exception { Resource r1 = registry.newCollection(); r1.setDescription("this is a collection to add comment"); registry.put("/d11/d12", r1); String comment1 = "this is qa comment 1 for collection d12"; String comment2 = "this is qa comment 2 for collection d12"; Comment c1 = new Comment(); c1.setResourcePath("/d11/d12"); c1.setText("This is default comment for d12"); c1.setUser("admin"); try { registry.addComment("/d11/d12", c1); registry.addComment("/d11/d12", new Comment(comment1)); registry.addComment("/d11/d12", new Comment(comment2)); } catch (RegistryException e) { fail("Valid commenting for resources scenario failed"); } Comment[] comments = null; try { comments = registry.getComments("/d11/d12"); } catch (RegistryException e) { fail("Failed to get comments for the resource /d11/d12"); } boolean commentFound = false; for (Comment comment : comments) { if (comment.getText().equals(comment1)) { commentFound = true; // //System.out.println(comment.getText()); // //System.out.println(comment.getResourcePath()); // //System.out.println(comment.getUser()); // //System.out.println(comment.getTime()); // break; } if (comment.getText().equals(comment2)) { commentFound = true; // //System.out.println(comment.getText()); // //System.out.println(comment.getResourcePath()); // //System.out.println(comment.getUser()); // //System.out.println(comment.getTime()); // break; } 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()); // break; } } assertTrue( commentFound, "comment '" + comment1 + " is not associated with the artifact /d11/d12"); try { Resource commentsResource = registry.get("/d11/d12;comments"); assertTrue( commentsResource instanceof Collection, "Comment collection resource should be a directory."); comments = (Comment[]) commentsResource.getContent(); List commentTexts = new ArrayList(); for (Comment comment : comments) { Resource commentResource = registry.get(comment.getPath()); commentTexts.add(new String((byte[]) commentResource.getContent())); } assertTrue( commentTexts.contains(comment1), comment1 + " is not associated for resource /d11/d12."); assertTrue( commentTexts.contains(comment2), comment2 + " is not associated for resource /d11/d12."); } catch (RegistryException e) { e.printStackTrace(); fail("Failed to get comments form URL: /d11/d12;comments"); } }