View Javadoc
1   package org.apache.turbine.services.intake;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import static org.junit.Assert.assertEquals;
23  import static org.junit.Assert.assertNotNull;
24  import static org.junit.Assert.assertTrue;
25  import static org.mockito.Mockito.mock;
26  
27  import java.io.File;
28  
29  import javax.servlet.ServletConfig;
30  import javax.servlet.http.HttpServletRequest;
31  import javax.servlet.http.HttpServletResponse;
32  
33  import org.apache.fulcrum.intake.IntakeService;
34  import org.apache.fulcrum.intake.model.Group;
35  import org.apache.fulcrum.parser.DefaultParameterParser;
36  import org.apache.turbine.annotation.AnnotationProcessor;
37  import org.apache.turbine.services.TurbineServices;
38  import org.apache.turbine.services.rundata.RunDataService;
39  import org.apache.turbine.test.BaseTestCase;
40  import org.apache.turbine.util.RunData;
41  import org.apache.turbine.util.TurbineConfig;
42  import org.junit.AfterClass;
43  import org.junit.Before;
44  import org.junit.BeforeClass;
45  import org.junit.Test;
46  
47  /**
48   * Unit test for Intake Tool, wrapping the Fulcrum Intake service.
49   *
50   * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a>
51   * @version $Id: IntakeToolTest.java 1754909 2016-08-02 12:55:35Z tv $
52   */
53  public class IntakeToolTest extends BaseTestCase
54  {
55      private static TurbineConfig tc = null;
56      private IntakeTool intakeTool;
57  
58      @Before
59      public void initTool() throws Exception
60      {
61          intakeTool = new IntakeTool();
62          AnnotationProcessor.process(intakeTool);
63          intakeTool.init(getRunData());
64      }
65  
66      @Test
67      public void testGet() throws Exception
68      {
69          File file = new File("./target/appData.ser");
70          assertTrue("Make sure serialized data file exists:" + file, file.exists());
71          Group group = intakeTool.get("LoginGroup", "loginGroupKey");
72          assertNotNull(group);
73          assertEquals("loginGroupKey", group.getGID());
74          assertEquals("LoginGroup", group.getIntakeGroupName());
75      }
76  
77      /**
78       * Make sure refresh DOESN'T do anything
79       *
80       * @throws Exception
81       */
82      @Test
83      public void testRefresh() throws Exception
84      {
85          int numberOfGroups = intakeTool.getGroups().size();
86          intakeTool.refresh();
87          assertEquals(numberOfGroups, intakeTool.getGroups().size());
88      }
89  
90      private RunData getRunData() throws Exception
91      {
92          RunDataService rds = (RunDataService) TurbineServices.getInstance().getService(RunDataService.SERVICE_NAME);
93          ServletConfig config = mock(ServletConfig.class);
94          HttpServletRequest request = getMockRequest();
95          HttpServletResponse response = mock(HttpServletResponse.class);
96          RunData runData = rds.getRunData(request, response, config);
97          assertEquals("Verify we are using Fulcrum parameter parser", DefaultParameterParser.class, runData.getParameters()
98              .getClass());
99          return runData;
100     }
101 
102     @BeforeClass
103     public static void setUp() throws Exception
104     {
105         tc = new TurbineConfig(".", "/conf/test/TestFulcrumComponents.properties");
106         tc.initialize();
107         TurbineServices.getInstance().getService(IntakeService.class.getName());
108     }
109 
110     @AfterClass
111     public static void tearDown() throws Exception
112     {
113         if (tc != null)
114         {
115             tc.dispose();
116         }
117     }
118 }