/**
 * JBoss, Home of Professional Open Source
 * Copyright 2012, 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.warp.jsf.ftest.producer;

import static org.junit.Assert.fail;

import java.io.FileNotFoundException;
import java.net.URL;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.drone.api.annotation.Drone;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.arquillian.test.spi.ArquillianProxyException;
import org.jboss.arquillian.warp.Activity;
import org.jboss.arquillian.warp.Inspection;
import org.jboss.arquillian.warp.Warp;
import org.jboss.arquillian.warp.WarpTest;
import org.jboss.arquillian.warp.exception.ServerWarpExecutionException;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openqa.selenium.WebDriver;

@RunWith(Arquillian.class)
@WarpTest
@RunAsClient
public class TestJSFResourceNotFound {

    @Drone
    WebDriver browser;

    @ArquillianResource
    URL contextPath;

    @Deployment
    public static WebArchive createDeployment() {
        return ShrinkWrap.create(WebArchive.class, "jsf-test.war")
                .addAsWebInfResource(EmptyAsset.INSTANCE, "faces-config.xml");
    }

    @Test
    public void testNotFound() {
        try {
            Warp.initiate(new Activity() {

                @Override
                public void perform() {
                    browser.navigate().to(contextPath + "faces/notFound.xhtml");
                }

            }).inspect(new Inspection() {
                private static final long serialVersionUID = 1L;
            });

            fail("expected server exception");
        } catch (ArquillianProxyException e) {
            // FileNotFoundException on server
        } catch (ServerWarpExecutionException e) {
            if (!(e.getCause() instanceof FileNotFoundException)) {
                fail("expected FileNotFound on server");
            }
        }
    }
}

@@ -845,38 +845,38 @@
 ort 
-static org.junit.Assert.fail;%0A
+java.io.FileNotFoundException;
 %0Aimp
@@ -883,36 +883,26 @@
 ort java.io.
-FileNotFound
+IO
 Exception;%0Ai
@@ -920,16 +920,47 @@
 net.URL;
+%0Aimport java.net.URLConnection;
 %0A%0Aimport
@@ -1235,71 +1235,8 @@
 ce;%0A
-import org.jboss.arquillian.test.spi.ArquillianProxyException;%0A
 impo
@@ -1405,81 +1405,8 @@
 st;%0A
-import org.jboss.arquillian.warp.exception.ServerWarpExecutionException;%0A
 impo
@@ -1483,21 +1483,22 @@
 i.asset.
-Empty
+String
 Asset;%0Ai
@@ -1985,27 +1985,56 @@
 rce(
-EmptyAsset.INSTANCE
+new StringAsset(%22%3Cfaces-config%3E%3C/faces-config%3E%22)
 , %22f
@@ -2106,26 +2106,8 @@
 ) %7B%0A
-        try %7B%0A    
     
@@ -2154,20 +2154,16 @@
         
-    
 @Overrid
@@ -2164,20 +2164,16 @@
 verride%0A
-    
         
@@ -2220,33 +2220,51 @@
     
-    browser.navigate().to
+try %7B%0A                    URL url = new URL
 (con
@@ -2275,10 +2275,9 @@
 Path
- +
+,
  %22fa
@@ -2283,21 +2283,24 @@
 aces/not
-Found
+Existing
 .xhtml%22)
@@ -2321,117 +2321,161 @@
     
-%7D%0A%0A            %7D).inspect(new Inspection() %7B%0A                private static final long serialVersionUID = 1L;
+    URLConnection connection = url.openConnection();%0A                    connection.getInputStream();%0A                %7D catch (FileNotFoundException e) %7B
 %0A   
@@ -2487,21 +2487,16 @@
     
-%7D);%0A%0A
         
     
@@ -2495,47 +2495,40 @@
     
-    fail(%22expected server exception%22);%0A
+// the FNFE is expected%0A        
     
@@ -2544,23 +2544,10 @@
 ch (
-ArquillianProxy
+IO
 Exce
@@ -2573,79 +2573,38 @@
     
-// FileNotFoundException on server%0A        %7D catch (ServerWarpExecution
+        throw new IllegalState
 Exce
@@ -2612,78 +2612,80 @@
 tion
- e) %7B%0A            if (!(e.getCause() instanceof FileNotFoundExcep
+(e);%0A                %7D%0A            %7D%0A%0A        %7D).inspect(new Inspec
 tion
-)
+(
 ) %7B%0A
@@ -2700,66 +2700,56 @@
     
-    fail(%22expected FileNotFound 
+private static final l
 on
+g
  ser
-ver%22);%0A            %7D
+ialVersionUID = 1L;
 %0A   
@@ -2750,21 +2750,23 @@
 L;%0A        %7D
+);
 %0A    %7D%0A%7D%0A

fix TestJSFResourceNotFound test on wildfly