@Test(groups = {"wso2.greg"}) public void CommentDelete() throws Exception { String r1Path = "/_c1d1/c1"; Collection r1 = registry.newCollection(); registry.put(r1Path, r1); String c1Path = registry.addComment(r1Path, new Comment("test comment1")); registry.addComment(r1Path, new Comment("test comment2")); Comment[] comments1 = registry.getComments(r1Path); assertEquals(comments1.length, 2, "There should be two comments."); String[] cTexts1 = {comments1[0].getText(), comments1[1].getText()}; assertTrue(containsString(cTexts1, "test comment1"), "comment is missing"); assertTrue(containsString(cTexts1, "test comment2"), "comment is missing"); registry.delete(comments1[0].getPath()); Comment[] comments2 = registry.getComments(r1Path); assertEquals(comments2.length, 1, "There should be one comment."); String[] cTexts2 = {comments2[0].getText()}; assertTrue(containsString(cTexts2, "test comment2"), "comment is missing"); assertTrue(!containsString(cTexts2, "test comment1"), "deleted comment still exists"); }
public void ResourceCopyTest() throws RegistryException { Resource r1 = registry.newResource(); r1.setProperty("test", "copy"); r1.setContent("c"); registry.put("/test1/copy/c1/copy1", r1); Collection c1 = registry.newCollection(); registry.put("/test1/move", c1); registry.copy("/test1/copy/c1/copy1", "/test1/copy/c2/copy2"); Resource newR1 = registry.get("/test1/copy/c2/copy2"); assertEquals( "Copied resource should have a property named 'test' with value 'copy'.", newR1.getProperty("test"), "copy"); Resource oldR1 = registry.get("/test1/copy/c1/copy1"); assertEquals( "Original resource should have a property named 'test' with value 'copy'.", oldR1.getProperty("test"), "copy"); String newContent = new String((byte[]) newR1.getContent()); String oldContent = new String((byte[]) oldR1.getContent()); assertEquals("Contents are not equal in copied resources", newContent, oldContent); }
public void CollectionCopyTest() throws RegistryException { Resource r1 = registry.newResource(); r1.setProperty("test", "copy"); r1.setContent("c"); registry.put("/test1/copy/copy3/c3/resource1", r1); Collection c1 = registry.newCollection(); registry.put("/test1/move", c1); registry.copy("/test1/copy/copy3", "/test1/newc/copy3"); Resource newR1 = registry.get("/test1/newc/copy3/c3/resource1"); assertEquals( "Copied resource should have a property named 'test' with value 'copy'.", newR1.getProperty("test"), "copy"); Resource oldR1 = registry.get("/test1/copy/copy3/c3/resource1"); assertEquals( "Original resource should have a property named 'test' with value 'copy'.", oldR1.getProperty("test"), "copy"); }
@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"); } }