add test cases to test S2GRAPH-186.
Project: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/commit/87a8cedd Tree: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/tree/87a8cedd Diff: http://git-wip-us.apache.org/repos/asf/incubator-s2graph/diff/87a8cedd Branch: refs/heads/master Commit: 87a8cedd00291f2bce9b14ea11df6e9a50d02fa0 Parents: f40affb Author: DO YUNG YOON <[email protected]> Authored: Mon Mar 26 09:57:25 2018 +0900 Committer: DO YUNG YOON <[email protected]> Committed: Mon Mar 26 09:57:25 2018 +0900 ---------------------------------------------------------------------- .../s2graph/core/rest/RequestParser.scala | 3 +- .../core/Integrate/IntegrateCommon.scala | 8 ++-- .../core/Integrate/VertexTestHelper.scala | 42 ++++++++++++++++++++ 3 files changed, 48 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/87a8cedd/s2core/src/main/scala/org/apache/s2graph/core/rest/RequestParser.scala ---------------------------------------------------------------------- diff --git a/s2core/src/main/scala/org/apache/s2graph/core/rest/RequestParser.scala b/s2core/src/main/scala/org/apache/s2graph/core/rest/RequestParser.scala index 4ef3b1c..f42d5eb 100644 --- a/s2core/src/main/scala/org/apache/s2graph/core/rest/RequestParser.scala +++ b/s2core/src/main/scala/org/apache/s2graph/core/rest/RequestParser.scala @@ -578,7 +578,8 @@ class RequestParser(graph: S2GraphLike) { } def toVertex(jsValue: JsValue, operation: String = "insert", serviceName: Option[String] = None, columnName: Option[String] = None): Seq[S2VertexLike] = { - ((jsValue \ "id").asOpt[JsValue].map(Seq(_)).getOrElse(Nil) ++ (jsValue \ "ids").asOpt[Seq[JsValue]].getOrElse(Nil)).flatMap(JSONParser.jsValueToAny).map { id => + ((jsValue \ "id").asOpt[JsValue].map(Seq(_)).getOrElse(Nil) ++ + (jsValue \ "ids").asOpt[Seq[JsValue]].getOrElse(Nil)).flatMap(JSONParser.jsValueToAny).map { id => val ts = parseOption[Long](jsValue, "timestamp").getOrElse(System.currentTimeMillis()) val sName = if (serviceName.isEmpty) parse[String](jsValue, "serviceName") else serviceName.get val cName = if (columnName.isEmpty) parse[String](jsValue, "columnName") else columnName.get http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/87a8cedd/s2core/src/test/scala/org/apache/s2graph/core/Integrate/IntegrateCommon.scala ---------------------------------------------------------------------- diff --git a/s2core/src/test/scala/org/apache/s2graph/core/Integrate/IntegrateCommon.scala b/s2core/src/test/scala/org/apache/s2graph/core/Integrate/IntegrateCommon.scala index c96231a..c7d9f59 100644 --- a/s2core/src/test/scala/org/apache/s2graph/core/Integrate/IntegrateCommon.scala +++ b/s2core/src/test/scala/org/apache/s2graph/core/Integrate/IntegrateCommon.scala @@ -96,11 +96,11 @@ trait IntegrateCommon extends FunSuite with Matchers with BeforeAndAfterAll { ("age", "integer", "0"), ("im", "string", "-") ) - - vertexPropsKeys.map { case (key, keyType, defaultValue) => - Management.addVertexProp(testServiceName, testColumnName, key, keyType, defaultValue, storeInGlobalIndex = true) + Seq(testColumnName, testTgtColumnName).foreach { columnName => + vertexPropsKeys.map { case (key, keyType, defaultValue) => + Management.addVertexProp(testServiceName, columnName, key, keyType, defaultValue, storeInGlobalIndex = true) + } } - // vertex type global index. // val globalVertexIndex = management.buildGlobalIndex(GlobalIndex.VertexType, "test_age_index", Seq("age")) http://git-wip-us.apache.org/repos/asf/incubator-s2graph/blob/87a8cedd/s2core/src/test/scala/org/apache/s2graph/core/Integrate/VertexTestHelper.scala ---------------------------------------------------------------------- diff --git a/s2core/src/test/scala/org/apache/s2graph/core/Integrate/VertexTestHelper.scala b/s2core/src/test/scala/org/apache/s2graph/core/Integrate/VertexTestHelper.scala index 603ca12..62c7e00 100644 --- a/s2core/src/test/scala/org/apache/s2graph/core/Integrate/VertexTestHelper.scala +++ b/s2core/src/test/scala/org/apache/s2graph/core/Integrate/VertexTestHelper.scala @@ -59,6 +59,33 @@ class VertexTestHelper extends IntegrateCommon { } } + test("[S2GRAPH-186]: escaping of double quotation marks") { + val ids = Seq("a", "\"a\"") + val (serviceName, stringColumnName) = (testServiceName, testTgtColumnName) + + val data = vertexInsertsPayloadString(serviceName, stringColumnName, ids) + val payload = Json.parse(Json.toJson(data).toString) + println(payload) + + val vertices = parser.toVertices(payload, "insert", Option(serviceName), + Option(stringColumnName)) + val srcVertices = vertices + Await.result(graph.mutateVertices(srcVertices, withWait = true), HttpRequestWaitingTime) + + val res = graph.getVertices(srcVertices).map { vertices => + PostProcess.verticesToJson(vertices) + } + + val ret = Await.result(res, HttpRequestWaitingTime) + val fetched = ret.as[Seq[JsValue]] + for { + (d, f) <- data.zip(fetched) + } yield { + (d \ "id") should be(f \ "id") + ((d \ "props") \ "age") should be((f \ "props") \ "age") + } + } + object VertexTestHelper { def vertexQueryJson(serviceName: String, columnName: String, ids: Seq[Int]) = { Json.parse( @@ -69,6 +96,15 @@ class VertexTestHelper extends IntegrateCommon { |] """.stripMargin) } + def vertexQueryJsonString(serviceName: String, columnName: String, ids: Seq[String]) = { + Json.parse( + s""" + |[ + |{"serviceName": "$serviceName", "columnName": "$columnName", "ids": [${ids.mkString(",")} + ]} + |] + """.stripMargin) + } def vertexInsertsPayload(serviceName: String, columnName: String, ids: Seq[Int]): Seq[JsValue] = { ids.map { id => @@ -76,6 +112,12 @@ class VertexTestHelper extends IntegrateCommon { } } + def vertexInsertsPayloadString(serviceName: String, columnName: String, ids: Seq[String]): Seq[JsValue] = { + ids.map { id => + Json.obj("id" -> id, "props" -> randomProps, "timestamp" -> System.currentTimeMillis()) + } + } + val vertexPropsKeys = List( ("age", "int") )
