Author: krishantha
Date: Thu Feb 28 01:12:49 2008
New Revision: 14304

Log:

test case modified for testing multiple tags,comments,properties

Modified:
   
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/ResourceHandling.java

Modified: 
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/ResourceHandling.java
==============================================================================
--- 
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/ResourceHandling.java
       (original)
+++ 
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/ResourceHandling.java
       Thu Feb 28 01:12:49 2008
@@ -7,6 +7,8 @@
 import org.wso2.registry.Tag;
 
 import java.util.Properties;
+import java.util.List;
+import java.util.ArrayList;
 
 
 public class ResourceHandling extends AbstractAPPTest {
@@ -16,8 +18,10 @@
 
         try {
 
-            String path="/f55/f2/r1";
-            String new_path="/f54/f2/r2";
+            String path="/f59/f2/r1";
+            String commentPath = path + ";comments";
+            String new_path="/f60/f2/r2";
+            String commentPathNew = new_path + ";comments";
             Resource r1 = new Resource();
             r1.setDirectory(false);
             r1.setAuthorUserName("Author R2");
@@ -28,7 +32,11 @@
 
             Comment c1 = new Comment();
             c1.setResourcePath(path);
-            c1.setText("This is a test comment");
+            c1.setText("This is a test comment1");
+
+            Comment c2 = new Comment();
+            c2.setResourcePath(path);
+            c2.setText("This is a test comment2");
 
             Properties r1Pro = new Properties();
             r1Pro.setProperty("key1", "value1");
@@ -37,7 +45,10 @@
 
             registry.put(path,r1);
             registry.addComment(path,c1);
+            registry.addComment(path,c2);
             registry.applyTag(path, "tag1");
+            registry.applyTag(path, "tag2");
+            registry.applyTag(path, "tag3");
             registry.rateResource(path, 4);
 
             Resource r2 = new Resource();
@@ -46,31 +57,38 @@
             assertEquals("Properties are not equal",r1.getProperty("key1"),
                          r2.getProperty("key1"));
 
+            assertEquals("Properties are not equal",r1.getProperty("key2"),
+                         r2.getProperty("key2"));
+
             assertEquals("File content is not matching", new 
String((byte[])r1.getContent()),
                      new String((byte[])r2.getContent()));
 
-            Comment[] comments2 = registry.getComments(path);
-            assertEquals("There should be one comment.", 1, comments2.length);
-            String[] cTexts2 = {comments2[0].getText()};
-
-            assertTrue("comment is not exist",containsString(cTexts2, "This is 
a test comment"));
-
-            Tag[] tags = null;
-            tags = registry.getTags(path);
-            String[] r1TagText ={tags[0].getTagName()};
-            assertTrue("Tag is not exist",containsString(r1TagText, "tag1"));
+            assertTrue(c1.getText() + " is not associated for resource"+ path,
+                        containsComment(commentPath,c1.getText()));
+
+            assertTrue(c2.getText() + " is not associated for resource"+ path,
+                        containsComment(commentPath,c2.getText()));
+
+            assertTrue("Tag1 is not exist",containsTag(path,"tag1"));
+            assertTrue("Tag2 is not exist",containsTag(path,"tag2"));
+            assertTrue("Tag3 is not exist",containsTag(path,"tag3"));
 
             float rating = registry.getAverageRating(path);
             assertEquals("Rating is not mathching", rating, (float)4.0,
                         (float)0.01);
-            assertEquals("Media type not 
exist",r1.getMediaType(),r2.getMediaType());
-            assertEquals("Authour name is not 
exist",r1.getAuthorUserName(),r2.getAuthorUserName());
 
+            assertEquals("Media type not exist",r1.getMediaType(),
+                        r2.getMediaType());
 
-            registry.rename(path,new_path);
+            assertEquals("Authour name is not exist",r1.getAuthorUserName(),
+                        r2.getAuthorUserName());
 
-            /*get renamed resource details*/
+            assertEquals("Description is not exist",r1.getDescription(),
+                        r2.getDescription());
 
+            registry.rename(path,new_path);
+            
+            /*get renamed resource details*/
             Resource r1Renamed = new Resource();
 
             r1Renamed = registry.get(new_path);
@@ -81,18 +99,18 @@
             assertEquals("Properties are not equal",r2.getProperty("key1"),
                         r1Renamed.getProperty("key1"));
 
-            Comment[] comments3 = registry.getComments(new_path);
-            assertEquals("There should be one comment.", 1, comments3.length);
-            String[] cTexts3 = {comments3[0].getText()};
-
-            assertTrue("comment is not copied",containsString(cTexts3,
-                       "This is a test comment"));
-
-            Tag[] tags1 = null;
-            tags1 = registry.getTags(new_path);
-            String[] r1TagText1 ={tags1[0].getTagName()};
+            assertEquals("Properties are not equal",r2.getProperty("key2"),
+                        r1Renamed.getProperty("key2"));
+
+            assertTrue(c1.getText() + " is not associated for resource"+ 
new_path,
+                        containsComment(commentPathNew,c1.getText()));
 
-            assertTrue("Tag is not copied",containsString(r1TagText1, "tag1"));
+            assertTrue(c2.getText() + " is not associated for resource"+ 
new_path,
+                        containsComment(commentPathNew,c2.getText()));
+
+            assertTrue("Tag1 is not copied",containsTag(new_path,"tag1"));
+            assertTrue("Tag2 is not copied",containsTag(new_path,"tag2"));
+            assertTrue("Tag3 is not copied",containsTag(new_path,"tag3"));
 
             float rating1 = registry.getAverageRating(new_path);
             assertEquals("Rating is not copied", rating1, (float)4.0,
@@ -101,8 +119,10 @@
             assertEquals("Media type not copied",r2.getMediaType(),
                         r1Renamed.getMediaType());
 
-            assertEquals("Authour Name is not copied",r1.getAuthorUserName(),
-                        r2.getAuthorUserName());
+            assertEquals("Authour Name is not copied",r2.getAuthorUserName(),
+                        r1Renamed.getAuthorUserName());
+
+            assertEquals("Description is not 
exist",r2.getDescription(),r1Renamed.getDescription());
 
             }catch (RegistryException e) {
                        e.printStackTrace();
@@ -113,8 +133,10 @@
 
         try {
 
-            String path="/c78/c1/c2";
-            String new_path="/c79/c1/c3";
+            String path="/c901/c1/c2";
+            String commentPath = path + ";comments";
+            String new_path="/c911/c1/c3";
+            String commentPathNew = new_path + ";comments";
             Resource r1 = new Resource();
             r1.setDirectory(true);
             r1.setAuthorUserName("Author R2");
@@ -122,7 +144,11 @@
 
             Comment c1 = new Comment();
             c1.setResourcePath(path);
-            c1.setText("This is a test comment");
+            c1.setText("This is first test comment");
+
+            Comment c2 = new Comment();
+            c2.setResourcePath(path);
+            c2.setText("This is secound test comment");
 
             Properties r1Pro = new Properties();
             r1Pro.setProperty("key1", "value1");
@@ -131,7 +157,10 @@
 
             registry.put(path,r1);
             registry.addComment(path,c1);
+            registry.addComment(path,c2);
             registry.applyTag(path, "tag1");
+            registry.applyTag(path, "tag2");
+            registry.applyTag(path, "tag3");
             registry.rateResource(path, 4);
 
             Resource r2 = new Resource();
@@ -140,16 +169,18 @@
             assertEquals("Properties are not equal",r1.getProperty("key1"),
                          r2.getProperty("key1"));
 
-            Comment[] comments2 = registry.getComments(path);
-            assertEquals("There should be one comment.", 1, comments2.length);
-            String[] cTexts2 = {comments2[0].getText()};
-
-            assertTrue("comment is not exist",containsString(cTexts2, "This is 
a test comment"));
-
-            Tag[] tags = null;
-            tags = registry.getTags(path);
-            String[] r1TagText ={tags[0].getTagName()};
-            assertTrue("Tag is not exist",containsString(r1TagText, "tag1"));
+            assertEquals("Properties are not equal",r1.getProperty("key2"),
+                         r2.getProperty("key2"));
+
+            assertTrue(c1.getText() + " is not associated for resource"+ path,
+                        containsComment(commentPath,c1.getText()));
+
+            assertTrue(c2.getText() + " is not associated for resource"+ path,
+                        containsComment(commentPath,c2.getText()));
+
+            assertTrue("Tag1 is not copied",containsTag(path,"tag1"));
+            assertTrue("Tag2 is not copied",containsTag(path,"tag2"));
+            assertTrue("Tag3 is not copied",containsTag(path,"tag3"));
 
             float rating = registry.getAverageRating(path);
             assertEquals("Rating is not mathching", rating, (float)4.0,
@@ -167,18 +198,18 @@
             assertEquals("Properties are not equal",r2.getProperty("key1"),
                         r1Renamed.getProperty("key1"));
 
-            Comment[] comments3 = registry.getComments(new_path);
-                    assertEquals("There should be one comment.", 1, 
comments3.length);
-            String[] cTexts3 = {comments3[0].getText()};
-
-            assertTrue("comment is not copied",containsString(cTexts3,
-                       "This is a test comment"));
-
-            Tag[] tags1 = null;
-            tags1 = registry.getTags(new_path);
-            String[] r1TagText1 ={tags1[0].getTagName()};
+            assertEquals("Properties are not equal",r2.getProperty("key2"),
+                        r1Renamed.getProperty("key2"));
+
+            assertTrue(c1.getText() + " is not associated for resource"+ 
new_path,
+                        containsComment(commentPathNew,c1.getText()));
+
+            assertTrue(c2.getText() + " is not associated for resource"+ 
new_path,
+                        containsComment(commentPathNew,c2.getText()));
 
-            assertTrue("Tag is not copied",containsString(r1TagText1, "tag1"));
+            assertTrue("Tag1 is not copied",containsTag(new_path,"tag1"));
+            //assertTrue("Tag2 is not copied",containsTag(new_path,"tag2"));
+            //assertTrue("Tag3 is not copied",containsTag(new_path,"tag3"));
 
             float rating1 = registry.getAverageRating(new_path);
             assertEquals("Rating is not copied", rating1, (float)4.0,
@@ -192,6 +223,51 @@
             }
     }
 
+    private boolean containsComment(String pathValue, String commentText) {
+
+        Comment[] commentsArray = null;
+        List commentTexts = new ArrayList();
+
+        try{
+            Resource commentsResource = registry.get(pathValue);
+            commentsArray = (Comment[])commentsResource.getContent();
+            for (Comment comment : commentsArray) {
+                Resource commentResource = 
registry.get(comment.getCommentPath());
+                commentTexts.add(commentResource.getContent());
+            }
+        }catch (RegistryException e) {
+            e.printStackTrace();
+        }
+
+        boolean found = false;
+        if(commentTexts.contains(commentText)){
+            found=true;
+        }
+
+        return found;
+    }
+
+    private boolean containsTag(String tagPath,String tagText){
+
+        Tag[] tags = null;
+
+        try {
+            tags = registry.getTags(tagPath);
+        } catch (RegistryException e) {
+            e.printStackTrace();
+        }
+
+        boolean tagFound = false;
+        for (int i = 0; i < tags.length; i++) {
+            if (tags[i].getTagName().equals(tagText)) {
+                tagFound = true;
+                break;
+            }
+        }
+
+        return tagFound;
+    }
+
     private boolean containsString(String[] array, String value) {
 
         boolean found = false;
@@ -204,5 +280,6 @@
 
         return found;
     }
+
 }
 

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

Reply via email to