Advertisement
aslak

Arquillian JSFUnit patch

Mar 17th, 2010
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 31.76 KB | None | 0 0
  1.  
  2. Property changes on: frameworks
  3. ___________________________________________________________________
  4. Added: svn:ignore
  5.    + .classpath
  6. .project
  7. .settings
  8. target
  9.  
  10.  
  11.  
  12.  
  13. Property changes on: frameworks/jsfunit
  14. ___________________________________________________________________
  15. Added: svn:ignore
  16.    + .classpath
  17. .project
  18. .settings
  19. target
  20.  
  21.  
  22.  
  23. Index: frameworks/jsfunit/src/main/java/org/jboss/arquillian/framework/jsfunit/JSFUnitPackager.java
  24. ===================================================================
  25. --- frameworks/jsfunit/src/main/java/org/jboss/arquillian/framework/jsfunit/JSFUnitPackager.java    (revision 0)
  26. +++ frameworks/jsfunit/src/main/java/org/jboss/arquillian/framework/jsfunit/JSFUnitPackager.java    (revision 0)
  27. @@ -0,0 +1,52 @@
  28. +/*
  29. + * JBoss, Home of Professional Open Source
  30. + * Copyright 2009, Red Hat Middleware LLC, and individual contributors
  31. + * by the @authors tag. See the copyright.txt in the distribution for a
  32. + * full listing of individual contributors.
  33. + *
  34. + * Licensed under the Apache License, Version 2.0 (the "License");
  35. + * you may not use this file except in compliance with the License.
  36. + * You may obtain a copy of the License at
  37. + * http://www.apache.org/licenses/LICENSE-2.0
  38. + * Unless required by applicable law or agreed to in writing, software
  39. + * distributed under the License is distributed on an "AS IS" BASIS,
  40. + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  41. + * See the License for the specific language governing permissions and
  42. + * limitations under the License.
  43. + */
  44. +package org.jboss.arquillian.framework.jsfunit;
  45. +
  46. +import java.util.Collection;
  47. +
  48. +import org.jboss.arquillian.spi.DeploymentPackager;
  49. +import org.jboss.shrinkwrap.api.Archive;
  50. +import org.jboss.shrinkwrap.api.spec.WebArchive;
  51. +
  52. +/**
  53. + * JSFUnitPackager
  54. + *
  55. + * @author <a href="mailto:aslak@conduct.no">Aslak Knutsen</a>
  56. + * @version $Revision: $
  57. + */
  58. +public class JSFUnitPackager implements DeploymentPackager
  59. +{
  60. +
  61. +   /* (non-Javadoc)
  62. +    * @see org.jboss.arquillian.spi.DeploymentPackager#generateDeployment(org.jboss.shrinkwrap.api.Archive, java.util.Collection)
  63. +    */
  64. +   @Override
  65. +   public Archive<?> generateDeployment(Archive<?> applicationArchive, Collection<Archive<?>> auxiliaryArchives)
  66. +   {
  67. +      if(WebArchive.class.isInstance(applicationArchive))
  68. +      {
  69. +         WebArchive applicationWebArchive = WebArchive.class.cast(applicationArchive);
  70. +         applicationWebArchive.addLibraries(auxiliaryArchives.toArray(new Archive[0]));
  71. +        
  72. +         return applicationWebArchive;
  73. +      }
  74. +      throw new RuntimeException(
  75. +            "Only ApplicatonArchives of type " + WebArchive.class.getName() + " are supported by the JSFUnitPackager, " +
  76. +            "ApplicationArchive is of type " + applicationArchive.getClass().getName());
  77. +   }
  78. +
  79. +}
  80. Index: frameworks/jsfunit/src/main/java/org/jboss/arquillian/framework/jsfunit/JSFUnitArchiveAppender.java
  81. ===================================================================
  82. --- frameworks/jsfunit/src/main/java/org/jboss/arquillian/framework/jsfunit/JSFUnitArchiveAppender.java (revision 0)
  83. +++ frameworks/jsfunit/src/main/java/org/jboss/arquillian/framework/jsfunit/JSFUnitArchiveAppender.java (revision 0)
  84. @@ -0,0 +1,69 @@
  85. +/*
  86. + * JBoss, Home of Professional Open Source
  87. + * Copyright 2009, Red Hat Middleware LLC, and individual contributors
  88. + * by the @authors tag. See the copyright.txt in the distribution for a
  89. + * full listing of individual contributors.
  90. + *
  91. + * Licensed under the Apache License, Version 2.0 (the "License");
  92. + * you may not use this file except in compliance with the License.
  93. + * You may obtain a copy of the License at
  94. + * http://www.apache.org/licenses/LICENSE-2.0
  95. + * Unless required by applicable law or agreed to in writing, software
  96. + * distributed under the License is distributed on an "AS IS" BASIS,
  97. + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  98. + * See the License for the specific language governing permissions and
  99. + * limitations under the License.
  100. + */
  101. +package org.jboss.arquillian.framework.jsfunit;
  102. +
  103. +import org.jboss.arquillian.spi.AuxiliaryArchiveAppender;
  104. +
  105. +import org.jboss.shrinkwrap.api.Archive;
  106. +import org.jboss.shrinkwrap.api.Archives;
  107. +import org.jboss.shrinkwrap.api.spec.JavaArchive;
  108. +
  109. +
  110. +/**
  111. + * JSFUnitArchiveAppender
  112. + *
  113. + * @author <a href="mailto:aslak@conduct.no">Aslak Knutsen</a>
  114. + * @version $Revision: $
  115. + */
  116. +public class JSFUnitArchiveAppender implements AuxiliaryArchiveAppender
  117. +{
  118. +
  119. +   /* (non-Javadoc)
  120. +    * @see org.jboss.arquillian.spi.AuxiliaryArchiveAppender#createAuxiliaryArchive()
  121. +    */
  122. +   @Override
  123. +   public Archive<?> createAuxiliaryArchive()
  124. +   {
  125. +      return Archives.create("arquillian-jsfunit.jar", JavaArchive.class)
  126. +                  .addPackages(
  127. +                        true,
  128. +                        org.jboss.jsfunit.jsfsession.JSFSession.class.getPackage(),
  129. +                        org.jboss.jsfunit.framework.WebClientSpec.class.getPackage(),
  130. +                        org.jboss.jsfunit.context.JSFUnitFacesContext.class.getPackage(),
  131. +                        org.jboss.jsfunit.seam.SeamUtil.class.getPackage(),
  132. +                        com.gargoylesoftware.htmlunit.BrowserVersion.class.getPackage(),
  133. +                        org.apache.commons.codec.Decoder.class.getPackage(),
  134. +                        org.apache.commons.httpclient.HttpClient.class.getPackage(),
  135. +                        org.apache.commons.io.IOUtils.class.getPackage(),
  136. +                        org.apache.commons.lang.StringUtils.class.getPackage(),
  137. +                        net.sourceforge.htmlunit.corejs.javascript.EvaluatorException.class.getPackage(),
  138. +                        org.w3c.css.sac.CSSException.class.getPackage(),
  139. +                        com.steadystate.css.dom.CSSOMObject.class.getPackage(),
  140. +                        org.cyberneko.html.HTMLComponent.class.getPackage())
  141. +                  .addResource("com/gargoylesoftware/htmlunit/javascript/configuration/FF2.properties")
  142. +                  .addResource("com/gargoylesoftware/htmlunit/javascript/configuration/FF3.properties")
  143. +                  .addResource("com/gargoylesoftware/htmlunit/javascript/configuration/IE6.properties")
  144. +                  .addResource("com/gargoylesoftware/htmlunit/javascript/configuration/IE7.properties")
  145. +                  .addResource("com/gargoylesoftware/htmlunit/javascript/configuration/IE8.properties")
  146. +                  .addResource("com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfiguration.xml")
  147. +                  .addResource("com/gargoylesoftware/htmlunit/javascript/configuration/JavaScriptConfiguration.xsd")
  148. +                  .addManifestResource("faces-config.xml")
  149. +                  .addManifestResource("web-fragment.xml");
  150. +
  151. +   }
  152. +
  153. +}
  154. Index: frameworks/jsfunit/src/main/resources/META-INF/services/org.jboss.arquillian.spi.AuxiliaryArchiveAppender
  155. ===================================================================
  156. --- frameworks/jsfunit/src/main/resources/META-INF/services/org.jboss.arquillian.spi.AuxiliaryArchiveAppender   (revision 0)
  157. +++ frameworks/jsfunit/src/main/resources/META-INF/services/org.jboss.arquillian.spi.AuxiliaryArchiveAppender   (revision 0)
  158. @@ -0,0 +1 @@
  159. +org.jboss.arquillian.framework.jsfunit.JSFUnitArchiveAppender
  160. \ No newline at end of file
  161. Index: frameworks/jsfunit/src/main/resources/META-INF/services/org.jboss.arquillian.spi.DeploymentPackager
  162. ===================================================================
  163. --- frameworks/jsfunit/src/main/resources/META-INF/services/org.jboss.arquillian.spi.DeploymentPackager (revision 0)
  164. +++ frameworks/jsfunit/src/main/resources/META-INF/services/org.jboss.arquillian.spi.DeploymentPackager (revision 0)
  165. @@ -0,0 +1 @@
  166. +org.jboss.arquillian.framework.jsfunit.JSFUnitPackager
  167. \ No newline at end of file
  168. Index: frameworks/jsfunit/src/main/resources/faces-config.xml
  169. ===================================================================
  170. --- frameworks/jsfunit/src/main/resources/faces-config.xml  (revision 0)
  171. +++ frameworks/jsfunit/src/main/resources/faces-config.xml  (revision 0)
  172. @@ -0,0 +1,16 @@
  173. +<?xml version="1.0"?>
  174. +<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
  175. +              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  176. +              xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
  177. +                                  http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
  178. +              version="2.0">
  179. +  
  180. +  <factory>
  181. +    <faces-context-factory>org.jboss.jsfunit.context.JSFUnitFacesContextFactory</faces-context-factory>
  182. +  </factory>
  183. +  
  184. +  <application>
  185. +     <variable-resolver>org.jboss.jsfunit.seam.ConversationScopeVariableResolver</variable-resolver>
  186. +  </application>
  187. +    
  188. +</faces-config>
  189. Index: frameworks/jsfunit/src/main/resources/web-fragment.xml
  190. ===================================================================
  191. --- frameworks/jsfunit/src/main/resources/web-fragment.xml  (revision 0)
  192. +++ frameworks/jsfunit/src/main/resources/web-fragment.xml  (revision 0)
  193. @@ -0,0 +1,31 @@
  194. +<web-fragment xmlns="http://java.sun.com/xml/ns/javaee"
  195. +    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  196. +    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-fragment_3_0.xsd"
  197. +    version="3.0">
  198. +
  199. +    <filter>
  200. +      <filter-name>JSFUnitFilter</filter-name>
  201. +      <filter-class>org.jboss.jsfunit.framework.JSFUnitFilter</filter-class>
  202. +    </filter>
  203. +
  204. +    <filter-mapping>
  205. +      <filter-name>JSFUnitFilter</filter-name>
  206. +      <url-pattern>/ArquillianServletRunner</url-pattern>
  207. +    </filter-mapping>    
  208. +    
  209. +<!--  
  210. +    <servlet>
  211. +      <servlet-name>JSFUnit Faces Servlet</servlet-name>
  212. +      <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
  213. +    </servlet>
  214. +
  215. +   <servlet-mapping>
  216. +      <servlet-name>JSFUnit Faces Servlet</servlet-name>
  217. +      <url-pattern>*.jsfunit</url-pattern>
  218. +   </servlet-mapping>
  219. +
  220. +   <welcome-file-list>
  221. +      <welcome-file>jsfunit/index.html</welcome-file>
  222. +   </welcome-file-list>
  223. + -->  
  224. +</web-fragment>
  225. \ No newline at end of file
  226. Index: frameworks/jsfunit/pom.xml
  227. ===================================================================
  228. --- frameworks/jsfunit/pom.xml  (revision 0)
  229. +++ frameworks/jsfunit/pom.xml  (revision 0)
  230. @@ -0,0 +1,85 @@
  231. +<?xml version="1.0" encoding="UTF-8"?>
  232. +   <!--
  233. +  vi:ts=2:sw=2:expandtab:
  234. +-->
  235. +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  236. +   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  237. +
  238. +   <!-- Parent -->
  239. +   <parent>
  240. +      <groupId>org.jboss.arquillian</groupId>
  241. +      <artifactId>arquillian-build</artifactId>
  242. +      <version>1.0.0-SNAPSHOT</version>
  243. +      <relativePath>../build/pom.xml</relativePath>
  244. +   </parent>
  245. +
  246. +   <!-- Model Version -->
  247. +   <modelVersion>4.0.0</modelVersion>
  248. +
  249. +   <!-- Artifact Configuration -->
  250. +   <groupId>org.jboss.arquillian.framework</groupId>
  251. +   <artifactId>arquillian-framework-jsfunit</artifactId>
  252. +   <name>Arquillian Framework JSFUnit</name>
  253. +   <description>JSFUnit integration for the Arquillian project</description>
  254. +
  255. +
  256. +   <!-- Properties -->
  257. +   <properties>
  258. +
  259. +
  260. +   </properties>
  261. +
  262. +   <!-- Dependencies -->
  263. +   <dependencies>
  264. +
  265. +      <!--
  266. +    org.jboss.arquillian
  267. +     -->
  268. +      <dependency>
  269. +         <groupId>org.jboss.arquillian</groupId>
  270. +         <artifactId>arquillian-spi</artifactId>
  271. +         <version>${project.version}</version>
  272. +      </dependency>
  273. +
  274. +      <dependency>
  275. +         <groupId>org.jboss.shrinkwrap</groupId>
  276. +         <artifactId>shrinkwrap-impl-base</artifactId>
  277. +      </dependency>
  278. +      <dependency>
  279. +         <groupId>org.jboss.shrinkwrap</groupId>
  280. +         <artifactId>shrinkwrap-spi</artifactId>
  281. +      </dependency>
  282. +
  283. +      <!--
  284. +    org.jboss.jsfunit
  285. +     -->
  286. +
  287. +     <dependency>
  288. +       <groupId>org.jboss.jsfunit</groupId>
  289. +       <artifactId>jboss-jsfunit-core</artifactId>
  290. +       <version>1.2.0.Final</version>
  291. +       <scope>compile</scope>
  292. +     </dependency>
  293. +
  294. +      <!--
  295. +    External Projects
  296. +     -->
  297. +    
  298. +      <dependency>
  299. +         <groupId>jboss.web</groupId>
  300. +         <artifactId>servlet-api</artifactId>
  301. +         <version>3.0.0.alpha-25</version>
  302. +         <scope>provided</scope>
  303. +      </dependency>
  304. +    
  305. +
  306. +      <dependency>
  307. +         <groupId>junit</groupId>
  308. +         <artifactId>junit</artifactId>
  309. +         <scope>test</scope>
  310. +      </dependency>
  311. +
  312. +   </dependencies>
  313. +
  314. +</project>
  315. +
  316. Index: frameworks/pom.xml
  317. ===================================================================
  318. --- frameworks/pom.xml  (revision 0)
  319. +++ frameworks/pom.xml  (revision 0)
  320. @@ -0,0 +1,33 @@
  321. +<?xml version="1.0" encoding="UTF-8"?>
  322. +<!--
  323. +  vi:ts=2:sw=2:expandtab:
  324. +-->
  325. +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  326. +  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  327. +
  328. +  <!-- Parent -->
  329. +  <parent>
  330. +    <groupId>org.jboss.arquillian</groupId>
  331. +    <artifactId>arquillian-parent</artifactId>
  332. +    <version>1.0.0-SNAPSHOT</version>
  333. +  </parent>
  334. +
  335. +  <!-- Model Information -->
  336. +  <modelVersion>4.0.0</modelVersion>
  337. +
  338. +  <!-- Artifact Information  -->
  339. +  <groupId>org.jboss.arquillian.framework</groupId>
  340. +  <artifactId>arquillian-framework-parent</artifactId>
  341. +  <packaging>pom</packaging>
  342. +  <name>Arguillian Framework Aggregator</name>
  343. +  <url>http://www.jboss.org</url>
  344. +  <description>Arguillian Framework Aggregator</description>
  345. +
  346. +  <!-- Aggregate Modules -->
  347. +  <modules>
  348. +    
  349. +    <module>jsfunit</module>
  350. +
  351. +  </modules>
  352. +
  353. +</project>
  354. Index: protocols/servlet/src/main/java/org/jboss/arquillian/protocol/servlet/ProtocolDeploymentAppender.java
  355. ===================================================================
  356. --- protocols/servlet/src/main/java/org/jboss/arquillian/protocol/servlet/ProtocolDeploymentAppender.java   (revision 4178)
  357. +++ protocols/servlet/src/main/java/org/jboss/arquillian/protocol/servlet/ProtocolDeploymentAppender.java   (working copy)
  358. @@ -19,6 +19,7 @@
  359.  import org.jboss.arquillian.spi.AuxiliaryArchiveAppender;
  360.  import org.jboss.shrinkwrap.api.Archive;
  361.  import org.jboss.shrinkwrap.api.Archives;
  362. +import org.jboss.shrinkwrap.api.spec.JavaArchive;
  363.  import org.jboss.shrinkwrap.api.spec.WebArchive;
  364.  
  365.  /**
  366. @@ -39,12 +40,21 @@
  367.     @Override
  368.     public Archive<?> createAuxiliaryArchive()
  369.     {
  370. +      JavaArchive archive = Archives.create("arquillian-protocol.jar", JavaArchive.class)
  371. +                     .addClasses(
  372. +                           SecurityActions.class,
  373. +                           ServletTestRunner.class
  374. +                     )
  375. +                     .addManifestResource("org/jboss/arquillian/protocol/servlet/web-fragment.xml", "web-fragment.xml");
  376. +      
  377. +      /*
  378.        WebArchive archive = Archives.create("arquillian-protocol.war", WebArchive.class)
  379.                       .setWebXML("org/jboss/arquillian/protocol/servlet/web.xml")
  380.                       .addClasses(
  381.                             SecurityActions.class,
  382.                             ServletTestRunner.class
  383.                       );
  384. +      */
  385.        return archive;
  386.     }
  387.  
  388. Index: protocols/servlet/src/main/java/org/jboss/arquillian/protocol/servlet/ServletMethodExecutor.java
  389. ===================================================================
  390. --- protocols/servlet/src/main/java/org/jboss/arquillian/protocol/servlet/ServletMethodExecutor.java    (revision 4178)
  391. +++ protocols/servlet/src/main/java/org/jboss/arquillian/protocol/servlet/ServletMethodExecutor.java    (working copy)
  392. @@ -49,7 +49,7 @@
  393.        }
  394.        
  395.        Class<?> testClass = testMethodExecutor.getInstance().getClass();
  396. -      String url = baseURL.toExternalForm() + "arquillian-protocol/" +  
  397. +      String url = baseURL.toExternalForm() + "test/ArquillianServletRunner" +  
  398.                          "?outputMode=serializedObject&className=" + testClass.getName() +
  399.                          "&methodName=" + testMethodExecutor.getMethod().getName();
  400.        
  401. Index: protocols/servlet/src/main/resources/org/jboss/arquillian/protocol/servlet/web.xml
  402. ===================================================================
  403. --- protocols/servlet/src/main/resources/org/jboss/arquillian/protocol/servlet/web.xml  (revision 4178)
  404. +++ protocols/servlet/src/main/resources/org/jboss/arquillian/protocol/servlet/web.xml  (working copy)
  405. @@ -1,5 +1,10 @@
  406. -<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  407. -<web-app version="2.4">
  408. +<?xml version="1.0" encoding="UTF-8"?>
  409. +<web-app version="2.5"
  410. +    xmlns="http://java.sun.com/xml/ns/javaee"
  411. +    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  412. +    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
  413. +    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  414. +
  415.      <display-name>Arquillian</display-name>
  416.      <servlet>
  417.          <servlet-name>ServletTestRunner</servlet-name>
  418. @@ -7,6 +12,6 @@
  419.      </servlet>
  420.      <servlet-mapping>
  421.          <servlet-name>ServletTestRunner</servlet-name>
  422. -        <url-pattern>/*</url-pattern>
  423. +        <url-pattern>/ArquillianServletRunner</url-pattern>
  424.      </servlet-mapping>
  425.  </web-app>
  426. \ No newline at end of file
  427. Index: protocols/servlet/src/main/resources/org/jboss/arquillian/protocol/servlet/web-fragment.xml
  428. ===================================================================
  429. --- protocols/servlet/src/main/resources/org/jboss/arquillian/protocol/servlet/web-fragment.xml (revision 0)
  430. +++ protocols/servlet/src/main/resources/org/jboss/arquillian/protocol/servlet/web-fragment.xml (revision 0)
  431. @@ -0,0 +1,16 @@
  432. +<?xml version="1.0" encoding="UTF-8"?>
  433. +<web-fragment version="3.0"
  434. +    xmlns="http://java.sun.com/xml/ns/javaee"
  435. +    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  436. +    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
  437. +    http://java.sun.com/xml/ns/javaee/web-fragment_3_0.xsd">
  438. +
  439. +    <servlet>
  440. +        <servlet-name>ServletTestRunner</servlet-name>
  441. +        <servlet-class>org.jboss.arquillian.protocol.servlet.ServletTestRunner</servlet-class>
  442. +    </servlet>
  443. +    <servlet-mapping>
  444. +        <servlet-name>ServletTestRunner</servlet-name>
  445. +        <url-pattern>/ArquillianServletRunner</url-pattern>
  446. +    </servlet-mapping>
  447. +</web-fragment>
  448. \ No newline at end of file
  449. Index: examples/junit/src/test/java/com/acme/jsf/JSFUnitTestCase.java
  450. ===================================================================
  451. --- examples/junit/src/test/java/com/acme/jsf/JSFUnitTestCase.java  (revision 0)
  452. +++ examples/junit/src/test/java/com/acme/jsf/JSFUnitTestCase.java  (revision 0)
  453. @@ -0,0 +1,84 @@
  454. +/*
  455. + * JBoss, Home of Professional Open Source
  456. + * Copyright 2009, Red Hat Middleware LLC, and individual contributors
  457. + * by the @authors tag. See the copyright.txt in the distribution for a
  458. + * full listing of individual contributors.
  459. + *
  460. + * Licensed under the Apache License, Version 2.0 (the "License");
  461. + * you may not use this file except in compliance with the License.
  462. + * You may obtain a copy of the License at
  463. + * http://www.apache.org/licenses/LICENSE-2.0
  464. + * Unless required by applicable law or agreed to in writing, software
  465. + * distributed under the License is distributed on an "AS IS" BASIS,
  466. + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  467. + * See the License for the specific language governing permissions and
  468. + * limitations under the License.
  469. + */
  470. +package com.acme.jsf;
  471. +
  472. +import org.jboss.arquillian.api.Deployment;
  473. +import org.jboss.arquillian.junit.Arquillian;
  474. +import org.jboss.jsfunit.framework.Environment;
  475. +import org.jboss.jsfunit.jsfsession.JSFServerSession;
  476. +import org.jboss.jsfunit.jsfsession.JSFSession;
  477. +import org.jboss.shrinkwrap.api.ArchivePaths;
  478. +import org.jboss.shrinkwrap.api.Archives;
  479. +import org.jboss.shrinkwrap.api.spec.WebArchive;
  480. +import org.jboss.shrinkwrap.impl.base.asset.ByteArrayAsset;
  481. +import org.junit.Assert;
  482. +import org.junit.Test;
  483. +import org.junit.runner.RunWith;
  484. +
  485. +/**
  486. + * JSFUnitTestCase
  487. + *
  488. + * @author <a href="mailto:aslak@conduct.no">Aslak Knutsen</a>
  489. + * @version $Revision: $
  490. + */
  491. +@RunWith(Arquillian.class)
  492. +public class JSFUnitTestCase
  493. +{
  494. +   @Deployment
  495. +   public static WebArchive createDeployment() {
  496. +      return Archives.create("test.war", WebArchive.class)
  497. +            .addClasses(
  498. +                  RequestScopeBean.class,
  499. +                  ScopeAwareBean.class)
  500. +            .setWebXML("jsf/jsf-web.xml")
  501. +            .addResource("jsf/index.xhtml", "index.xhtml")
  502. +            .addWebResource("jsf/faces-config.xml", "faces-config.xml")
  503. +            .addWebResource(
  504. +                  new ByteArrayAsset("<beans/>".getBytes()),
  505. +                  ArchivePaths.create("beans.xml"));
  506. +   }
  507. +
  508. +   @Test
  509. +   public void shouldExecutePage() throws Exception
  510. +   {
  511. +      JSFSession jsfSession = new JSFSession("/index.jsf");
  512. +
  513. +      Assert.assertTrue(Environment.is12Compatible());
  514. +      Assert.assertTrue(Environment.is20Compatible());
  515. +      Assert.assertEquals(2, Environment.getJSFMajorVersion());
  516. +      Assert.assertEquals(0, Environment.getJSFMinorVersion());
  517. +
  518. +      JSFServerSession server = jsfSession.getJSFServerSession();
  519. +      
  520. +      Assert.assertEquals("request", server.getManagedBeanValue("#{requestBean.scope}"));
  521. +   }
  522. +
  523. +   @Test
  524. +   public void shouldExecutePage2() throws Exception
  525. +   {
  526. +      JSFSession jsfSession = new JSFSession("/index.jsf");
  527. +
  528. +      Assert.assertTrue(Environment.is12Compatible());
  529. +      Assert.assertTrue(Environment.is20Compatible());
  530. +      Assert.assertEquals(2, Environment.getJSFMajorVersion());
  531. +      Assert.assertEquals(0, Environment.getJSFMinorVersion());
  532. +
  533. +      JSFServerSession server = jsfSession.getJSFServerSession();
  534. +      
  535. +      Assert.assertEquals("request", server.getManagedBeanValue("#{requestBean.scope}"));
  536. +   }
  537. +}
  538. Index: examples/junit/src/main/java/com/acme/jsf/ScopeAwareBean.java
  539. ===================================================================
  540. --- examples/junit/src/main/java/com/acme/jsf/ScopeAwareBean.java   (revision 0)
  541. +++ examples/junit/src/main/java/com/acme/jsf/ScopeAwareBean.java   (revision 0)
  542. @@ -0,0 +1,33 @@
  543. +package com.acme.jsf;
  544. +
  545. +import java.util.Map;
  546. +
  547. +import javax.faces.context.ExternalContext;
  548. +import javax.faces.context.FacesContext;
  549. +
  550. +/**
  551. + *
  552. + * @author ssilvert
  553. + */
  554. +public class ScopeAwareBean {
  555. +
  556. +   public String getScope()
  557. +   {
  558. +      FacesContext facesCtx = FacesContext.getCurrentInstance();
  559. +      ExternalContext extCtx = facesCtx.getExternalContext();
  560. +      
  561. +      Map scopeMap = extCtx.getRequestMap();
  562. +      if (scopeMap.containsValue(this)) return "request";
  563. +      
  564. +      scopeMap = facesCtx.getViewRoot().getViewMap();
  565. +      if (scopeMap.containsValue(this)) return "view";
  566. +      
  567. +      scopeMap = extCtx.getSessionMap();
  568. +      if (scopeMap.containsValue(this)) return "session";
  569. +      
  570. +      scopeMap = extCtx.getApplicationMap();
  571. +      if (scopeMap.containsValue(this)) return "application";
  572. +      
  573. +      return "unknown";
  574. +   }
  575. +}
  576. Index: examples/junit/src/main/java/com/acme/jsf/RequestScopeBean.java
  577. ===================================================================
  578. --- examples/junit/src/main/java/com/acme/jsf/RequestScopeBean.java (revision 0)
  579. +++ examples/junit/src/main/java/com/acme/jsf/RequestScopeBean.java (revision 0)
  580. @@ -0,0 +1,39 @@
  581. +/*
  582. + * JBoss, Home of Professional Open Source.
  583. + * Copyright 2009, Red Hat Middleware LLC, and individual contributors
  584. + * as indicated by the @author tags. See the copyright.txt file in the
  585. + * distribution for a full listing of individual contributors.
  586. + *
  587. + * This is free software; you can redistribute it and/or modify it
  588. + * under the terms of the GNU Lesser General Public License as
  589. + * published by the Free Software Foundation; either version 2.1 of
  590. + * the License, or (at your option) any later version.
  591. + *
  592. + * This software is distributed in the hope that it will be useful,
  593. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  594. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  595. + * Lesser General Public License for more details.
  596. + *
  597. + * You should have received a copy of the GNU Lesser General Public
  598. + * License along with this software; if not, write to the Free
  599. + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  600. + * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  601. + */
  602. +
  603. +package com.acme.jsf;
  604. +
  605. +import javax.enterprise.context.RequestScoped;
  606. +import javax.faces.bean.ManagedBean;
  607. +
  608. +
  609. +/**
  610. + *
  611. + * @author Stan Silvert
  612. + * @since 1.0
  613. + */
  614. +@ManagedBean(name="requestBean")
  615. +@RequestScoped
  616. +public class RequestScopeBean extends ScopeAwareBean
  617. +{
  618. +    
  619. +}
  620. Index: examples/junit/src/main/resources/jsf/index.xhtml
  621. ===================================================================
  622. --- examples/junit/src/main/resources/jsf/index.xhtml   (revision 0)
  623. +++ examples/junit/src/main/resources/jsf/index.xhtml   (revision 0)
  624. @@ -0,0 +1,18 @@
  625. +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  626. +<html xmlns="http://www.w3.org/1999/xhtml"
  627. +      xmlns:h="http://java.sun.com/jsf/html"
  628. +      xmlns:f="http://java.sun.com/jsf/core">
  629. +<body>
  630. +  
  631. +   <center>
  632. +     <f:view>
  633. +        <h2><h:outputText value="JSF2 Sample Application"/></h2>
  634. +        <h3><h:outputText value="Test Managed Bean Annotations"/></h3>
  635. +        <h:outputText value="requestBean.scope = #{requestBean.scope}"/><br/>
  636. +        <h3><h:outputText value="Test Project Stage"/></h3>
  637. +        <h:outputText value="project stage = #{facesContext.application.projectStage}"/>
  638. +     </f:view>
  639. +    
  640. +   </center>
  641. +</body>
  642. +</html>
  643. Index: examples/junit/src/main/resources/jsf/faces-config.xml
  644. ===================================================================
  645. --- examples/junit/src/main/resources/jsf/faces-config.xml  (revision 0)
  646. +++ examples/junit/src/main/resources/jsf/faces-config.xml  (revision 0)
  647. @@ -0,0 +1,32 @@
  648. +<?xml version="1.0"?>
  649. +
  650. + <!--
  651. + * JBoss, Home of Professional Open Source.
  652. + * Copyright 2007, Red Hat Middleware LLC, and individual contributors
  653. + * as indicated by the @author tags. See the copyright.txt file in the
  654. + * distribution for a full listing of individual contributors.
  655. + *
  656. + * This is free software; you can redistribute it and/or modify it
  657. + * under the terms of the GNU Lesser General Public License as
  658. + * published by the Free Software Foundation; either version 2.1 of
  659. + * the License, or (at your option) any later version.
  660. + *
  661. + * This software is distributed in the hope that it will be useful,
  662. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  663. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  664. + * Lesser General Public License for more details.
  665. + *
  666. + * You should have received a copy of the GNU Lesser General Public
  667. + * License along with this software; if not, write to the Free
  668. + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  669. + * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  670. + -->
  671. +
  672. +<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
  673. +              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  674. +              xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
  675. +                                  http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
  676. +              version="2.0">
  677. +  
  678. +    
  679. +</faces-config>
  680. Index: examples/junit/src/main/resources/jsf/jsf-web.xml
  681. ===================================================================
  682. --- examples/junit/src/main/resources/jsf/jsf-web.xml   (revision 0)
  683. +++ examples/junit/src/main/resources/jsf/jsf-web.xml   (revision 0)
  684. @@ -0,0 +1,29 @@
  685. +<?xml version="1.0"?>
  686. +<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  687. +   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
  688. +   version="3.0">
  689. +
  690. +   <context-param>
  691. +      <param-name>javax.faces.PROJECT_STAGE</param-name>
  692. +      <param-value>Development</param-value>
  693. +   </context-param>
  694. +   <context-param>
  695. +      <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
  696. +      <param-value>.xhtml</param-value>
  697. +   </context-param>
  698. +  
  699. +   <servlet>
  700. +      <servlet-name>Faces Servlet</servlet-name>
  701. +      <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
  702. +      <load-on-startup>1</load-on-startup>
  703. +   </servlet>
  704. +
  705. +   <servlet-mapping>
  706. +      <servlet-name>Faces Servlet</servlet-name>
  707. +      <url-pattern>*.jsf</url-pattern>
  708. +   </servlet-mapping>
  709. +
  710. +   <welcome-file-list>
  711. +      <welcome-file>index.xhtml</welcome-file>
  712. +   </welcome-file-list>
  713. +</web-app>
  714. Index: examples/junit/pom.xml
  715. ===================================================================
  716. --- examples/junit/pom.xml  (revision 4178)
  717. +++ examples/junit/pom.xml  (working copy)
  718. @@ -223,7 +223,23 @@
  719.           <version>${project.version}</version>
  720.        </dependency>
  721.  
  722. +   <!-- JSF Setup TEST -->
  723. +
  724.        <dependency>
  725. +         <groupId>org.jboss.arquillian.framework</groupId>
  726. +         <artifactId>arquillian-framework-jsfunit</artifactId>
  727. +         <version>${project.version}</version>
  728. +      </dependency>
  729. +
  730. +      <dependency>
  731. +         <groupId>javax.faces</groupId>
  732. +         <artifactId>jsf-api</artifactId>
  733. +         <version>2.0.2-FCS</version>
  734. +         <scope>provided</scope>
  735. +      </dependency>
  736. +
  737. +
  738. +      <dependency>
  739.           <groupId>org.jboss.arquillian.example</groupId>
  740.           <artifactId>arquillian-example-domain</artifactId>
  741.           <version>${project.version}</version>
  742. @@ -259,8 +275,14 @@
  743.           <version>1.4.1</version>
  744.           <scope>test</scope>
  745.        </dependency>
  746. -  
  747. +      
  748.        <dependency>
  749. +         <groupId>org.jboss.shrinkwrap</groupId>
  750. +         <artifactId>shrinkwrap-extension-classmanipulation</artifactId>
  751. +         <scope>test</scope>
  752. +      </dependency>
  753. +
  754. +      <dependency>
  755.           <groupId>junit</groupId>
  756.           <artifactId>junit</artifactId>
  757.           <scope>test</scope>
  758. Index: pom.xml
  759. ===================================================================
  760. --- pom.xml (revision 4178)
  761. +++ pom.xml (working copy)
  762. @@ -59,7 +59,9 @@
  763.      <module>containers</module>
  764.  
  765.      <module>examples</module>
  766. -
  767. +  
  768. +   <module>frameworks</module>
  769. +  
  770.      <module>doc/reference</module>
  771.  </modules>
  772.  
  773. Index: examples/junit/pom.xml
  774. ===================================================================
  775. --- examples/junit/pom.xml  (revision 4178)
  776. +++ examples/junit/pom.xml  (working copy)
  777. @@ -223,7 +223,23 @@
  778.           <version>${project.version}</version>
  779.        </dependency>
  780.  
  781. +   <!-- JSF Setup TEST -->
  782. +
  783.        <dependency>
  784. +         <groupId>org.jboss.arquillian.framework</groupId>
  785. +         <artifactId>arquillian-framework-jsfunit</artifactId>
  786. +         <version>${project.version}</version>
  787. +      </dependency>
  788. +
  789. +      <dependency>
  790. +         <groupId>javax.faces</groupId>
  791. +         <artifactId>jsf-api</artifactId>
  792. +         <version>2.0.2-FCS</version>
  793. +         <scope>provided</scope>
  794. +      </dependency>
  795. +
  796. +
  797. +      <dependency>
  798.           <groupId>org.jboss.arquillian.example</groupId>
  799.           <artifactId>arquillian-example-domain</artifactId>
  800.           <version>${project.version}</version>
  801. @@ -259,8 +275,14 @@
  802.           <version>1.4.1</version>
  803.           <scope>test</scope>
  804.        </dependency>
  805. -  
  806. +      
  807.        <dependency>
  808. +         <groupId>org.jboss.shrinkwrap</groupId>
  809. +         <artifactId>shrinkwrap-extension-classmanipulation</artifactId>
  810. +         <scope>test</scope>
  811. +      </dependency>
  812. +
  813. +      <dependency>
  814.           <groupId>junit</groupId>
  815.           <artifactId>junit</artifactId>
  816.           <scope>test</scope>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement