-
Notifications
You must be signed in to change notification settings - Fork 3
/
PlcOpenSerializeTest.java
57 lines (47 loc) · 2.02 KB
/
PlcOpenSerializeTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package org.plcopen.xcore.serde;
import java.io.File;
import java.io.IOException;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceFactoryRegistryImpl;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.plcopen.xml.tc60201.serde.PlcOpenSerializer;
import org.plcopen.xml.tc60201.util.Tc60201ResourceFactoryImpl;
public class PlcOpenSerializeTest {
ResourceSet resourceSet = null;
@Before
public void setUp() throws Exception {
resourceSet = new ResourceSetImpl();
ResourceFactoryRegistryImpl.INSTANCE.getExtensionToFactoryMap().put("xml", new Tc60201ResourceFactoryImpl());
ResourceFactoryRegistryImpl.INSTANCE.getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl());
}
@Test
public void loadXmlTest() throws IOException {
File xmlFile = new File("examples/minimal.xml");
PlcOpenSerializer serializer = new PlcOpenSerializer();
Resource resource = serializer.loadXMLResource(xmlFile);
Assert.assertNotNull(resource);
}
@Test
public void serializeTest() throws IOException {
File xmlFile = new File("examples/minimal.xml");
PlcOpenSerializer serializer = new PlcOpenSerializer();
serializer.writeXMI(xmlFile, resourceSet, "generated/demo_xmi.xmi");
Resource resource = serializer.loadXMIResource(new File("generated/demo_xmi.xmi"));
Assert.assertNotNull(resource);
resource.save(null);
}
@Test
public void roundtripTest() throws IOException {
File xmlFile = new File("examples/minimal.xml");
PlcOpenSerializer serializer = new PlcOpenSerializer();
serializer.writeXMI(xmlFile, resourceSet, "generated/demo_xmi.xmi");
URI modelURI = URI.createFileURI(new File("generated/demo_xmi.xmi").getAbsolutePath());
serializer.writeXML(resourceSet.getResource(modelURI, true), "generated/demo_generated.xml");
}
}