Author: krishantha
Date: Mon Jan 21 04:59:00 2008
New Revision: 12634

Log:

added more test cases for versioning test.

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

Modified: 
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/VersionTest.java
==============================================================================
--- 
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/VersionTest.java
    (original)
+++ 
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/VersionTest.java
    Mon Jan 21 04:59:00 2008
@@ -31,7 +31,7 @@
         try {
             if (registry == null) {
                 server.start();
-                registry = new RemoteRegistry(new 
URL("http://localhost:8081/wso2registry/atom";), "admin", "admin");
+                registry = new RemoteRegistry(new 
URL("http://localhost:8080/wso2registry/atom";), "admin", "admin");
             }
         } catch (Exception e) {
             fail("Failed to initialize the registry.");
@@ -159,4 +159,209 @@
         assertEquals("Restored file content is not matching",new 
String((byte[]) r1.getContent()),new String((byte[]) r3.getContent()));
         
     }
+
+    public void testUpdatedResourceRestore(){
+
+        Resource r1 = new Resource();
+        String content="this is my content new";
+        r1.setContent(content.getBytes());
+        String path="/c20/c21/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 get:" + new String((byte[]) 
r4.getContent()));
+        System.out.println("File content put:" + new String((byte[]) 
r1.getContent()));
+        assertEquals("File content is not Equal", new String((byte[]) 
r1.getContent()), new String((byte[]) r4.getContent()));
+
+        /*update the resource*/
+        Resource r5 = new Resource();
+        String content_update="this is my content updated";
+        r5.setContent(content_update.getBytes());                              
                               
+        String path_updated="/c20/c21/r1";
+        try{
+        registry.put(path_updated, r5);
+        } catch (RegistryException e){
+            fail("Failed to put test resources to" + path_updated);
+        }
+
+        /*read the resource*/
+        Resource r6= new Resource();
+        try{
+            r6=registry.get(path);
+        }catch (RegistryException e){
+            fail("Failed to read content from the file");
+        }
+
+        System.out.println("File content updated expected:" + new 
String((byte[]) r5.getContent()));
+        System.out.println("File content updated actual:" + new 
String((byte[]) r6.getContent()));
+
+
+        /*restore delted resource*/
+
+        try{
+            registry.restoreVersion("/c20/c21?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[]) 
r1.getContent()));
+        System.out.println("File content:" + new String((byte[]) 
r4.getContent()));
+        System.out.println("File content:" + new String((byte[]) 
r5.getContent()));
+        System.out.println("File content:" + new String((byte[]) 
r6.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()));
+
+    }
+
+    public void testReadfromVersionsPage(){
+
+        Resource r1 = new Resource();
+        String content="this is my content new";
+        r1.setContent(content.getBytes());
+        String path="/c22/c23/r1";
+        try{
+            registry.put(path, r1);
+            registry.put(path, r1);
+            registry.put(path, r1);
+        } catch (RegistryException e){
+            fail("Failed to put test resources to" + path);
+        }
+
+        /*read the resource*/
+        String path_versions="/c22/c23/r1?v=2";
+
+        Resource r4= new Resource();
+        try{
+            r4=registry.get(path_versions);
+
+        }catch (RegistryException e){
+            fail("Failed to read content from the file");
+        }
+
+        System.out.println("File content get:" + new String((byte[]) 
r4.getContent()));
+        System.out.println("File content put:" + new String((byte[]) 
r1.getContent()));
+        assertEquals("File content is not Equal", new String((byte[]) 
r1.getContent()), new String((byte[]) r4.getContent()));
+
+        String[] strarr= null;
+        try{
+           strarr=registry.getVersions("/c22/c23/r1");
+
+        }catch (RegistryException e){
+            fail("Failed to read content from the file");
+        }
+
+        for(int i=0;i<strarr.length;i++){
+            System.out.println(strarr[i]);
+
+            if(strarr[i].equals(path_versions)){
+                Resource r6= new Resource();
+                try{
+                    r6=registry.get(strarr[i]);
+                }catch (RegistryException e){
+                    fail("Failed to read content from the file");
+                }
+                System.out.println("File content get:" + new String((byte[]) 
r6.getContent()));
+                System.out.println("File content put:" + new String((byte[]) 
r1.getContent()));
+                assertEquals("File content is not Equal", new String((byte[]) 
r1.getContent()), new String((byte[]) r6.getContent()));
+
+                break;
+            }
+        }
+    }
+
+     public void testDeletedCollectionRestore(){
+
+        Resource r1 = new Resource();
+        String content="this is my content";
+        r1.setContent(content.getBytes());
+        String path="/c25/c26/c27/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()));
+        assertEquals("File content is not Equal",new String((byte[]) 
r1.getContent()),new String((byte[]) r4.getContent()));
+
+        /*delete the collection*/
+        String collection_path="/c25/c26";
+
+        try{
+            registry.delete(collection_path);
+        }catch (RegistryException e){
+            fail("Failed to delete the collection at" + collection_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("Collection not deleted.",deleted);
+
+        /*restore delted collection*/
+        /*
+        try{
+            registry.restoreVersion("/c25/c26?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