Author: krishantha
Date: Wed Feb 27 01:38:29 2008
New Revision: 14261

Log:

added testcases to test copy resources/collections.

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

Added: 
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/ResourceHandling.java
==============================================================================
--- (empty file)
+++ 
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/ResourceHandling.java
       Wed Feb 27 01:38:29 2008
@@ -0,0 +1,208 @@
+package org.wso2.registry.app;
+
+
+import org.wso2.registry.Comment;
+import org.wso2.registry.RegistryException;
+import org.wso2.registry.Resource;
+import org.wso2.registry.Tag;
+
+import java.util.Properties;
+
+
+public class ResourceHandling extends AbstractAPPTest {
+
+    
+    public void testResourceCopy() {
+
+        try {
+
+            String path="/f55/f2/r1";
+            String new_path="/f54/f2/r2";
+            Resource r1 = new Resource();
+            r1.setDirectory(false);
+            r1.setAuthorUserName("Author R2");
+            r1.setDescription("This is a file to be renamed");
+            byte[] r1content = "R2 content".getBytes();
+            r1.setContent(r1content);
+            r1.setMediaType("txt");
+
+            Comment c1 = new Comment();
+            c1.setResourcePath(path);
+            c1.setText("This is a test comment");
+
+            Properties r1Pro = new Properties();
+            r1Pro.setProperty("key1", "value1");
+            r1Pro.setProperty("key2", "value2");
+            r1.setProperties(r1Pro);
+
+            registry.put(path,r1);
+            registry.addComment(path,c1);
+            registry.applyTag(path, "tag1");
+            registry.rateResource(path, 4);
+
+            Resource r2 = new Resource();
+            r2 = registry.get(path);
+
+            assertEquals("Properties are not equal",r1.getProperty("key1"),
+                         r2.getProperty("key1"));
+
+            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"));
+
+            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());
+
+
+            registry.rename(path,new_path);
+
+            /*get renamed resource details*/
+
+            Resource r1Renamed = new Resource();
+
+            r1Renamed = registry.get(new_path);
+
+            assertEquals("File content is not matching", new 
String((byte[])r2.getContent()),
+                     new String((byte[])r1Renamed.getContent()));
+
+            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()};
+
+            assertTrue("Tag is not copied",containsString(r1TagText1, "tag1"));
+
+            float rating1 = registry.getAverageRating(new_path);
+            assertEquals("Rating is not copied", rating1, (float)4.0,
+                        (float)0.01);
+
+            assertEquals("Media type not copied",r2.getMediaType(),
+                        r1Renamed.getMediaType());
+
+            assertEquals("Authour Name is not copied",r1.getAuthorUserName(),
+                        r2.getAuthorUserName());
+
+            }catch (RegistryException e) {
+                       e.printStackTrace();
+            }
+    }
+
+    public void testCollectionCopy() {
+
+        try {
+
+            String path="/c78/c1/c2";
+            String new_path="/c79/c1/c3";
+            Resource r1 = new Resource();
+            r1.setDirectory(true);
+            r1.setAuthorUserName("Author R2");
+            r1.setDescription("This is a file to be renamed");
+
+            Comment c1 = new Comment();
+            c1.setResourcePath(path);
+            c1.setText("This is a test comment");
+
+            Properties r1Pro = new Properties();
+            r1Pro.setProperty("key1", "value1");
+            r1Pro.setProperty("key2", "value2");
+            r1.setProperties(r1Pro);
+
+            registry.put(path,r1);
+            registry.addComment(path,c1);
+            registry.applyTag(path, "tag1");
+            registry.rateResource(path, 4);
+
+            Resource r2 = new Resource();
+            r2 = registry.get(path);
+
+            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"));
+
+            float rating = registry.getAverageRating(path);
+            assertEquals("Rating is not mathching", rating, (float)4.0,
+                        (float)0.01);
+            assertEquals("Authour name is not 
exist",r1.getAuthorUserName(),r2.getAuthorUserName());
+
+            registry.rename(path,new_path);
+
+            /*get renamed resource details*/
+
+            Resource r1Renamed = new Resource();
+
+            r1Renamed = registry.get(new_path);
+
+            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()};
+
+            assertTrue("Tag is not copied",containsString(r1TagText1, "tag1"));
+
+            float rating1 = registry.getAverageRating(new_path);
+            assertEquals("Rating is not copied", rating1, (float)4.0,
+                        (float)0.01);
+
+            assertEquals("Author Name is not copied",r1.getAuthorUserName(),
+                        r2.getAuthorUserName());
+
+            }catch (RegistryException e) {
+                       e.printStackTrace();
+            }
+    }
+
+    private boolean containsString(String[] array, String value) {
+
+        boolean found = false;
+        for (String anArray : array) {
+            if (anArray.startsWith(value)) {
+                found = true;
+                break;
+            }
+        }
+
+        return found;
+    }
+}
+

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

Reply via email to