-
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.
fixes #59
- Loading branch information
Showing
6 changed files
with
211 additions
and
9 deletions.
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
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
64 changes: 64 additions & 0 deletions
64
...ng.dsl/src/test/java/app/hypermedia/testing/dsl/tests/generator/hydra/IdentifierTest.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,64 @@ | ||
app.hypermedia.testing.dsl.tests.generator.hydra.IdentifierTest.expectTypeWithPrefix_generatesStep=[ | ||
{ | ||
"map": { | ||
"steps": { | ||
"myArrayList": [ | ||
{ | ||
"map": { | ||
"children": { | ||
"myArrayList": [ | ||
{ | ||
"map": { | ||
"type": "Identifier", | ||
"value": "http://example.com/NewUser" | ||
}, | ||
"empty": false | ||
} | ||
], | ||
"empty": false | ||
}, | ||
"classId": "http://example.com/CreateUser", | ||
"type": "Class" | ||
}, | ||
"empty": false | ||
} | ||
], | ||
"empty": false | ||
} | ||
}, | ||
"empty": false | ||
} | ||
] | ||
|
||
|
||
app.hypermedia.testing.dsl.tests.generator.hydra.IdentifierTest.expectType_generatesStep=[ | ||
{ | ||
"map": { | ||
"steps": { | ||
"myArrayList": [ | ||
{ | ||
"map": { | ||
"children": { | ||
"myArrayList": [ | ||
{ | ||
"map": { | ||
"type": "Identifier", | ||
"value": "http://example.com/NewUser" | ||
}, | ||
"empty": false | ||
} | ||
], | ||
"empty": false | ||
}, | ||
"classId": "http://example.com/CreateUser", | ||
"type": "Class" | ||
}, | ||
"empty": false | ||
} | ||
], | ||
"empty": false | ||
} | ||
}, | ||
"empty": false | ||
} | ||
] |
73 changes: 73 additions & 0 deletions
73
...g.dsl/src/test/java/app/hypermedia/testing/dsl/tests/generator/hydra/IdentifierTest.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,73 @@ | ||
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 IdentifierTest { | ||
@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 Class <http://example.com/CreateUser> { | ||
Expect Id <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 Class ex:CreateUser { | ||
Expect Id 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() | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...esting.dsl/src/test/java/app/hypermedia/testing/dsl/tests/hydra/ExpectIdParsingTest.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,59 @@ | ||
/* | ||
* 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.IdentifierStatement | ||
import app.hypermedia.testing.dsl.core.ClassBlock | ||
|
||
@ExtendWith(InjectionExtension) | ||
@InjectWith(HydraInjectorProvider) | ||
class ExpectIdParsingTest { | ||
@Inject extension ParseHelper<HydraScenario> | ||
|
||
@Test | ||
def void expectId_canBeUsedWithUri() { | ||
// when | ||
val result = ''' | ||
With Class <http://example.com/User> { | ||
Expect Id <http://example.com/Tomasz> | ||
} | ||
'''.parse | ||
|
||
// then | ||
TestHelpers.assertModelParsedSuccessfully(result) | ||
|
||
val clas = result.steps.get(0) as ClassBlock | ||
val expectation = clas.children.get(0) as IdentifierStatement | ||
assertThat(expectation.id.value).isEqualTo('http://example.com/Tomasz') | ||
} | ||
|
||
@Test | ||
def void expectId_canBeUsedWithPrefixedName() { | ||
// when | ||
val result = ''' | ||
PREFIX ex: <http://example.com/> | ||
With Class <http://example.com/User> { | ||
Expect Id ex:Tomasz | ||
} | ||
'''.parse | ||
|
||
// then | ||
TestHelpers.assertModelParsedSuccessfully(result) | ||
|
||
val clas = result.steps.get(0) as ClassBlock | ||
val expectation = clas.children.get(0) as IdentifierStatement | ||
assertThat(expectation.id.value).isEqualTo('ex:Tomasz') | ||
} | ||
} |