aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Ross2013-09-11 06:43:11 (EDT)
committerJohn Ross2013-09-16 13:37:02 (EDT)
commit3c706bc913e9fbad1cf43dcb8a3b99e8f4d33763 (patch)
treee6e8db1ab18cb9c19561bcaec50885741d180349
parent5f41f307cf746e0e3469855f20f798962e051221 (diff)
downloadrt.equinox.bundles-3c706bc913e9fbad1cf43dcb8a3b99e8f4d33763.zip
rt.equinox.bundles-3c706bc913e9fbad1cf43dcb8a3b99e8f4d33763.tar.gz
rt.equinox.bundles-3c706bc913e9fbad1cf43dcb8a3b99e8f4d33763.tar.bz2
-rw-r--r--bundles/org.eclipse.equinox.compendium.tests/.classpath1
-rw-r--r--bundles/org.eclipse.equinox.compendium.tests/build.properties5
-rwxr-xr-xbundles/org.eclipse.equinox.compendium.tests/bundles_src/metatype/getMinMax.tb1/META-INF/MANIFEST.MF3
-rwxr-xr-xbundles/org.eclipse.equinox.compendium.tests/bundles_src/metatype/getMinMax.tb1/OSGI-INF/metatype/metadata.xml19
-rwxr-xr-xbundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/GetMinMaxTest.java103
5 files changed, 130 insertions, 1 deletions
diff --git a/bundles/org.eclipse.equinox.compendium.tests/.classpath b/bundles/org.eclipse.equinox.compendium.tests/.classpath
index 083dc88..bd28735 100644
--- a/bundles/org.eclipse.equinox.compendium.tests/.classpath
+++ b/bundles/org.eclipse.equinox.compendium.tests/.classpath
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" output="bundle_tests/metatype/getMinMax.tb1" path="bundles_src/metatype/getMinMax.tb1"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" output="bundle_tests/metatype/tb1" path="bundles_src/metatype/tb1"/>
diff --git a/bundles/org.eclipse.equinox.compendium.tests/build.properties b/bundles/org.eclipse.equinox.compendium.tests/build.properties
index 74bbb3f..3b5070b 100644
--- a/bundles/org.eclipse.equinox.compendium.tests/build.properties
+++ b/bundles/org.eclipse.equinox.compendium.tests/build.properties
@@ -31,6 +31,8 @@ source.bundle_tests/metatype.tb7.jar = bundles_src/metatype/tb7/
manifest.bundle_tests/metatype.tb7.jar = META-INF/MANIFEST.MF
source.bundle_tests/metatype.extendable.tb1.jar = bundles_src/metatype/extendable.tb1/
manifest.bundle_tests/metatype.extendable.tb1.jar = META-INF/MANIFEST.MF
+source.bundle_tests/metatype.getMinMax.tb1.jar = bundles_src/metatype/getMinMax.tb1/
+manifest.bundle_tests/metatype.getMinMax.tb1.jar = META-INF/MANIFEST.MF
jars.compile.order = bundle_tests/metatype/metatype.tb1.jar,\
bundle_tests/metatype/metatype.tb2.jar,\
@@ -39,4 +41,5 @@ jars.compile.order = bundle_tests/metatype/metatype.tb1.jar,\
bundle_tests/metatype/metatype.tb5.jar,\
bundle_tests/metatype/metatype.tb6.jar,\
bundle_tests/metatype/metatype.tb7.jar,\
- bundle_tests/metatype/metatype.extendable.tb1.jar
+ bundle_tests/metatype/metatype.extendable.tb1.jar,\
+ bundle_tests/metatype/metatype.getMinMax.tb1.jar
diff --git a/bundles/org.eclipse.equinox.compendium.tests/bundles_src/metatype/getMinMax.tb1/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.compendium.tests/bundles_src/metatype/getMinMax.tb1/META-INF/MANIFEST.MF
new file mode 100755
index 0000000..a8b8456
--- /dev/null
+++ b/bundles/org.eclipse.equinox.compendium.tests/bundles_src/metatype/getMinMax.tb1/META-INF/MANIFEST.MF
@@ -0,0 +1,3 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-SymbolicName: org.eclipse.equinox.metatype.tests.getMinMax.tb1
diff --git a/bundles/org.eclipse.equinox.compendium.tests/bundles_src/metatype/getMinMax.tb1/OSGI-INF/metatype/metadata.xml b/bundles/org.eclipse.equinox.compendium.tests/bundles_src/metatype/getMinMax.tb1/OSGI-INF/metatype/metadata.xml
new file mode 100755
index 0000000..f525328
--- /dev/null
+++ b/bundles/org.eclipse.equinox.compendium.tests/bundles_src/metatype/getMinMax.tb1/OSGI-INF/metatype/metadata.xml
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<md:MetaData
+ xmlns:md="http://www.org.osgi/xmlns/metatype/v1.0.0/md"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.org.osgi/xmlns/metatype/v1.0.0/md metatype.xsd">
+ <OCD id="getMinMax" name="getMinMax">
+ <AD id="getMax" type="Integer" max="0"/>
+ <AD id="getMaxNull" type="Integer" min="0"/>
+ <AD id="getMin" type="Integer" min="5"/>
+ <AD id="getMinNull" type="Integer" max="25"/>
+ <AD id="getMaxAsNotANumber" type="String" max="1.0.0"/>
+ <AD id="getMinAsNotANumber" type="String" min="foo"/>
+ <AD id="minMaxValidUsingInt" type="Password" min="8" max="16"/>
+ <AD id="minMaxValidUsingString" type="String" min="1" max="1.2"/>
+ </OCD>
+ <Designate pid="org.eclipse.equinox.metatype.tests.getMinMax.tb1">
+ <Object ocdref="getMinMax"/>
+ </Designate>
+</md:MetaData>
diff --git a/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/GetMinMaxTest.java b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/GetMinMaxTest.java
new file mode 100755
index 0000000..2ab4512
--- /dev/null
+++ b/bundles/org.eclipse.equinox.compendium.tests/src/org/eclipse/equinox/metatype/tests/GetMinMaxTest.java
@@ -0,0 +1,103 @@
+/*******************************************************************************
+ * Copyright (c) 2013 IBM Corporation and others
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.equinox.metatype.tests;
+
+import org.eclipse.equinox.metatype.*;
+import org.osgi.framework.Bundle;
+import org.osgi.service.metatype.ObjectClassDefinition;
+
+public class GetMinMaxTest extends AbstractTest {
+ private Bundle bundle;
+ private EquinoxObjectClassDefinition ocd;
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ bundle = bundleInstaller.installBundle("getMinMax.tb1"); //$NON-NLS-1$
+ bundle.start();
+ EquinoxMetaTypeInformation mti = metatype.getMetaTypeInformation(bundle);
+ ocd = mti.getObjectClassDefinition("org.eclipse.equinox.metatype.tests.getMinMax.tb1", null); //$NON-NLS-1$
+ }
+
+ public void testGetMax() throws Exception {
+ assertMaxValue("getMax", "0"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testGetMaxAsNotANumber() {
+ assertMaxValue("getMaxAsNotANumber", "1.0.0"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testGetMaxNull() {
+ assertMaxValue("getMaxNull", null); //$NON-NLS-1$
+ }
+
+ public void testGetMin() {
+ assertMinValue("getMin", "5"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testGetMinAsNotANumber() {
+ assertMinValue("getMinAsNotANumber", "foo"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ public void testGetMinNull() {
+ assertMinValue("getMinNull", null); //$NON-NLS-1$
+ }
+
+ public void testMinMaxStringValidationUsingInteger() {
+ String name = "minMaxValidUsingInt"; //$NON-NLS-1$
+ assertValid(name, "12345678"); //$NON-NLS-1$
+ assertValid(name, "1234567812345678"); //$NON-NLS-1$
+ assertInvalid(name, "1234567"); //$NON-NLS-1$
+ assertInvalid(name, "12345678123456789"); //$NON-NLS-1$
+ }
+
+ public void testMinMaxStringValidationUsingString() {
+ String name = "minMaxValidUsingString"; //$NON-NLS-1$
+ assertValid(name, "1"); //$NON-NLS-1$
+ assertValid(name, "1.2"); //$NON-NLS-1$
+ assertInvalid(name, "0"); //$NON-NLS-1$
+ assertInvalid(name, "1.3"); //$NON-NLS-1$
+ }
+
+ private void assertMaxValue(String name, String value) {
+ assertMinMaxValue(true, name, value);
+ }
+
+ private void assertMinValue(String name, String value) {
+ assertMinMaxValue(false, name, value);
+ }
+
+ private void assertMinMaxValue(boolean max, String name, String value) {
+ EquinoxAttributeDefinition ad = getAttributeDefinition(name);
+ assertEquals("Wrong " + (max ? "max" : "min") + " value", value, max ? ad.getMax() : ad.getMin()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ }
+
+ private void assertValid(String name, String value) {
+ assertValidation(name, value, true);
+
+ }
+
+ private void assertInvalid(String name, String value) {
+ assertValidation(name, value, false);
+ }
+
+ private void assertValidation(String name, String value, boolean valid) {
+ EquinoxAttributeDefinition ad = getAttributeDefinition(name);
+ if (valid)
+ assertEquals("Should be valid", "", ad.validate(value)); //$NON-NLS-1$ //$NON-NLS-2$
+ else
+ assertTrue("Should be invalid", ad.validate(value).length() > 0); //$NON-NLS-1$
+ }
+
+ private EquinoxAttributeDefinition getAttributeDefinition(String name) {
+ EquinoxAttributeDefinition[] ads = ocd.getAttributeDefinitions(ObjectClassDefinition.ALL);
+ return (EquinoxAttributeDefinition) findAttributeDefinitionById(name, ads);
+ }
+}