Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » Registering files needed by a dsl for Unit tests
Registering files needed by a dsl for Unit tests [message #1853706] Thu, 14 July 2022 08:08 Go to next message
Loredana Hozan is currently offline Loredana HozanFriend
Messages: 33
Registered: January 2019
I have a dsl language A (datamodel) which generates dsl language B (model), in language A i can declare csv files (which are located in src/main/reosurces/csvFiles) and the data from the csvs should be visible in language B. The functionality works, but when i try to do unit tests for the functionality, it looks like the csv files are not registered, because the values from the csvs are not present in language B, and i am not sure what i can do to register the csvs. The code for the test is as follows:
	extension DatamodelDslGenerator generator
	def void testGeneration(){
		val fsa = new InMemoryFileSystemAccess()

//			Guice.createInjector(new AbstractGenericModule() {
//			def Class<? extends IEncodingProvider> bindIEncodingProvider() {
//				return IEncodingProvider.Runtime
//			}
//		}).injectMembers(fsa);
//		fsa.files.put("csvFiles/CommitmentItemType.csv", fsa.readTextFile("CommitmentItemType.csv" ,"csvFiles/"))
//		fsa.files.put("src/main/resources/csvFiles/ProductCode.csv", fsa.readTextFile("src/main/resources/csvFiles/ProductCode.csv"))
//		fsa.files.put("C:/Dev/com.datamodel.tests/src/main/resources/csvFiles/ProductCode.csv", fsa.readTextFile("C:/Dev/com.datamodel.tests/src/main/resources/csvFiles/ProductCode.csv"))
//		fsa.files.put("ProductCode.csv", fsa.readTextFile("ProductCode.csv"))
               fsa.generateFile("pom.xml", "CONFIG", dslTestModel.pomFileContent)
	      generator.doGenerate(resourceSetProvider.get.getResource(URI::createFileURI("resource/myTest.datamodel"), true), fsa, new GeneratorContext())
			dslTestModel.modelForTestGeneration, fsa.files.get(IFileSystemAccess::DEFAULT_OUTPUT+"myTest.model").toString

I tried to register the csv files with the fsa using different paths but i get an error stating that the file can not be found : org.eclipse.xtext.util.RuntimeIOException: File not found: csvFiles/CommitmentItemType.csv.
Any idea on how i can register the csv files?
Re: Registering files needed by a dsl for Unit tests [message #1853707 is a reply to message #1853706] Thu, 14 July 2022 08:39 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14654
Registered: July 2009
Senior Member
reading the code this should work, but i assume you need to encode the output config name into the file name in put
i propose to debug org.eclipse.xtext.generator.InMemoryFileSystemAccess.readTextFile(String, String) or whatever you call

Twitter : @chrdietrich
Blog :
Previous Topic:Building Standalone Compiler with Maven - My Method No Longer Works
Next Topic:Formatting inserts spaces despite hidden WS
Goto Forum:

Current Time: Wed Feb 28 10:45:15 GMT 2024

Powered by FUDForum. Page generated in 0.02505 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top