Author: krishantha
Date: Mon Jan 21 01:50:42 2008
New Revision: 12580
Log:
Added:
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/TaggingTest.java
Added:
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/TaggingTest.java
==============================================================================
--- (empty file)
+++
trunk/registry/modules/core/src/test/java/org/wso2/registry/app/TaggingTest.java
Mon Jan 21 01:50:42 2008
@@ -0,0 +1,463 @@
+
+package org.wso2.registry.app;
+
+import junit.framework.TestCase;
+import org.wso2.registry.*;
+
+import java.net.URL;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: krishantha
+ * Date: Jan 17, 2008
+ * Time: 7:28:19 AM
+ * To change this template use File | Settings | File Templates.
+ */
+
+
+public class TaggingTest 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 testAddTagging() {
+ // add a resource
+
+ try {
+ Resource r1 = new Resource();
+
+ r1.setAuthorUserName("Author q1");
+ byte[] r1content = "q1 content".getBytes();
+ r1.setContent(r1content);
+ registry.put("/d11/r1", r1);
+
+ Resource r2 = new Resource();
+ r2.setAuthorUserName("Author q2");
+ byte[] r2content = "q2 content".getBytes();
+ r2.setContent(r2content);
+ registry.put("/d11/r2", r2);
+
+ Resource r3 = new Resource();
+ r3.setAuthorUserName("Author q3");
+ byte[] r3content = "q3 content".getBytes();
+ r3.setContent(r3content);
+ registry.put("/d11/r3", r3);
+
+
+ } catch (RegistryException e) {
+ fail("Failed to put test resources.");
+ }
+
+ try {
+
+ registry.applyTag("/d11/r1", "jsp");
+ registry.applyTag("/d11/r2", "jsp");
+ registry.applyTag("/d11/r3", "java");
+ } catch (RegistryException e) {
+ fail("Valid tagging scenario failed");
+ }
+
+ TaggedResourcePath[] paths = null;
+ try {
+
+ paths = registry.getResourcePathsWithTag("jsp");
+ } catch (RegistryException e) {
+ fail("Failed to get resources with tag 'jsp'");
+ }
+ boolean artifactFound = false;
+ for (int i = 0; i < paths.length; i++) {
+ System.out.println("Available resource paths:" +
paths[i].getResourcePath());
+
+ if (paths[i].getResourcePath().equals("/d11/r1")) {
+
+ artifactFound = true;
+ //break;
+ }
+ }
+ assertTrue("/d11/r1 is not tagged with the tag \"jsp\"",
artifactFound);
+
+ Tag[] tags = null;
+
+
+ try {
+ tags = registry.getTags("/d11/r1");
+ } catch (RegistryException e) {
+ fail("Failed to get tags for the resource /d11/r1");
+ }
+
+ boolean tagFound = false;
+ for (int i = 0; i < tags.length; i++) {
+ if (tags[i].getTagName().equals("jsp")) {
+ tagFound = true;
+ break;
+ }
+ }
+ assertTrue("tag 'jsp' is not associated with the artifact /d11/r1",
tagFound);
+
+ /* try {
+ //registry.delete("/d11");
+ } catch (RegistryException e) {
+ fail("Failed to delete test resources.");
+ }
+ */
+
+ TaggedResourcePath[] paths2 = null;
+
+ try {
+ paths2 = registry.getResourcePathsWithTag("jsp");
+ } catch (RegistryException e) {
+ fail("Failed to get resources with tag 'jsp'");
+ }
+
+// assertEquals("Tag based search should not return paths of deleted
resources.", paths2.length, 0);
+ }
+
+ public void testDuplicateTagging() {
+
+ try {
+ Resource r1 = new Resource();
+
+ r1.setAuthorUserName("Author q1 duplicate");
+ byte[] r1content = "q1 content".getBytes();
+ r1.setContent(r1content);
+ registry.put("/d12/r1", r1);
+
+
+ } catch (RegistryException e) {
+ fail("Failed to put test resources.");
+ }
+
+ try {
+
+ registry.applyTag("/d12/r1", "tag1");
+ registry.applyTag("/d12/r1", "tag2");
+
+ } catch (RegistryException e) {
+ fail("Valid tagging scenario failed");
+ }
+
+ Tag[] tags = null;
+
+ try {
+ tags = registry.getTags("/d12/r1");
+ } catch (RegistryException e) {
+ fail("Failed to get tags for the resource /d11/r1");
+ }
+
+ boolean tagFound = false;
+ for (int i = 0; i < tags.length; i++) {
+ if (tags[i].getTagName().equals("tag1")) {
+ tagFound = true;
+ System.out.println(tags[i].getTagName());
+ System.out.println(tags[i].getCategory());
+ System.out.println(tags[i].getTagCount());
+
+ break;
+
+ }
+ }
+ assertTrue("tag 'tag1' is not associated with the artifact /d12/r1",
tagFound);
+ }
+
+ public void testAddTaggingCollection() {
+
+ try {
+ Resource r1 = new Resource();
+
+ r1.setAuthorUserName("Author q1 collection");
+ r1.setDirectory(true);
+ registry.put("/d13/d14", r1);
+
+
+ } catch (RegistryException e) {
+ fail("Failed to put Collection.");
+ }
+
+ try {
+
+ registry.applyTag("/d13/d14", "col_tag1");
+
+ } catch (RegistryException e) {
+ fail("Valid tagging scenario failed");
+ }
+
+ Tag[] tags = null;
+
+ try {
+ tags = registry.getTags("/d13/d14");
+ } catch (RegistryException e) {
+ fail("Failed to get tags for the collection /d13/d14");
+ }
+
+ boolean tagFound = false;
+ for (int i = 0; i < tags.length; i++) {
+ if (tags[i].getTagName().equals("col_tag1")) {
+ tagFound = true;
+ System.out.println(tags[i].getTagName());
+ System.out.println(tags[i].getCategory());
+ System.out.println(tags[i].getTagCount());
+ break;
+
+ }
+ }
+ assertTrue("tag 'col_tag1' is not associated with the artifact
/d13/d14", tagFound);
+ }
+
+ public void testEditTagging() {
+
+ try {
+
+ Resource r1=new Resource();
+ r1.setAuthorUserName("Author q1 Edit");
+ byte[] r1content = "q1 content".getBytes();
+ r1.setContent(r1content);
+ registry.put("/d14/d13/r1", r1);
+
+
+
+ } catch (RegistryException e) {
+ fail("Failed to put Resource.");
+ }
+
+ try {
+
+ registry.applyTag("/d14/d13/r1", "tag1");
+ registry.applyTag("/d14/d13/r1", "tag2");
+
+ } catch (RegistryException e) {
+ fail("Valid tagging scenario failed");
+ }
+
+ Tag[] tags = null;
+
+ try {
+ tags = registry.getTags("/d14/d13/r1");
+ } catch (RegistryException e) {
+ fail("Failed to get tags for the collection /d14/d13/r1");
+ }
+
+ boolean tagFound = false;
+ for (int i = 0; i < tags.length; i++) {
+ if (tags[i].getTagName().equals("tag1")) {
+ tagFound = true;
+ System.out.println(tags[i].getTagName());
+ System.out.println(tags[i].getCategory());
+ System.out.println(tags[i].getTagCount());
+ System.out.println(tags.length);
+
+ tags[i].setTagName("tag1_updated");
+ break;
+
+ }
+
+ }
+
+ TaggedResourcePath[] paths = null;
+ try {
+
+ paths = registry.getResourcePathsWithTag("tag1");
+
+ } catch (RegistryException e) {
+ fail("Failed to get resources with tag 'tag1'");
+ }
+ boolean artifactFound = false;
+ for (int i = 0; i < paths.length; i++) {
+ if (paths[i].getResourcePath().equals("/d14/d13/r1")) {
+ System.out.println(paths[i].getResourcePath());
+ System.out.println(paths[i].getTagCount());
+ System.out.println(paths[i].getTagCounts());
+ artifactFound = true;
+ //break;
+ }
+ }
+ assertTrue("/d11/r1 is not tagged with the tag \"jsp\"",
artifactFound);
+ assertTrue("tag 'col_tag1' is not associated with the artifact
/d14/d13/r1", tagFound);
+ }
+
+ public void testRemoveResourceTagging() {
+
+ try {
+
+ Resource r1=new Resource();
+ r1.setAuthorUserName("Author q1 remove");
+ byte[] r1content = "q1 content".getBytes();
+ r1.setContent(r1content);
+ registry.put("/d15/d14/r1", r1);
+
+
+
+ } catch (RegistryException e) {
+ fail("Failed to put Resource.");
+ }
+
+ try {
+
+ registry.applyTag("/d15/d14/r1", "tag1");
+ registry.applyTag("/d15/d14/r1", "tag2");
+
+ } catch (RegistryException e) {
+ fail("Valid tagging scenario failed");
+ }
+
+ Tag[] tags = null;
+
+ try {
+ tags = registry.getTags("/d15/d14/r1");
+ } catch (RegistryException e) {
+ fail("Failed to get tags for the collection /d15/d14/r1");
+ }
+
+ boolean tagFound = false;
+ for (int i = 0; i < tags.length; i++) {
+ System.out.println("Available tags:" + tags[i].getTagName());
+ if (tags[i].getTagName().equals("tag1")) {
+ tagFound = true;
+ System.out.println(tags[i].getTagName());
+ System.out.println(tags[i].getCategory());
+ System.out.println(tags[i].getTagCount());
+ System.out.println(tags.length);
+
+ //break;
+
+ }
+
+ }
+
+ assertTrue("tag 'tag1' is not associated with the artifact
/d15/d14/r1", tagFound);
+
+ /*remove tag goes here*/
+
+ try{
+ registry.removeTag("/d15/d14/r1","tag1");
+ }catch(RegistryException e){
+ fail("Failed to remove tag1 from /d15/d14/r1");
+ }
+
+ TaggedResourcePath[] paths = null;
+ try {
+
+ paths = registry.getResourcePathsWithTag("tag1");
+
+ } catch (RegistryException e) {
+ fail("Failed to get resources with tag 'tag1'");
+ }
+ boolean artifactFound = false;
+ for (int i = 0; i < paths.length; i++) {
+ System.out.println("tag1 Available at:" +
paths[i].getResourcePath());
+ if (paths[i].getResourcePath().equals("/d15/d14/r1")) {
+ System.out.println(paths[i].getResourcePath());
+ System.out.println(paths[i].getTagCount());
+ System.out.println(paths[i].getTagCounts());
+ artifactFound = true;
+ //break;
+ }
+ }
+ assertFalse("/d15/d14/r1 is not tagged with the tag \"tag1\"",
artifactFound);
+ //assertTrue("/d15/d14/r1 is not tagged with the tag \"tag1\"",
artifactFound);
+ assertTrue("tag 'tag1' is not associated with the artifact
/d15/d14/r1", tagFound);
+ }
+
+ public void testRemoveCollectionTagging() {
+
+ try {
+
+ Resource r1=new Resource();
+ r1.setAuthorUserName("Author q1 remove");
+ r1.setDirectory(true);
+ registry.put("/d15/d14/d13/d12", r1);
+
+
+ } catch (RegistryException e) {
+ fail("Failed to put Collection.");
+ }
+
+ try {
+
+ registry.applyTag("/d15/d14/d13", "tag1");
+ registry.applyTag("/d15/d14/d13", "tag2");
+ registry.applyTag("/d15/d14/d13", "tag3");
+
+ } catch (RegistryException e) {
+ fail("Valid tagging scenario failed");
+ }
+
+ Tag[] tags = null;
+
+ try {
+ tags = registry.getTags("/d15/d14/d13");
+
+ } catch (RegistryException e) {
+ fail("Failed to get tags for the collection /d15/d14/d13");
+ }
+ System.out.println("getTagCount:" + tags[0].getTagCount());
+
+ boolean tagFound = false;
+ for (int i = 0; i < tags.length; i++) {
+ System.out.println("Available tags:" +
tags[i].getTagName());
+ System.out.println("getTagCount for:" +
tags[i].getTagCount());
+ if (tags[i].getTagName().equals("tag1")) {
+ tagFound = true;
+ System.out.println("getTagName:" +
tags[i].getTagName());
+ System.out.println("getCategory:" +
tags[i].getCategory());
+ System.out.println("getTagCount:" +
tags[i].getTagCount());
+ System.out.println("TagLength:" + tags.length);
+
+ //break;
+
+ }
+
+ }
+
+ assertTrue("tag 'tag1' is not associated with the artifact
/d15/d14/d13", tagFound);
+
+ /*remove tag goes here*/
+
+ try{
+ registry.removeTag("/d15/d14/d13","tag1");
+ }catch(RegistryException e){
+ fail("Failed to remove tag1 from /d15/d14/d13");
+ }
+
+ TaggedResourcePath[] paths = null;
+ try {
+
+ paths = registry.getResourcePathsWithTag("tag1");
+
+ } catch (RegistryException e) {
+ fail("Failed to get resources with tag 'tag1'");
+ }
+
+ System.out.println("Path tag counts:" + paths.length);
+ boolean artifactFound = false;
+ for (int i = 0; i < paths.length; i++) {
+ System.out.println("tag1 Available at:" +
paths[i].getResourcePath());
+ System.out.println("getTagCounts:" +
paths[i].getTagCounts());
+ System.out.println("getTagCount:" + paths[i].getTagCount());
+
+ if (paths[i].getResourcePath().equals("/d15/d14/d13")) {
+ System.out.println("getResourcePath:" +
paths[i].getResourcePath());
+ System.out.println("getTagCount:" +
paths[i].getTagCount());
+ System.out.println("getTagCounts:" +
paths[i].getTagCounts());
+ artifactFound = true;
+ //break;
+ }
+ }
+ assertFalse("/d15/d14/d13 is not tagged with the tag \"tag1\"",
artifactFound);
+ //assertTrue("/d15/d14/r1 is not tagged with the tag \"tag1\"",
artifactFound);
+ assertTrue("tag 'tag1' is not associated with the artifact
/d15/d14/d13", tagFound);
+ }
+
+
+}
+
_______________________________________________
Registry-dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/registry-dev