You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2020/11/26 14:24:08 UTC
[sling-org-apache-sling-junit-core] branch
SLING-9915-junit-annotation-int-tests updated: WIP continued - fix
integration tests setup
This is an automated email from the ASF dual-hosted git repository.
bdelacretaz pushed a commit to branch SLING-9915-junit-annotation-int-tests
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-junit-core.git
The following commit(s) were added to refs/heads/SLING-9915-junit-annotation-int-tests by this push:
new 4aa41bc WIP continued - fix integration tests setup
4aa41bc is described below
commit 4aa41bcb60c64eb0de795e54774e8f45c7e4f1aa
Author: Bertrand Delacretaz <bd...@apache.org>
AuthorDate: Thu Nov 26 15:23:23 2020 +0100
WIP continued - fix integration tests setup
---
.gitignore | 2 +-
src/it/annotations-it/bnd.bnd | 8 +--
.../apache/sling/junit/it/TestReferenceJITest.java | 23 +++++++--
.../sling/junit/annotations/ReferenceIT.java | 10 +++-
.../org/apache/sling/junit/tests/MyService.java | 25 ----------
.../sling/junit/tests/TestReferenceJTest.java | 57 ----------------------
.../junit/tests/impl/MyCoolServiceForTesting.java | 42 ----------------
.../junit/tests/impl/MyLameServiceForTesting.java | 41 ----------------
8 files changed, 29 insertions(+), 179 deletions(-)
diff --git a/.gitignore b/.gitignore
index 24e5066..947429b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,4 @@
-/target
+target
.idea
.classpath
.metadata
diff --git a/src/it/annotations-it/bnd.bnd b/src/it/annotations-it/bnd.bnd
index 6ba7cba..e9c2749 100644
--- a/src/it/annotations-it/bnd.bnd
+++ b/src/it/annotations-it/bnd.bnd
@@ -1,7 +1 @@
-# Nothing needed here so far for this bundle
-Sling-Test-Regexp: .*JITest
-Import-Package:org.junit.platform.*;resolution:=optional, \
- *
--includeresource:org.apache.sling.junit.core-1.1.1-SNAPSHOT.jar;lib:=true
-Provide-Capability:\
- osgi.contract;osgi.contract=JavaJSONP;uses:="javax.json,javax.json.spi,javax.json.stream";version:List<Version>="1.1,1.0"
\ No newline at end of file
+Sling-Test-Regexp: .*JITest
\ No newline at end of file
diff --git a/src/it/annotations-it/src/main/java/org/apache/sling/junit/it/TestReferenceJITest.java b/src/it/annotations-it/src/main/java/org/apache/sling/junit/it/TestReferenceJITest.java
index f9e916d..694a8ba 100644
--- a/src/it/annotations-it/src/main/java/org/apache/sling/junit/it/TestReferenceJITest.java
+++ b/src/it/annotations-it/src/main/java/org/apache/sling/junit/it/TestReferenceJITest.java
@@ -21,6 +21,7 @@ import org.apache.sling.junit.annotations.SlingAnnotationsTestRunner;
import org.apache.sling.junit.annotations.TestReference;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.osgi.service.cm.ConfigurationAdmin;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertNotNull;
@@ -41,14 +42,28 @@ public class TestReferenceJITest {
@TestReference
MyServiceIT myService;
+ @TestReference
+ ConfigurationAdmin configAdmin;
+
+ @Test
+ public void testOsgiReferences() {
+ assertNotNull(configAdmin);
+ }
+
+ @Test
+ public void testNoTargetReferences() {
+ assertNotNull(myService);
+ }
@Test
- public void exampleTestReference(){
-// assertTrue(true);
+ public void testNotFoundReference() {
+ assertNull(myNullService);
+ }
+
+ @Test
+ public void testTargetReferences(){
assertNotNull(myCoolService);
assertNotNull(myLameService);
- assertNull(myNullService);
- assertNotNull(myService);
assertEquals("Cool Service", myCoolService.getName());
assertEquals("Lame Service", myLameService.getName());
assertTrue(myService.getName().equals(myCoolService.getName()) ||
diff --git a/src/it/annotations-it/src/test/java/org/apache/sling/junit/annotations/ReferenceIT.java b/src/it/annotations-it/src/test/java/org/apache/sling/junit/annotations/ReferenceIT.java
index c0be505..f9816b3 100644
--- a/src/it/annotations-it/src/test/java/org/apache/sling/junit/annotations/ReferenceIT.java
+++ b/src/it/annotations-it/src/test/java/org/apache/sling/junit/annotations/ReferenceIT.java
@@ -35,13 +35,14 @@ import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.PaxExamServer;
import org.ops4j.pax.exam.options.extra.VMOption;
-
+import org.apache.sling.testing.paxexam.SlingOptions;
import static org.apache.sling.testing.paxexam.SlingOptions.logback;
import static org.apache.sling.testing.paxexam.SlingOptions.slingQuickstartOakTar;
import static org.ops4j.pax.exam.CoreOptions.composite;
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
import static org.ops4j.pax.exam.CoreOptions.systemProperty;
import static org.ops4j.pax.exam.CoreOptions.when;
+import static org.ops4j.pax.exam.CoreOptions.junitBundles;
import org.apache.sling.testing.paxexam.TestSupport;
@@ -79,6 +80,9 @@ public class ReferenceIT extends TestSupport {
final String workingDirectory = workingDirectory();
+ // Need recent commons.johnzon for the osgi.contract=JavaJSONP capability
+ SlingOptions.versionResolver.setVersion("org.apache.sling", "org.apache.sling.commons.johnzon", "1.2.6");
+
return composite(
// TODO not sure why the below list of bundles is different from
// running tests with PaxExam.class (SLING-9929)
@@ -91,7 +95,9 @@ public class ReferenceIT extends TestSupport {
systemProperty("org.osgi.service.http.port").value(String.valueOf(httpPort)),
slingQuickstartOakTar(workingDirectory, httpPort),
+
testBundle("bundle.filename"),
+ mavenBundle().groupId("org.apache.sling").artifactId("org.apache.sling.junit.core").versionAsInProject(),
logback(),
mavenBundle().groupId("org.apache.felix").artifactId("org.apache.felix.log").version("1.2.4"),
@@ -136,6 +142,6 @@ public class ReferenceIT extends TestSupport {
response.checkContentContains("TEST RUN FINISHED");
response.checkContentContains("failures:0");
response.checkContentContains("ignored:0");
- response.checkContentContains("tests:1");
+ response.checkContentContains("tests:4");
}
}
diff --git a/src/main/java/org/apache/sling/junit/tests/MyService.java b/src/main/java/org/apache/sling/junit/tests/MyService.java
deleted file mode 100644
index fcbba0a..0000000
--- a/src/main/java/org/apache/sling/junit/tests/MyService.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * 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.junit.tests;
-
-public interface MyService {
- /** @return Name of the Service which is used to discover the Service by the User **/
- String getName();
-
- /** @return Description of the Service **/
- String getDescription();
-}
diff --git a/src/main/java/org/apache/sling/junit/tests/TestReferenceJTest.java b/src/main/java/org/apache/sling/junit/tests/TestReferenceJTest.java
deleted file mode 100644
index 216d8b2..0000000
--- a/src/main/java/org/apache/sling/junit/tests/TestReferenceJTest.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * 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.junit.tests;
-
-import org.apache.sling.junit.annotations.SlingAnnotationsTestRunner;
-import org.apache.sling.junit.annotations.TestReference;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import static junit.framework.TestCase.assertEquals;
-import static junit.framework.TestCase.assertNotNull;
-import static junit.framework.TestCase.assertNull;
-import static junit.framework.TestCase.assertTrue;
-
-
-@RunWith(SlingAnnotationsTestRunner.class)
-public class TestReferenceJTest {
-
- @TestReference(target ="(component.name=org.apache.sling.junit.tests.impl.MyCoolServiceForTesting)")
- MyService myCoolService;
-
- @TestReference(target ="(component.name=org.apache.sling.junit.tests.impl.MyLameServiceForTesting)")
- MyService myLameService;
-
- @TestReference(target ="(component.name=org.apache.sling.junit.tests.impl.MyNonExistingServiceForTesting)")
- MyService myNullService;
-
- @TestReference
- MyService myService;
-
-
- @Test
- public void exampleTestReference(){
- assertNotNull(myCoolService);
- assertNotNull(myLameService);
- assertNull(myNullService);
- assertNotNull(myService);
- assertEquals("Cool Service", myCoolService.getName());
- assertEquals("Lame Service", myLameService.getName());
- assertTrue(myService.getName().equals(myCoolService.getName()) ||
- myService.getName().equals(myLameService.getName()));
- }
-}
diff --git a/src/main/java/org/apache/sling/junit/tests/impl/MyCoolServiceForTesting.java b/src/main/java/org/apache/sling/junit/tests/impl/MyCoolServiceForTesting.java
deleted file mode 100644
index 471ee64..0000000
--- a/src/main/java/org/apache/sling/junit/tests/impl/MyCoolServiceForTesting.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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.junit.tests.impl;
-
-import org.apache.sling.junit.tests.MyService;
-import org.osgi.service.component.annotations.Component;
-
-@Component(
- service = MyService.class
-)
-public class MyCoolServiceForTesting implements MyService {
-
- /**
- * @return Name of the Service which is used to discover the Service by the User
- **/
- @Override
- public String getName() {
- return "Cool Service";
- }
-
- /**
- * @return Description of the Service
- **/
- @Override
- public String getDescription() {
- return "My Cool Service is for testing @TestReference for in running JUnit tests within Sling";
- }
-}
diff --git a/src/main/java/org/apache/sling/junit/tests/impl/MyLameServiceForTesting.java b/src/main/java/org/apache/sling/junit/tests/impl/MyLameServiceForTesting.java
deleted file mode 100644
index 7a473c8..0000000
--- a/src/main/java/org/apache/sling/junit/tests/impl/MyLameServiceForTesting.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * 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.junit.tests.impl;
-
-import org.apache.sling.junit.tests.MyService;
-import org.osgi.service.component.annotations.Component;
-
-@Component(
- service = MyService.class
-)
-public class MyLameServiceForTesting implements MyService{
- /**
- * @return Name of the Service which is used to discover the Service by the User
- **/
- @Override
- public String getName() {
- return "Lame Service";
- }
-
- /**
- * @return Description of the Service
- **/
- @Override
- public String getDescription() {
- return "My Lame Service is for testing @TestReference for in running JUnit tests within Sling";
- }
-}