Author: bdelacretaz
Date: Thu Sep 17 14:47:58 2015
New Revision: 1703637
URL: http://svn.apache.org/r1703637
Log:
Test access to OSGi services
Added:
sling/whiteboard/bdelacretaz/test-rules/src/test/java/org/apache/sling/testing/rules/OsgiServicesTest.java
Modified:
sling/whiteboard/bdelacretaz/test-rules/pom.xml
sling/whiteboard/bdelacretaz/test-rules/src/main/java/org/apache/sling/testing/rules/ServerSideTestRule.java
sling/whiteboard/bdelacretaz/test-rules/src/test/java/org/apache/sling/testing/rules/DummyTest.java
Modified: sling/whiteboard/bdelacretaz/test-rules/pom.xml
URL:
http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/test-rules/pom.xml?rev=1703637&r1=1703636&r2=1703637&view=diff
==============================================================================
--- sling/whiteboard/bdelacretaz/test-rules/pom.xml (original)
+++ sling/whiteboard/bdelacretaz/test-rules/pom.xml Thu Sep 17 14:47:58 2015
@@ -44,6 +44,25 @@
<version>2.0.0</version>
</dependency>
<dependency>
+ <!-- TODO remove this once we remove our dummy/sample tests -->
+ <groupId>org.apache.sling</groupId>
+ <artifactId>org.apache.sling.junit.core</artifactId>
+ <version>1.0.11-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <!-- TODO remove this once we remove our dummy/sample tests -->
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.core</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <!-- TODO remove this once we remove our dummy/sample tests -->
+ <groupId>org.osgi</groupId>
+ <artifactId>org.osgi.compendium</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
Modified:
sling/whiteboard/bdelacretaz/test-rules/src/main/java/org/apache/sling/testing/rules/ServerSideTestRule.java
URL:
http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/test-rules/src/main/java/org/apache/sling/testing/rules/ServerSideTestRule.java?rev=1703637&r1=1703636&r2=1703637&view=diff
==============================================================================
---
sling/whiteboard/bdelacretaz/test-rules/src/main/java/org/apache/sling/testing/rules/ServerSideTestRule.java
(original)
+++
sling/whiteboard/bdelacretaz/test-rules/src/main/java/org/apache/sling/testing/rules/ServerSideTestRule.java
Thu Sep 17 14:47:58 2015
@@ -45,6 +45,9 @@ public class ServerSideTestRule extends
/** Build a server-side test rule that can use a specific test server */
ServerSideTestRule(Class<?> underTest, String serverSelector) {
+ if(serverSelector!=null) {
+ throw new IllegalArgumentException("Server selectors are not
implemented yet");
+ }
this.classUnderTest = underTest;
// Unique and somewhat identifiable name for our test bundle
Modified:
sling/whiteboard/bdelacretaz/test-rules/src/test/java/org/apache/sling/testing/rules/DummyTest.java
URL:
http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/test-rules/src/test/java/org/apache/sling/testing/rules/DummyTest.java?rev=1703637&r1=1703636&r2=1703637&view=diff
==============================================================================
---
sling/whiteboard/bdelacretaz/test-rules/src/test/java/org/apache/sling/testing/rules/DummyTest.java
(original)
+++
sling/whiteboard/bdelacretaz/test-rules/src/test/java/org/apache/sling/testing/rules/DummyTest.java
Thu Sep 17 14:47:58 2015
@@ -19,6 +19,8 @@ package org.apache.sling.testing.rules;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import java.util.Random;
+
import org.junit.Rule;
import org.junit.Test;
@@ -28,8 +30,9 @@ public class DummyTest {
public final ServerSideTestRule t = new ServerSideTestRule(getClass());
@Test
- public void semiRandomFailure() {
- assertTrue("Semi-randomly failing, by design", Math.random() < 0.5);
+ public void failsOften() {
+ final Random r = new Random(System.currentTimeMillis());
+ assertTrue("Semi-randomly failing, by design", r.nextBoolean());
}
@Test
Added:
sling/whiteboard/bdelacretaz/test-rules/src/test/java/org/apache/sling/testing/rules/OsgiServicesTest.java
URL:
http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/test-rules/src/test/java/org/apache/sling/testing/rules/OsgiServicesTest.java?rev=1703637&view=auto
==============================================================================
---
sling/whiteboard/bdelacretaz/test-rules/src/test/java/org/apache/sling/testing/rules/OsgiServicesTest.java
(added)
+++
sling/whiteboard/bdelacretaz/test-rules/src/test/java/org/apache/sling/testing/rules/OsgiServicesTest.java
Thu Sep 17 14:47:58 2015
@@ -0,0 +1,54 @@
+/*
+ * 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.sling.testing.rules;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.sling.junit.rules.OSGiService;
+import org.junit.Rule;
+import org.junit.Test;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.cm.ConfigurationAdmin;
+
+public class OsgiServicesTest {
+
+ @Rule
+ public final ServerSideTestRule t = new ServerSideTestRule(getClass());
+
+ @Rule
+ public OSGiService<ConfigurationAdmin> configAdminService =
OSGiService.ofClass(ConfigurationAdmin.class);
+
+ @Rule
+ public OSGiService<BundleContext> bundleContextService =
OSGiService.ofClass(BundleContext.class);
+
+ @Test
+ public void testConfigAdmin() throws Exception {
+ assertNotNull(
+ "Expecting ConfigurationAdmin to be injected by Sling test
runner",
+ configAdminService.get());
+
+ final String pid = "TEST_" + getClass().getName() +
System.currentTimeMillis();
+ assertNotNull("Expecting config " + pid + " to be created",
+ configAdminService.get().getConfiguration(pid));
+ }
+
+ @Test
+ public void testBundleContext() throws Exception {
+ assertTrue(bundleContextService.get().getBundles().length > 1);
+ }
+}