enable published data validation

add flag to indicate the last component for autocompletion

Change-Id: Ice97969b2043dd0e15d00576e605d19a7528f21d
diff --git a/catalog/tests/unit-tests/query/test-query-adapter.cpp b/catalog/tests/unit-tests/query/test-query-adapter.cpp
index b49ea03..8b210b7 100644
--- a/catalog/tests/unit-tests/query/test-query-adapter.cpp
+++ b/catalog/tests/unit-tests/query/test-query-adapter.cpp
@@ -101,7 +101,7 @@
                  uint64_t viewEnd)
     {
       return makeReplyData(segmentPrefix, value, segmentNo, isFinalBlock,
-                           isAutocomplete, resultCount, viewStart, viewEnd);
+                           isAutocomplete, resultCount, viewStart, viewEnd, false);
     }
 
     void
@@ -113,7 +113,8 @@
     void
     prepareSegments(const ndn::Name& segmentPrefix,
                     const std::string& sqlString,
-                    bool autocomplete)
+                    bool autocomplete,
+                    bool lastComponent)
     {
       BOOST_CHECK_EQUAL(sqlString, "SELECT name FROM cmip5 WHERE name=\'test\';");
       Json::Value fileList;
@@ -122,7 +123,8 @@
       fileList.append("/ndn/test3");
 
       std::shared_ptr<ndn::Data> data = makeReplyData(segmentPrefix,
-                                                      fileList, 0, true, false, 3, 0, 2);
+                                                      fileList, 0, true, false,
+                                                      3, 0, 2, lastComponent);
       m_mutex.lock();
       m_cache.insert(*data);
       m_mutex.unlock();
@@ -158,9 +160,10 @@
 
     bool
     json2AutocompletionSqlTest(std::stringstream& sqlQuery,
-                               Json::Value& jsonValue)
+                               Json::Value& jsonValue,
+                               bool& lastComponent)
     {
-      return json2AutocompletionSql(sqlQuery, jsonValue);
+      return json2AutocompletionSql(sqlQuery, jsonValue, lastComponent);
     }
 
     bool
@@ -505,22 +508,29 @@
 
     std::stringstream ss;
     Json::Value testJson;
+    bool lastComponent = false;
     testJson["?"] = "/";
-    BOOST_CHECK_EQUAL(true, queryAdapterTest2.json2AutocompletionSqlTest(ss, testJson));
+    BOOST_CHECK_EQUAL(true,
+                      queryAdapterTest2.json2AutocompletionSqlTest(ss, testJson, lastComponent));
+    BOOST_CHECK_EQUAL(lastComponent, false);
     BOOST_CHECK_EQUAL("SELECT DISTINCT activity FROM cmip5;", ss.str());
 
     ss.str("");
     ss.clear();
     testJson.clear();
     testJson["?"] = "/Activity/";
-    BOOST_CHECK_EQUAL(true, queryAdapterTest2.json2AutocompletionSqlTest(ss, testJson));
+    BOOST_CHECK_EQUAL(true,
+                      queryAdapterTest2.json2AutocompletionSqlTest(ss, testJson, lastComponent));
+    BOOST_CHECK_EQUAL(lastComponent, false);
     BOOST_CHECK_EQUAL("SELECT DISTINCT product FROM cmip5 WHERE activity='Activity';", ss.str());
 
     ss.str("");
     ss.clear();
     testJson.clear();
     testJson["?"] = "/Activity/Product/Organization/Model/Experiment/";
-    BOOST_CHECK_EQUAL(true, queryAdapterTest2.json2AutocompletionSqlTest(ss, testJson));
+    BOOST_CHECK_EQUAL(true,
+                      queryAdapterTest2.json2AutocompletionSqlTest(ss, testJson, lastComponent));
+    BOOST_CHECK_EQUAL(lastComponent, false);
     BOOST_CHECK_EQUAL("SELECT DISTINCT frequency FROM cmip5 WHERE activity='Activity' AND \
 experiment='Experiment' AND model='Model' AND organization='Organization' AND product='Product';",
      ss.str());
@@ -530,7 +540,9 @@
     testJson.clear();
     testJson["?"] = "/Activity/Product/Organization/Model/Experiment/Frequency/Modeling/\
 Variable/Ensemble/";
-    BOOST_CHECK_EQUAL(true, queryAdapterTest2.json2AutocompletionSqlTest(ss, testJson));
+    BOOST_CHECK_EQUAL(true,
+                      queryAdapterTest2.json2AutocompletionSqlTest(ss, testJson, lastComponent));
+    BOOST_CHECK_EQUAL(lastComponent, true);
     BOOST_CHECK_EQUAL("SELECT DISTINCT time FROM cmip5 WHERE activity='Activity' AND ensemble=\
 'Ensemble' AND experiment='Experiment' AND frequency='Frequency' AND model='Model' AND \
 modeling_realm='Modeling' AND organization='Organization' AND product='Product' AND variable_name=\
@@ -543,26 +555,31 @@
 
     std::stringstream ss;
     Json::Value testJson;
+    bool lastComponent = false;
     testJson["?"] = "serchTest";
-    BOOST_CHECK_EQUAL(false, queryAdapterTest2.json2AutocompletionSqlTest(ss, testJson));
+    BOOST_CHECK_EQUAL(false,
+                      queryAdapterTest2.json2AutocompletionSqlTest(ss, testJson, lastComponent));
 
     ss.str("");
     ss.clear();
     testJson.clear();
     testJson["?"] = "/cmip5";
-    BOOST_CHECK_EQUAL(false, queryAdapterTest2.json2AutocompletionSqlTest(ss, testJson));
+    BOOST_CHECK_EQUAL(false,
+                      queryAdapterTest2.json2AutocompletionSqlTest(ss, testJson, lastComponent));
 
     ss.str("");
     ss.clear();
     Json::Value testJson2; //simply clear does not work
     testJson2[0] = "test";
-    BOOST_CHECK_EQUAL(false, queryAdapterTest2.json2AutocompletionSqlTest(ss, testJson2));
+    BOOST_CHECK_EQUAL(false,
+                      queryAdapterTest2.json2AutocompletionSqlTest(ss, testJson2, lastComponent));
 
     ss.str("");
     ss.clear();
     Json::Value testJson3;
     testJson3 = Json::Value(Json::arrayValue);
-    BOOST_CHECK_EQUAL(false, queryAdapterTest2.json2AutocompletionSqlTest(ss, testJson3));
+    BOOST_CHECK_EQUAL(false,
+                      queryAdapterTest2.json2AutocompletionSqlTest(ss, testJson3, lastComponent));
 
     ss.str("");
     ss.clear();
@@ -570,7 +587,8 @@
     Json::Value param;
     param[0] = "test";
     testJson4["name"] = param;
-    BOOST_CHECK_EQUAL(false, queryAdapterTest2.json2AutocompletionSqlTest(ss, testJson4));
+    BOOST_CHECK_EQUAL(false,
+                      queryAdapterTest2.json2AutocompletionSqlTest(ss, testJson4, lastComponent));
 }
 
   BOOST_AUTO_TEST_CASE(QueryAdapterPrefixBasedSearchSuccessTest)