Skip to content
Snippets Groups Projects
Commit 9766dc31 authored by Stefan Herrnleben's avatar Stefan Herrnleben
Browse files

refactor parsers write model to file method

parent 699e670c
No related branches found
No related tags found
No related merge requests found
...@@ -49,17 +49,14 @@ public class Parser { ...@@ -49,17 +49,14 @@ public class Parser {
return baos.toByteArray(); return baos.toByteArray();
} }
public static File convertToTempFile(NetworkInfrastructure networkInfrastructure) throws IOException { public static void writeToFile(NetworkInfrastructure networkInfrastructure, File file) throws IOException {
File output = File.createTempFile("dni-", ".dni");
output.deleteOnExit();
ResourceSet resourceSet = new ResourceSetImpl(); ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap() resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap()
.put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl()); .put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());
resourceSet.getPackageRegistry().put(DNIPackage.eNS_URI, DNIPackage.eINSTANCE); resourceSet.getPackageRegistry().put(DNIPackage.eNS_URI, DNIPackage.eINSTANCE);
Resource resource = resourceSet.createResource(URI.createURI(output.toURI().getPath())); Resource resource = resourceSet.createResource(URI.createFileURI(file.toURI().getPath()));
resource.getContents().add(networkInfrastructure); resource.getContents().add(networkInfrastructure);
resource.save(Collections.EMPTY_MAP); resource.save(Collections.EMPTY_MAP);
return output;
} }
} }
...@@ -26,7 +26,9 @@ public class ParserTest { ...@@ -26,7 +26,9 @@ public class ParserTest {
public void shouldConvertModelToFile() throws IOException { public void shouldConvertModelToFile() throws IOException {
DNIFactoryImpl factory = new DNIFactoryImpl(); DNIFactoryImpl factory = new DNIFactoryImpl();
NetworkInfrastructure model = factory.createNetworkInfrastructure(); NetworkInfrastructure model = factory.createNetworkInfrastructure();
File file = Parser.convertToTempFile(model); File file = File.createTempFile("junit-dni-", ".dni");
file.deleteOnExit();
Parser.writeToFile(model, file);
Assert.assertTrue(file.length() > 100); Assert.assertTrue(file.length() > 100);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment