-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(hydra-dsl): explicit rdf:type expectation statement
re #50
- Loading branch information
Showing
5 changed files
with
227 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
92 changes: 92 additions & 0 deletions
92
...sting.dsl/src/test/java/app/hypermedia/testing/dsl/tests/generator/hydra/RdfTypeTest.snap
This file contains 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,92 @@ | ||
app.hypermedia.testing.dsl.tests.generator.hydra.RdfTypeTest.expectTypeWithPrefix_generatesStep=[ | ||
{ | ||
"map": { | ||
"steps": { | ||
"myArrayList": [ | ||
{ | ||
"map": { | ||
"children": { | ||
"myArrayList": [ | ||
{ | ||
"map": { | ||
"children": { | ||
"myArrayList": [ | ||
{ | ||
"map": { | ||
"propertyId": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", | ||
"strict": true, | ||
"type": "Property", | ||
"value": "http://example.com/NewUser" | ||
}, | ||
"empty": false | ||
} | ||
], | ||
"empty": false | ||
}, | ||
"type": "Invocation" | ||
}, | ||
"empty": false | ||
} | ||
], | ||
"empty": false | ||
}, | ||
"operationId": "http://example.com/CreateUser", | ||
"strict": false, | ||
"type": "Operation" | ||
}, | ||
"empty": false | ||
} | ||
], | ||
"empty": false | ||
} | ||
}, | ||
"empty": false | ||
} | ||
] | ||
|
||
|
||
app.hypermedia.testing.dsl.tests.generator.hydra.RdfTypeTest.expectType_generatesStep=[ | ||
{ | ||
"map": { | ||
"steps": { | ||
"myArrayList": [ | ||
{ | ||
"map": { | ||
"children": { | ||
"myArrayList": [ | ||
{ | ||
"map": { | ||
"children": { | ||
"myArrayList": [ | ||
{ | ||
"map": { | ||
"propertyId": "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", | ||
"strict": true, | ||
"type": "Property", | ||
"value": "http://example.com/NewUser" | ||
}, | ||
"empty": false | ||
} | ||
], | ||
"empty": false | ||
}, | ||
"type": "Invocation" | ||
}, | ||
"empty": false | ||
} | ||
], | ||
"empty": false | ||
}, | ||
"operationId": "http://example.com/CreateUser", | ||
"strict": false, | ||
"type": "Operation" | ||
}, | ||
"empty": false | ||
} | ||
], | ||
"empty": false | ||
} | ||
}, | ||
"empty": false | ||
} | ||
] |
77 changes: 77 additions & 0 deletions
77
...ting.dsl/src/test/java/app/hypermedia/testing/dsl/tests/generator/hydra/RdfTypeTest.xtend
This file contains 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,77 @@ | ||
package app.hypermedia.testing.dsl.tests.generator.hydra | ||
|
||
import org.eclipse.xtext.generator.InMemoryFileSystemAccess | ||
import org.junit.jupiter.api.^extension.ExtendWith | ||
import org.eclipse.xtext.testing.extensions.InjectionExtension | ||
import org.eclipse.xtext.testing.InjectWith | ||
import com.google.inject.Inject | ||
import org.eclipse.xtext.testing.util.ParseHelper | ||
import app.hypermedia.testing.dsl.hydra.HydraScenario | ||
import org.junit.jupiter.api.Test | ||
import static io.github.jsonSnapshot.SnapshotMatcher.* | ||
import org.eclipse.xtext.generator.IGenerator2 | ||
import org.junit.jupiter.api.BeforeAll | ||
import org.junit.jupiter.api.AfterAll | ||
import org.json.JSONObject | ||
import app.hypermedia.testing.dsl.tests.HydraInjectorProvider | ||
import org.eclipse.xtext.generator.GeneratorContext | ||
|
||
@ExtendWith(InjectionExtension) | ||
@InjectWith(HydraInjectorProvider) | ||
class RdfTypeTest { | ||
@Inject IGenerator2 generator | ||
@Inject extension ParseHelper<HydraScenario> | ||
@BeforeAll | ||
static def beforeAll() { | ||
start() | ||
} | ||
|
||
@AfterAll | ||
static def afterAll() { | ||
validateSnapshots(); | ||
} | ||
|
||
@Test | ||
def expectType_generatesStep() { | ||
// given | ||
val model = ''' | ||
With Operation <http://example.com/CreateUser> { | ||
Invoke { | ||
Expect Type <http://example.com/NewUser> | ||
} | ||
} | ||
'''.parse | ||
|
||
// when | ||
val fsa = new InMemoryFileSystemAccess() | ||
generator.doGenerate(model.eResource, fsa, new GeneratorContext()) | ||
println(fsa.textFiles) | ||
|
||
// then | ||
val file = new JSONObject(fsa.textFiles.values.get(0).toString) | ||
expect(file).toMatchSnapshot() | ||
} | ||
|
||
@Test | ||
def expectTypeWithPrefix_generatesStep() { | ||
// given | ||
val model = ''' | ||
PREFIX ex: <http://example.com/> | ||
With Operation ex:CreateUser { | ||
Invoke { | ||
Expect Type ex:NewUser | ||
} | ||
} | ||
'''.parse | ||
|
||
// when | ||
val fsa = new InMemoryFileSystemAccess() | ||
generator.doGenerate(model.eResource, fsa, new GeneratorContext()) | ||
println(fsa.textFiles) | ||
|
||
// then | ||
val file = new JSONObject(fsa.textFiles.values.get(0).toString) | ||
expect(file).toMatchSnapshot() | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...ting.dsl/src/test/java/app/hypermedia/testing/dsl/tests/hydra/ExpectTypeParsingTest.xtend
This file contains 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,42 @@ | ||
/* | ||
* generated by Xtext 2.18.0 | ||
*/ | ||
package app.hypermedia.testing.dsl.tests.hydra | ||
|
||
import app.hypermedia.testing.dsl.hydra.HydraScenario | ||
import app.hypermedia.testing.dsl.tests.HydraInjectorProvider | ||
import com.google.inject.Inject | ||
import org.eclipse.xtext.testing.InjectWith | ||
import org.eclipse.xtext.testing.extensions.InjectionExtension | ||
import org.eclipse.xtext.testing.util.ParseHelper | ||
import org.junit.jupiter.api.^extension.ExtendWith | ||
import org.junit.jupiter.api.Test | ||
import static org.assertj.core.api.Assertions.* | ||
import app.hypermedia.testing.dsl.tests.TestHelpers | ||
import app.hypermedia.testing.dsl.hydra.RdfTypeStatement | ||
import app.hypermedia.testing.dsl.hydra.OperationBlock | ||
|
||
@ExtendWith(InjectionExtension) | ||
@InjectWith(HydraInjectorProvider) | ||
class ExpectTypeParsingTest { | ||
@Inject extension ParseHelper<HydraScenario> | ||
|
||
@Test | ||
def void prefixedName_termCanContainNonLetterCharacters() { | ||
// when | ||
val result = ''' | ||
With Operation <http://example.com/CreateUser> { | ||
Invoke { | ||
Expect Type <http://example.com/NewUser> | ||
} | ||
} | ||
'''.parse | ||
|
||
// then | ||
TestHelpers.assertModelParsedSuccessfully(result) | ||
|
||
val operation = result.steps.get(0) as OperationBlock | ||
val expectation = operation.invocations.get(0).response.children.get(0) as RdfTypeStatement | ||
assertThat(expectation.id.value).isEqualTo('http://example.com/NewUser') | ||
} | ||
} |