[jboss-svn-commits] JBoss Common SVN: r4359 - in arquillian/trunk/containers/glassfish-embedded-30: src/main/java/org/jboss/arquillian/glassfish and 5 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri May 7 13:38:03 EDT 2010
Author: aslak
Date: 2010-05-07 13:38:03 -0400 (Fri, 07 May 2010)
New Revision: 4359
Added:
arquillian/trunk/containers/glassfish-embedded-30/src/test/java/org/
arquillian/trunk/containers/glassfish-embedded-30/src/test/java/org/jboss/
arquillian/trunk/containers/glassfish-embedded-30/src/test/java/org/jboss/arquillian/
arquillian/trunk/containers/glassfish-embedded-30/src/test/java/org/jboss/arquillian/glassfish/
arquillian/trunk/containers/glassfish-embedded-30/src/test/java/org/jboss/arquillian/glassfish/GlassFishEmbeddedContainerTestCase.java
arquillian/trunk/containers/glassfish-embedded-30/src/test/java/org/jboss/arquillian/glassfish/TestServlet.java
Modified:
arquillian/trunk/containers/glassfish-embedded-30/pom.xml
arquillian/trunk/containers/glassfish-embedded-30/src/main/java/org/jboss/arquillian/glassfish/GlassFishConfiguration.java
arquillian/trunk/containers/glassfish-embedded-30/src/main/java/org/jboss/arquillian/glassfish/GlassFishEmbeddedContainer.java
Log:
ARQ-95 Added InstanceRoot/AutoDelete configuration option, A Simple TestCase, and fixed Deployment name.
Modified: arquillian/trunk/containers/glassfish-embedded-30/pom.xml
===================================================================
--- arquillian/trunk/containers/glassfish-embedded-30/pom.xml 2010-05-07 16:52:22 UTC (rev 4358)
+++ arquillian/trunk/containers/glassfish-embedded-30/pom.xml 2010-05-07 17:38:03 UTC (rev 4359)
@@ -87,6 +87,23 @@
<version>${version.glassfish}</version>
</dependency>
+ <!--
+ Test
+ -->
+
+ <dependency>
+ <groupId>org.jboss.arquillian</groupId>
+ <artifactId>arquillian-impl-base</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+
</dependencies>
</project>
Modified: arquillian/trunk/containers/glassfish-embedded-30/src/main/java/org/jboss/arquillian/glassfish/GlassFishConfiguration.java
===================================================================
--- arquillian/trunk/containers/glassfish-embedded-30/src/main/java/org/jboss/arquillian/glassfish/GlassFishConfiguration.java 2010-05-07 16:52:22 UTC (rev 4358)
+++ arquillian/trunk/containers/glassfish-embedded-30/src/main/java/org/jboss/arquillian/glassfish/GlassFishConfiguration.java 2010-05-07 17:38:03 UTC (rev 4359)
@@ -16,6 +16,8 @@
*/
package org.jboss.arquillian.glassfish;
+import java.util.UUID;
+
import org.jboss.arquillian.spi.ContainerConfiguration;
import org.jboss.arquillian.spi.ContainerProfile;
@@ -29,7 +31,9 @@
public class GlassFishConfiguration implements ContainerConfiguration
{
private int bindPort = 8080;
-
+ private String instanceRoot = "target/glassfish_" + UUID.randomUUID().toString();
+ private boolean autoDelete = true;
+
public ContainerProfile getContainerProfile()
{
return ContainerProfile.CLIENT;
@@ -44,5 +48,24 @@
{
this.bindPort = bindPort;
}
+
+ public String getInstanceRoot()
+ {
+ return instanceRoot;
+ }
+ public void setInstanceRoot(String instanceRoot)
+ {
+ this.instanceRoot = instanceRoot;
+ }
+
+ public boolean getAutoDelete()
+ {
+ return autoDelete;
+ }
+
+ public void setAutoDelete(boolean autoDelete)
+ {
+ this.autoDelete = autoDelete;
+ }
}
Modified: arquillian/trunk/containers/glassfish-embedded-30/src/main/java/org/jboss/arquillian/glassfish/GlassFishEmbeddedContainer.java
===================================================================
--- arquillian/trunk/containers/glassfish-embedded-30/src/main/java/org/jboss/arquillian/glassfish/GlassFishEmbeddedContainer.java 2010-05-07 16:52:22 UTC (rev 4358)
+++ arquillian/trunk/containers/glassfish-embedded-30/src/main/java/org/jboss/arquillian/glassfish/GlassFishEmbeddedContainer.java 2010-05-07 17:38:03 UTC (rev 4359)
@@ -16,6 +16,7 @@
*/
package org.jboss.arquillian.glassfish;
+import java.io.File;
import java.net.URL;
import org.glassfish.api.deployment.DeployCommandParameters;
@@ -58,12 +59,16 @@
final Server.Builder builder = new Server.Builder(GlassFishEmbeddedContainer.class.getName());
final EmbeddedFileSystem.Builder embeddedFsBuilder = new EmbeddedFileSystem.Builder();
- final EmbeddedFileSystem embeddedFs = embeddedFsBuilder.build();
+ final EmbeddedFileSystem embeddedFs = embeddedFsBuilder
+ .instanceRoot(
+ new File(
+ this.configuration.getInstanceRoot()))
+ .autoDelete(this.configuration.getAutoDelete())
+ .build();
builder.embeddedFileSystem(embeddedFs);
server = builder.build();
-
- //final ContainerBuilder<EmbeddedContainer> containerBuilder = server.createConfig(ContainerBuilder.Type.all);
+
server.addContainer(ContainerBuilder.Type.all);
}
@@ -101,8 +106,8 @@
DeployCommandParameters params = new DeployCommandParameters();
params.enabled = true;
params.target = target;
- params.name = archive.getName();
-
+ params.name = createDeploymentName(archive.getName());
+
server.getDeployer().deploy(
archive.as(ShrinkwrapReadableArchive.class),
params);
@@ -133,15 +138,19 @@
{
UndeployCommandParameters params = new UndeployCommandParameters();
params.target = target;
- params.name = archive.getName();
-
+ params.name = createDeploymentName(archive.getName());
try
{
- server.getDeployer().undeploy(archive.getName(), params);
+ server.getDeployer().undeploy(params.name, params);
}
catch (Exception e)
{
throw new DeploymentException("Could not undeploy " + archive.getName(), e);
}
}
+
+ private String createDeploymentName(String archiveName)
+ {
+ return archiveName.substring(0, archiveName.lastIndexOf("."));
+ }
}
Added: arquillian/trunk/containers/glassfish-embedded-30/src/test/java/org/jboss/arquillian/glassfish/GlassFishEmbeddedContainerTestCase.java
===================================================================
--- arquillian/trunk/containers/glassfish-embedded-30/src/test/java/org/jboss/arquillian/glassfish/GlassFishEmbeddedContainerTestCase.java (rev 0)
+++ arquillian/trunk/containers/glassfish-embedded-30/src/test/java/org/jboss/arquillian/glassfish/GlassFishEmbeddedContainerTestCase.java 2010-05-07 17:38:03 UTC (rev 4359)
@@ -0,0 +1,94 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.arquillian.glassfish;
+
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.net.URL;
+
+import org.jboss.arquillian.impl.DynamicServiceLoader;
+import org.jboss.arquillian.impl.XmlConfigurationBuilder;
+import org.jboss.arquillian.impl.context.SuiteContext;
+import org.jboss.arquillian.spi.Context;
+import org.jboss.arquillian.spi.DeployableContainer;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * GlassFishEmbeddedContainerTestCase
+ *
+ * @author <a href="mailto:aslak at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+public class GlassFishEmbeddedContainerTestCase
+{
+ private DeployableContainer container;
+
+ private Context context = new SuiteContext(new DynamicServiceLoader());
+
+ private WebArchive war = ShrinkWrap.create("test.war", WebArchive.class)
+ .addClass(TestServlet.class);
+
+ @Before
+ public void startup() throws Exception
+ {
+ container = new GlassFishEmbeddedContainer();
+ container.setup(context, new XmlConfigurationBuilder().build());
+ container.start(context);
+ container.deploy(context, war);
+ }
+
+ @After
+ public void shutdown() throws Exception
+ {
+ container.undeploy(context, war);
+ container.stop(context);
+ }
+
+ @Test
+ public void shouldBeAbleToDeployWebArchive() throws Exception
+ {
+ String body = readAllAndClose(new URL("http://localhost:8080/test/Test").openStream());
+
+ Assert.assertEquals(
+ "Verify that the servlet was deployed and returns expected result",
+ "hello",
+ body);
+ }
+
+ private String readAllAndClose(InputStream is) throws Exception
+ {
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ try
+ {
+ int read;
+ while( (read = is.read()) != -1)
+ {
+ out.write(read);
+ }
+ }
+ finally
+ {
+ try { is.close(); } catch (Exception e) { }
+ }
+ return out.toString();
+ }
+}
Added: arquillian/trunk/containers/glassfish-embedded-30/src/test/java/org/jboss/arquillian/glassfish/TestServlet.java
===================================================================
--- arquillian/trunk/containers/glassfish-embedded-30/src/test/java/org/jboss/arquillian/glassfish/TestServlet.java (rev 0)
+++ arquillian/trunk/containers/glassfish-embedded-30/src/test/java/org/jboss/arquillian/glassfish/TestServlet.java 2010-05-07 17:38:03 UTC (rev 4359)
@@ -0,0 +1,43 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * Licensed 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.jboss.arquillian.glassfish;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.annotation.WebServlet;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * TestServlet
+ *
+ * @author <a href="mailto:aslak at redhat.com">Aslak Knutsen</a>
+ * @version $Revision: $
+ */
+ at WebServlet(urlPatterns = "/Test")
+public class TestServlet extends HttpServlet
+{
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
+ {
+ response.getWriter().append("hello");
+ }
+}
More information about the jboss-svn-commits
mailing list