You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ace.apache.org by ma...@apache.org on 2010/05/08 12:59:54 UTC
svn commit: r942358 - in /incubator/ace/trunk/ace-discovery-property: pom.xml
src/test/java/org/apache/ace/discovery/property/PropertyBasedDiscoveryTest.java
src/test/java/org/apache/ace/discovery/property/SimpleDiscoveryTest.java
Author: marrs
Date: Sat May 8 10:59:54 2010
New Revision: 942358
URL: http://svn.apache.org/viewvc?rev=942358&view=rev
Log:
Added unit tests.
Added:
incubator/ace/trunk/ace-discovery-property/src/test/java/org/apache/ace/discovery/property/SimpleDiscoveryTest.java
Modified:
incubator/ace/trunk/ace-discovery-property/pom.xml
incubator/ace/trunk/ace-discovery-property/src/test/java/org/apache/ace/discovery/property/PropertyBasedDiscoveryTest.java
Modified: incubator/ace/trunk/ace-discovery-property/pom.xml
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-discovery-property/pom.xml?rev=942358&r1=942357&r2=942358&view=diff
==============================================================================
--- incubator/ace/trunk/ace-discovery-property/pom.xml (original)
+++ incubator/ace/trunk/ace-discovery-property/pom.xml Sat May 8 10:59:54 2010
@@ -25,7 +25,7 @@
<groupId>org.apache.ace</groupId>
<artifactId>ace-pom</artifactId>
<version>0.8.0-SNAPSHOT</version>
- <relativePath>../pom/</relativePath>
+ <relativePath>../pom/</relativePath>
</parent>
<groupId>org.apache.ace</groupId>
@@ -56,6 +56,11 @@
<version>${version}</version>
</dependency>
<dependency>
+ <groupId>${groupId}</groupId>
+ <artifactId>ace-util</artifactId>
+ <version>${version}</version>
+ </dependency>
+ <dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.core</artifactId>
</dependency>
@@ -68,5 +73,4 @@
<artifactId>org.apache.felix.dependencymanager</artifactId>
</dependency>
</dependencies>
-
</project>
\ No newline at end of file
Modified: incubator/ace/trunk/ace-discovery-property/src/test/java/org/apache/ace/discovery/property/PropertyBasedDiscoveryTest.java
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-discovery-property/src/test/java/org/apache/ace/discovery/property/PropertyBasedDiscoveryTest.java?rev=942358&r1=942357&r2=942358&view=diff
==============================================================================
--- incubator/ace/trunk/ace-discovery-property/src/test/java/org/apache/ace/discovery/property/PropertyBasedDiscoveryTest.java (original)
+++ incubator/ace/trunk/ace-discovery-property/src/test/java/org/apache/ace/discovery/property/PropertyBasedDiscoveryTest.java Sat May 8 10:59:54 2010
@@ -30,31 +30,21 @@ import org.apache.ace.discovery.property
import org.junit.Test;
import org.osgi.service.cm.ConfigurationException;
-/**
- * @author Toni Menzel
- * @since Dec 6, 2009
- */
-public class PropertyBasedDiscoveryTest
-{
-
+public class PropertyBasedDiscoveryTest {
@Test
- public void discoverWithoutPropertyUpdate()
- {
+ public void discoverWithoutPropertyUpdate() {
PropertyBasedDiscovery discovery = new PropertyBasedDiscovery();
URL url = discovery.discover();
- assertThat( url, is( nullValue() ) );
+ assertThat(url, is(nullValue()));
}
@Test
- public void discoverWithPropertyUpdate()
- throws ConfigurationException, URISyntaxException
- {
+ public void discoverWithPropertyUpdate() throws ConfigurationException, URISyntaxException {
PropertyBasedDiscovery discovery = new PropertyBasedDiscovery();
Dictionary dict = new Hashtable();
- dict.put( DiscoveryConstants.DISCOVERY_URL_KEY, "file://local" );
-
- discovery.updated( dict );
+ dict.put(DiscoveryConstants.DISCOVERY_URL_KEY, "file://local");
+ discovery.updated(dict);
URL url = discovery.discover();
- assertThat( url.toURI(), is( equalTo( new URI( "file://local" ) ) ) );
+ assertThat(url.toURI(), is(equalTo(new URI("file://local"))));
}
}
Added: incubator/ace/trunk/ace-discovery-property/src/test/java/org/apache/ace/discovery/property/SimpleDiscoveryTest.java
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-discovery-property/src/test/java/org/apache/ace/discovery/property/SimpleDiscoveryTest.java?rev=942358&view=auto
==============================================================================
--- incubator/ace/trunk/ace-discovery-property/src/test/java/org/apache/ace/discovery/property/SimpleDiscoveryTest.java (added)
+++ incubator/ace/trunk/ace-discovery-property/src/test/java/org/apache/ace/discovery/property/SimpleDiscoveryTest.java Sat May 8 10:59:54 2010
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ace.discovery.property;
+
+import static org.apache.ace.test.utils.TestUtils.UNIT;
+
+import java.net.URL;
+import java.util.Dictionary;
+import java.util.Hashtable;
+
+import org.apache.ace.discovery.property.constants.DiscoveryConstants;
+import org.apache.ace.test.constants.TestConstants;
+import org.osgi.service.cm.ConfigurationException;
+import org.testng.annotations.BeforeTest;
+import org.testng.annotations.Test;
+
+public class SimpleDiscoveryTest {
+
+ private static final String SERVERURL_KEY = DiscoveryConstants.DISCOVERY_URL_KEY;
+ private static final String VALID_URL = "http://test.url.com:" + TestConstants.PORT;
+ private static final String INVALID_URL = "malformed url";
+
+ private PropertyBasedDiscovery m_discovery;
+
+ @BeforeTest(alwaysRun = true)
+ protected void setUp() throws Exception {
+ m_discovery = new PropertyBasedDiscovery();
+ }
+
+ /**
+ * Test if setting a valid configuration is handled correctly
+ * @throws Exception
+ */
+ @Test(groups = { UNIT })
+ public void simpleDiscoveryValidConfiguration() throws ConfigurationException {
+ Dictionary<String, String> properties = new Hashtable<String, String>();
+ properties.put(SERVERURL_KEY, VALID_URL);
+ m_discovery.updated(properties);
+ URL url = m_discovery.discover();
+ assert VALID_URL.equals(url.toString()) : "Configured url was not returned";
+ }
+
+ /**
+ * Test if setting an invalid configuration is handled correctly.
+ * @throws ConfigurationException
+ */
+ @Test(groups = {UNIT}, expectedExceptions = ConfigurationException.class)
+ public void simpleDiscoveryInvalidConfiguration() throws ConfigurationException {
+ Dictionary<String, String> properties = new Hashtable<String, String>();
+ properties.put(SERVERURL_KEY, INVALID_URL);
+ m_discovery.updated(properties);
+ }
+
+ /**
+ * Test if supplying an empty configuration results in the service's default being used.
+ * @throws ConfigurationException
+ */
+ @Test(groups = {UNIT})
+ public void simpleDiscoveryEmptyConfiguration() throws ConfigurationException {
+ // set valid config
+ Dictionary<String, String> properties = new Hashtable<String, String>();
+ properties.put(SERVERURL_KEY, VALID_URL);
+ m_discovery.updated(properties);
+ // set empty config
+ m_discovery.updated(null);
+ }
+}