Skip to content

Commit

Permalink
#1 testfix (missing test config, typeName wrapper - typeOf[Boolean].t…
Browse files Browse the repository at this point in the history
…oString returning `Boolean` vs `scala.Boolean` + test
  • Loading branch information
dk1844 committed Dec 7, 2021
1 parent d872bc6 commit f91f20d
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import za.co.absa.standardization.types.TypedStructField

import scala.reflect.runtime.universe._
import scala.util.{Failure, Success, Try}
import FieldValidator._

class FieldValidator {

Expand All @@ -45,12 +46,15 @@ class FieldValidator {
}
}



protected def checkMetadataKey[T: TypeTag](field: TypedStructField,
metadataKey: String,
issueConstructor: String => ValidationIssue = ValidationError.apply): Seq[ValidationIssue] = {

def optionToValidationIssueSeq(option: Option[_], typeName: String): Seq[ValidationIssue] = {
option.map(_ => Nil).getOrElse(
Seq(issueConstructor(s"$metadataKey metadata value of field '${field.name}' is not $typeName in String format"))
Seq(issueConstructor(s"$metadataKey metadata value of field '${field.name}' is not ${simpleTypeName(typeName)} in String format"))
)
}

Expand All @@ -67,4 +71,13 @@ class FieldValidator {
}
}

object FieldValidator extends FieldValidator
object FieldValidator extends FieldValidator {
/**
* Keeps part of the string after last dot. E.g. `scala.Boolean` -> `Boolean`. Does nothing if there is no dot.
* @param typeName possibly dot-separated type name
* @return simple type name
*/
private[field] def simpleTypeName(typeName: String) = {
typeName.split("""\.""").last
}
}
5 changes: 4 additions & 1 deletion src/test/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

standardization.recordId.generation.strategy="none"
standardization.recordId.generation.strategy="none"

standardization.defaultTimestampTimeZone.default="CET"
standardization.defaultTimestampTimeZone.xml="Africa/Johannesburg"
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2021 ABSA Group Limited
*
* Licensed 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 za.co.absa.standardization.validation.field

import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should.Matchers

class FieldValidatorSuite extends AnyFunSuite with Matchers {

test("strip type name prefixes where they exists") {
FieldValidator.simpleTypeName("za.co.absa.standardization.validation.field.FieldValidator") shouldBe "FieldValidator"
FieldValidator.simpleTypeName("scala.Boolean") shouldBe "Boolean"
}

test("be no-op for no prefixes") {
FieldValidator.simpleTypeName("Boolean") shouldBe "Boolean"
}
}

0 comments on commit f91f20d

Please sign in to comment.