/**
 * JBoss, Home of Professional Open Source
 * Copyright 2013, 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.portal.warp.jsf.it;

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.graphene.findby.FindByJQuery;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.portal.api.PortalTest;
import org.jboss.arquillian.portal.api.PortalURL;
import org.jboss.arquillian.portal.warp.jsf.PortletPhase;
import org.jboss.arquillian.test.api.ArquillianResource;
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.jsf.AfterPhase;
import org.jboss.arquillian.warp.jsf.BeforePhase;
import org.jboss.arquillian.warp.jsf.Phase;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.descriptor.api.Descriptors;
import org.jboss.shrinkwrap.descriptor.api.webapp30.WebAppDescriptor;
import org.jboss.shrinkwrap.descriptor.api.webcommon30.WebAppVersionType;
import org.jboss.shrinkwrap.portal.api.PortletArchive;
import org.jboss.shrinkwrap.resolver.api.maven.Maven;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

import javax.faces.bean.ManagedProperty;
import java.io.File;
import java.net.URL;

import static org.jboss.arquillian.warp.client.filter.http.HttpFilters.request;
import static org.jboss.arquillian.portal.warp.Phase.ACTION;
import static org.jboss.arquillian.portal.warp.Phase.RENDER;
import static org.junit.Assert.assertEquals;

/**
 * @author <a href="http://community.jboss.org/people/kenfinni">Ken Finnigan</a>
 */
@RunWith(Arquillian.class)
@WarpTest
@PortalTest
public class JSFPortletWarpTest {

    private static final String NEW_VALUE = "New Value";

    @Deployment
    public static PortletArchive createDeployment() {
        PortletArchive archive = ShrinkWrap.create(PortletArchive.class, "JSFPortletWarp.war");

        File[] libs = Maven.resolver()
                .loadPomFromFile("pom.xml")
                .resolve("org.jboss.portletbridge:portletbridge-impl")
                .withTransitivity()
                .asFile();

        archive.createFacesPortlet("JsfFormSubmit", "JSF Form Portlet", "form.xhtml")
                .addAsWebResource("form.xhtml", "form.xhtml")
                .addClass(Bean.class)
                .addAsLibraries(libs);

//        WebAppDescriptor webXml = Descriptors.create(WebAppDescriptor.class)
//                .addDefaultNamespaces()
//                .version(WebAppVersionType._3_0);
//
//        archive.setWebXML(new StringAsset(webXml.exportAsString()));
        return archive;
    }

    @FindByJQuery("[id$=':input']")
    private WebElement inputField;

    @FindByJQuery("[id$=':submit']")
    private WebElement submitButton;

    @Drone
    WebDriver browser;

    @ArquillianResource
    @PortalURL
    URL portalURL;

    @RunAsClient
    @Test
    public void test() {
        browser.navigate().to(portalURL);

        Warp
            .initiate(new Activity() {
                @Override
                public void perform() {
                    inputField.clear();
                    inputField.sendKeys(NEW_VALUE);
                    submitButton.click();
                }
            })
            .group()
                .observe(request().index(1))
                .inspect(new Inspection() {
                    private static final long serialVersionUID = 1L;

                    @ManagedProperty("#{bean}")
                    Bean bean;

                    @PortletPhase(ACTION) @BeforePhase(Phase.UPDATE_MODEL_VALUES)
                    public void testBeanValueBeforeUpdate() {
                        assertEquals("Bean value should not be updated yet.", Bean.HELLO_JSF_PORTLET, bean.getText());
                    }

                    @PortletPhase(ACTION) @AfterPhase(Phase.UPDATE_MODEL_VALUES)
                    public void testBeanValueAfterUpdate() {
                        assertEquals("Bean value should now be updated.", NEW_VALUE, bean.getText());
                    }
                })
            .group()
                .observe(request().index(2))
                .inspect(new Inspection() {
                    private static final long serialVersionUID = 1L;

                    @ManagedProperty("#{bean}")
                    Bean bean;

                    @PortletPhase(RENDER) @BeforePhase(Phase.RENDER_RESPONSE)
                    public void testBeanValueBeforeRenderResponse() {
                        assertEquals("Bean value should still contain new value.", NEW_VALUE, bean.getText());
                    }
                })
            .execute();
    }
}

@@ -1685,259 +1685,8 @@
 ap;%0A
-import org.jboss.shrinkwrap.api.asset.StringAsset;%0Aimport org.jboss.shrinkwrap.descriptor.api.Descriptors;%0Aimport org.jboss.shrinkwrap.descriptor.api.webapp30.WebAppDescriptor;%0Aimport org.jboss.shrinkwrap.descriptor.api.webcommon30.WebAppVersionType;%0A
 impo
@@ -3102,255 +3102,8 @@
 );%0A%0A
-//        WebAppDescriptor webXml = Descriptors.create(WebAppDescriptor.class)%0A//                .addDefaultNamespaces()%0A//                .version(WebAppVersionType._3_0);%0A//%0A//        archive.setWebXML(new StringAsset(webXml.exportAsString()));%0A
     

Remove commented code from test