001package org.apache.turbine.services.intake; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import static org.junit.Assert.assertEquals; 023import static org.junit.Assert.assertNotNull; 024import static org.junit.Assert.assertTrue; 025import static org.mockito.Mockito.mock; 026 027import java.io.File; 028 029import javax.servlet.ServletConfig; 030import javax.servlet.http.HttpServletRequest; 031import javax.servlet.http.HttpServletResponse; 032 033import org.apache.fulcrum.intake.IntakeService; 034import org.apache.fulcrum.intake.model.Group; 035import org.apache.fulcrum.parser.DefaultParameterParser; 036import org.apache.turbine.annotation.AnnotationProcessor; 037import org.apache.turbine.services.TurbineServices; 038import org.apache.turbine.services.rundata.RunDataService; 039import org.apache.turbine.test.BaseTestCase; 040import org.apache.turbine.util.RunData; 041import org.apache.turbine.util.TurbineConfig; 042import org.junit.AfterClass; 043import org.junit.Before; 044import org.junit.BeforeClass; 045import org.junit.Test; 046 047/** 048 * Unit test for Intake Tool, wrapping the Fulcrum Intake service. 049 * 050 * @author <a href="mailto:epugh@upstate.com">Eric Pugh</a> 051 * @version $Id: IntakeToolTest.java 1754909 2016-08-02 12:55:35Z tv $ 052 */ 053public class IntakeToolTest extends BaseTestCase 054{ 055 private static TurbineConfig tc = null; 056 private IntakeTool intakeTool; 057 058 @Before 059 public void initTool() throws Exception 060 { 061 intakeTool = new IntakeTool(); 062 AnnotationProcessor.process(intakeTool); 063 intakeTool.init(getRunData()); 064 } 065 066 @Test 067 public void testGet() throws Exception 068 { 069 File file = new File("./target/appData.ser"); 070 assertTrue("Make sure serialized data file exists:" + file, file.exists()); 071 Group group = intakeTool.get("LoginGroup", "loginGroupKey"); 072 assertNotNull(group); 073 assertEquals("loginGroupKey", group.getGID()); 074 assertEquals("LoginGroup", group.getIntakeGroupName()); 075 } 076 077 /** 078 * Make sure refresh DOESN'T do anything 079 * 080 * @throws Exception 081 */ 082 @Test 083 public void testRefresh() throws Exception 084 { 085 int numberOfGroups = intakeTool.getGroups().size(); 086 intakeTool.refresh(); 087 assertEquals(numberOfGroups, intakeTool.getGroups().size()); 088 } 089 090 private RunData getRunData() throws Exception 091 { 092 RunDataService rds = (RunDataService) TurbineServices.getInstance().getService(RunDataService.SERVICE_NAME); 093 ServletConfig config = mock(ServletConfig.class); 094 HttpServletRequest request = getMockRequest(); 095 HttpServletResponse response = mock(HttpServletResponse.class); 096 RunData runData = rds.getRunData(request, response, config); 097 assertEquals("Verify we are using Fulcrum parameter parser", DefaultParameterParser.class, runData.getParameters() 098 .getClass()); 099 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}