Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.acme.portlet;
- import static org.jboss.arquillian.api.RunModeType.AS_CLIENT;
- import java.io.ByteArrayOutputStream;
- import java.io.File;
- import java.io.InputStream;
- import java.net.URL;
- import org.jboss.arquillian.api.Deployment;
- import org.jboss.arquillian.api.Run;
- import org.jboss.arquillian.junit.Arquillian;
- import org.jboss.shrinkwrap.api.Archive;
- import org.jboss.shrinkwrap.api.ArchivePaths;
- import org.jboss.shrinkwrap.api.ShrinkWrap;
- import org.jboss.shrinkwrap.api.exporter.ZipExporter;
- import org.jboss.shrinkwrap.api.spec.WebArchive;
- import org.junit.Assert;
- import org.junit.Test;
- import org.junit.runner.RunWith;
- @RunWith(Arquillian.class)
- @Run(AS_CLIENT)
- public class PortletTest
- {
- @Deployment
- public static Archive<?> createDeployment()
- {
- Archive<?> deployment = ShrinkWrap.create("test.war", WebArchive.class)
- .addPackage(PortletTest.class.getPackage())
- .setWebXML("test-web.xml")
- .addWebResource("test-portlet.xml", ArchivePaths.create("portlet.xml"));
- deployment.as(ZipExporter.class).exportZip(new File("target/test.war"), true);
- return deployment;
- }
- @Test
- public void shouldBeAbleTo() throws Exception
- {
- String body = readAllAndClose(new URL("http://localhost:8080/portal/public/classic/Test").openStream());
- Assert.assertTrue(
- "Verify that the servlet was deployed and returns expected result",
- body.contains("testing"));
- }
- 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();
- }
- }
Add Comment
Please, Sign In to add comment