Author: navssurtani
Date: 2008-06-04 12:19:41 -0400 (Wed, 04 Jun 2008)
New Revision: 5951
Added:
searchable/trunk/src/test/java/TransformerTest.java
Modified:
searchable/trunk/src/main/java/org/jboss/cache/search/Transformer.java
Log:
Fixed up Transfomer methods and wrote Test for it. 3 Tests pass.
Modified: searchable/trunk/src/main/java/org/jboss/cache/search/Transformer.java
===================================================================
--- searchable/trunk/src/main/java/org/jboss/cache/search/Transformer.java 2008-06-04
15:47:45 UTC (rev 5950)
+++ searchable/trunk/src/main/java/org/jboss/cache/search/Transformer.java 2008-06-04
16:19:41 UTC (rev 5951)
@@ -13,7 +13,7 @@
{
public static String getKey(String docId)
{
- //Comes in the format "Fqn=[a/b/c]Key=[key]"
+ //docID comes in the format "Fqn=[/a/b/c]Key=[key]"
// This will be the index of the first time the sub-String "key=[" occurs
within the whole String.
int startIndex = docId.indexOf("Key=[");
@@ -23,7 +23,7 @@
int endIndex = docId.indexOf("]", startIndex);
//Make the startIndex index point at the first char in the key sequence.
- startIndex += 1;
+ startIndex += 5;
//The resultant key that will be returned.
String key = docId.substring(startIndex, endIndex);
@@ -33,9 +33,12 @@
public static Fqn getFqn(String docId)
{
+ //docId comes in the format "Fqn=[/a/b/c]Key=[key]"
+
+
// This will be the index of the first time the sub-String "Fqn=[" occurs
within the whole String.
//Adding 1 so that the index being pointed at will be the first character in the
Fqn sequence.
- int startIndex = docId.indexOf("Fqn=[") + 1;
+ int startIndex = docId.indexOf("[") + 1;
//The endIndex of the Fqn sequence so that we know when to cut out the sub-String.
int endIndex = docId.indexOf("]");
Added: searchable/trunk/src/test/java/TransformerTest.java
===================================================================
--- searchable/trunk/src/test/java/TransformerTest.java (rev 0)
+++ searchable/trunk/src/test/java/TransformerTest.java 2008-06-04 16:19:41 UTC (rev
5951)
@@ -0,0 +1,53 @@
+import org.jboss.cache.Fqn;
+import org.jboss.cache.search.Transformer;
+import org.testng.annotations.Test;
+
+/**
+ * Created by IntelliJ IDEA.
+ * User: navin
+ * Date: Jun 4, 2008
+ * Time: 3:52:58 PM
+ * To change this template use File | Settings | File Templates.
+ */
+
+@Test
+public class TransformerTest
+{
+ public void testGenerateId()
+ {
+
+ Fqn fqn = Fqn.fromString("/a/b/c");
+ String key = "key";
+
+ String generatedId = Transformer.generateId(fqn, key);
+
+ assert generatedId.contentEquals("Fqn=[/a/b/c]Key=[key]");
+
+ assert ! generatedId.contentEquals("/ab/c/d");
+ }
+
+ public void testGetFqn()
+ {
+ Fqn fqn = Transformer.getFqn("Fqn=[/cat/dog/person]Key=[key]");
+
+ Fqn expectedFqn = Fqn.fromString("/cat/dog/person");
+
+ assert fqn.equals(expectedFqn);
+
+ expectedFqn = Fqn.fromString("/dog/cat/person");
+
+ assert !fqn.equals(expectedFqn);
+
+ }
+
+ public void testGetKey()
+ {
+ String key = Transformer.getKey("Fqn=[/a/b/c]Key=[thisIsMyKey]");
+
+ assert key.contentEquals("thisIsMyKey");
+
+ assert ! key.contentEquals("thisIsNotMyKey");
+
+ }
+
+}
Show replies by date