lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yo...@apache.org
Subject svn commit: r1501809 - in /lucene/dev/trunk/solr: core/src/test/org/apache/solr/rest/schema/TestManagedSchemaFieldResource.java test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java test-framework/src/java/org/apache/solr/util/RestTestBase.java
Date Wed, 10 Jul 2013 15:54:35 GMT
Author: yonik
Date: Wed Jul 10 15:54:35 2013
New Revision: 1501809

URL: http://svn.apache.org/r1501809
Log:
tests: use single quoted json for readability

Modified:
    lucene/dev/trunk/solr/core/src/test/org/apache/solr/rest/schema/TestManagedSchemaFieldResource.java
    lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
    lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/util/RestTestBase.java

Modified: lucene/dev/trunk/solr/core/src/test/org/apache/solr/rest/schema/TestManagedSchemaFieldResource.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/core/src/test/org/apache/solr/rest/schema/TestManagedSchemaFieldResource.java?rev=1501809&r1=1501808&r2=1501809&view=diff
==============================================================================
--- lucene/dev/trunk/solr/core/src/test/org/apache/solr/rest/schema/TestManagedSchemaFieldResource.java
(original)
+++ lucene/dev/trunk/solr/core/src/test/org/apache/solr/rest/schema/TestManagedSchemaFieldResource.java
Wed Jul 10 15:54:35 2013
@@ -58,14 +58,14 @@ public class TestManagedSchemaFieldResou
   @Test
   public void testAddFieldBadFieldType() throws Exception {
     assertJPut("/schema/fields/newfield",
-        "{\"type\":\"not_in_there_at_all\",\"stored\":\"false\"}",
+        json( "{'type':'not_in_there_at_all','stored':'false'}" ),
         "/error/msg==\"Field \\'newfield\\': Field type \\'not_in_there_at_all\\' not found.\"");
   }
 
   @Test
   public void testAddFieldMismatchedName() throws Exception {
     assertJPut("/schema/fields/newfield",
-        "{\"name\":\"something_else\",\"type\":\"text\",\"stored\":\"false\"}",
+        json( "{'name':'something_else','type':'text','stored':'false'}" ),
         "/error/msg==\"Field name in the request body \\'something_else\\'"
             + " doesn\\'t match field name in the request URL \\'newfield\\'\"");
   }
@@ -73,7 +73,7 @@ public class TestManagedSchemaFieldResou
   @Test
   public void testAddFieldBadProperty() throws Exception {
     assertJPut("/schema/fields/newfield",
-        "{\"type\":\"text\",\"no_property_with_this_name\":\"false\"}",
+        json( "{'type':'text','no_property_with_this_name':'false'}" ),
         "/error/msg==\"java.lang.IllegalArgumentException: Invalid field property: no_property_with_this_name\"");
   }
   
@@ -85,7 +85,7 @@ public class TestManagedSchemaFieldResou
             "/response/lst[@name='error']/int[@name='code'] = '404'");
     
     assertJPut("/schema/fields/newfield",
-        "{\"type\":\"text\",\"stored\":\"false\"}",
+        json( "{'type':'text','stored':'false'}" ),
         "/responseHeader/status==0");
     
     assertQ("/schema/fields/newfield?indent=on&wt=xml",
@@ -176,9 +176,9 @@ public class TestManagedSchemaFieldResou
   @Test
   public void testPostCopy() throws Exception {
     assertJPost("/schema/fields",
-              "[{\"name\":\"fieldA\",\"type\":\"text\",\"stored\":\"false\"},"
-               + "{\"name\":\"fieldB\",\"type\":\"text\",\"stored\":\"false\"},"
-               + " {\"name\":\"fieldC\",\"type\":\"text\",\"stored\":\"false\", \"copyFields\":[\"fieldB\"]}]",
+        json(    "[{'name':'fieldA','type':'text','stored':'false'},"
+               + " {'name':'fieldB','type':'text','stored':'false'},"
+               + " {'name':'fieldC','type':'text','stored':'false', 'copyFields':['fieldB']}]"
),
                 "/responseHeader/status==0");
     assertQ("/schema/copyfields/?indent=on&wt=xml&source.fl=fieldC",
         "count(/response/arr[@name='copyFields']/lst) = 1"

Modified: lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java?rev=1501809&r1=1501808&r2=1501809&view=diff
==============================================================================
--- lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java (original)
+++ lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java Wed
Jul 10 15:54:35 2013
@@ -76,6 +76,8 @@ import java.util.Map;
 import java.util.logging.ConsoleHandler;
 import java.util.logging.Handler;
 import java.util.logging.Level;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import static com.google.common.base.Preconditions.checkNotNull;
 
@@ -642,7 +644,7 @@ public abstract class SolrTestCaseJ4 ext
   /**
    * Validates a query matches some JSON test expressions and closes the
    * query. The text expression is of the form path:JSON.  To facilitate
-   * easy embedding in Java strings, the JSON can have double quotes
+   * easy embedding in Java strings, the JSON tests can have double quotes
    * replaced with single quotes.
    * <p>
    * Please use this with care: this makes it easy to match complete
@@ -677,7 +679,7 @@ public abstract class SolrTestCaseJ4 ext
 
       for (String test : tests) {
         if (test == null || test.length()==0) continue;
-        String testJSON = test.replace('\'', '"');
+        String testJSON = json(test);
 
         try {
           failed = true;
@@ -934,6 +936,24 @@ public abstract class SolrTestCaseJ4 ext
     return sd;
   }
 
+  /** Converts "test JSON" and returns standard JSON.
+   *  Currently this only consists of changing unescaped single quotes to double quotes,
+   *  and escaped single quotes to single quotes.
+   *
+   * The primary purpose is to be able to easily embed JSON strings in a JAVA string
+   * with the best readability.
+   *
+   * This transformation is automatically applied to JSON test srings (like assertJQ).
+   */
+  public static String json(String testJSON) {
+    testJSON = nonEscapedSingleQuotePattern.matcher(testJSON).replaceAll("\"");
+    testJSON = escapedSingleQuotePattern.matcher(testJSON).replaceAll("'");
+    return testJSON;
+  }
+  private static Pattern nonEscapedSingleQuotePattern = Pattern.compile("(?<!\\\\)\'");
+  private static Pattern escapedSingleQuotePattern = Pattern.compile("\\\\\'");
+
+
   /** Creates JSON from a SolrInputDocument.  Doesn't currently handle boosts. */
   public static String json(SolrInputDocument doc) {
      CharArr out = new CharArr();

Modified: lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/util/RestTestBase.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/util/RestTestBase.java?rev=1501809&r1=1501808&r2=1501809&view=diff
==============================================================================
--- lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/util/RestTestBase.java (original)
+++ lucene/dev/trunk/solr/test-framework/src/java/org/apache/solr/util/RestTestBase.java Wed
Jul 10 15:54:35 2013
@@ -229,8 +229,7 @@ abstract public class RestTestBase exten
 
     for (String test : tests) {
       if (null == test || 0 == test.length()) continue;
-      String testJSON = test.replaceAll("(?<!\\\\)\'", "\"");
-      testJSON = testJSON.replaceAll("\\\\\'", "'");
+      String testJSON = json(test);
 
       try {
         failed = true;
@@ -311,8 +310,7 @@ abstract public class RestTestBase exten
 
     for (String test : tests) {
       if (null == test || 0 == test.length()) continue;
-      String testJSON = test.replaceAll("(?<!\\\\)\'", "\"");
-      testJSON = testJSON.replaceAll("\\\\\'", "'");
+      String testJSON = json(test);
 
       try {
         failed = true;
@@ -391,8 +389,7 @@ abstract public class RestTestBase exten
 
     for (String test : tests) {
       if (null == test || 0 == test.length()) continue;
-      String testJSON = test.replaceAll("(?<!\\\\)\'", "\"");
-      testJSON = testJSON.replaceAll("\\\\\'", "'");
+      String testJSON = json(test);
 
       try {
         failed = true;



Mime
View raw message