You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by gk...@apache.org on 2008/01/15 02:19:31 UTC

svn commit: r611986 - in /cocoon/trunk/core/cocoon-servlet-service: cocoon-servlet-service-components/ cocoon-servlet-service-components/src/ cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/components/ cocoon-servlet-se...

Author: gkossakowski
Date: Mon Jan 14 17:19:28 2008
New Revision: 611986

URL: http://svn.apache.org/viewvc?rev=611986&view=rev
Log:
COCOON-2161: Fixed bug in creation of absolute URI and added test case covering this functionality.

Added:
    cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/test/
    cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/test/java/
    cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/test/java/org/
    cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/test/java/org/apache/
    cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/test/java/org/apache/cocoon/
    cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/test/java/org/apache/cocoon/servletservice/
    cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/test/java/org/apache/cocoon/servletservice/AbsoluteServletConnectionTestCase.java   (with props)
    cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/test/java/org/apache/cocoon/servletservice/MockServlet.java   (with props)
Modified:
    cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/pom.xml
    cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/   (props changed)
    cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/components/ServletSource.java
    cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/AbsoluteServletConnection.java

Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/pom.xml
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/pom.xml?rev=611986&r1=611985&r2=611986&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/pom.xml (original)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/pom.xml Mon Jan 14 17:19:28 2008
@@ -71,6 +71,24 @@
       <artifactId>servlet-api</artifactId>
       <scope>provided</scope>
     </dependency>
+    <!-- test -->
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.cocoon</groupId>
+      <artifactId>cocoon-core</artifactId>
+      <type>test-jar</type>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.cocoon</groupId>
+      <artifactId>cocoon-sitemap-impl</artifactId>
+      <type>test-jar</type>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
   
   <build>

Propchange: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Mon Jan 14 17:19:28 2008
@@ -1 +1 @@
-site
+site

Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/components/ServletSource.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/components/ServletSource.java?rev=611986&r1=611985&r2=611986&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/components/ServletSource.java (original)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/components/ServletSource.java Mon Jan 14 17:19:28 2008
@@ -107,6 +107,10 @@
     private ServletConnection createServletConnection(String location) throws MalformedURLException {
         URI locationUri = null;
         try {
+            if (logger.isDebugEnabled()) {
+                logger.debug("Trying to create a servlet connection for location " + location);
+            }
+            
             locationUri = new URI(location);
             if (!locationUri.isAbsolute()) {
                 throw new MalformedURLException("Only absolute URIs are allowed for the block protocol. "

Added: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/test/java/org/apache/cocoon/servletservice/AbsoluteServletConnectionTestCase.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/test/java/org/apache/cocoon/servletservice/AbsoluteServletConnectionTestCase.java?rev=611986&view=auto
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/test/java/org/apache/cocoon/servletservice/AbsoluteServletConnectionTestCase.java (added)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/test/java/org/apache/cocoon/servletservice/AbsoluteServletConnectionTestCase.java Mon Jan 14 17:19:28 2008
@@ -0,0 +1,59 @@
+/*
+ * 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.
+ */
+package org.apache.cocoon.servletservice;
+
+import java.net.URI;
+
+import org.apache.avalon.framework.configuration.DefaultConfiguration;
+import org.apache.cocoon.callstack.CallStack;
+import org.apache.cocoon.callstack.environment.CallFrameHelper;
+import org.apache.cocoon.core.container.ContainerTestCase;
+import org.apache.cocoon.core.container.spring.avalon.ComponentInfo;
+import org.apache.cocoon.core.container.spring.avalon.ConfigurationInfo;
+
+public class AbsoluteServletConnectionTestCase extends ContainerTestCase {
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        CallStack.enter();
+        CallStack.getCurrentFrame().setAttribute(CallStackHelper.SUPER_CALL, new Boolean(false));
+        CallFrameHelper.setContext(getContext());
+        new MockServlet();
+    }
+    
+    protected void addComponents(ConfigurationInfo info) throws Exception {
+        super.addComponents(info);
+        //Add MockServlet bean
+        ComponentInfo componentInfo = new ComponentInfo();
+        componentInfo.setComponentClassName(MockServlet.class.getName());
+        componentInfo.setRole(MockServlet.beanId);
+        componentInfo.setConfiguration(new DefaultConfiguration("-"));
+        info.addComponent(componentInfo);
+    }
+    
+    /**
+     * Tests if absolute URI conforms our definition of absolute URI when servlet protocol is used.
+     * Test for COCOON-2161.
+     */
+    public void testURI() throws Exception {
+        String path = "/path";
+        AbsoluteServletConnection connection = new AbsoluteServletConnection(MockServlet.beanId, path, null);
+        URI uri = new URI(MockServlet.beanId + AbsoluteServletConnection.ABSOLUTE_SERVLET_SOURCE_POSTFIX, null, path, null, null);
+        uri = new URI("servlet", uri.toASCIIString(), null);
+        assertEquals("Check if absolute URI is constructed properly", uri, connection.getURI());
+    }
+}

Propchange: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/test/java/org/apache/cocoon/servletservice/AbsoluteServletConnectionTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/test/java/org/apache/cocoon/servletservice/MockServlet.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/test/java/org/apache/cocoon/servletservice/MockServlet.java?rev=611986&view=auto
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/test/java/org/apache/cocoon/servletservice/MockServlet.java (added)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/test/java/org/apache/cocoon/servletservice/MockServlet.java Mon Jan 14 17:19:28 2008
@@ -0,0 +1,26 @@
+/*
+ * 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.
+ */
+package org.apache.cocoon.servletservice;
+
+import javax.servlet.http.HttpServlet;
+
+public class MockServlet extends HttpServlet {
+
+    static final String beanId = "test.servlet";
+
+    public MockServlet() { }
+}

Propchange: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-components/src/test/java/org/apache/cocoon/servletservice/MockServlet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/AbsoluteServletConnection.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/AbsoluteServletConnection.java?rev=611986&r1=611985&r2=611986&view=diff
==============================================================================
--- cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/AbsoluteServletConnection.java (original)
+++ cocoon/trunk/core/cocoon-servlet-service/cocoon-servlet-service-impl/src/main/java/org/apache/cocoon/servletservice/AbsoluteServletConnection.java Mon Jan 14 17:19:28 2008
@@ -67,7 +67,7 @@
 
         URI reqUri = null;
         try {
-            this.uri = new URI(serviceName, null, path, queryString, null);
+            this.uri = new URI(serviceName  + ABSOLUTE_SERVLET_SOURCE_POSTFIX, null, path, queryString, null);
             this.uri = new URI("servlet", this.uri.toASCIIString(), null);
             reqUri = new URI("servlet", null, path, queryString, null);
         } catch (URISyntaxException e) {



Re: Integration tests

Posted by Reinhard Poetz <re...@apache.org>.
Grzegorz Kossakowski wrote:
> Reinhard Poetz pisze:
>> Grzegorz Kossakowski wrote:
>>> gkossakowski@apache.org pisze:
>>>
>>> I'm not sure how to say this but... Guys, there is a lot of to cover
>>> by test
>>> in this module and writing tests in trunk is not painful by any means.
>> you are right and this particular bug was my fault because I haven't
>> written any
>> tests yet. However, if you followed my commit messages, you saw that I
>> was able
>> to enable integration tests for trunk ('mvn install -P it' from
>> cocoon-webapp runs the tests in cocoon-webapp/src/test/java). My next
>> step on my todo list is covering the SSF with tests.
> 
> Yes I was very happy to see your commits. However, I always thought that it's first that you write
> unit tests for covering the most basic functionality and ITs for testing how different parts
> interact with each other.
> 
> Doesn't it make sense to write a few unit tests first? What kind of ITs do you plan to write?
> 
>> Could somebody with admin rights on vmbuild help me with adding the
>> integration tests to Continuum?
> 
> Sure, tell what command exactly is needed to be fired. Is mvn clean install -P allbocks,it enough?
> 


-- 
Reinhard Pötz                            Managing Director, {Indoqa} GmbH
                           http://www.indoqa.com/en/people/reinhard.poetz/

Member of the Apache Software Foundation
Apache Cocoon Committer, PMC member, PMC Chair        reinhard@apache.org
_________________________________________________________________________

Re: Integration tests

Posted by Bertrand Delacretaz <bd...@apache.org>.
On Jan 15, 2008 9:44 PM, Reinhard Poetz <re...@apache.org> wrote:
> Grzegorz Kossakowski wrote:
> > ...I
> > guess it should be always easier to write isolated unit tests than ITs. Am I
> > wrong?
>
> hmmm, it depends. Integration tests for Cocoon have always been tests at
> HTTP/XHTML level....

Might be just a question of terminology. When you're creating an HTTP
servlet, it is not really usable outside of an HTTP environment.

So (and test purists might hate me for saying that ;-), one could
argue that testing servlets via HTTP is actually a unit test. It's
just that it happens over HTTP instead of being just java method
calls.

-Bertrand

Re: Integration tests

Posted by Reinhard Poetz <re...@apache.org>.
Grzegorz Kossakowski wrote:
> Reinhard Poetz pisze:
>> Grzegorz Kossakowski wrote:
>>> Reinhard Poetz pisze:
>>> 
>>> Yes I was very happy to see your commits. However, I always thought that
>>> it's first that you write unit tests for covering the most basic 
>>> functionality and ITs for testing how different parts interact with each
>>> other.
>>> 
>>> Doesn't it make sense to write a few unit tests first?
>> :-) yes, I fully agree. However, I wanted to explore the code by writing 
>> unit tests but I failed. Maybe I invested to less time but I came to the 
>> conclustion that it is easier to write integration tests.
> 
> I don't understand what you mean exactly. Do you mean it was too complicated
> to write unit tests? I haven't taken a closer look at your IT work but I
> guess it should be always easier to write isolated unit tests than ITs. Am I
> wrong?

hmmm, it depends. Integration tests for Cocoon have always been tests at 
HTTP/XHTML level. The only difficult part is setting up the environment. 
Everything else is checking if an http call produces the right output which is 
fairly easy using XPath asserts or XMLDiff.

>>> What kind of ITs do you plan to write?
>> I want to test ... o absolute and relative connections to servlet services 
>> o connecting to blocks using the servlet:/ protocol o super connections o
>> accessing information coming from the original request o error handling o
>> postable sources o servlet-service generator/transformer/serializer
> 
> I don't want to be pesky but... most of these items looks like perfect cases
> for unit tests. Don't they?
> 
> I'm not feeling good about testing basic functionality by using ITs because
> it introduces too much dependencies, IMHO. 

What kind of dependencies?

> It was Daniel who taught me how to
> keep number of dependencies in tests as small as possible. He was endlessly
> reminding me when I was working during GSoC to use classes inheriting from
> pure TestCase and now I see he was perfectly right.
> 
> Tests are normal code, the more complicated dependencies you introduce the
> more it's hard to maintain such code...

My problem is that the time that I can dedicate to this task is very limited and 
I fear that if it gets too complicated (for me) or time-consuming I won't do it.

>>> Sure, tell what command exactly is needed to be fired. Is mvn clean 
>>> install -P allbocks,it enough?
>> yes
> 
> Configuration at Continuum updated.

Thanks!

-- 
Reinhard Pötz                            Managing Director, {Indoqa} GmbH
                           http://www.indoqa.com/en/people/reinhard.poetz/

Member of the Apache Software Foundation
Apache Cocoon Committer, PMC member, PMC Chair        reinhard@apache.org
_________________________________________________________________________

Re: Integration tests

Posted by Grzegorz Kossakowski <gk...@apache.org>.
Reinhard Poetz pisze:
> Grzegorz Kossakowski wrote:
>> Reinhard Poetz pisze:
>>
>> Yes I was very happy to see your commits. However, I always thought
>> that it's
>> first that you write unit tests for covering the most basic
>> functionality and
>> ITs for testing how different parts interact with each other.
>>
>> Doesn't it make sense to write a few unit tests first? 
> 
> :-) yes, I fully agree. However, I wanted to explore the code by writing
> unit tests but I failed. Maybe I invested to less time but I came to the
> conclustion that it is easier to write integration tests.

I don't understand what you mean exactly. Do you mean it was too complicated to write unit tests? I
haven't taken a closer look at your IT work but I guess it should be always easier to write isolated
unit tests than ITs. Am I wrong?

>> What kind of ITs do you plan to write?
> 
> I want to test ...
>  o absolute and relative connections to servlet services
>  o connecting to blocks using the servlet:/ protocol
>  o super connections
>  o accessing information coming from the original request
>  o error handling
>  o postable sources
>  o servlet-service generator/transformer/serializer

I don't want to be pesky but... most of these items looks like perfect cases for unit tests. Don't they?

I'm not feeling good about testing basic functionality by using ITs because it introduces too much
dependencies, IMHO. It was Daniel who taught me how to keep number of dependencies in tests as small
as possible. He was endlessly reminding me when I was working during GSoC to use classes inheriting
from pure TestCase and now I see he was perfectly right.

Tests are normal code, the more complicated dependencies you introduce the more it's hard to
maintain such code...

>>
>> Sure, tell what command exactly is needed to be fired. Is mvn clean
>> install
>> -P allbocks,it enough?
> 
> yes

Configuration at Continuum updated.

-- 
Grzegorz Kossakowski
Committer and PMC Member of Apache Cocoon
http://reflectingonthevicissitudes.wordpress.com/

Re: Integration tests

Posted by Reinhard Poetz <re...@apache.org>.
Grzegorz Kossakowski wrote:
> Reinhard Poetz pisze:
>> Grzegorz Kossakowski wrote:
>>> gkossakowski@apache.org pisze:
>>> 
>>> I'm not sure how to say this but... Guys, there is a lot of to cover by
>>> test in this module and writing tests in trunk is not painful by any
>>> means.
>> you are right and this particular bug was my fault because I haven't 
>> written any tests yet. However, if you followed my commit messages, you saw
>> that I was able to enable integration tests for trunk ('mvn install -P it'
>> from cocoon-webapp runs the tests in cocoon-webapp/src/test/java). My next 
>> step on my todo list is covering the SSF with tests.
> 
> Yes I was very happy to see your commits. However, I always thought that it's
> first that you write unit tests for covering the most basic functionality and
> ITs for testing how different parts interact with each other.
> 
> Doesn't it make sense to write a few unit tests first? 

:-) yes, I fully agree. However, I wanted to explore the code by writing unit 
tests but I failed. Maybe I invested to less time but I came to the conclustion 
that it is easier to write integration tests.

> What kind of ITs do you plan to write?

I want to test ...
  o absolute and relative connections to servlet services
  o connecting to blocks using the servlet:/ protocol
  o super connections
  o accessing information coming from the original request
  o error handling
  o postable sources
  o servlet-service generator/transformer/serializer

>> Could somebody with admin rights on vmbuild help me with adding the 
>> integration tests to Continuum?
> 
> Sure, tell what command exactly is needed to be fired. Is mvn clean install
> -P allbocks,it enough?

yes

-- 
Reinhard Pötz                            Managing Director, {Indoqa} GmbH
                           http://www.indoqa.com/en/people/reinhard.poetz/

Member of the Apache Software Foundation
Apache Cocoon Committer, PMC member, PMC Chair        reinhard@apache.org
_________________________________________________________________________

Re: Integration tests

Posted by Grzegorz Kossakowski <gk...@apache.org>.
Reinhard Poetz pisze:
> Grzegorz Kossakowski wrote:
>> gkossakowski@apache.org pisze:
>>
>> I'm not sure how to say this but... Guys, there is a lot of to cover
>> by test
>> in this module and writing tests in trunk is not painful by any means.
> 
> you are right and this particular bug was my fault because I haven't
> written any
> tests yet. However, if you followed my commit messages, you saw that I
> was able
> to enable integration tests for trunk ('mvn install -P it' from
> cocoon-webapp runs the tests in cocoon-webapp/src/test/java). My next
> step on my todo list is covering the SSF with tests.

Yes I was very happy to see your commits. However, I always thought that it's first that you write
unit tests for covering the most basic functionality and ITs for testing how different parts
interact with each other.

Doesn't it make sense to write a few unit tests first? What kind of ITs do you plan to write?

> Could somebody with admin rights on vmbuild help me with adding the
> integration tests to Continuum?

Sure, tell what command exactly is needed to be fired. Is mvn clean install -P allbocks,it enough?

-- 
Grzegorz Kossakowski
Committer and PMC Member of Apache Cocoon
http://reflectingonthevicissitudes.wordpress.com/

Integration tests

Posted by Reinhard Poetz <re...@apache.org>.
Grzegorz Kossakowski wrote:
> gkossakowski@apache.org pisze:
>> Author: gkossakowski Date: Mon Jan 14 17:19:28 2008 New Revision: 611986
>> 
>> URL: http://svn.apache.org/viewvc?rev=611986&view=rev Log: COCOON-2161:
>> Fixed bug in creation of absolute URI and added test case covering this
>> functionality.
> 
> I'm not sure how to say this but... Guys, there is a lot of to cover by test
> in this module and writing tests in trunk is not painful by any means.

you are right and this particular bug was my fault because I haven't written any
tests yet. However, if you followed my commit messages, you saw that I was able
to enable integration tests for trunk ('mvn install -P it' from
cocoon-webapp runs the tests in cocoon-webapp/src/test/java). My next step on my 
todo list is covering the SSF with tests.

Could somebody with admin rights on vmbuild help me with adding the integration 
tests to Continuum?

-- 
Reinhard Pötz                            Managing Director, {Indoqa} GmbH
                           http://www.indoqa.com/en/people/reinhard.poetz/

Member of the Apache Software Foundation
Apache Cocoon Committer, PMC member, PMC Chair        reinhard@apache.org
_________________________________________________________________________

Re: svn commit: r611986 - in /cocoon/trunk/core/cocoon-servlet-service: cocoon-servlet-service-components/ cocoon-servlet-service-components/src/ cocoon-servlet-service-components/src/main/java/org/apache/cocoon/servletservice/components/ cocoon-servlet-se...

Posted by Grzegorz Kossakowski <gk...@apache.org>.
gkossakowski@apache.org pisze:
> Author: gkossakowski
> Date: Mon Jan 14 17:19:28 2008
> New Revision: 611986
> 
> URL: http://svn.apache.org/viewvc?rev=611986&view=rev
> Log:
> COCOON-2161: Fixed bug in creation of absolute URI and added test case covering this functionality.

I'm not sure how to say this but... Guys, there is a lot of to cover by test in this module and
writing tests in trunk is not painful by any means.

This bug clearly positively proves we need to have strong test-coverage for
cocoon-servlet-service-components as it actually impacts every bit of Cocoon.

-- 
Grzegorz Kossakowski
Committer and PMC Member of Apache Cocoon
http://reflectingonthevicissitudes.wordpress.com/