You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@griffin.apache.org by gu...@apache.org on 2018/06/14 03:13:29 UTC

incubator-griffin git commit: param json reader test case

Repository: incubator-griffin
Updated Branches:
  refs/heads/master 89959d9f4 -> d63f6f4ae


param json reader test case

Author: Grant <gr...@gmail.com>

Closes #299 from grant-xuexu/refactoring/testcase.


Project: http://git-wip-us.apache.org/repos/asf/incubator-griffin/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-griffin/commit/d63f6f4a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-griffin/tree/d63f6f4a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-griffin/diff/d63f6f4a

Branch: refs/heads/master
Commit: d63f6f4aed0fb9cc54d50af4590aa7c076cc33c6
Parents: 89959d9
Author: Grant <gr...@gmail.com>
Authored: Thu Jun 14 11:13:20 2018 +0800
Committer: Lionel Liu <bh...@163.com>
Committed: Thu Jun 14 11:13:20 2018 +0800

----------------------------------------------------------------------
 .../params/reader/ParamJsonReaderSpec.scala     | 65 ++++++++++++++++++++
 1 file changed, 65 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-griffin/blob/d63f6f4a/measure/src/test/scala/org/apache/griffin/measure/configuration/params/reader/ParamJsonReaderSpec.scala
----------------------------------------------------------------------
diff --git a/measure/src/test/scala/org/apache/griffin/measure/configuration/params/reader/ParamJsonReaderSpec.scala b/measure/src/test/scala/org/apache/griffin/measure/configuration/params/reader/ParamJsonReaderSpec.scala
new file mode 100644
index 0000000..13a76c6
--- /dev/null
+++ b/measure/src/test/scala/org/apache/griffin/measure/configuration/params/reader/ParamJsonReaderSpec.scala
@@ -0,0 +1,65 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+*/
+package org.apache.griffin.measure.configuration.params.reader
+
+import org.apache.griffin.measure.configuration.params.DQConfig
+import org.scalatest.{FlatSpec, Matchers}
+
+import scala.io.Source
+import scala.util.{Failure, Success}
+
+class ParamJsonReaderSpec extends FlatSpec with Matchers{
+
+
+  "params " should "be parsed from a valid file" in {
+    val bufferedSource = Source.fromFile(getClass.getResource("/_accuracy-batch-sparksql.json").getFile)
+    val jsonString = bufferedSource.getLines().mkString
+    bufferedSource.close
+
+    val reader :ParamReader = ParamJsonReader(jsonString)
+    val params = reader.readConfig[DQConfig]
+    params match {
+      case Success(v) =>
+        v.evaluateRule.getRules(0).dslType should === ("spark-sql")
+        v.evaluateRule.getRules(0).name should === ("missRecords")
+      case Failure(_) =>
+        fail("it should not happen")
+    }
+
+  }
+
+  it should "fail for an invalid file" in {
+    val bufferedSource = Source.fromFile(getClass.getResource("/invalidconfigs/missingrule_accuracy_batch_sparksql.json").getFile)
+    val jsonString = bufferedSource.getLines().mkString
+    bufferedSource.close
+
+    val reader :ParamReader = ParamJsonReader(jsonString)
+    val params = reader.readConfig[DQConfig]
+    params match {
+      case Success(_) =>
+        fail("it is an invalid config file")
+      case Failure(e) =>
+        e.getMessage should include ("evaluate.rule should not be null")
+    }
+
+  }
+
+}
+
+