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

add method to clone dni model

parent 44523544
No related branches found
No related tags found
No related merge requests found
Showing with 104 additions and 31 deletions
...@@ -12,21 +12,21 @@ import org.junit.Test; ...@@ -12,21 +12,21 @@ import org.junit.Test;
import tools.descartes.dni.dnimm3ap.AdaptationPoints; import tools.descartes.dni.dnimm3ap.AdaptationPoints;
import tools.descartes.dni.dnimm3ap.impl.AdaptationPointsImpl; import tools.descartes.dni.dnimm3ap.impl.AdaptationPointsImpl;
import tools.descartes.dni.dnimm3ap.impl.DNIAPFactoryImpl; import tools.descartes.dni.dnimm3ap.impl.DNIAPFactoryImpl;
import tools.descartes.dni.dnimm3ap.tools.DniApParser; import tools.descartes.dni.dnimm3ap.tools.DNIAPParser;
public class ParserTest { public class ParserTest {
@Test @Test
public void shouldConvertFileToModel() { public void shouldConvertFileToModel() {
File file = new File("resources-test/scenario0B.dniap"); File file = new File("resources-test/scenario0B.dniap");
AdaptationPointsImpl adaptationPoints = DniApParser.convertToModel(file); AdaptationPointsImpl adaptationPoints = DNIAPParser.convertToModel(file);
Assert.assertTrue(adaptationPoints.getRepositories().getNodes().size() > 0); Assert.assertTrue(adaptationPoints.getRepositories().getNodes().size() > 0);
} }
@Test @Test
public void shouldConvertFileToModelWithNetworkStructure() { public void shouldConvertFileToModelWithNetworkStructure() {
File file = new File("resources-test/scenario0B.dniap"); File file = new File("resources-test/scenario0B.dniap");
AdaptationPointsImpl adaptationPoints = DniApParser.convertToModel(file); AdaptationPointsImpl adaptationPoints = DNIAPParser.convertToModel(file);
Assert.assertEquals(6, adaptationPoints.getNetworkInfrastructure().getStructure().getNodes().size()); Assert.assertEquals(6, adaptationPoints.getNetworkInfrastructure().getStructure().getNodes().size());
} }
...@@ -36,7 +36,7 @@ public class ParserTest { ...@@ -36,7 +36,7 @@ public class ParserTest {
AdaptationPoints model = factory.createAdaptationPoints(); AdaptationPoints model = factory.createAdaptationPoints();
File file = File.createTempFile("junit-dni-", ".dniap"); File file = File.createTempFile("junit-dni-", ".dniap");
file.deleteOnExit(); file.deleteOnExit();
DniApParser.writeToFile(model, file); DNIAPParser.writeToFile(model, file);
Assert.assertTrue(file.length() > 100); Assert.assertTrue(file.length() > 100);
} }
...@@ -44,7 +44,7 @@ public class ParserTest { ...@@ -44,7 +44,7 @@ public class ParserTest {
public void shouldConvertModelToByteArray() throws IOException { public void shouldConvertModelToByteArray() throws IOException {
DNIAPFactoryImpl factory = new DNIAPFactoryImpl(); DNIAPFactoryImpl factory = new DNIAPFactoryImpl();
AdaptationPoints model = factory.createAdaptationPoints(); AdaptationPoints model = factory.createAdaptationPoints();
byte[] bytes = DniApParser.convertToByteArray(model); byte[] bytes = DNIAPParser.convertToByteArray(model);
Assert.assertTrue(bytes.length > 10); Assert.assertTrue(bytes.length > 10);
} }
...@@ -52,21 +52,8 @@ public class ParserTest { ...@@ -52,21 +52,8 @@ public class ParserTest {
public void shouldConvertByteArrayToModel() throws IOException { public void shouldConvertByteArrayToModel() throws IOException {
Path path = Paths.get("resources-test/scenario0B.dniap"); Path path = Paths.get("resources-test/scenario0B.dniap");
byte[] data = Files.readAllBytes(path); byte[] data = Files.readAllBytes(path);
AdaptationPoints adaptationPoints = DniApParser.convertToModel(data); AdaptationPoints adaptationPoints = DNIAPParser.convertToModel(data);
Assert.assertTrue(adaptationPoints.getRepositories().getNodes().size() > 0); Assert.assertTrue(adaptationPoints.getRepositories().getNodes().size() > 0);
} }
@Test
public void shouldCloneModel() {
File file = new File("resources-test/scenario0B.dniap");
AdaptationPointsImpl adaptationPoints1 = DniApParser.convertToModel(file);
AdaptationPointsImpl adaptationPoints2 = DniApParser.clone(adaptationPoints1);
Assert.assertNotEquals(adaptationPoints1, adaptationPoints2);
Assert.assertEquals(adaptationPoints1.getNetworkInfrastructure().getStructure().getNodes().size(),
adaptationPoints2.getNetworkInfrastructure().getStructure().getNodes().size());
Assert.assertEquals(
adaptationPoints1.getNetworkInfrastructure().getStructure().getNodes().get(0).getUid_generated(),
adaptationPoints2.getNetworkInfrastructure().getStructure().getNodes().get(0).getUid_generated());
}
} }
package tools.descartes.dni.dnimm3.tools;
import java.io.File;
import org.junit.Assert;
import org.junit.Test;
import tools.descartes.dni.dnimm3ap.impl.AdaptationPointsImpl;
import tools.descartes.dni.dnimm3ap.tools.DNIAPParser;
import tools.descartes.dni.dnimm3ap.tools.DNIAPUtil;
public class UtilTest {
@Test
public void shouldCloneModel() {
File file = new File("resources-test/scenario0B.dniap");
AdaptationPointsImpl adaptationPoints1 = DNIAPParser.convertToModel(file);
AdaptationPointsImpl adaptationPoints2 = DNIAPUtil.cloneModel(adaptationPoints1);
Assert.assertNotEquals(adaptationPoints1, adaptationPoints2);
Assert.assertEquals(adaptationPoints1.getNetworkInfrastructure().getStructure().getNodes().size(),
adaptationPoints2.getNetworkInfrastructure().getStructure().getNodes().size());
Assert.assertEquals(
adaptationPoints1.getNetworkInfrastructure().getStructure().getNodes().get(0).getUid_generated(),
adaptationPoints2.getNetworkInfrastructure().getStructure().getNodes().get(0).getUid_generated());
}
}
...@@ -10,14 +10,16 @@ import org.eclipse.emf.common.util.URI; ...@@ -10,14 +10,16 @@ import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
import tools.descartes.dni.dnimm3ap.AdaptationPoints; import tools.descartes.dni.dnimm3ap.AdaptationPoints;
import tools.descartes.dni.dnimm3ap.DNIAPPackage; import tools.descartes.dni.dnimm3ap.DNIAPPackage;
import tools.descartes.dni.dnimm3ap.impl.AdaptationPointsImpl; import tools.descartes.dni.dnimm3ap.impl.AdaptationPointsImpl;
public class DniApParser { public class DNIAPParser {
private DNIAPParser() {
}
public static AdaptationPointsImpl convertToModel(File file) { public static AdaptationPointsImpl convertToModel(File file) {
ResourceSet resourceSet = new ResourceSetImpl(); ResourceSet resourceSet = new ResourceSetImpl();
...@@ -60,8 +62,4 @@ public class DniApParser { ...@@ -60,8 +62,4 @@ public class DniApParser {
resource.save(Collections.EMPTY_MAP); resource.save(Collections.EMPTY_MAP);
} }
public static AdaptationPointsImpl clone(AdaptationPoints adaptationPoints) {
return (AdaptationPointsImpl) EcoreUtil.copy(adaptationPoints);
}
} }
package tools.descartes.dni.dnimm3ap.tools;
import org.eclipse.emf.ecore.util.EcoreUtil;
import tools.descartes.dni.dnimm3ap.AdaptationPoints;
import tools.descartes.dni.dnimm3ap.impl.AdaptationPointsImpl;
public class DNIAPUtil {
private DNIAPUtil() {
}
public static AdaptationPointsImpl cloneModel(AdaptationPoints adaptationPoints) {
return (AdaptationPointsImpl) EcoreUtil.copy(adaptationPoints);
}
}
...@@ -18,14 +18,14 @@ public class ParserTest { ...@@ -18,14 +18,14 @@ public class ParserTest {
@Test @Test
public void shouldConvertFileToModel() { public void shouldConvertFileToModel() {
File file = new File("resources-test/scenario0A.dni"); File file = new File("resources-test/scenario0A.dni");
NetworkInfrastructureImpl networkInfrastructure = DniParser.convertToModel(file); NetworkInfrastructureImpl networkInfrastructure = DNIParser.convertToModel(file);
Assert.assertEquals(6, networkInfrastructure.getStructure().getNodes().size()); Assert.assertEquals(6, networkInfrastructure.getStructure().getNodes().size());
} }
@Test @Test
public void shouldConvertFileWithAdaptationToModel() { public void shouldConvertFileWithAdaptationToModel() {
File file = new File("resources-test/scenario0B.dni"); File file = new File("resources-test/scenario0B.dni");
NetworkInfrastructureImpl networkInfrastructure = DniParser.convertToModel(file); NetworkInfrastructureImpl networkInfrastructure = DNIParser.convertToModel(file);
Assert.assertEquals(6, networkInfrastructure.getStructure().getNodes().size()); Assert.assertEquals(6, networkInfrastructure.getStructure().getNodes().size());
} }
...@@ -35,7 +35,7 @@ public class ParserTest { ...@@ -35,7 +35,7 @@ public class ParserTest {
NetworkInfrastructure model = factory.createNetworkInfrastructure(); NetworkInfrastructure model = factory.createNetworkInfrastructure();
File file = File.createTempFile("junit-dni-", ".dni"); File file = File.createTempFile("junit-dni-", ".dni");
file.deleteOnExit(); file.deleteOnExit();
DniParser.writeToFile(model, file); DNIParser.writeToFile(model, file);
Assert.assertTrue(file.length() > 100); Assert.assertTrue(file.length() > 100);
} }
...@@ -43,7 +43,7 @@ public class ParserTest { ...@@ -43,7 +43,7 @@ public class ParserTest {
public void shouldConvertModelToByteArray() throws IOException { public void shouldConvertModelToByteArray() throws IOException {
DNIFactoryImpl factory = new DNIFactoryImpl(); DNIFactoryImpl factory = new DNIFactoryImpl();
NetworkInfrastructure model = factory.createNetworkInfrastructure(); NetworkInfrastructure model = factory.createNetworkInfrastructure();
byte[] bytes = DniParser.convertToByteArray(model); byte[] bytes = DNIParser.convertToByteArray(model);
Assert.assertTrue(bytes.length > 100); Assert.assertTrue(bytes.length > 100);
} }
...@@ -51,7 +51,7 @@ public class ParserTest { ...@@ -51,7 +51,7 @@ public class ParserTest {
public void shouldConvertByteArrayToModel() throws IOException { public void shouldConvertByteArrayToModel() throws IOException {
Path path = Paths.get("resources-test/scenario0A.dni"); Path path = Paths.get("resources-test/scenario0A.dni");
byte[] data = Files.readAllBytes(path); byte[] data = Files.readAllBytes(path);
NetworkInfrastructureImpl networkInfrastructure = DniParser.convertToModel(data); NetworkInfrastructureImpl networkInfrastructure = DNIParser.convertToModel(data);
Assert.assertEquals(6, networkInfrastructure.getStructure().getNodes().size()); Assert.assertEquals(6, networkInfrastructure.getStructure().getNodes().size());
} }
......
package tools.descartes.dni.dnimm3.tools;
import java.io.File;
import org.junit.Assert;
import org.junit.Test;
import tools.descartes.dni.dnimm3.impl.NetworkInfrastructureImpl;
public class UtilTest {
@Test
public void shouldCloneModel() {
File file = new File("resources-test/scenario0B.dni");
NetworkInfrastructureImpl networkInfrastructure1 = DNIParser.convertToModel(file);
NetworkInfrastructureImpl networkInfrastructure2 = DNIUtil.cloneModel(networkInfrastructure1);
Assert.assertNotEquals(networkInfrastructure1, networkInfrastructure2);
Assert.assertEquals(networkInfrastructure1.getStructure().getNodes().size(),
networkInfrastructure2.getStructure().getNodes().size());
Assert.assertEquals(networkInfrastructure1.getStructure().getNodes().get(0).getUid_generated(),
networkInfrastructure2.getStructure().getNodes().get(0).getUid_generated());
}
}
...@@ -16,7 +16,10 @@ import tools.descartes.dni.dnimm3.DNIPackage; ...@@ -16,7 +16,10 @@ import tools.descartes.dni.dnimm3.DNIPackage;
import tools.descartes.dni.dnimm3.NetworkInfrastructure; import tools.descartes.dni.dnimm3.NetworkInfrastructure;
import tools.descartes.dni.dnimm3.impl.NetworkInfrastructureImpl; import tools.descartes.dni.dnimm3.impl.NetworkInfrastructureImpl;
public class DniParser { public class DNIParser {
private DNIParser() {
}
public static NetworkInfrastructureImpl convertToModel(File file) { public static NetworkInfrastructureImpl convertToModel(File file) {
ResourceSet resourceSet = new ResourceSetImpl(); ResourceSet resourceSet = new ResourceSetImpl();
......
package tools.descartes.dni.dnimm3.tools;
import org.eclipse.emf.ecore.util.EcoreUtil;
import tools.descartes.dni.dnimm3.NetworkInfrastructure;
import tools.descartes.dni.dnimm3.impl.NetworkInfrastructureImpl;
public class DNIUtil {
private DNIUtil() {
}
public static NetworkInfrastructureImpl cloneModel(NetworkInfrastructure networkInfrastructure) {
return (NetworkInfrastructureImpl) EcoreUtil.copy(networkInfrastructure);
}
}
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