[Registry-dev] svn commit r9941 - trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc

svn at wso2.org svn at wso2.org
Tue Nov 20 01:00:27 PST 2007


Author: chathura
Date: Tue Nov 20 01:00:22 2007
New Revision: 9941

Modified:
   trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/JDBCRegistryTest.java
Log:

Added a test case for testing custom queries with return type comment.



Modified: trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/JDBCRegistryTest.java
==============================================================================
--- trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/JDBCRegistryTest.java	(original)
+++ trunk/registry/modules/core/src/test/java/org/wso2/registry/jdbc/JDBCRegistryTest.java	Tue Nov 20 01:00:22 2007
@@ -733,6 +733,69 @@
         }
     }
 
+    public void testUserDefinedCommentsQuery() {
+
+        try {
+
+            Resource r1 = new Resource();
+            String r1Content = "this is r1 content";
+            r1.setContent(r1Content.getBytes());
+            r1.setDescription("production ready.");
+            String r1Path = "/c5/r1";
+            registry.put(r1Path, r1);
+
+            Resource r2 = new Resource();
+            String r2Content = "content for r2 :)";
+            r2.setContent(r2Content);
+            r2.setDescription("ready for production use.");
+            String r2Path = "/c5/r2";
+            registry.put(r2Path, r2);
+
+            Resource r3 = new Resource();
+            String r3Content = "content for r3 :)";
+            r3.setContent(r3Content);
+            r3.setDescription("only for government use.");
+            String r3Path = "/c5/r3";
+            registry.put(r3Path, r3);
+
+            registry.addComment("/c5/r1", new Comment("we have to change this file."));
+            registry.addComment("/c5/r2", new Comment("replace this with a better one"));
+            registry.addComment("/c5/r3", new Comment("import all dependencies for this resource"));
+
+            String sql1 = "SELECT C.CM_ID FROM COMMENTS C, ARTIFACTS A WHERE A.AID=C.AID AND A.DESCRIPTION LIKE ?";
+            Resource q1 = new Resource();
+            q1.setContent(sql1);
+            q1.setMediaType(RegistryConstants.SQL_QUERY_MEDIA_TYPE);
+            q1.setProperty(RegistryConstants.RESULT_TYPE_PROPERTY_NAME,
+                    RegistryConstants.COMMENTS_RESULT_TYPE);
+            registry.put("/qs/q4", q1);
+
+        } catch (RegistryException e) {
+            fail("Valid put resource scenarios failed.");
+        }
+
+        try {
+            Resource result1 = registry.executeQuery("/qs/q4", new String[] {"%production%"});
+
+            assertTrue("Search with result type Comment should return a collection.",
+                    result1.isDirectory());
+
+            String[] commentPaths = (String[]) result1.getContent();
+            assertEquals("There should be two match comments.", commentPaths.length, 2);
+
+            Resource c1 = registry.get(commentPaths[0]);
+            assertEquals("First matching comment is incorrect",
+                    (String) c1.getContent(), "we have to change this file.");
+
+            Resource c2 = registry.get(commentPaths[1]);
+            assertEquals("Second matching comment is incorrect",
+                    (String) c2.getContent(), "replace this with a better one");
+
+        } catch (RegistryException e) {
+            fail("Failed to execute query.");
+        }
+    }
+
     public void testTagsAsResources() {
 
         //Resource r1 = new Resource();



More information about the Registry-dev mailing list