Created
August 31, 2011 22:23
-
-
Save aslakknutsen/1184904 to your computer and use it in GitHub Desktop.
JSFUnit Rewrite - No need to deploy HTMLUnit etc incontianer, only minimal infrastruct to support Assertion of server state after Render complete phase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* JBoss, Home of Professional Open Source | |
* Copyright 2011 Red Hat Inc. and/or its affiliates and other contributors | |
* as indicated by the @authors tag. All rights reserved. | |
* 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. | |
*/ | |
import java.net.URL; | |
import javax.enterprise.context.RequestScoped; | |
import javax.inject.Inject; | |
import junit.framework.Assert; | |
import org.jboss.arquillian.container.test.api.Deployment; | |
import org.jboss.arquillian.junit.Arquillian; | |
import org.jboss.arquillian.test.api.ArquillianResource; | |
import org.jboss.jsfunit.jsfsession.JSFClientSession; | |
import org.jboss.jsfunit.jsfsession.JSFServerSession; | |
import org.jboss.shrinkwrap.api.ShrinkWrap; | |
import org.jboss.shrinkwrap.api.spec.WebArchive; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import org.w3c.dom.Element; | |
@RunWith(Arquillian.class) | |
public class APiTestCase | |
{ | |
@Deployment | |
public static WebArchive deployment() { | |
return ShrinkWrap.create(WebArchive.class); | |
} | |
@Test | |
public void shouldbeAbleToCallBothClientAndServer(@ArquillianResource URL base) throws Exception | |
{ | |
JSFClientSession client = Request(new URL(base, "index.jsf"), | |
new ServerState() | |
{ | |
@Inject | |
private MyCDIBean bean; | |
@Override | |
public void validate(JSFServerSession session) | |
{ | |
Assert.assertEquals("test", session.getManagedBeanValue("my.bean")); | |
Assert.assertEquals("test2", bean.getName()); | |
} | |
}); | |
Element element = client.getElement("myRenderedComp"); | |
Assert.assertEquals("test-3", element); | |
} | |
// Server side state | |
@RequestScoped | |
public class MyCDIBean { | |
String getName() {return null; } | |
} | |
// API | |
public interface ServerState { | |
void validate(JSFServerSession session); | |
} | |
public static JSFClientSession Request(URL url, ServerState serverState) | |
{ | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment