You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by jg...@apache.org on 2011/10/03 15:04:04 UTC
svn commit: r1178401 [3/3] - in /openejb/trunk/arquillian-tomee:
arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/
arquillian-tomee-remote/src/main/java/org/apache/openejb/arquillian/remote/
arquillian-tomee-tests/ arquillian-...
Added: openejb/trunk/arquillian-tomee/arquillian-tomee-tests/src/test/java/org/apache/openejb/arquillian/tests/TestSetup.java
URL: http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-tests/src/test/java/org/apache/openejb/arquillian/tests/TestSetup.java?rev=1178401&view=auto
==============================================================================
--- openejb/trunk/arquillian-tomee/arquillian-tomee-tests/src/test/java/org/apache/openejb/arquillian/tests/TestSetup.java (added)
+++ openejb/trunk/arquillian-tomee/arquillian-tomee-tests/src/test/java/org/apache/openejb/arquillian/tests/TestSetup.java Mon Oct 3 13:04:03 2011
@@ -0,0 +1,132 @@
+/**
+ * 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.openejb.arquillian.tests;
+
+import org.jboss.shrinkwrap.api.ArchivePaths;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
+import org.jboss.shrinkwrap.api.asset.StringAsset;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.jboss.shrinkwrap.descriptor.api.Descriptors;
+import org.jboss.shrinkwrap.descriptor.api.spec.servlet.web.WebAppDescriptor;
+import org.junit.Assert;
+
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintWriter;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.net.URL;
+
+import static junit.framework.Assert.assertNotNull;
+import static junit.framework.Assert.assertTrue;
+
+public abstract class TestSetup {
+
+ public static void assertFields(Object obj) throws IllegalAccessException {
+ final Field[] fields = obj.getClass().getDeclaredFields();
+
+ for (Field field : fields) {
+ field.setAccessible(true);
+ Assert.assertNotNull(field.getName(), field.get(obj));
+ }
+ }
+
+ public WebArchive createDeployment(Class...archiveClasses) {
+ WebAppDescriptor descriptor = Descriptors.create(WebAppDescriptor.class)
+ .version("3.0");
+ decorateDescriptor(descriptor);
+
+ WebArchive archive = ShrinkWrap.create(WebArchive.class, getTestContextName() + ".war")
+ .setWebXML(new StringAsset(descriptor.exportAsString()))
+ .addAsWebInfResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml"));
+ if (archiveClasses != null) {
+ for (Class c: archiveClasses) {
+ archive.addClass(c);
+ }
+ }
+ decorateArchive(archive);
+
+ return archive;
+ }
+
+ protected String getTestContextName() {
+ return this.getClass().getSimpleName();
+ }
+
+ protected void decorateDescriptor(WebAppDescriptor descriptor) {
+
+ }
+
+ protected void decorateArchive(WebArchive archive) {
+
+ }
+
+ protected void validateTest(String expectedOutput) throws IOException {
+ validateTest(getTestContextName(), expectedOutput);
+ }
+
+ protected void validateTest(String servlet, String expectedOutput) throws IOException {
+ final InputStream is = new URL("http://localhost:9080/" + getTestContextName() + "/" + servlet).openStream();
+ final ByteArrayOutputStream os = new ByteArrayOutputStream();
+
+ int bytesRead = -1;
+ byte[] buffer = new byte[8192];
+ while ((bytesRead = is.read(buffer)) > -1) {
+ os.write(buffer, 0, bytesRead);
+ }
+
+ is.close();
+ os.close();
+
+ String output = new String(os.toByteArray(), "UTF-8");
+ assertNotNull("Response shouldn't be null", output);
+ assertTrue("Output should contain: " + expectedOutput + "\n" + output, output.contains(expectedOutput));
+ }
+
+ public static void run(ServletRequest req, ServletResponse resp, Object obj) throws IOException {
+ final Class<?> clazz = obj.getClass();
+ final Method[] methods = clazz.getMethods();
+
+ resp.setContentType("text/plain");
+ final PrintWriter writer = resp.getWriter();
+
+ for (Method method : methods) {
+ if (method.getName().startsWith("test")) {
+
+ writer.print(method.getName());
+
+ writer.print("=");
+
+ try {
+ method.invoke(obj);
+ writer.println("true");
+ } catch (Throwable e) {
+ writer.println("false");
+ writer.println("");
+ writer.println("STACKTRACE");
+ writer.println("");
+ e.printStackTrace(writer);
+ }
+ }
+ }
+ }
+
+}
Added: openejb/trunk/arquillian-tomee/arquillian-tomee-tests/src/test/resources/arquillian.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-tests/src/test/resources/arquillian.xml?rev=1178401&view=auto
==============================================================================
--- openejb/trunk/arquillian-tomee/arquillian-tomee-tests/src/test/resources/arquillian.xml (added)
+++ openejb/trunk/arquillian-tomee/arquillian-tomee-tests/src/test/resources/arquillian.xml Mon Oct 3 13:04:03 2011
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--
+
+ 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.
+-->
+<arquillian
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
+
+ <container qualifier="tomee" default="true">
+ <configuration>
+ <property name="dir">/tmp/arquillian-apache-tomee</property>
+ <property name="httpPort">9080</property>
+ <property name="stopPort">9005</property>
+ <property name="tomcatVersion"></property>
+ <property name="openejbVersion">1.0.0-beta-1</property>
+ </configuration>
+ </container>
+</arquillian>
\ No newline at end of file
Added: openejb/trunk/arquillian-tomee/arquillian-tomee-tests/src/test/resources/persistence.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/arquillian-tomee/arquillian-tomee-tests/src/test/resources/persistence.xml?rev=1178401&view=auto
==============================================================================
--- openejb/trunk/arquillian-tomee/arquillian-tomee-tests/src/test/resources/persistence.xml (added)
+++ openejb/trunk/arquillian-tomee/arquillian-tomee-tests/src/test/resources/persistence.xml Mon Oct 3 13:04:03 2011
@@ -0,0 +1,15 @@
+<persistence xmlns="http://java.sun.com/xml/ns/persistence"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
+ version="2.0">
+ <persistence-unit name="test">
+ <class>org.apache.openejb.arquillian.ServletPersistenceInjectionTest$Address</class>
+ <class>org.apache.openejb.arquillian.ServletFilterPersistenceInjectionTest$Address</class>
+<!--
+ <properties>
+ <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/>
+ </properties>
+-->
+ <class>org.apache.openejb.arquillian.ServletListenerPersistenceInjectionTest$Address</class>
+ </persistence-unit>
+</persistence>
\ No newline at end of file