package org.wildfly.swarm.integration.jaxrs;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.wildfly.swarm.container.Container;
import org.wildfly.swarm.jaxrs.JAXRSArchive;

import static org.fest.assertions.Assertions.assertThat;

/**
 * @author Bob McWhirter
 */
//@RunWith(Arquillian.class)
public class JAXRSTest  {

    @Deployment
    public static Archive createDeployment() throws Exception {
        JAXRSArchive deployment = ShrinkWrap.create(JAXRSArchive.class);
        deployment.addResource(MyResource.class);
        deployment.addAllDependencies();
        deployment.staticContent();
        return deployment;
    }

//    @RunAsClient @Test
    public void testSimple() throws IOException {
        assertThat(fetch("http://localhost:8080/")).contains("Howdy at");
        assertThat(fetch("http://localhost:8080/static-content.txt")).contains("This is static.");
    }

    protected String fetch(String urlStr) throws IOException {
        URL url = new URL(urlStr);
        StringBuffer buffer = new StringBuffer();
        try (InputStream in = url.openStream()) {
            int numRead = 0;
            while (numRead >= 0) {
                byte[] b = new byte[1024];
                numRead = in.read(b);
                if (numRead < 0) {
                    break;
                }
                buffer.append(new String(b, 0, numRead));
            }
        }

        return buffer.toString();
    }

}

@@ -83,22 +83,40 @@
 ava.
-io.InputStream
+net.URL;%0Aimport java.util.Arrays
 ;%0Aim
@@ -125,23 +125,25 @@
 rt java.
-net.URL
+util.List
 ;%0A%0Aimpor
@@ -288,24 +288,137 @@
 ian.
-junit.Arquillian
+drone.api.annotation.Drone;%0Aimport org.jboss.arquillian.junit.Arquillian;%0Aimport org.jboss.arquillian.test.api.ArquillianResource
 ;%0Aim
@@ -571,41 +571,99 @@
 org.
-wildfly.swarm.container.Container
+openqa.selenium.WebDriver;%0Aimport org.wildfly.swarm.arquillian.adapter.ArtifactDependencies
 ;%0Aim
@@ -797,18 +797,16 @@
 ter%0A */%0A
-//
 @RunWith
@@ -847,18 +847,98 @@
 XRSTest 
- 
 %7B
+%0A%0A    @ArquillianResource%0A    URL contextRoot;%0A%0A    @Drone%0A    WebDriver browser;
 %0A%0A    @D
@@ -1138,49 +1138,8 @@
 s);%0A
-        deployment.addAllDependencies();%0A
     
@@ -1208,32 +1208,33 @@
  %7D%0A%0A
-//
     @
-RunAsClient @T
+ArtifactDependenci
 es
-t
 %0A   
@@ -1245,764 +1245,489 @@
 lic 
-void testSimple() throws IOException %7B%0A        assertThat(fetch(%22http://localhost:8080/%22)).contains(%22Howdy at%22);%0A        assertThat(fetch(%22http://localhost:8080/static-content.txt%22)).contains(%22This is static.%22);%0A    %7D%0A%0A    protected String fetch(String urlStr) throws IOException %7B%0A        URL url = new URL(urlStr);%0A        StringBuffer buffer = new StringBuffer();%0A        try (InputStream in = url.openStream()) %7B%0A            int numRead = 0;%0A            while (numRead %3E= 0) %7B%0A                byte%5B%5D b = new byte%5B1024%5D;%0A                numRead = in.read(b);%0A                if (numRead %3C 0) %7B%0A                    break;%0A                %7D%0A                buffer.append(new String(b, 0, numRead));%0A            %7D%0A        %7D%0A%0A        return buffer.toString(
+static List%3CString%3E appDependencies() %7B%0A        return Arrays.asList(%0A                %22org.wildfly.swarm:wildfly-swarm-jaxrs%22%0A        );%0A    %7D%0A%0A    @RunAsClient%0A    @Test%0A    public void testSimple() throws IOException %7B%0A        browser.navigate().to(contextRoot);%0A        assertThat(browser.getPageSource()).contains(%22This is index.html.%22);%0A%0A        browser.navigate().to(contextRoot + %22/static-content.txt%22);%0A        assertThat(browser.getPageSource()).contains(%22This is static.%22
 );%0A 

Enable JAXRSTest