summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPierrick MARIE2012-02-14 04:56:29 (EST)
committerBenjamin CabeĢ2012-02-14 05:19:01 (EST)
commitae9d70ce26c066a66de55a7acbbcba6783f52e6c (patch)
tree17b08755f0d165cbd3b92cd2515e6a9cdfb7430e
parent0d52e74c6148ad267dfd071384b999972c2ee3c3 (diff)
downloadorg.eclipse.koneki.simulators-ae9d70ce26c066a66de55a7acbbcba6783f52e6c.zip
org.eclipse.koneki.simulators-ae9d70ce26c066a66de55a7acbbcba6783f52e6c.tar.gz
org.eclipse.koneki.simulators-ae9d70ce26c066a66de55a7acbbcba6783f52e6c.tar.bz2
Validation of the last unit tests
-rw-r--r--omadm/bundles/org.eclipse.koneki.simulators.omadm.editor/src/org/eclipse/koneki/simulators/omadm/editor/wizards/DevCreationWizardPage.java2
-rw-r--r--omadm/bundles/org.eclipse.koneki.simulators.omadm.editor/src/org/eclipse/koneki/simulators/omadm/editor/wizards/NewOMADMSimulationWizard.java2
-rw-r--r--omadm/bundles/org.eclipse.koneki.simulators.omadm.model/src/org/eclipse/koneki/simulators/omadm/model/impl/DeviceImpl.java33
-rw-r--r--omadm/bundles/org.eclipse.koneki.simulators.omadm.model/src/org/eclipse/koneki/simulators/omadm/model/util/DeviceHelpers.java4
-rw-r--r--omadm/bundles/org.eclipse.koneki.simulators.omadm.model/src/org/eclipse/koneki/simulators/omadm/model/util/NodeHelpers.java5
-rw-r--r--omadm/tests/org.eclipse.koneki.simulators.omadm.model.tests/src/org/eclipse/koneki/simulators/omadm/model/tests/DeviceHelpersTest.java13
6 files changed, 33 insertions, 26 deletions
diff --git a/omadm/bundles/org.eclipse.koneki.simulators.omadm.editor/src/org/eclipse/koneki/simulators/omadm/editor/wizards/DevCreationWizardPage.java b/omadm/bundles/org.eclipse.koneki.simulators.omadm.editor/src/org/eclipse/koneki/simulators/omadm/editor/wizards/DevCreationWizardPage.java
index 6c9e962..84cedf3 100644
--- a/omadm/bundles/org.eclipse.koneki.simulators.omadm.editor/src/org/eclipse/koneki/simulators/omadm/editor/wizards/DevCreationWizardPage.java
+++ b/omadm/bundles/org.eclipse.koneki.simulators.omadm.editor/src/org/eclipse/koneki/simulators/omadm/editor/wizards/DevCreationWizardPage.java
@@ -19,7 +19,6 @@ import org.eclipse.koneki.simulators.omadm.editor.Messages;
import org.eclipse.koneki.simulators.omadm.model.Device;
import org.eclipse.koneki.simulators.omadm.model.OMADMSimulatorFactory;
import org.eclipse.koneki.simulators.omadm.model.util.DeviceHelpers;
-import org.eclipse.koneki.simulators.omadm.model.util.NodeHelpers;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
@@ -38,7 +37,6 @@ public class DevCreationWizardPage extends WizardPage implements IWizardPage {
public DevCreationWizardPage(final String pageName) {
super(pageName);
device = OMADMSimulatorFactory.eINSTANCE.createDevice();
- device.setTree(NodeHelpers.initTree());
}
@Override
diff --git a/omadm/bundles/org.eclipse.koneki.simulators.omadm.editor/src/org/eclipse/koneki/simulators/omadm/editor/wizards/NewOMADMSimulationWizard.java b/omadm/bundles/org.eclipse.koneki.simulators.omadm.editor/src/org/eclipse/koneki/simulators/omadm/editor/wizards/NewOMADMSimulationWizard.java
index c9d9549..e12aee8 100644
--- a/omadm/bundles/org.eclipse.koneki.simulators.omadm.editor/src/org/eclipse/koneki/simulators/omadm/editor/wizards/NewOMADMSimulationWizard.java
+++ b/omadm/bundles/org.eclipse.koneki.simulators.omadm.editor/src/org/eclipse/koneki/simulators/omadm/editor/wizards/NewOMADMSimulationWizard.java
@@ -33,7 +33,6 @@ import org.eclipse.koneki.simulators.omadm.editor.internal.Activator;
import org.eclipse.koneki.simulators.omadm.model.Device;
import org.eclipse.koneki.simulators.omadm.model.OMADMSimulation;
import org.eclipse.koneki.simulators.omadm.model.OMADMSimulatorFactory;
-import org.eclipse.koneki.simulators.omadm.model.util.NodeHelpers;
import org.eclipse.ui.IEditorDescriptor;
import org.eclipse.ui.INewWizard;
import org.eclipse.ui.IWorkbench;
@@ -58,7 +57,6 @@ public class NewOMADMSimulationWizard extends Wizard implements INewWizard {
setWindowTitle(org.eclipse.koneki.simulators.omadm.editor.Messages.Wizard_Title);
device = OMADMSimulatorFactory.eINSTANCE.createDevice();
- device.setTree(NodeHelpers.initTree());
this.newFileCreationPage = new WizardNewFileCreationPage(getClass().getName() + "#FileCreationPage", selection); //$NON-NLS-1$
this.newFileCreationPage.setTitle(org.eclipse.koneki.simulators.omadm.editor.Messages.Wizard_NewFile_Title);
diff --git a/omadm/bundles/org.eclipse.koneki.simulators.omadm.model/src/org/eclipse/koneki/simulators/omadm/model/impl/DeviceImpl.java b/omadm/bundles/org.eclipse.koneki.simulators.omadm.model/src/org/eclipse/koneki/simulators/omadm/model/impl/DeviceImpl.java
index 9be548f..598e11e 100644
--- a/omadm/bundles/org.eclipse.koneki.simulators.omadm.model/src/org/eclipse/koneki/simulators/omadm/model/impl/DeviceImpl.java
+++ b/omadm/bundles/org.eclipse.koneki.simulators.omadm.model/src/org/eclipse/koneki/simulators/omadm/model/impl/DeviceImpl.java
@@ -145,10 +145,11 @@ public class DeviceImpl extends EObjectImpl implements Device {
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
*
- * @generated
+ * @generated NOT
*/
protected DeviceImpl() {
super();
+ setTree(NodeHelpers.initTree());
}
/**
@@ -183,10 +184,14 @@ public class DeviceImpl extends EObjectImpl implements Device {
DeviceIdType oldDeviceIdType = deviceIdType;
deviceIdType = newDeviceIdType == null ? DEVICE_ID_TYPE_EDEFAULT : newDeviceIdType;
+ String newDeviceId = DeviceHelpers.getDeviceIdTypeAndValue(deviceId)[1];
+
if (newDeviceIdType != DEVICE_ID_TYPE_EDEFAULT) {
- setDeviceId(deviceIdType.getName() + ":" + DeviceHelpers.getDeviceIdTypeAndValue(deviceId)[1]);
- } else {
- // setDeviceId(DeviceHelpers.getDeviceIdTypeAndValue(deviceId)[1]);
+ if (newDeviceId != null) {
+ setDeviceId(deviceIdType.getName() + ":" + DeviceHelpers.getDeviceIdTypeAndValue(deviceId)[1]);
+ } else {
+ setDeviceId(deviceIdType.getName() + ":" + deviceId);
+ }
}
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, OMADMSimulatorPackage.DEVICE__DEVICE_ID_TYPE, oldDeviceIdType, deviceIdType));
@@ -264,16 +269,14 @@ public class DeviceImpl extends EObjectImpl implements Device {
@Override
public void setDeviceId(String newDeviceId) {
String oldDeviceId = deviceId;
- Node devIdNode = NodeHelpers.findFirstNode(NodeHelpers.getNode(getTree(), "./DevInfo"), "DevId");
- if (devIdNode != null) {
- if (!newDeviceId.equals(oldDeviceId)) {
+ Node root = getTree();
+ Node devIdNode = NodeHelpers.findFirstNode(NodeHelpers.getNode(root, "./DevInfo"), "DevId");
+ if (devIdNode != null && newDeviceId != null) {
+ if (newDeviceId != null && !newDeviceId.equals(oldDeviceId)) {
devIdNode.setData(newDeviceId);
}
deviceId = newDeviceId;
- /*
- * Update the DeviceIdType
- */
String deviceIdType = DeviceHelpers.getDeviceIdTypeAndValue(deviceId)[0];
if (deviceIdType != null) {
@@ -285,7 +288,15 @@ public class DeviceImpl extends EObjectImpl implements Device {
setDeviceIdType(DeviceIdType.FREE);
}
} else {
- setDeviceIdType(DeviceIdType.FREE);
+ if (deviceId != null) {
+ if (deviceId.matches("^[0-9]{15}$")) {
+ setDeviceIdType(DeviceIdType.IMEI);
+ } else if (deviceId.matches("^[a-fA-F0-9]{12}$")) {
+ setDeviceIdType(DeviceIdType.MAC_ADDRESS);
+ } else {
+ setDeviceIdType(DeviceIdType.FREE);
+ }
+ }
}
}
diff --git a/omadm/bundles/org.eclipse.koneki.simulators.omadm.model/src/org/eclipse/koneki/simulators/omadm/model/util/DeviceHelpers.java b/omadm/bundles/org.eclipse.koneki.simulators.omadm.model/src/org/eclipse/koneki/simulators/omadm/model/util/DeviceHelpers.java
index fee3186..c66b1a8 100644
--- a/omadm/bundles/org.eclipse.koneki.simulators.omadm.model/src/org/eclipse/koneki/simulators/omadm/model/util/DeviceHelpers.java
+++ b/omadm/bundles/org.eclipse.koneki.simulators.omadm.model/src/org/eclipse/koneki/simulators/omadm/model/util/DeviceHelpers.java
@@ -78,9 +78,9 @@ public class DeviceHelpers {
if (deviceId != null) {
switch (device.getDeviceIdType()) {
case IMEI:
- return deviceId.matches("^[0-9]{15}$");
+ return deviceId.matches("^[0-9]{15}$") || deviceId.matches("^IMEI:[0-9]{15}$");
case MAC_ADDRESS:
- return deviceId.matches("^[a-fA-F0-9]{12}$");
+ return deviceId.matches("^[a-fA-F0-9]{12}$") || deviceId.matches("^MAC_ADDRESS:[a-fA-F0-9]{12}$");
default:
return deviceId.matches("^\\S+(\\s+\\S+)*$");
}
diff --git a/omadm/bundles/org.eclipse.koneki.simulators.omadm.model/src/org/eclipse/koneki/simulators/omadm/model/util/NodeHelpers.java b/omadm/bundles/org.eclipse.koneki.simulators.omadm.model/src/org/eclipse/koneki/simulators/omadm/model/util/NodeHelpers.java
index 1555be0..d2d4507 100644
--- a/omadm/bundles/org.eclipse.koneki.simulators.omadm.model/src/org/eclipse/koneki/simulators/omadm/model/util/NodeHelpers.java
+++ b/omadm/bundles/org.eclipse.koneki.simulators.omadm.model/src/org/eclipse/koneki/simulators/omadm/model/util/NodeHelpers.java
@@ -42,8 +42,6 @@ public class NodeHelpers {
}
}
-
-
private static boolean isValidRootNodeName(final String nodeName) {
return nodeName != null && nodeName.matches("^.$");
}
@@ -332,6 +330,9 @@ public class NodeHelpers {
if (node == null)
return false;
+ if (node.getRoot() == node)
+ return false;
+
for (String name : notAllowedNode) {
if (name.equals(node.getName())) {
return false;
diff --git a/omadm/tests/org.eclipse.koneki.simulators.omadm.model.tests/src/org/eclipse/koneki/simulators/omadm/model/tests/DeviceHelpersTest.java b/omadm/tests/org.eclipse.koneki.simulators.omadm.model.tests/src/org/eclipse/koneki/simulators/omadm/model/tests/DeviceHelpersTest.java
index 9142a5b..4e60969 100644
--- a/omadm/tests/org.eclipse.koneki.simulators.omadm.model.tests/src/org/eclipse/koneki/simulators/omadm/model/tests/DeviceHelpersTest.java
+++ b/omadm/tests/org.eclipse.koneki.simulators.omadm.model.tests/src/org/eclipse/koneki/simulators/omadm/model/tests/DeviceHelpersTest.java
@@ -42,17 +42,17 @@ public class DeviceHelpersTest {
{ "FEDCBA987654", true, false, true }, { "fedcba987654", true, false, true }, { "AaBcCcDdEeFf", true, false, true }, };
for (Object[] testData : testDatas) {
final Device freeDevice = OMADMSimulatorFactory.eINSTANCE.createDevice();
- // freeDevice.setDeviceId((String) testData[0]);
+ freeDevice.setDeviceId((String) testData[0]);
freeDevice.setDeviceIdType(DeviceIdType.FREE);
- // assertEquals(freeDevice.getDeviceId(), ((Boolean) testData[1]).booleanValue(), isValidDeviceId(freeDevice));
+ assertEquals(freeDevice.getDeviceId(), ((Boolean) testData[1]).booleanValue(), isValidDeviceId(freeDevice));
final Device imeiDevice = OMADMSimulatorFactory.eINSTANCE.createDevice();
- // imeiDevice.setDeviceId((String) testData[0]);
+ imeiDevice.setDeviceId((String) testData[0]);
imeiDevice.setDeviceIdType(DeviceIdType.IMEI);
- // assertEquals(imeiDevice.getDeviceId(), ((Boolean) testData[2]).booleanValue(), isValidDeviceId(imeiDevice));
+ assertEquals(imeiDevice.getDeviceId(), ((Boolean) testData[2]).booleanValue(), isValidDeviceId(imeiDevice));
final Device macDevice = OMADMSimulatorFactory.eINSTANCE.createDevice();
- // macDevice.setDeviceId((String) testData[0]);
+ macDevice.setDeviceId((String) testData[0]);
macDevice.setDeviceIdType(DeviceIdType.MAC_ADDRESS);
- // assertEquals(macDevice.getDeviceId(), ((Boolean) testData[3]).booleanValue(), isValidDeviceId(macDevice));
+ assertEquals(macDevice.getDeviceId(), ((Boolean) testData[3]).booleanValue(), isValidDeviceId(macDevice));
}
}
@@ -62,7 +62,6 @@ public class DeviceHelpersTest {
final Node root = OMADMSimulatorFactory.eINSTANCE.createNode();
root.setFormat(NodeFormat.CHR);
final Device device = OMADMSimulatorFactory.eINSTANCE.createDevice();
- device.setTree(root);
assertTrue(isValidRootNodeType(device));
}