|
|
|
|
Re: Creating a Resource from files in InMemoryFileSystemAccess [message #1803947 is a reply to message #1803932] |
Thu, 14 March 2019 05:39 |
Mehmetcan Sinir Messages: 55 Registered: September 2018 |
Member |
|
|
yes but how can I call getResource on a File that is not in the file system?
Resource resource = rs.getResource(URI.createURI("test.mydsl"), true);
let's say test.mydsl is not in the filesystem (it is save in the InMemoryFileSystemAccess object) like this:
@Inject
private InMemoryFileSystemAccess fileAccess;
@Test
myTestMethod() {
String content = "Friend friend"
fileAccess.generateFile("mydsl.test", "DEFAULT_OUTPUT", content);
}
Now how can I create a resource from "mydsl.test"? Below .doesn't work because test.mydsl is not in the file system?
ResourceSet rs = injector.getInstance(ResourceSet.class);
Resource resource = rs.getResource(URI.createURI("test.mydsl"), true);
Or am I using InMemoryFileSystemAccess wrong here? I am trying to use it in my tests, first I am using it to generate InMemory code that will be the input for my generators. Hope that makes sense to you.
[Updated on: Thu, 14 March 2019 05:43] Report message to a moderator
|
|
|
Re: Creating a Resource from files in InMemoryFileSystemAccess [message #1803948 is a reply to message #1803947] |
Thu, 14 March 2019 06:18 |
|
hi
InMemoryFileSystemAccess is not for loading model files
i still dont understand what you want to do. can you describe the complete usecase in pseudocode
@Test
myTestMethod() {
String content = "Friend friend"
// 1 create resourceset
// 2 create resource
// 3 call resource.load with stream
// 4 call generator
// dont know why you call generate file here
// you can also use parse helper to load a resource from a string
fileAccess.generateFile("mydsl.test", "DEFAULT_OUTPUT", content);
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
[Updated on: Thu, 14 March 2019 06:27] Report message to a moderator
|
|
|
Re: Creating a Resource from files in InMemoryFileSystemAccess [message #1803949 is a reply to message #1803948] |
Thu, 14 March 2019 06:27 |
|
@Inject
ParseHelper<Model> parseHelper
@Test
def void loadModel() {
val result = parseHelper.parse('''
Hello Xtext!
''')
val resource = result.eResource
@Inject
Provider<ResourceSet> rsp
@Test
def void loadModel() {
val rs = rsp.get
val r = rs.createResource(URI.createURI("demo.mydsl"))
val content = '''
Hello A!
Hello B!
'''
r.load(new StringInputStream(content), null)
val errors = r.errors
Assertions.assertTrue(errors.isEmpty, '''Unexpected errors: «errors.join(", ")»''')
val model = r.contents.head as Model
println(model.greetings.map[name])
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Re: Creating a Resource from files in InMemoryFileSystemAccess [message #1803951 is a reply to message #1803949] |
Thu, 14 March 2019 06:40 |
|
or you make use of the inmemory uri handler
@Inject
Provider<ResourceSet> rsp
@Test
def void loadModel() {
val rs = rsp.get
val handler = new InMemoryURIHandler()
handler += "inmemory:/demo.mydsl" -> '''Hello A! Hello B!'''
rs.URIConverter.URIHandlers.add(0, handler)
val r = rs.getResource(URI.createURI("inmemory:/demo.mydsl"), true)
r.load(null)
val errors = r.errors
Assertions.assertTrue(errors.isEmpty, '''Unexpected errors: «errors.join(", ")»''')
val model = r.contents.head as Model
println(model.greetings.map[name])
}
def void +=(InMemoryURIHandler handler, Pair<String, String> file) {
val f = handler.getInMemoryFile(URI.createURI(file.key))
f.contents = file.value.bytes
f.exists = true
}
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Re: Creating a Resource from files in InMemoryFileSystemAccess [message #1804500 is a reply to message #1803951] |
Wed, 27 March 2019 09:27 |
Mehmetcan Sinir Messages: 55 Registered: September 2018 |
Member |
|
|
Hi Christian
Thank you for your replies.
We have currently solved this issue.
The use case was to test if the generators are generating the expected output.
Due to Project Constraints, I could not use the inMemoryFileSystemAccess. I solved the issue by using the TemporaryFolder Framework from JUNIT, i.e. run generators and the output files will be generated in a temporary folder. Then I compare them with the expected output.
However, your replies are very informative and will certainly come in handy for future problems.
Thanks again!
[Updated on: Wed, 27 March 2019 09:28] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.03362 seconds