-
Notifications
You must be signed in to change notification settings - Fork 2
Add a basic testing framework #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/scala/eu/neverblink/jelly/cli/command/rdf/RDFFromJelly.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| package eu.neverblink.jelly.cli.command.rdf | ||
| import caseapp.* | ||
| import eu.neverblink.jelly.cli.JellyCommand | ||
|
|
||
| case class FromJellyRDFOptions() | ||
Karolina-Bogacka marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| object RDFFromJelly extends JellyCommand[FromJellyRDFOptions]: | ||
| override def names: List[List[String]] = List( | ||
| List("rdf from-jelly"), | ||
Ostrzyciel marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) | ||
|
|
||
| override def run(options: FromJellyRDFOptions, remainingArgs: RemainingArgs): Unit = | ||
| // This is a placeholder for the actual implementation | ||
| println("rdf from-jelly") | ||
| println(options) | ||
| println(remainingArgs) | ||
20 changes: 20 additions & 0 deletions
20
src/test/scala/eu/neverblink/jelly/cli/command/RDFFromJellySpec.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| package eu.neverblink.jelly.cli.command | ||
|
|
||
| import eu.neverblink.jelly.cli.command.helpers.DataGenHelper | ||
| import org.scalatest.BeforeAndAfterEach | ||
| import org.scalatest.matchers.should.Matchers | ||
| import org.scalatest.wordspec.AnyWordSpec | ||
|
|
||
| trait CleanUpFilesAfterTest extends BeforeAndAfterEach { | ||
Karolina-Bogacka marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| this: AnyWordSpec => | ||
| override def afterEach(): Unit = { | ||
| DataGenHelper.cleanUpFile() | ||
| } | ||
| } | ||
|
|
||
| class RDFFromJellySpec extends AnyWordSpec with Matchers with CleanUpFilesAfterTest: | ||
| "rdf from-jelly command" should { | ||
| "be able to convert a Jelly file to NTriples" in { | ||
| val jellyFile = DataGenHelper.generateJellyFile(3) | ||
| } | ||
| } | ||
50 changes: 50 additions & 0 deletions
50
src/test/scala/eu/neverblink/jelly/cli/command/helpers/DataGenHelper.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| package eu.neverblink.jelly.cli.command.helpers | ||
|
|
||
| import eu.ostrzyciel.jelly.convert.jena.riot.JellyLanguage | ||
| import org.apache.jena.rdf.model.{Model, ModelFactory, ResourceFactory} | ||
| import org.apache.jena.riot.RDFDataMgr | ||
|
|
||
| import java.io.FileOutputStream | ||
| import java.nio.file.{Files, Paths} | ||
| import scala.util.Using | ||
|
|
||
| /* | ||
| * This class will be used to generate test data | ||
| */ | ||
| object DataGenHelper: | ||
|
|
||
| private val testFile = "testInput.jelly" | ||
|
|
||
| /* | ||
| * This method generates a triple model with nTriples | ||
| * @param nTriples number of triples to generate | ||
| * @return Model | ||
| */ | ||
| def generateTripleModel(nTriples: Int): Model = | ||
| val model = ModelFactory.createDefaultModel() | ||
| val subStr = "http://example.org/subject" | ||
| val predStr = "http://example.org/predicate" | ||
| val objStr = "http://example.org/object" | ||
| val tripleList = (1 to nTriples).map { i => | ||
| val sub = ResourceFactory.createResource(s"$subStr/$i") | ||
| val pred = ResourceFactory.createProperty(s"$predStr/$i") | ||
| val obj = ResourceFactory.createResource(s"$objStr/$i") | ||
| val stat = ResourceFactory.createStatement(sub, pred, obj) | ||
| model.add(stat) | ||
| } | ||
| model | ||
|
|
||
| /* This method generates a Jelly file with nTriples | ||
| * @param nTriples number of triples to generate | ||
| * @param fileName name of the file to generate | ||
| */ | ||
| def generateJellyFile(nTriples: Int): Unit = | ||
| val model = generateTripleModel(nTriples) | ||
| // TODO: Add configurable generation for different variants of Jelly (small strict etc) | ||
| Using.resource(FileOutputStream(testFile)) { file => | ||
| RDFDataMgr.write(file, model, JellyLanguage.JELLY) | ||
| } | ||
|
|
||
| /* This method cleans up the file after the test*/ | ||
| def cleanUpFile(): Unit = | ||
| Files.deleteIfExists(Paths.get(testFile)) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.