summaryrefslogtreecommitdiff
path: root/ksm-model/test/de
diff options
context:
space:
mode:
authoryvesf <yvesf-git@xapek.org>2011-05-09 23:37:38 +0200
committeryvesf <yvesf-git@xapek.org>2011-05-10 20:56:04 +0200
commitd99fac83ac0b02c2e8d1e93c18a25a3c92539726 (patch)
tree5c5fb9fe75073f0556a81201ef5d6de249d07a15 /ksm-model/test/de
downloadksm-rcp-d99fac83ac0b02c2e8d1e93c18a25a3c92539726.tar.gz
ksm-rcp-d99fac83ac0b02c2e8d1e93c18a25a3c92539726.zip
Vor-Ergebnisse Studienarbeit
Diffstat (limited to 'ksm-model/test/de')
-rw-r--r--ksm-model/test/de/dhbw/horb/ksm/xmlschema/TestConnection.java30
-rw-r--r--ksm-model/test/de/dhbw/horb/ksm/xmlschema/TestKSM.java47
-rw-r--r--ksm-model/test/de/dhbw/horb/ksm/xmlschema/TestNode.java87
-rw-r--r--ksm-model/test/de/dhbw/horb/ksm/xmlschema/TestNodeGroup.java102
-rw-r--r--ksm-model/test/de/dhbw/horb/ksm/xmlschema/TestProperties.java119
-rw-r--r--ksm-model/test/de/dhbw/horb/ksm/xmlschema/Utils.java18
6 files changed, 403 insertions, 0 deletions
diff --git a/ksm-model/test/de/dhbw/horb/ksm/xmlschema/TestConnection.java b/ksm-model/test/de/dhbw/horb/ksm/xmlschema/TestConnection.java
new file mode 100644
index 0000000..dcc2e2b
--- /dev/null
+++ b/ksm-model/test/de/dhbw/horb/ksm/xmlschema/TestConnection.java
@@ -0,0 +1,30 @@
+package de.dhbw.horb.ksm.xmlschema;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import de.dhbw.horb.ksm.model.api.Connection;
+import de.dhbw.horb.ksm.model.api.KSM;
+import de.dhbw.horb.ksm.model.api.Node;
+import de.dhbw.horb.ksm.model.api.NodeGroup;
+import de.dhbw.horb.ksm.model.impl.KSMFactory;
+
+public class TestConnection {
+ @Test
+ public void testConnectionEvents() {
+ PropertyChangeListener listenerMock = Mockito
+ .mock(PropertyChangeListener.class);
+
+ KSM ksm = KSMFactory.createEmptyKSM();
+ NodeGroup nodeGroup = ksm.getNodeGroup();
+ Node node = nodeGroup.createNode();
+ node.addPropertyChangeListener(listenerMock);
+ Connection connection = node.createConnection("bla");
+ node.removeConnection(connection);
+ Mockito.verify(listenerMock, Mockito.times(2)).propertyChange(
+ Mockito.any(PropertyChangeEvent.class));
+ }
+}
diff --git a/ksm-model/test/de/dhbw/horb/ksm/xmlschema/TestKSM.java b/ksm-model/test/de/dhbw/horb/ksm/xmlschema/TestKSM.java
new file mode 100644
index 0000000..4d85e34
--- /dev/null
+++ b/ksm-model/test/de/dhbw/horb/ksm/xmlschema/TestKSM.java
@@ -0,0 +1,47 @@
+package de.dhbw.horb.ksm.xmlschema;
+
+import javax.xml.bind.JAXBException;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import de.dhbw.horb.ksm.model.api.Connection;
+import de.dhbw.horb.ksm.model.api.KSM;
+import de.dhbw.horb.ksm.model.api.Node;
+import de.dhbw.horb.ksm.model.api.NodeGroup;
+import de.dhbw.horb.ksm.model.impl.KSMFactory;
+
+public class TestKSM {
+ @Test
+ public void testLookup() throws JAXBException {
+ KSM myKSM = KSMFactory.createEmptyKSM();
+ Node node1 = myKSM.getNodeGroup().createNode();
+ NodeGroup nodeGroup1 = myKSM.getNodeGroup().createNodeGroup();
+ Node node2 = nodeGroup1.createNode();
+
+ Assert.assertSame(node1, myKSM.lookupNode(node1.getId()));
+ Assert.assertSame(node2, myKSM.lookupNode(node2.getId()));
+
+ KSM reloadedKSM = Utils.saveAndReload(myKSM);
+ Assert.assertEquals(node1.getId(), reloadedKSM
+ .lookupNode(node1.getId()).getId());
+
+ Assert.assertEquals(node2.getId(), reloadedKSM
+ .lookupNode(node2.getId()).getId());
+
+ Assert.assertSame(nodeGroup1, myKSM.lookupNodeGroup(nodeGroup1.getId()));
+ Assert.assertEquals(nodeGroup1.getId(),
+ reloadedKSM.lookupNodeGroup(nodeGroup1.getId()).getId());
+ }
+
+ @Test
+ public void testIncomingConnections() {
+ KSM myKSM = KSMFactory.createEmptyKSM();
+ Node node1 = myKSM.getNodeGroup().createNode();
+ Node node2 = myKSM.getNodeGroup().createNode();
+ @SuppressWarnings("unused")
+ Connection connection = node1.createConnection(node2);
+ Node incomingNode = myKSM.getIncomingConnections(node2).get(0);
+ Assert.assertSame(node1, incomingNode);
+ }
+} \ No newline at end of file
diff --git a/ksm-model/test/de/dhbw/horb/ksm/xmlschema/TestNode.java b/ksm-model/test/de/dhbw/horb/ksm/xmlschema/TestNode.java
new file mode 100644
index 0000000..0ab305d
--- /dev/null
+++ b/ksm-model/test/de/dhbw/horb/ksm/xmlschema/TestNode.java
@@ -0,0 +1,87 @@
+package de.dhbw.horb.ksm.xmlschema;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+
+import javax.xml.bind.JAXBException;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import de.dhbw.horb.ksm.model.api.Connection;
+import de.dhbw.horb.ksm.model.api.KSM;
+import de.dhbw.horb.ksm.model.api.Node;
+import de.dhbw.horb.ksm.model.api.NodeGroup;
+import de.dhbw.horb.ksm.model.impl.KSMFactory;
+
+public class TestNode {
+ private static final String PROP_VALUE = "hello-world";
+ private static final String PROP_NAME = "visual.name";
+
+ @Test
+ public void testNodeAndStringProperty() throws JAXBException {
+ KSM ksm = KSMFactory.createEmptyKSM();
+ Assert.assertNotNull(ksm);
+
+ NodeGroup nodeGroup = ksm.getNodeGroup();
+ Node node = nodeGroup.createNode();
+ node.getProperties().setString(PROP_NAME, PROP_VALUE);
+
+ NodeGroup createNodeGroup = nodeGroup.createNodeGroup();
+ createNodeGroup.createNode();
+
+ KSM ksmCopy = Utils.saveAndReload(ksm);
+
+ Assert.assertEquals(1, ksmCopy.getNodeGroup().getNodes().size());
+ Assert.assertEquals(PROP_VALUE, ksmCopy.getNodeGroup().getNodes()
+ .get(0).getProperties().getString(PROP_NAME));
+ }
+
+ @Test
+ public void testNodeConnectionsCreate() throws JAXBException {
+ KSM ksm = KSMFactory.createEmptyKSM();
+ Node node1 = ksm.getNodeGroup().createNode();
+ Node node2 = ksm.getNodeGroup().createNode();
+
+ @SuppressWarnings("unused")
+ Connection connection = node1.createConnection(node2);
+
+ String to = node1.getConnections().get(0).getTo();
+ Assert.assertSame(node2, ksm.lookupNode(to));
+
+ KSM ksmCopy = Utils.saveAndReload(ksm);
+ Assert.assertEquals(node2.getId(), ksmCopy.lookupNode(to).getId());
+ }
+
+ @Test
+ public void testNodeConnectionsRemove() {
+ KSM ksm = KSMFactory.createEmptyKSM();
+ Node node1 = ksm.getNodeGroup().createNode();
+ Node node2 = ksm.getNodeGroup().createNode();
+
+ Connection connection = node1.createConnection(node2);
+ Assert.assertEquals(1, node1.getConnections().size());
+
+ Assert.assertTrue(node1.removeConnection(connection));
+ Assert.assertFalse(node1.removeConnection(connection));
+ Assert.assertFalse(node1.removeConnection(connection));
+ Assert.assertEquals(0, node1.getConnections().size());
+ Assert.assertEquals(0, ksm.getIncomingConnections(node2).size());
+ }
+
+ @Test
+ public void testNodeGroupEvents() {
+ PropertyChangeListener listenerMock = Mockito
+ .mock(PropertyChangeListener.class);
+
+ KSM ksm = KSMFactory.createEmptyKSM();
+ NodeGroup nodeGroup = ksm.getNodeGroup();
+ Node node = nodeGroup.createNode();
+ node.addPropertyChangeListener(listenerMock);
+ Connection connection = node.createConnection("bla");
+ node.removeConnection(connection);
+ Mockito.verify(listenerMock, Mockito.times(2)).propertyChange(
+ Mockito.any(PropertyChangeEvent.class));
+ }
+} \ No newline at end of file
diff --git a/ksm-model/test/de/dhbw/horb/ksm/xmlschema/TestNodeGroup.java b/ksm-model/test/de/dhbw/horb/ksm/xmlschema/TestNodeGroup.java
new file mode 100644
index 0000000..5ae6e40
--- /dev/null
+++ b/ksm-model/test/de/dhbw/horb/ksm/xmlschema/TestNodeGroup.java
@@ -0,0 +1,102 @@
+package de.dhbw.horb.ksm.xmlschema;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+
+import javax.xml.bind.JAXBException;
+
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import junit.framework.Assert;
+import de.dhbw.horb.ksm.model.api.KSM;
+import de.dhbw.horb.ksm.model.api.Node;
+import de.dhbw.horb.ksm.model.api.NodeGroup;
+import de.dhbw.horb.ksm.model.impl.KSMFactory;
+
+public class TestNodeGroup {
+ @Test
+ public void testCreateNodeGroup() throws JAXBException {
+ KSM ksm = KSMFactory.createEmptyKSM();
+ Assert.assertNotNull(ksm);
+
+ NodeGroup root = ksm.getNodeGroup();
+ NodeGroup subNodeGroup = root.createNodeGroup();
+
+ KSM ksmCopy = Utils.saveAndReload(ksm);
+ Assert.assertEquals(root.getId(), ksmCopy.getNodeGroup().getId());
+
+ Assert.assertEquals(ksm.getNodeGroup().getNodeGroups().size(), ksmCopy
+ .getNodeGroup().getNodeGroups().size());
+ Assert.assertEquals(ksm.getNodeGroup().getNodeGroups().get(0).getId(),
+ subNodeGroup.getId());
+ }
+
+ @Test
+ public void testRemoveNode() throws JAXBException {
+ KSM ksm = KSMFactory.createEmptyKSM();
+ Node node1 = ksm.getNodeGroup().createNode();
+ Node node2 = ksm.getNodeGroup().createNode();
+ Assert.assertTrue(ksm.getNodeGroup().removeNode(node1));
+ Assert.assertEquals(1, ksm.getNodeGroup().getNodes().size());
+
+ KSM ksmCopy = Utils.saveAndReload(ksm);
+ Node lookupNode2 = ksmCopy.lookupNode(node2.getId());
+ Assert.assertTrue(ksmCopy.getNodeGroup().removeNode(lookupNode2));
+ Assert.assertEquals(0, ksmCopy.getNodeGroup().getNodes().size());
+ }
+
+ @Test
+ public void testRemoveNodeGroup() throws JAXBException {
+ KSM ksm = KSMFactory.createEmptyKSM();
+ NodeGroup nodeGroup1 = ksm.getNodeGroup().createNodeGroup();
+ NodeGroup nodeGroup2 = ksm.getNodeGroup().createNodeGroup();
+ Assert.assertTrue(ksm.getNodeGroup().removeNodeGroup(nodeGroup1));
+ Assert.assertEquals(1, ksm.getNodeGroup().getNodeGroups().size());
+
+ KSM ksmCopy = Utils.saveAndReload(ksm);
+ NodeGroup lookupNodeGroup2 = ksmCopy.lookupNodeGroup(nodeGroup2.getId());
+ Assert.assertTrue(ksmCopy.getNodeGroup().removeNodeGroup(lookupNodeGroup2));
+ Assert.assertEquals(0, ksmCopy.getNodeGroup().getNodes().size());
+ }
+
+ @Test
+ public void testAddNode() throws JAXBException {
+ KSM ksm = KSMFactory.createEmptyKSM();
+ Node node = ksm.getNodeGroup().createNode();
+ ksm.getNodeGroup().removeNode(node);
+ ksm.getNodeGroup().addNode(node);
+
+ Assert.assertEquals(1, ksm.getNodeGroup().getNodes().size());
+ }
+
+ @Test
+ public void testAddNodeGroup() throws JAXBException {
+ KSM ksm = KSMFactory.createEmptyKSM();
+ NodeGroup nodeGroup = ksm.getNodeGroup().createNodeGroup();
+ Assert.assertTrue(ksm.getNodeGroup().removeNodeGroup(nodeGroup));
+ ksm.getNodeGroup().addNodeGroup(nodeGroup);
+
+ Assert.assertEquals(1, ksm.getNodeGroup().getNodeGroups().size());
+ }
+
+ @Test
+ public void testNodeGroupEvents() {
+ PropertyChangeListener listenerMock = Mockito
+ .mock(PropertyChangeListener.class);
+ KSM ksm = KSMFactory.createEmptyKSM();
+ NodeGroup nodeGroup = ksm.getNodeGroup();
+ nodeGroup.addPropertyChangeListener(listenerMock);
+ nodeGroup.createNode();
+ NodeGroup nodeGroup2 = nodeGroup.createNodeGroup();
+ Mockito.verify(listenerMock, Mockito.times(2)).propertyChange(
+ Mockito.any(PropertyChangeEvent.class));
+
+ Mockito.reset(listenerMock);
+ nodeGroup2.addPropertyChangeListener(listenerMock);
+ nodeGroup2.createNode();
+ nodeGroup.createNodeGroup();
+ Mockito.verify(listenerMock, Mockito.times(2)).propertyChange(
+ Mockito.any(PropertyChangeEvent.class));
+ }
+}
diff --git a/ksm-model/test/de/dhbw/horb/ksm/xmlschema/TestProperties.java b/ksm-model/test/de/dhbw/horb/ksm/xmlschema/TestProperties.java
new file mode 100644
index 0000000..985325f
--- /dev/null
+++ b/ksm-model/test/de/dhbw/horb/ksm/xmlschema/TestProperties.java
@@ -0,0 +1,119 @@
+package de.dhbw.horb.ksm.xmlschema;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.List;
+
+import javax.xml.bind.JAXBException;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.junit.Test;
+import org.mockito.Mockito;
+
+import de.dhbw.horb.ksm.model.api.Connection;
+import de.dhbw.horb.ksm.model.api.KSM;
+import de.dhbw.horb.ksm.model.api.Node;
+import de.dhbw.horb.ksm.model.api.NodeGroup;
+import de.dhbw.horb.ksm.model.api.Properties;
+import de.dhbw.horb.ksm.model.impl.KSMFactory;
+
+public class TestProperties extends TestCase {
+ @Test
+ public void testStringDecimalIntegerWithSameName() throws JAXBException {
+ KSM myKSM = KSMFactory.createEmptyKSM();
+ NodeGroup rootNodeGroup = myKSM.getNodeGroup();
+ Properties properties = rootNodeGroup.getProperties();
+ properties.setString("testbla", "blabla");
+ properties.setDecimal("testbla", new BigDecimal(123.213123));
+ properties.setInteger("testbla", new BigInteger("123123"));
+ properties.setBoolean("testbla", false);
+ KSM myKSMCopy = Utils.saveAndReload(myKSM);
+ Assert.assertEquals(properties.getString("testbla"), myKSMCopy
+ .getNodeGroup().getProperties().getString("testbla"));
+ Assert.assertEquals(properties.getDecimal("testbla"), myKSMCopy
+ .getNodeGroup().getProperties().getDecimal("testbla"));
+ Assert.assertEquals(properties.getInteger("testbla"), myKSMCopy
+ .getNodeGroup().getProperties().getInteger("testbla"));
+ }
+
+ @Test
+ public void testListProperties() throws JAXBException {
+ KSM myKSM = KSMFactory.createEmptyKSM();
+ NodeGroup rootNodeGroup = myKSM.getNodeGroup();
+ Properties properties = rootNodeGroup.getProperties();
+ {
+ List<BigDecimal> decimalList = properties
+ .createDecimalList("meine.Liste");
+ Assert.assertNotNull(decimalList);
+ Assert.assertNull(properties.createDecimalList("meine.Liste"));
+ }
+ {
+ List<String> stringList = properties
+ .createStringList("meine.stringListe");
+ Assert.assertNotNull(stringList);
+ Assert.assertNull(properties.createStringList("meine.stringListe"));
+ }
+ {
+ properties.removeStringList("meine.stringListe");
+ System.out.println(properties.getStringList("meine.stringListe"));
+ Assert.assertTrue(properties.removeDecimalList("meine.Liste"));
+ }
+ }
+
+ @Test
+ public void testPropertiesKSMNodeNodeGroupConnection() {
+ KSM ksm = KSMFactory.createEmptyKSM();
+ Assert.assertNotNull(ksm.getProperties());
+
+ NodeGroup nodeGroup = ksm.getNodeGroup();
+ Assert.assertNotNull(nodeGroup.getProperties());
+
+ Node node = nodeGroup.createNode();
+ Assert.assertNotNull(node.getProperties());
+
+ Node node2 = nodeGroup.createNode();
+ Connection connection = node.createConnection(node2);
+ Assert.assertNotNull(connection.getProperties());
+ }
+
+ @Test
+ public void testPropertiesEvents() {
+ PropertyChangeListener listenerMock = Mockito
+ .mock(PropertyChangeListener.class);
+ KSM ksm = KSMFactory.createEmptyKSM();
+ Properties properties = ksm.getProperties();
+
+ properties.addPropertyChangeListener(listenerMock);
+ Mockito.reset(listenerMock);
+ properties.setString("a", "b");
+ Mockito.verify(listenerMock).propertyChange(Mockito.any(PropertyChangeEvent.class));
+
+ Mockito.reset(listenerMock);
+ properties.setDecimal("a", new BigDecimal(5));
+ Mockito.verify(listenerMock).propertyChange(Mockito.any(PropertyChangeEvent.class));
+
+ Mockito.reset(listenerMock);
+ properties.setInteger("a", BigInteger.valueOf(1000));
+ Mockito.verify(listenerMock).propertyChange(Mockito.any(PropertyChangeEvent.class));
+
+ Mockito.reset(listenerMock);
+ properties.setBoolean("a", true);
+ Mockito.verify(listenerMock).propertyChange(Mockito.any(PropertyChangeEvent.class));
+
+ Mockito.reset(listenerMock);
+ properties.createStringList("foo");
+ Mockito.verify(listenerMock).propertyChange(Mockito.any(PropertyChangeEvent.class));
+
+ Mockito.reset(listenerMock);
+ properties.createDecimalList("foo");
+ Mockito.verify(listenerMock).propertyChange(Mockito.any(PropertyChangeEvent.class));
+
+ Mockito.reset(listenerMock);
+ properties.createIntegerList("foo");
+ Mockito.verify(listenerMock).propertyChange(Mockito.any(PropertyChangeEvent.class));
+ }
+}
diff --git a/ksm-model/test/de/dhbw/horb/ksm/xmlschema/Utils.java b/ksm-model/test/de/dhbw/horb/ksm/xmlschema/Utils.java
new file mode 100644
index 0000000..4ac54c8
--- /dev/null
+++ b/ksm-model/test/de/dhbw/horb/ksm/xmlschema/Utils.java
@@ -0,0 +1,18 @@
+package de.dhbw.horb.ksm.xmlschema;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+
+import javax.xml.bind.JAXBException;
+
+import de.dhbw.horb.ksm.model.api.KSM;
+import de.dhbw.horb.ksm.model.impl.KSMFactory;
+
+public class Utils {
+ static KSM saveAndReload(KSM ksm ) throws JAXBException {
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
+ KSMFactory.saveKSM(ksm, os);
+ ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
+ return KSMFactory.loadKSM(is);
+ }
+}