Author: krishantha
Date: Mon Jan 21 01:53:39 2008
New Revision: 12584

Log:



Added:
   
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/CommentTest.java

Added: 
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/CommentTest.java
==============================================================================
--- (empty file)
+++ 
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/CommentTest.java
    Mon Jan 21 01:53:39 2008
@@ -0,0 +1,450 @@
+
+package org.wso2.registry.app;
+
+import junit.framework.TestCase;
+import org.wso2.registry.Registry;
+import org.wso2.registry.Resource;
+import org.wso2.registry.RegistryException;
+import org.wso2.registry.Comment;
+
+import java.net.URL;
+import java.util.List;
+import java.util.ArrayList;
+
+/*
+ * Created by IntelliJ IDEA.
+ * User: krishantha
+ * Date: Jan 16, 2008
+ * Time: 5:14:30 PM
+ * To change this template use File | Settings | File Templates.
+ */
+
+public class CommentTest extends TestCase {
+
+    RegistryServer server = new RegistryServer();
+    private  static Registry registry = null;
+
+    public void setUp() {
+        try {
+            if (registry == null) {
+                server.start();
+                registry = new RemoteRegistry(new 
URL("http://localhost:8080/wso2registry/atom";), "admin", "admin");
+            }
+        } catch (Exception e) {
+            fail("Failed to initialize the registry.");
+        }
+    }
+
+    public void testAddCommenttoResourece(){
+
+        try {
+            Resource r1 = new Resource();
+            r1.setAuthorUserName("Author q1");
+            byte[] r1content = "R1 content".getBytes();
+            r1.setContent(r1content);
+            registry.put("/d1/r3", r1);
+
+        }catch (RegistryException e) {
+            fail("Failed to put resources.");
+        }
+
+        String comment1 = "this is qa comment 4";
+        String comment2 = "this is qa comment 5";
+        try {
+
+            Comment c1= new Comment();
+            c1.setPath("/d1/r3");
+            c1.setText("This is default comment");
+            c1.setUser("admin");
+
+
+            registry.addComment("/d1/r3",c1);
+            registry.addComment("/d1/r3", new Comment(comment1));
+            registry.addComment("/d1/r3", new Comment(comment2));
+        } catch (RegistryException e) {
+            fail("Valid commenting for resources scenario failed");
+        }
+
+        Comment[] comments = null;
+
+        try {
+
+            comments = registry.getComments("/d1/r3");
+        } catch (RegistryException e) {
+            fail("Failed to get comments for the resource /d1/r3");
+        }
+
+        boolean commentFound = false;
+               
+        for (Comment comment : comments) {
+            if (comment.getText().equals(comment1)) {
+                commentFound = true;
+
+                System.out.println(comment.getText());
+                System.out.println(comment.getPath());
+                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.getPath());
+                System.out.println(comment.getUser());
+                System.out.println(comment.getTime());
+                //break;
+            }
+
+             if (comment.getText().equals("This is default comment")) {
+                commentFound = true;
+                System.out.println(comment.getText());
+                System.out.println(comment.getPath());
+                System.out.println(comment.getUser());
+                System.out.println(comment.getTime());
+                //break;
+            }
+        }
+
+        
+        assertTrue("comment '" + comment1 +
+                " is not associated with the artifact /d1/r3", commentFound);
+
+        try {
+
+            Resource commentsResource = registry.get("/d1/r3;comments");
+            assertTrue("Comment collection resource should be a directory.",
+                    commentsResource.isDirectory());
+            String[] commentPaths = (String[]) commentsResource.getContent();
+
+            List commentTexts = new ArrayList();
+            for (String commentPath : commentPaths) {
+                Resource commentResource = registry.get(commentPath);
+                commentTexts.add(commentResource.getContent());
+            }
+
+            assertTrue(comment1 + " is not associated for resource /d1/r3.",
+                    commentTexts.contains(comment1));
+            assertTrue(comment2 + " is not associated for resource /d1/r3.",
+                    commentTexts.contains(comment2));
+
+        } catch (RegistryException e) {
+            e.printStackTrace();
+            fail("Failed to get comments form URL: /d1/r3;comments");
+        }
+
+        /*try {
+            //registry.delete("/d12");
+        } catch (RegistryException e) {
+            fail("Failed to delete test resources.");
+        } */
+
+
+}
+
+
+public void testAddCommenttoCollection(){
+
+try {
+   Resource r1 = new Resource();
+   r1.setAuthorUserName("Author q1");
+   r1.setDescription("this is a collection to add comment");
+   r1.setDirectory(true);
+
+   registry.put("/d11/d12", r1);
+
+}catch (RegistryException e) {
+   fail("Failed to put collection.");
+}
+
+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.setPath("/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.getPath());
+       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.getPath());
+       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.getPath());
+       System.out.println(comment.getUser());
+       System.out.println(comment.getTime());
+       //break;
+   }
+}
+
+
+assertTrue("comment '" + comment1 +
+       " is not associated with the artifact /d11/d12", commentFound);
+
+try {
+
+   Resource commentsResource = registry.get("/d11/d12;comments");
+   assertTrue("Comment collection resource should be a directory.",
+           commentsResource.isDirectory());
+   String[] commentPaths = (String[]) commentsResource.getContent();
+
+   List commentTexts = new ArrayList();
+   for (String commentPath : commentPaths) {
+       Resource commentResource = registry.get(commentPath);
+       commentTexts.add(commentResource.getContent());
+   }
+
+   assertTrue(comment1 + " is not associated for resource /d11/d12.",
+           commentTexts.contains(comment1));
+   assertTrue(comment2 + " is not associated for resource /d11/d12.",
+           commentTexts.contains(comment2));
+
+} catch (RegistryException e) {
+   e.printStackTrace();
+   fail("Failed to get comments form URL: /d11/d12;comments");
+}
+
+/*try {
+   //registry.delete("/d12");
+} catch (RegistryException e) {
+   fail("Failed to delete test resources.");
+} */
+
+
+
+}
+
+public void testAddCommenttoRoot(){
+
+try {
+   Resource r1 = new Resource();
+   r1.setAuthorUserName("Author q1");
+   r1.setDescription("this is a collection to add comment");
+   r1.setDirectory(true);
+
+   registry.put("/", r1);
+
+}catch (RegistryException e) {
+   fail("Failed to put collection.");
+}
+
+String comment1 = "this is qa comment 1 for root";
+String comment2 = "this is qa comment 2 for root";
+
+
+   Comment c1= new Comment();
+   c1.setPath("/");
+   c1.setText("This is default comment for root");
+   c1.setUser("admin");
+
+try {
+   registry.addComment("/",c1);
+   registry.addComment("/", new Comment(comment1));
+   registry.addComment("/", new Comment(comment2));
+} catch (RegistryException e) {
+   fail("Valid commenting for resources scenario failed");
+}
+
+Comment[] comments = null;
+
+try {
+
+   comments = registry.getComments("/");
+} catch (RegistryException e) {
+   fail("Failed to get comments for the resource /");
+}
+
+boolean commentFound = false;
+
+for (Comment comment : comments) {
+   if (comment.getText().equals(comment1)) {
+       commentFound = true;
+
+       System.out.println(comment.getText());
+       System.out.println(comment.getPath());
+       System.out.println(comment.getUser());
+       System.out.println(comment.getTime());
+       System.out.println("\n");
+       //break;
+   }
+
+    if (comment.getText().equals(comment2)) {
+       commentFound = true;
+       System.out.println(comment.getText());
+       System.out.println(comment.getPath());
+       System.out.println(comment.getUser());
+       System.out.println(comment.getTime());
+       System.out.println("\n");
+       //break;
+   }
+
+    if (comment.getText().equals(c1.getText())) {
+       commentFound = true;
+       System.out.println(comment.getText());
+       System.out.println(comment.getPath());
+       System.out.println(comment.getUser());
+       System.out.println(comment.getTime());
+       System.out.println("\n");
+       //break;
+   }
+}
+
+
+assertTrue("comment '" + comment1 +
+       " is not associated with the artifact /", commentFound);
+
+try {
+
+   Resource commentsResource = registry.get("/;comments");
+   assertTrue("Comment collection resource should be a directory.",
+           commentsResource.isDirectory());
+   String[] commentPaths = (String[]) commentsResource.getContent();
+
+   List commentTexts = new ArrayList();
+   for (String commentPath : commentPaths) {
+       Resource commentResource = registry.get(commentPath);
+       commentTexts.add(commentResource.getContent());
+   }
+
+   assertTrue(comment1 + " is not associated for resource /.",
+           commentTexts.contains(comment1));
+   assertTrue(comment2 + " is not associated for resource /.",
+           commentTexts.contains(comment2));
+
+} catch (RegistryException e) {
+   e.printStackTrace();
+   fail("Failed to get comments form URL: /;comments");
+}
+
+/*try {
+   //registry.delete("/d12");
+} catch (RegistryException e) {
+   fail("Failed to delete test resources.");
+} */
+
+}
+
+    public void testEditComment(){
+
+        try {
+            Resource r1 = new Resource();
+            r1.setAuthorUserName("Author q1");
+            r1.setDescription("this is a resource to edit comment");
+            r1.setDirectory(false);
+
+            registry.put("/c10/c11/r1", r1);
+        }catch (RegistryException e) {
+            fail("Failed to put Resource.");
+        }
+
+        Comment c1= new Comment();
+        c1.setPath("/c10/c11/r1");
+        c1.setText("This is default comment ");
+        c1.setUser("admin");
+
+        try {
+            registry.addComment("/c10/c11/r1",c1);
+        } catch (RegistryException e) {
+            fail("Valid commenting for resources scenario failed");
+        }
+
+        Comment[] comments = null;
+
+        try {
+            comments = registry.getComments("/c10/c11/r1");
+        } catch (RegistryException e) {
+            fail("Failed to get comments for the resource /c10/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.getPath());
+               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 /c10/c11/r1", commentFound);
+
+        try {
+
+            Resource commentsResource = registry.get("/c10/c11/r1;comments");
+            
+            assertTrue("Comment resource should be a 
directory.",commentsResource.isDirectory());
+            String[] commentPaths = (String[]) commentsResource.getContent();
+
+            List commentTexts = new ArrayList();
+
+            for (String commentPath : commentPaths) {
+                Resource commentResource = registry.get(commentPath);
+                commentTexts.add(commentResource.getContent());
+                System.out.println("comment:" + commentResource.getContent());
+            }
+
+            assertTrue(c1.getText() + " is not associated for resource 
/c10/c11/r1.",
+           commentTexts.contains(c1.getText()));
+        } catch (RegistryException e) {
+            e.printStackTrace();
+            fail("Failed to get comments form URL:/c10/c11/r1;comments");
+        }
+
+
+     /*Edit comment goes here*/
+     /*
+        try{
+            registry.editComment("/c10/c11/r1","This is the edited comment");
+        }catch(RegistryException e){
+            fail("Failed to Edit comment on /c10/c11/r1");
+        }
+       */ 
+    }
+
+}
+
+

_______________________________________________
Registry-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/registry-dev

Reply via email to