You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@turbine.apache.org by pa...@apache.org on 2019/01/17 15:22:49 UTC
svn commit: r1851538 - in
/turbine/fulcrum/trunk/parser/src/test/org/apache/fulcrum/parser/pool: ./
BaseValueParserPoolTest.java CookieParserPoolTest.java
ParameterParserPoolTest.java
Author: painter
Date: Thu Jan 17 15:22:49 2019
New Revision: 1851538
URL: http://svn.apache.org/viewvc?rev=1851538&view=rev
Log:
Unit tests
Added:
turbine/fulcrum/trunk/parser/src/test/org/apache/fulcrum/parser/pool/
turbine/fulcrum/trunk/parser/src/test/org/apache/fulcrum/parser/pool/BaseValueParserPoolTest.java
turbine/fulcrum/trunk/parser/src/test/org/apache/fulcrum/parser/pool/CookieParserPoolTest.java
turbine/fulcrum/trunk/parser/src/test/org/apache/fulcrum/parser/pool/ParameterParserPoolTest.java
Added: turbine/fulcrum/trunk/parser/src/test/org/apache/fulcrum/parser/pool/BaseValueParserPoolTest.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/parser/src/test/org/apache/fulcrum/parser/pool/BaseValueParserPoolTest.java?rev=1851538&view=auto
==============================================================================
--- turbine/fulcrum/trunk/parser/src/test/org/apache/fulcrum/parser/pool/BaseValueParserPoolTest.java (added)
+++ turbine/fulcrum/trunk/parser/src/test/org/apache/fulcrum/parser/pool/BaseValueParserPoolTest.java Thu Jan 17 15:22:49 2019
@@ -0,0 +1,123 @@
+package org.apache.fulcrum.parser.pool;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+
+import org.apache.avalon.framework.component.ComponentException;
+import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
+import org.apache.fulcrum.parser.BaseValueParser;
+import org.apache.fulcrum.parser.ParserService;
+import org.apache.fulcrum.testcontainer.BaseUnit5Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+
+/**
+ * Test the BaseValueParserFactory and BaseValueParserPool classes.
+ *
+ * @author <a href="mailto:painter@apache.org">Jeffery Painter</a>
+ * @version $Id: BaseValueParserPoolTest.java 222043 2019-01-17 08:17:33Z painter $
+ */
+public class BaseValueParserPoolTest extends BaseUnit5Test
+{
+
+ private BaseValueParser parser;
+ private ParserService parserService;
+
+ /**
+ * Use commons pool to manage value parsers
+ */
+ private BaseValueParserPool valueParserPool;
+
+
+ /**
+ * Performs any initialization that must happen before each test is run.
+ * @throws Exception if parser service not found
+ */
+ @BeforeEach
+ public void setUp() throws Exception
+ {
+ try
+ {
+ parserService = (ParserService)this.lookup(ParserService.ROLE);
+
+ // Define the default configuration
+ GenericObjectPoolConfig config = new GenericObjectPoolConfig();
+ config.setMaxIdle(1);
+ config.setMaxTotal(1);
+
+ // init the pool
+ valueParserPool
+ = new BaseValueParserPool(new BaseValueParserFactory(), config);
+
+ }
+ catch (ComponentException e)
+ {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ /**
+ * Clean up after each test is run.
+ */
+ @AfterEach
+ public void tearDown()
+ {
+ parserService.putParser(parser);
+ this.release(parserService);
+ }
+
+ /**
+ * @throws Exception generic exception
+ */
+ @Test
+ public void testFactoryMethods() throws Exception
+ {
+
+ try
+ {
+ // borrow a new parser and assign it to the parser service
+ parser = valueParserPool.borrowObject();
+ parser.setParserService(parserService);
+
+ // test adding parameters
+ parser.add("test1", "val1");
+ assertEquals(parser.get("test1"), "val1");
+
+ // clear the parser for reset
+ parser.clear();
+ assertTrue(parser.isValid());
+
+ valueParserPool.returnObject( parser );
+
+ } catch ( Exception e )
+ {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+
+
+ }
+
+}
Added: turbine/fulcrum/trunk/parser/src/test/org/apache/fulcrum/parser/pool/CookieParserPoolTest.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/parser/src/test/org/apache/fulcrum/parser/pool/CookieParserPoolTest.java?rev=1851538&view=auto
==============================================================================
--- turbine/fulcrum/trunk/parser/src/test/org/apache/fulcrum/parser/pool/CookieParserPoolTest.java (added)
+++ turbine/fulcrum/trunk/parser/src/test/org/apache/fulcrum/parser/pool/CookieParserPoolTest.java Thu Jan 17 15:22:49 2019
@@ -0,0 +1,110 @@
+package org.apache.fulcrum.parser.pool;
+
+
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+import static org.mockito.Mockito.mock;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.avalon.framework.component.ComponentException;
+import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
+import org.apache.fulcrum.parser.DefaultCookieParser;
+import org.apache.fulcrum.parser.ParserService;
+import org.apache.fulcrum.testcontainer.BaseUnit5Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+
+
+/**
+ * Test the CookieParserFactory and CookieParserPool classes.
+ *
+ * @author <a href="mailto:painter@apache.org">Jeffery Painter</a>
+ * @version $Id: CookieParserPoolTest.java 222043 2019-01-17 08:17:33Z painter $
+ */
+public class CookieParserPoolTest extends BaseUnit5Test
+{
+ private DefaultCookieParser parser;
+ private ParserService parserService;
+
+ /**
+ * Use commons pool to manage value parsers
+ */
+ private CookieParserPool cookieParserPool;
+
+ /**
+ * Performs any initialization that must happen before each test is run.
+ * @throws Exception if parser service not found
+ */
+ @BeforeEach
+ public void setUp() throws Exception
+ {
+ try
+ {
+ parserService = (ParserService)this.lookup(ParserService.ROLE);
+
+
+ // Define the default configuration
+ GenericObjectPoolConfig config = new GenericObjectPoolConfig();
+ config.setMaxIdle(1);
+ config.setMaxTotal(1);
+
+ // init the pool
+ cookieParserPool
+ = new CookieParserPool(new CookieParserFactory(), config);
+
+ }
+ catch (ComponentException e)
+ {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ /**
+ * Clean up after each test is run.
+ */
+ @AfterEach
+ public void tearDown()
+ {
+ parserService.putParser(parser);
+ this.release(parserService);
+ }
+
+ /**
+ * @throws Exception generic exception
+ */
+ @Test
+ public void testFactoryMethods() throws Exception
+ {
+ try
+ {
+ // borrow a new parser and assign it to the parser service
+ parser = cookieParserPool.borrowObject();
+ parser.setParserService(parserService);
+
+ // Populate parser with mock servlet data
+ HttpServletRequest request = getMockRequest();
+ HttpServletResponse response = mock(HttpServletResponse.class);
+ parser.setData(request, response);
+
+ // test setting cookies
+ parser.set("test1", "val1");
+
+ // clear the parser for reset
+ parser.clear();
+ assertTrue(parser.isValid());
+
+ cookieParserPool.returnObject( parser );
+
+ } catch ( Exception e )
+ {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+}
Added: turbine/fulcrum/trunk/parser/src/test/org/apache/fulcrum/parser/pool/ParameterParserPoolTest.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/parser/src/test/org/apache/fulcrum/parser/pool/ParameterParserPoolTest.java?rev=1851538&view=auto
==============================================================================
--- turbine/fulcrum/trunk/parser/src/test/org/apache/fulcrum/parser/pool/ParameterParserPoolTest.java (added)
+++ turbine/fulcrum/trunk/parser/src/test/org/apache/fulcrum/parser/pool/ParameterParserPoolTest.java Thu Jan 17 15:22:49 2019
@@ -0,0 +1,120 @@
+package org.apache.fulcrum.parser.pool;
+
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+
+import org.apache.avalon.framework.component.ComponentException;
+import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
+import org.apache.fulcrum.parser.DefaultParameterParser;
+import org.apache.fulcrum.parser.ParserService;
+import org.apache.fulcrum.testcontainer.BaseUnit5Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+
+/**
+ * Test the DefaultParameterParserFactory and DefaultParameterParserPool classes.
+ *
+ * @author <a href="mailto:painter@apache.org">Jeffery Painter</a>
+ * @version $Id: ParameterParserPoolTest.java 222043 2019-01-17 08:17:33Z painter $
+ */
+public class ParameterParserPoolTest extends BaseUnit5Test
+{
+ private DefaultParameterParser parser;
+ private ParserService parserService;
+
+ /**
+ * Use commons pool to manage parameter parsers
+ */
+ private DefaultParameterParserPool parameterParserPool;
+
+ /**
+ * Performs any initialization that must happen before each test is run.
+ * @throws Exception if parser service not found
+ */
+ @BeforeEach
+ public void setUp() throws Exception
+ {
+ try
+ {
+ parserService = (ParserService)this.lookup(ParserService.ROLE);
+
+ // Define the default configuration
+ GenericObjectPoolConfig config = new GenericObjectPoolConfig();
+ config.setMaxIdle(1);
+ config.setMaxTotal(1);
+
+ // init the pool
+ parameterParserPool
+ = new DefaultParameterParserPool(new DefaultParameterParserFactory(), config);;
+
+ }
+ catch (ComponentException e)
+ {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+ /**
+ * Clean up after each test is run.
+ */
+ @AfterEach
+ public void tearDown()
+ {
+ parserService.putParser(parser);
+ this.release(parserService);
+ }
+
+ /**
+ * @throws Exception generic exception
+ */
+ @Test
+ public void testFactoryMethods() throws Exception
+ {
+ try
+ {
+ // borrow a new parser and assign it to the parser service
+ parser = parameterParserPool.borrowObject();
+ parser.setParserService(parserService);
+
+ // test adding parameters
+ parser.add("test1", "val1");
+ assertEquals(parser.get("test1"), "val1");
+
+ // clear the parser for reset
+ parser.clear();
+ assertTrue(parser.isValid());
+
+ parameterParserPool.returnObject( parser );
+
+ } catch ( Exception e )
+ {
+ e.printStackTrace();
+ fail(e.getMessage());
+ }
+ }
+
+}