Author: bdelacretaz
Date: Fri Sep 18 08:27:32 2015
New Revision: 1703764
URL: http://svn.apache.org/viewvc?rev=1703764&view=rev
Log:
SLING-5040 - test additional embedded dependencies
Added:
sling/whiteboard/bdelacretaz/test-rules/src/test/java/org/apache/sling/testing/rules/EmbeddedDependenciesTest.java
sling/whiteboard/bdelacretaz/test-rules/src/test/java/org/apache/sling/testing/rules/SomePojo.java
sling/whiteboard/bdelacretaz/test-rules/src/test/java/org/apache/sling/testing/rules/SomeString.java
sling/whiteboard/bdelacretaz/test-rules/src/test/java/org/apache/sling/testing/rules/SomeUtility.java
Modified:
sling/whiteboard/bdelacretaz/test-rules/src/main/java/org/apache/sling/testing/rules/ClientSideSupport.java
sling/whiteboard/bdelacretaz/test-rules/src/main/java/org/apache/sling/testing/rules/DefaultClientSideSupport.java
sling/whiteboard/bdelacretaz/test-rules/src/main/java/org/apache/sling/testing/rules/ServerSideTestRule.java
Modified:
sling/whiteboard/bdelacretaz/test-rules/src/main/java/org/apache/sling/testing/rules/ClientSideSupport.java
URL:
http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/test-rules/src/main/java/org/apache/sling/testing/rules/ClientSideSupport.java?rev=1703764&r1=1703763&r2=1703764&view=diff
==============================================================================
---
sling/whiteboard/bdelacretaz/test-rules/src/main/java/org/apache/sling/testing/rules/ClientSideSupport.java
(original)
+++
sling/whiteboard/bdelacretaz/test-rules/src/main/java/org/apache/sling/testing/rules/ClientSideSupport.java
Fri Sep 18 08:27:32 2015
@@ -19,11 +19,12 @@ package org.apache.sling.testing.rules;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
+import java.util.Collection;
import org.junit.runners.model.MultipleFailureException;
interface ClientSideSupport {
- InputStream buildTestBundle(Class<?> c, String bundleSymbolicName);
+ InputStream buildTestBundle(Class<?> c, Collection<Class<?>>
embeddedClasses, String bundleSymbolicName);
void installBundle(InputStream bundle, String bundleSymbolicName) throws
MalformedURLException, IOException;
void uninstallBundle(String bundleSymbolicName) throws
MalformedURLException, IOException;
void runTests(String testSelectionPath, int testReadyTimeoutSeconds)
throws MalformedURLException, IOException, MultipleFailureException;
Modified:
sling/whiteboard/bdelacretaz/test-rules/src/main/java/org/apache/sling/testing/rules/DefaultClientSideSupport.java
URL:
http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/test-rules/src/main/java/org/apache/sling/testing/rules/DefaultClientSideSupport.java?rev=1703764&r1=1703763&r2=1703764&view=diff
==============================================================================
---
sling/whiteboard/bdelacretaz/test-rules/src/main/java/org/apache/sling/testing/rules/DefaultClientSideSupport.java
(original)
+++
sling/whiteboard/bdelacretaz/test-rules/src/main/java/org/apache/sling/testing/rules/DefaultClientSideSupport.java
Fri Sep 18 08:27:32 2015
@@ -17,6 +17,7 @@
package org.apache.sling.testing.rules;
import static org.junit.Assert.fail;
+
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
@@ -25,6 +26,7 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
import javax.xml.bind.DatatypeConverter;
@@ -32,6 +34,7 @@ import javax.xml.bind.DatatypeConverter;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
import org.junit.runners.model.MultipleFailureException;
+import org.ops4j.pax.tinybundles.core.TinyBundle;
import org.ops4j.pax.tinybundles.core.TinyBundles;
import org.osgi.framework.Constants;
@@ -46,14 +49,15 @@ class DefaultClientSideSupport implement
/** Build a test bundle that contains c as a Sling server-side test.
* Need to include the ServerSideTest class as c refers to it.
*/
- public InputStream buildTestBundle(Class<?> c, String bundleSymbolicName) {
- // TODO find the required classes via reflection?
- return TinyBundles.bundle()
- .set(Constants.BUNDLE_SYMBOLICNAME, bundleSymbolicName)
- .set("Sling-Test-Regexp", c.getName() + ".*")
- .add(c)
- .add(ServerSideTestRule.class)
- .build(TinyBundles.withBnd());
+ public InputStream buildTestBundle(Class<?> c, Collection<Class<?>>
embeddedClasses, String bundleSymbolicName) {
+ final TinyBundle b = TinyBundles.bundle()
+ .set(Constants.BUNDLE_SYMBOLICNAME, bundleSymbolicName)
+ .set("Sling-Test-Regexp", c.getName() + ".*")
+ .add(c);
+ for(Class<?> clz : embeddedClasses) {
+ b.add(clz);
+ }
+ return b.build(TinyBundles.withBnd());
}
public void setCredentials(URLConnection c) {
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=1703764&r1=1703763&r2=1703764&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
Fri Sep 18 08:27:32 2015
@@ -18,7 +18,9 @@ package org.apache.sling.testing.rules;
import java.io.InputStream;
import java.text.SimpleDateFormat;
+import java.util.ArrayList;
import java.util.Date;
+import java.util.List;
import java.util.UUID;
import org.junit.rules.ExternalResource;
@@ -34,6 +36,7 @@ public class ServerSideTestRule extends
private final Class<?> classUnderTest;
private final String bundleSymbolicName;
private final ClientSideSupport css;
+ private final List<Class<?>> embeddedClasses = new ArrayList<Class<?>>();
// TODO configurable
private final int testReadyTimeoutSeconds = 5;
@@ -61,6 +64,14 @@ public class ServerSideTestRule extends
} catch(Exception ignoreWeAreProbablyOnTheServerSide) {
}
css = s;
+
+ embeddedClasses.add(getClass());
+ }
+
+ /** Specify additional classes to embed in the test bundle */
+ public ServerSideTestRule embed(Class<?> c) {
+ embeddedClasses.add(c);
+ return this;
}
@Override
@@ -73,7 +84,7 @@ public class ServerSideTestRule extends
@Override
public void evaluate() throws Throwable {
if(css != null) {
- final InputStream bundle =
css.buildTestBundle(classUnderTest, bundleSymbolicName);
+ final InputStream bundle =
css.buildTestBundle(classUnderTest, embeddedClasses, bundleSymbolicName);
// TODO check that test is absent before installing
bundle??
// Or verify the "version" of the test??
css.installBundle(bundle, bundleSymbolicName);
Added:
sling/whiteboard/bdelacretaz/test-rules/src/test/java/org/apache/sling/testing/rules/EmbeddedDependenciesTest.java
URL:
http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/test-rules/src/test/java/org/apache/sling/testing/rules/EmbeddedDependenciesTest.java?rev=1703764&view=auto
==============================================================================
---
sling/whiteboard/bdelacretaz/test-rules/src/test/java/org/apache/sling/testing/rules/EmbeddedDependenciesTest.java
(added)
+++
sling/whiteboard/bdelacretaz/test-rules/src/test/java/org/apache/sling/testing/rules/EmbeddedDependenciesTest.java
Fri Sep 18 08:27:32 2015
@@ -0,0 +1,47 @@
+/*
+ * 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.assertEquals;
+
+import org.junit.Rule;
+import org.junit.Test;
+
+/** Test that requires some additional classes that are not found
+ * on the server-side. Used to validate the mechanism that embeds
+ * required classes in the teleporter bundle.
+ */
+public class EmbeddedDependenciesTest {
+
+ @Rule
+ public final ServerSideTestRule t = new ServerSideTestRule(getClass())
+ // TODO simple dependencies should be detected automatically
+ .embed(SomeUtility.class)
+ .embed(SomePojo.class)
+ .embed(SomeString.class)
+ ;
+
+ @Test
+ public void testSum() {
+ assertEquals(84, new SomeUtility().getSum());
+ }
+
+ @Test
+ public void testOk() {
+ assertEquals("okok", new SomeUtility().getOk());
+ }
+}
Added:
sling/whiteboard/bdelacretaz/test-rules/src/test/java/org/apache/sling/testing/rules/SomePojo.java
URL:
http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/test-rules/src/test/java/org/apache/sling/testing/rules/SomePojo.java?rev=1703764&view=auto
==============================================================================
---
sling/whiteboard/bdelacretaz/test-rules/src/test/java/org/apache/sling/testing/rules/SomePojo.java
(added)
+++
sling/whiteboard/bdelacretaz/test-rules/src/test/java/org/apache/sling/testing/rules/SomePojo.java
Fri Sep 18 08:27:32 2015
@@ -0,0 +1,24 @@
+/*
+ * 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;
+
+/** POJO used indirectly by RequiredDependenciesTest */
+public class SomePojo {
+ int getValue() {
+ return 42;
+ }
+}
Added:
sling/whiteboard/bdelacretaz/test-rules/src/test/java/org/apache/sling/testing/rules/SomeString.java
URL:
http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/test-rules/src/test/java/org/apache/sling/testing/rules/SomeString.java?rev=1703764&view=auto
==============================================================================
---
sling/whiteboard/bdelacretaz/test-rules/src/test/java/org/apache/sling/testing/rules/SomeString.java
(added)
+++
sling/whiteboard/bdelacretaz/test-rules/src/test/java/org/apache/sling/testing/rules/SomeString.java
Fri Sep 18 08:27:32 2015
@@ -0,0 +1,25 @@
+/*
+ * 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;
+
+/** POJO used indirectly by RequiredDependenciesTest */
+public class SomeString {
+ @Override
+ public String toString() {
+ return "ok";
+ }
+}
Added:
sling/whiteboard/bdelacretaz/test-rules/src/test/java/org/apache/sling/testing/rules/SomeUtility.java
URL:
http://svn.apache.org/viewvc/sling/whiteboard/bdelacretaz/test-rules/src/test/java/org/apache/sling/testing/rules/SomeUtility.java?rev=1703764&view=auto
==============================================================================
---
sling/whiteboard/bdelacretaz/test-rules/src/test/java/org/apache/sling/testing/rules/SomeUtility.java
(added)
+++
sling/whiteboard/bdelacretaz/test-rules/src/test/java/org/apache/sling/testing/rules/SomeUtility.java
Fri Sep 18 08:27:32 2015
@@ -0,0 +1,45 @@
+/*
+ * 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 java.util.ArrayList;
+import java.util.List;
+
+/** Utility class used directly by RequiredDependenciesTest */
+public class SomeUtility {
+ int getSum() {
+ final List<SomePojo> list = new ArrayList<SomePojo>();
+ list.add(new SomePojo());
+ list.add(new SomePojo());
+ int sum = 0;
+ for(SomePojo p : list) {
+ sum += p.getValue();
+ }
+ return sum;
+ }
+
+ public String getOk() {
+ final List<SomeString> list = new ArrayList<SomeString>();
+ list.add(new SomeString());
+ list.add(new SomeString());
+ String result = "";
+ for(SomeString p : list) {
+ result += p;
+ }
+ return result;
+ }
+}