sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asa...@apache.org
Subject svn commit: r1609056 - in /sling/trunk/testing/samples/sample-tests: pom.xml src/main/java/org/apache/sling/testing/samples/sampletests/OsgiAwareWithRuleTest.java
Date Wed, 09 Jul 2014 08:26:53 GMT
Author: asanso
Date: Wed Jul  9 08:26:52 2014
New Revision: 1609056

URL: http://svn.apache.org/r1609056
Log:
SLING-3751 - Create a JUnit rule to inject a service reference into a test

* added showcase test

Added:
    sling/trunk/testing/samples/sample-tests/src/main/java/org/apache/sling/testing/samples/sampletests/OsgiAwareWithRuleTest.java
Modified:
    sling/trunk/testing/samples/sample-tests/pom.xml

Modified: sling/trunk/testing/samples/sample-tests/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/sample-tests/pom.xml?rev=1609056&r1=1609055&r2=1609056&view=diff
==============================================================================
--- sling/trunk/testing/samples/sample-tests/pom.xml (original)
+++ sling/trunk/testing/samples/sample-tests/pom.xml Wed Jul  9 08:26:52 2014
@@ -35,7 +35,7 @@
     <description>Bundle that supplies sample server-side test classes for the Sling
JUnit extensions</description>
     
     <properties>
-        <junit.version>4.8.2</junit.version>
+        <junit.version>4.11</junit.version>
     </properties>
 
     <scm>
@@ -87,7 +87,7 @@
         <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
-            <version>4.8.2</version>
+            <version>${junit.version}</version>
             <scope>provided</scope>
         </dependency>
         <dependency>

Added: sling/trunk/testing/samples/sample-tests/src/main/java/org/apache/sling/testing/samples/sampletests/OsgiAwareWithRuleTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/testing/samples/sample-tests/src/main/java/org/apache/sling/testing/samples/sampletests/OsgiAwareWithRuleTest.java?rev=1609056&view=auto
==============================================================================
--- sling/trunk/testing/samples/sample-tests/src/main/java/org/apache/sling/testing/samples/sampletests/OsgiAwareWithRuleTest.java
(added)
+++ sling/trunk/testing/samples/sample-tests/src/main/java/org/apache/sling/testing/samples/sampletests/OsgiAwareWithRuleTest.java
Wed Jul  9 08:26:52 2014
@@ -0,0 +1,48 @@
+/*
+ * 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.samples.sampletests;
+
+import static org.junit.Assert.assertNotNull;
+
+import org.apache.sling.junit.annotations.SlingAnnotationsTestRunner;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.cm.ConfigurationAdmin;
+import org.apache.sling.junit.rules.Service;
+
+/** Test OSGi services injection */
+@RunWith(SlingAnnotationsTestRunner.class)
+public class OsgiAwareWithRuleTest {
+    
+    @Rule
+    public Service configAdminService = new Service(ConfigurationAdmin.class);
+   
+    @Test
+    public void testConfigAdmin() throws Exception {
+        ConfigurationAdmin configAdmin = configAdminService.getService(ConfigurationAdmin.class);
+        assertNotNull(
+                "Expecting ConfigurationAdmin to be injected by Sling test runner", 
+                configAdmin);
+        
+        final String name = "TEST_" + getClass().getName() + System.currentTimeMillis();
+        assertNotNull("Expecting config " + name + " to be created",
+                configAdmin.getConfiguration(name));
+    }
+}



Mime
View raw message