Skip to content

Commit

Permalink
Explicitly use utf8 instead of system default for parsing feature files
Browse files Browse the repository at this point in the history
This problem is already fixed in the TCK which is not released yet. Thus this commit fixes the problem in Neo4j for now. All of the parsing overhead introduced here can be removed once Neo4j is updated to M12 of the TCK
  • Loading branch information
SaschaPeukert committed Aug 28, 2018
1 parent 287115d commit be5c7e8
Show file tree
Hide file tree
Showing 24 changed files with 92 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
# https://neo4j.com/licensing/
#

#encoding: utf-8

Feature: AggregationAcceptance

Background:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
# https://neo4j.com/licensing/
#

#encoding: utf-8

Feature: BuiltInProcedureAcceptance

Background:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
# https://neo4j.com/licensing/
#

#encoding: utf-8

Feature: CaseExpression

Scenario: Case should handle mixed number types
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
# https://neo4j.com/licensing/
#

#encoding: utf-8

Feature: ConstraintAcceptance

Scenario: Merge node with prop and label and unique index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
# https://neo4j.com/licensing/
#

#encoding: utf-8

Feature: DeleteAcceptance

Scenario: Return properties from deleted node
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
# https://neo4j.com/licensing/
#

#encoding: utf-8

Feature: ExplainAcceptance

Background:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
# https://neo4j.com/licensing/
#

#encoding: utf-8

Feature: ForeachAcceptance

Scenario: Add labels inside FOREACH
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
# https://neo4j.com/licensing/
#

#encoding: utf-8

Feature: IndexAcceptance

Scenario: Handling numerical literal on the left when using an index
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
# https://neo4j.com/licensing/
#

#encoding: utf-8

Feature: MatchAcceptance

Scenario: Filter on path nodes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
# https://neo4j.com/licensing/
#

#encoding: utf-8

Feature: MergeLegacyAcceptance

Scenario: Using a single bound node
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
# https://neo4j.com/licensing/
#

#encoding: utf-8

Feature: OperatorChaining

Scenario: Long chains of integer comparisons
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
# https://neo4j.com/licensing/
#

#encoding: utf-8

Feature: OptionalMatchAcceptance

Scenario: Id on null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
# https://neo4j.com/licensing/
#

#encoding: utf-8

Feature: OrderByAcceptance

Scenario: ORDER BY nodes should return null results last in ascending order
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
# https://neo4j.com/licensing/
#

#encoding: utf-8

Feature: PatternExpressionAcceptance

Scenario: Returning an `extract()` expression
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
# https://neo4j.com/licensing/
#

#encoding: utf-8

Feature: PatternPredicates

Background:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
# https://neo4j.com/licensing/
#

#encoding: utf-8

Feature: ProcedureCallAcceptance

Background:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
# https://neo4j.com/licensing/
#

#encoding: utf-8

Feature: ReturnAcceptance

Scenario: Filter should work
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
# https://neo4j.com/licensing/
#

#encoding: utf-8

Feature: ShortestPathAcceptance

Background:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
# https://neo4j.com/licensing/
#

#encoding: utf-8

Feature: SkipLimitAcceptance

Background:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
# https://neo4j.com/licensing/
#

#encoding: utf-8

Feature: UnwindAcceptance

Scenario: Flat type support in list literal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
# https://neo4j.com/licensing/
#

#encoding: utf-8

Feature: VarLengthAcceptance

Background:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import org.junit.Assert.fail
import org.junit.jupiter.api.Test
import org.junit.platform.runner.JUnitPlatform
import org.junit.runner.RunWith
import org.opencypher.tools.tck.api.{CypherTCK, Scenario}
import org.opencypher.tools.tck.api.Scenario

@RunWith(classOf[JUnitPlatform])
abstract class BaseAcceptanceTest extends BaseFeatureTest {
Expand All @@ -42,7 +42,8 @@ abstract class BaseAcceptanceTest extends BaseFeatureTest {
val featuresURI: URI = getClass.getResource("/cypher/features").toURI

val scenarios: Seq[Scenario] = {
val all = CypherTCK.parseFilesystemFeatures(new File(featuresURI)).flatMap(_.scenarios)
val all = parseFilesystemFeatures(new File(featuresURI)).flatMap(_.scenarios) //TODO: Change this back to the following line when TCK M12 is released
//val all = CypherTCK.parseFilesystemFeatures(new File(featuresURI)).flatMap(_.scenarios)
filterScenarios(all, featureToRun, scenarioToRun)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import org.junit.Assert.fail
import org.junit.jupiter.api.Test
import org.junit.platform.runner.JUnitPlatform
import org.junit.runner.RunWith
import org.opencypher.tools.tck.api.{CypherTCK, Scenario}
import org.opencypher.tools.tck.api.Scenario

@RunWith(classOf[JUnitPlatform])
abstract class BaseTCKTests extends BaseFeatureTest {
Expand All @@ -35,8 +35,8 @@ abstract class BaseTCKTests extends BaseFeatureTest {
val featureToRun = ""
val scenarioToRun = ""

val scenarios: Seq[Scenario] =
filterScenarios(CypherTCK.allTckScenarios, featureToRun, scenarioToRun)
val scenarios: Seq[Scenario] = filterScenarios(allTckScenarios, featureToRun, scenarioToRun) //TODO: Change this back to the following line when TCK M12 is released
// filterScenarios(CypherTCK.allTckScenarios, featureToRun, scenarioToRun)

@Test
def debugTokensNeedToBeEmpty(): Unit = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,53 @@
*/
package cypher.features

import org.opencypher.tools.tck.api.Scenario
import java.io.File
import java.net.URL
import java.nio.file.{FileSystems, Files, Paths}
import java.util

import org.opencypher.tools.tck.api.CypherTCK.{featureSuffix, featuresPath, parseFeature}
import org.opencypher.tools.tck.api.{Feature, Scenario}

import scala.collection.JavaConverters._
import scala.io.{Codec, Source}

abstract class BaseFeatureTest {

// ---- TCK methods
// TODO: Remove those when M12 is released

def parseFilesystemFeatures(directory: File): Seq[Feature] = {
require(directory.isDirectory)
val featureFileNames = directory.listFiles.filter(_.getName.endsWith(featureSuffix))
featureFileNames.map(parseFilesystemFeature)
}

def parseFilesystemFeature(file: File): Feature = {
parseFeature(file.getAbsolutePath, Source.fromFile(file)(Codec.UTF8).mkString)
}

def parseClasspathFeature(pathUrl: URL): Feature = {
parseFeature(pathUrl.toString, Source.fromURL(pathUrl)(Codec.UTF8).mkString)
}

def allTckScenarios: Seq[Scenario] = parseClasspathFeatures(featuresPath).flatMap(_.scenarios)

def parseClasspathFeatures(path: String): Seq[Feature] = {
val resource = getClass.getResource(path).toURI
val fs = FileSystems.newFileSystem(resource, new util.HashMap[String, String]) // Needed to support `Paths.get` below
try {
val directoryPath = Paths.get(resource)
val paths = Files.newDirectoryStream(directoryPath).asScala.toSeq
val featurePathStrings = paths.map(path => path.toString).filter(_.endsWith(featureSuffix))
val featureUrls = featurePathStrings.map(getClass.getResource(_))
featureUrls.map(parseClasspathFeature)
} finally {
fs.close()
}
}
// ---- TCK methods end

def filterScenarios(allScenarios: Seq[Scenario], featureToRun: String, scenarioToRun: String): Seq[Scenario] = {
if (featureToRun.nonEmpty) {
val filteredFeature = allScenarios.filter(s => s.featureName.contains(featureToRun))
Expand Down

0 comments on commit be5c7e8

Please sign in to comment.