-
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.
test(dsl-core): generating JSON for links
- Loading branch information
Showing
3 changed files
with
333 additions
and
0 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
182 changes: 182 additions & 0 deletions
182
...a.testing.dsl/src/test/java/app/hypermedia/testing/dsl/tests/generator/core/LinkTest.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,182 @@ | ||
app.hypermedia.testing.dsl.tests.generator.core.LinkTest.canGenerateForClassLink=[ | ||
{ | ||
"map": { | ||
"steps": { | ||
"myArrayList": [ | ||
{ | ||
"map": { | ||
"children": { | ||
"myArrayList": [ | ||
{ | ||
"map": { | ||
"children": { | ||
"myArrayList": [ | ||
{ | ||
"map": { | ||
"propertyId": "name", | ||
"strict": true, | ||
"type": "Property" | ||
}, | ||
"empty": false | ||
} | ||
], | ||
"empty": false | ||
}, | ||
"rel": "author", | ||
"strict": false, | ||
"type": "Link" | ||
}, | ||
"empty": false | ||
} | ||
], | ||
"empty": false | ||
}, | ||
"classId": "Article", | ||
"type": "Class" | ||
}, | ||
"empty": false | ||
}, | ||
{ | ||
"map": { | ||
"children": { | ||
"myArrayList": [ | ||
{ | ||
"map": { | ||
"propertyId": "name", | ||
"strict": true, | ||
"type": "Property" | ||
}, | ||
"empty": false | ||
} | ||
], | ||
"empty": false | ||
}, | ||
"rel": "author", | ||
"strict": false, | ||
"type": "Link" | ||
}, | ||
"empty": false | ||
} | ||
], | ||
"empty": false | ||
} | ||
}, | ||
"empty": false | ||
} | ||
] | ||
|
||
|
||
app.hypermedia.testing.dsl.tests.generator.core.LinkTest.canGenerateForLinkStatement=[ | ||
{ | ||
"map": { | ||
"steps": { | ||
"myArrayList": [ | ||
{ | ||
"map": { | ||
"children": { | ||
"myArrayList": [ | ||
{ | ||
"map": { | ||
"rel": "author", | ||
"strict": true, | ||
"type": "Link" | ||
}, | ||
"empty": false | ||
} | ||
], | ||
"empty": false | ||
}, | ||
"classId": "Article", | ||
"type": "Class" | ||
}, | ||
"empty": false | ||
} | ||
], | ||
"empty": false | ||
} | ||
}, | ||
"empty": false | ||
} | ||
] | ||
|
||
|
||
app.hypermedia.testing.dsl.tests.generator.core.LinkTest.canGenerateForStrictClassLink=[ | ||
{ | ||
"map": { | ||
"steps": { | ||
"myArrayList": [ | ||
{ | ||
"map": { | ||
"children": { | ||
"myArrayList": [ | ||
{ | ||
"map": { | ||
"children": { | ||
"myArrayList": [ | ||
{ | ||
"map": { | ||
"propertyId": "name", | ||
"strict": true, | ||
"type": "Property" | ||
}, | ||
"empty": false | ||
} | ||
], | ||
"empty": false | ||
}, | ||
"rel": "author", | ||
"strict": true, | ||
"type": "Link" | ||
}, | ||
"empty": false | ||
} | ||
], | ||
"empty": false | ||
}, | ||
"classId": "Article", | ||
"type": "Class" | ||
}, | ||
"empty": false | ||
} | ||
], | ||
"empty": false | ||
} | ||
}, | ||
"empty": false | ||
} | ||
] | ||
|
||
|
||
app.hypermedia.testing.dsl.tests.generator.core.LinkTest.canGenerateForTopLevelLink=[ | ||
{ | ||
"map": { | ||
"steps": { | ||
"myArrayList": [ | ||
{ | ||
"map": { | ||
"children": { | ||
"myArrayList": [ | ||
{ | ||
"map": { | ||
"propertyId": "name", | ||
"strict": true, | ||
"type": "Property" | ||
}, | ||
"empty": false | ||
} | ||
], | ||
"empty": false | ||
}, | ||
"rel": "author", | ||
"strict": false, | ||
"type": "Link" | ||
}, | ||
"empty": false | ||
} | ||
], | ||
"empty": false | ||
} | ||
}, | ||
"empty": false | ||
} | ||
] |
114 changes: 114 additions & 0 deletions
114
....testing.dsl/src/test/java/app/hypermedia/testing/dsl/tests/generator/core/LinkTest.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,114 @@ | ||
package app.hypermedia.testing.dsl.tests.generator.core | ||
|
||
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.core.Model | ||
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.CoreInjectorProvider | ||
import org.eclipse.xtext.generator.GeneratorContext | ||
|
||
@ExtendWith(InjectionExtension) | ||
@InjectWith(CoreInjectorProvider) | ||
class LinkTest { | ||
@Inject IGenerator2 generator | ||
@Inject extension ParseHelper<Model> | ||
|
||
@BeforeAll | ||
static def beforeAll() { | ||
start() | ||
} | ||
|
||
@AfterAll | ||
static def afterAll() { | ||
validateSnapshots(); | ||
} | ||
|
||
@Test | ||
def canGenerateForTopLevelLink() { | ||
// given | ||
val model = ''' | ||
With Link "author" { | ||
Expect Property "name" | ||
} | ||
'''.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 canGenerateForClassLink() { | ||
// given | ||
val model = ''' | ||
With Class "Article" { | ||
With Link "author" { | ||
Expect Property "name" | ||
} | ||
} | ||
'''.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 canGenerateForStrictClassLink() { | ||
// given | ||
val model = ''' | ||
With Class "Article" { | ||
Expect Link "author" { | ||
Expect Property "name" | ||
} | ||
} | ||
'''.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 canGenerateForLinkStatement() { | ||
// given | ||
val model = ''' | ||
With Class "Article" { | ||
Expect Link "author" | ||
} | ||
'''.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() | ||
} | ||
} |