Author: krishantha
Date: Fri Jan 18 05:49:18 2008
New Revision: 12486

Log:

Testcases added

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

Added: 
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/VersionTest.java
==============================================================================
--- (empty file)
+++ 
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/VersionTest.java
    Fri Jan 18 05:49:18 2008
@@ -0,0 +1,154 @@
+package org.wso2.registry.app;
+
+import junit.framework.TestCase;
+import org.wso2.registry.Registry;
+import org.wso2.registry.RegistryException;
+import org.wso2.registry.Resource;
+
+import java.net.URL;
+
+/*
+ * Created by IntelliJ IDEA.
+ * User: krishantha
+ * Date: Jan 18, 2008
+ * Time: 11:23:00 AM
+ * To change this template use File | Settings | File Templates.
+ */
+public class VersionTest 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 testResourceRestore() throws RegistryException {
+            
+        Resource r1 = new Resource();
+        r1.setContent("Content1");
+        registry.put("/wso2/wsas/v1/r1/resource1", r1);
+        registry.put("/wso2/wsas/v1/resource1", r1);
+        Resource esb = new Resource();
+        esb.setContent("ESB content");
+        registry.put("/wso2/esb/v2/resource1", esb);
+        Resource resource1 = registry.get("/wso2/wsas/v1");
+        String[] content1 = ((String[])resource1.getContent());
+        assertEquals(2, content1.length);
+        assertEquals("/wso2/wsas/v1/r1", content1[0]);
+        assertEquals("/wso2/wsas/v1/resource1", content1[1]);
+        registry.delete("/wso2/wsas/v1");
+
+        Resource r2 = new Resource();
+        r2.setContent("Content2");
+        registry.put("/wso2/wsas/v1/r2/resource2", r2);
+        registry.put("/wso2/wsas/v1/resource2", r2);
+        resource1 = registry.get("/wso2/wsas/v1");
+        content1 = ((String[])resource1.getContent());
+        assertEquals(2, content1.length);
+
+        assertEquals("/wso2/wsas/v1/r2", content1[0]);
+        assertEquals("/wso2/wsas/v1/resource2", content1[1]);
+
+
+        registry.restoreVersion("/wso2/wsas?v=3");
+        resource1 = registry.get("/wso2/wsas/v1");
+        content1 = ((String[])resource1.getContent());
+        assertEquals(2, content1.length);
+        assertEquals("/wso2/wsas/v1/r1", content1[0]);
+        assertEquals("/wso2/wsas/v1/resource1", content1[1]);
+
+        Resource newresource = new Resource();
+        newresource.setContent("newcontent");
+        registry.put("/wso2/wsas/v1/r3", newresource);
+        resource1 = registry.get("/wso2/wsas/v1");
+        content1 = ((String[])resource1.getContent());
+        assertEquals(3, content1.length);
+        assertEquals("/wso2/wsas/v1/r1", content1[0]);
+        assertEquals("/wso2/wsas/v1/resource1", content1[1]);
+        assertEquals("/wso2/wsas/v1/r3", content1[2]);
+
+        registry.restoreVersion("/wso2/wsas?v=3");
+        resource1 = registry.get("/wso2/wsas/v1");
+        content1 = ((String[])resource1.getContent());
+        assertEquals(2, content1.length);
+        assertEquals("/wso2/wsas/v1/r1", content1[0]);
+        assertEquals("/wso2/wsas/v1/resource1", content1[1]);
+
+    }
+
+    public void testDeletedResourceRestore(){
+
+        Resource r1 = new Resource();
+        String content="this is my content";
+        r1.setContent(content.getBytes());
+        String path="/c10/c11/r1";
+        try{
+        registry.put(path, r1);
+        } catch (RegistryException e){
+            fail("Failed to put test resources to" + path);
+        }
+
+        /*read the resource*/
+        Resource r4= new Resource();
+        try{
+            r4=registry.get(path);
+        }catch (RegistryException e){
+            fail("Failed to read content from the file");
+        }
+        
+        System.out.println("File content:" + new String((byte[]) 
r4.getContent()));
+
+
+        /*delete the resource*/
+
+        try{
+            registry.delete(path);
+        }catch (RegistryException e){
+            fail("Failed to delete the resource at" + path);
+        }
+        
+        /*try to read deleted resource*/
+        boolean deleted= false;
+        Resource r2= new Resource();
+        try{
+            r2=registry.get(path);
+        }catch (RegistryException e){
+            if(r2.getContent()==null){
+            deleted=true;
+            }
+            //fail("Failed to read content from the deleted resource");
+        }
+        
+        assertTrue("Resource not deleted",deleted);
+
+        /*restore delted resource*/
+
+        try{
+            registry.restoreVersion("/c10/c11?v=1");
+        }catch(RegistryException e){
+            fail("Couldn't restore the version");
+        }
+       
+        /*read restored version*/
+
+        Resource r3= new Resource();
+        try{
+            r3=registry.get(path);
+        }catch (RegistryException e){
+            fail("Failed to read content from the resotered file");
+        }
+        System.out.println("File content:" + new String((byte[]) 
r4.getContent()));
+        System.out.println("File content:" + new String((byte[]) 
r1.getContent()));
+        System.out.println("File content:" + new String((byte[]) 
r3.getContent()));
+        assertEquals("Restored file content is not matching",new 
String((byte[]) r1.getContent()),new String((byte[]) r3.getContent()));
+        
+    }
+}

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

Reply via email to