summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Liebig2008-04-25 04:32:05 (EDT)
committerStefan Liebig2008-04-25 04:32:05 (EDT)
commite2091a75f4cc01ef71a14fe3cd4fc4701cd31d6a (patch)
treefa0a0ef393d966b1457701455dc4e38286aef598
parentead1966a896f8b8b8b8feb349cc3947493a9415b (diff)
downloadorg.eclipse.riena-e2091a75f4cc01ef71a14fe3cd4fc4701cd31d6a.zip
org.eclipse.riena-e2091a75f4cc01ef71a14fe3cd4fc4701cd31d6a.tar.gz
org.eclipse.riena-e2091a75f4cc01ef71a14fe3cd4fc4701cd31d6a.tar.bz2
initial load
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/internal/core/config/ConfigSymbolReplaceTest.java140
1 files changed, 140 insertions, 0 deletions
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/internal/core/config/ConfigSymbolReplaceTest.java b/org.eclipse.riena.tests/src/org/eclipse/riena/internal/core/config/ConfigSymbolReplaceTest.java
new file mode 100644
index 0000000..16b6108
--- /dev/null
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/internal/core/config/ConfigSymbolReplaceTest.java
@@ -0,0 +1,140 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2008 compeople AG 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:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.internal.core.config;
+
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.eclipse.riena.tests.RienaTestCase;
+import org.osgi.service.cm.ConfigurationException;
+
+/**
+ * Test the <code>ConfigSymbolReplace</code> class.
+ */
+public class ConfigSymbolReplaceTest extends RienaTestCase {
+
+ private Dictionary<String, String> dictionary;
+ private ConfigSymbolReplace translator;
+ private Dictionary<String, String> book;
+
+ private static final String REF_KEY = "ref";
+ private static final String WWW_ECLIPSE_ORG = "www.eclipse.org";
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.riena.tests.RienaTestCase#setUp()
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ dictionary = new Hashtable<String, String>();
+ book = new Hashtable<String, String>();
+ translator = new ConfigSymbolReplace();
+ }
+
+ public void testUpdatedWrongKey() throws ConfigurationException {
+ dictionary.put("host", "${host");
+ try {
+ translator.updated(dictionary);
+ fail();
+ } catch (RuntimeException e) {
+ assertTrue(e.getMessage().contains("Incomplete"));
+ }
+ }
+
+ public void testUpdatedRecursiveKeyDirectly() throws ConfigurationException {
+ dictionary.put("host", "${host}");
+ try {
+ translator.updated(dictionary);
+ fail();
+ } catch (RuntimeException e) {
+ assertTrue(e.getMessage().contains("[host]"));
+ }
+ }
+
+ public void testUpdatedRecursiveKeyIndirectly1() throws ConfigurationException {
+ dictionary.put("a", "${b}");
+ dictionary.put("b", "${a}");
+ try {
+ translator.updated(dictionary);
+ fail();
+ } catch (RuntimeException e) {
+ assertTrue(e.getMessage().contains("loop"));
+ }
+ }
+
+ public void testUpdatedRecursiveKeyIndirectly2() throws ConfigurationException {
+ dictionary.put("a", "${b}");
+ dictionary.put("b", "${c}");
+ dictionary.put("c", "${a}");
+ try {
+ translator.updated(dictionary);
+ fail();
+ } catch (RuntimeException e) {
+ assertTrue(e.getMessage().contains("loop"));
+ }
+ }
+
+ public void testModifyWrongKey() throws ConfigurationException {
+ dictionary.put("host", WWW_ECLIPSE_ORG);
+ translator.updated(dictionary);
+
+ book.put(REF_KEY, "${host");
+ try {
+ translator.modifyConfiguration(null, book);
+ fail();
+ } catch (RuntimeException e) {
+ assertTrue(e.getMessage().contains("${host"));
+ }
+ }
+
+ public void testModifyEmptyKey() throws ConfigurationException {
+ dictionary.put("", WWW_ECLIPSE_ORG);
+ translator.updated(dictionary);
+
+ book.put(REF_KEY, "${}");
+ translator.modifyConfiguration(null, book);
+
+ assertEquals(WWW_ECLIPSE_ORG, book.get(REF_KEY));
+ }
+
+ public void testModifySingle() throws ConfigurationException {
+ dictionary.put("host", WWW_ECLIPSE_ORG);
+ translator.updated(dictionary);
+
+ book.put(REF_KEY, "${host}");
+ translator.modifyConfiguration(null, book);
+
+ assertEquals(WWW_ECLIPSE_ORG, book.get(REF_KEY));
+ }
+
+ public void testModifyDoubleSequentialy() throws ConfigurationException {
+ dictionary.put("host", WWW_ECLIPSE_ORG);
+ translator.updated(dictionary);
+
+ book.put(REF_KEY, "${host}${host}");
+ translator.modifyConfiguration(null, book);
+
+ assertEquals(WWW_ECLIPSE_ORG + WWW_ECLIPSE_ORG, book.get(REF_KEY));
+ }
+
+ public void testModifyDoubleNested() throws ConfigurationException {
+ dictionary.put("url", "http://${host}/path");
+ dictionary.put("host", WWW_ECLIPSE_ORG);
+ translator.updated(dictionary);
+
+ book.put(REF_KEY, "${url}");
+ translator.modifyConfiguration(null, book);
+
+ assertEquals("http://" + WWW_ECLIPSE_ORG + "/path", book.get(REF_KEY));
+ }
+}