View Javadoc
1   /*
2    * JBoss, Home of Professional Open Source
3    * Copyright 2014, Red Hat, Inc. and/or its affiliates, and individual
4    * contributors by the @authors tag. See the copyright.txt in the
5    * distribution for a full listing of individual contributors.
6    *
7    * Licensed under the Apache License, Version 2.0 (the "License");
8    * you may not use this file except in compliance with the License.
9    * You may obtain a copy of the License at
10   * http://www.apache.org/licenses/LICENSE-2.0
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.jboss.as.quickstarts.tasksJsf;
18  
19  import static org.junit.Assert.assertNotNull;
20  import static org.junit.Assert.assertNull;
21  import static org.junit.Assert.assertTrue;
22  
23  import java.io.FileNotFoundException;
24  import java.util.logging.Level;
25  import java.util.logging.Logger;
26  
27  import javax.enterprise.inject.Instance;
28  import javax.faces.context.FacesContext;
29  import javax.inject.Inject;
30  
31  import org.jboss.arquillian.container.test.api.Deployment;
32  import org.jboss.arquillian.junit.Arquillian;
33  import org.jboss.shrinkwrap.api.spec.WebArchive;
34  import org.junit.Test;
35  import org.junit.runner.RunWith;
36  
37  /**
38   * @author Lukas Fryc
39   */
40  @RunWith(Arquillian.class)
41  public class ResourcesTest {
42  
43      public static final String WEBAPP_SRC = "src/main/webapp";
44  
45      @Deployment
46      public static WebArchive deployment() throws IllegalArgumentException, FileNotFoundException {
47          return new DefaultDeployment().withPersistence().withFaces().getArchive()
48                  .addClasses(Resources.class, FacesContextStub.class);
49      }
50  
51      @Inject
52      private Instance<FacesContext> facesContextInstance;
53  
54      @Inject
55      private Instance<Logger> loggerInstance;
56  
57      @Test
58      public void facesContext_should_be_provided_from_current_context() {
59          FacesContextStub.setCurrentInstance(new FacesContextStub("stub"));
60  
61          FacesContext facesContext = facesContextInstance.get();
62          assertNotNull(facesContext);
63          assertTrue(facesContext instanceof FacesContextStub);
64  
65          FacesContextStub.setCurrentInstance(null);
66  
67          facesContext = facesContextInstance.get();
68          assertNull(facesContext);
69      }
70  
71      @Test
72      public void logger_should_be_provided_and_be_able_to_log_information_message() {
73          Logger logger = loggerInstance.get();
74          assertNotNull(logger);
75          assertTrue(logger instanceof Logger);
76          logger.log(Level.INFO, "test message");
77      }
78  
79  }