You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-dev@jakarta.apache.org by vm...@apache.org on 2004/03/06 22:01:29 UTC

cvs commit: jakarta-cactus/scratchpad/cactus2/samples/servlet/conf aspectwerkz.xml

vmassol     2004/03/06 13:01:29

  Modified:    scratchpad/cactus2/framework/src/main/org/apache/cactus/framework/internal/orchestrator
                        Orchestrator.java
               scratchpad/cactus2/framework/src/main/org/apache/cactus/framework/internal/orchestrator/handlers
                        GetResultHandler.java SetResultHandler.java
                        GetTestHandler.java SetTestHandler.java
               scratchpad/cactus2/framework/conf aspectwerkz.xml
               scratchpad/cactus2/samples/servlet/conf aspectwerkz.xml
  Added:       scratchpad/cactus2/framework/src/main/org/apache/cactus/framework/internal/orchestrator
                        OrchestratorClient.java
               scratchpad/cactus2/framework/src/main/org/apache/cactus/framework/aspect
                        ClientInterceptionAspect.java
               scratchpad/cactus2/framework/src/test/org/apache/cactus/framework/internal/orchestrator
                        OrchestratorClientTest.java
               scratchpad/cactus2/framework/src/main/org/apache/cactus/framework/internal
                        ClientManager.java
  Removed:     scratchpad/cactus2/framework/src/main/org/apache/cactus/framework/aspect
                        InitializationAspect.java
  Log:
  - Now have a SetTestHandler working
  - Use only 1 aspect to intercept client side because had some issue with AW and different aspects plugging onto the same join point (problem was with ordering)
  - Refactorings
  - OrchestratorClientTest not fully working yet
  
  Revision  Changes    Path
  1.3       +20 -23    jakarta-cactus/scratchpad/cactus2/framework/src/main/org/apache/cactus/framework/internal/orchestrator/Orchestrator.java
  
  Index: Orchestrator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/scratchpad/cactus2/framework/src/main/org/apache/cactus/framework/internal/orchestrator/Orchestrator.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Orchestrator.java	22 Feb 2004 19:57:36 -0000	1.2
  +++ Orchestrator.java	6 Mar 2004 21:01:29 -0000	1.3
  @@ -30,7 +30,9 @@
   public class Orchestrator
   {
       private int port;
  -
  +    
  +    private HttpServer server;
  +    
       public Orchestrator(int port)
       {
           this.port = port;
  @@ -46,31 +48,26 @@
           // Setup HTTP server and attach to it handlers to manage
           // the executing test and to manage retrieval of test results
   
  -        HttpServer server = new HttpServer();
  +        this.server = new HttpServer();
           SocketListener listener = new SocketListener();
           listener.setPort(getPort());
  -        server.addListener(listener);
  +        this.server.addListener(listener);
   
  -        HttpContext getTestContext = new HttpContext();
  -        getTestContext.setContextPath("/gettest");
  -        getTestContext.addHandler(new GetTestHandler());
  -        server.addContext(getTestContext);
  -
  -        HttpContext setTestContext = new HttpContext();
  -        setTestContext.setContextPath("/settest");
  -        setTestContext.addHandler(new SetTestHandler());
  -        server.addContext(setTestContext);
  -
  -        HttpContext getResultContext = new HttpContext();
  -        getResultContext.setContextPath("/getresult");
  -        getResultContext.addHandler(new GetResultHandler());
  -        server.addContext(getResultContext);
  -
  -        HttpContext setResultContext = new HttpContext();
  -        setResultContext.setContextPath("/setresult");
  -        setResultContext.addHandler(new SetResultHandler());
  -        server.addContext(setResultContext);
  +        HttpContext context = this.server.addContext("/");
  +        
  +        context.addHandler(new SetResultHandler());
  +        context.addHandler(new GetResultHandler());
  +
  +        SetTestHandler setTestHandler = new SetTestHandler();
  +        context.addHandler(setTestHandler);
  +        context.addHandler(new GetTestHandler(setTestHandler));
   
  -        server.start();
  +        this.server.start();
       }
  +
  +    public void stop() throws InterruptedException
  +    {
  +        this.server.stop();
  +    }
  +    
   }
  
  
  
  1.1                  jakarta-cactus/scratchpad/cactus2/framework/src/main/org/apache/cactus/framework/internal/orchestrator/OrchestratorClient.java
  
  Index: OrchestratorClient.java
  ===================================================================
  /* 
   * ========================================================================
   * 
   * Copyright 2004 The Apache Software Foundation.
   *
   * Licensed 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.cactus.framework.internal.orchestrator;
  
  import java.io.IOException;
  import java.io.InputStream;
  import java.net.HttpURLConnection;
  import java.net.MalformedURLException;
  import java.net.URL;
  
  import org.apache.cactus.framework.internal.orchestrator.handlers.GetTestHandler;
  import org.apache.cactus.framework.internal.orchestrator.handlers.SetTestHandler;
  
  public class OrchestratorClient
  {
      public void setTest(String name)
      	throws MalformedURLException, IOException
      {
  	    // TODO: get port from configuration
  	    URL url = new URL(
  	        "http://localhost:7777" + SetTestHandler.PATH_IN_CONTEXT
  	        + "?name=" + name);
  	 
  	    // TODO: use proper logging system
  	    System.err.println("URL = [" + url + "]");
  	    HttpURLConnection connection = 
  	        (HttpURLConnection) url.openConnection(); 
  	    connection.setRequestMethod("GET");
  	    connection.getInputStream();
      }
  
      public String getTest()
  		throws MalformedURLException, IOException
      {
  	    // TODO: get port from configuration
  	    URL url = new URL(
  	        "http://localhost:7777" + GetTestHandler.PATH_IN_CONTEXT);
  	 
  	    // TODO: use proper logging system
  	    System.err.println("URL = [" + url + "]");
  	    HttpURLConnection connection = 
  	        (HttpURLConnection) url.openConnection(); 
  	    connection.setRequestMethod("GET");
  
  	    InputStream in = connection.getInputStream();
  	    byte[] b = new byte[in.available()];
  	    in.read(b);
  	    
  	    return new String(b);
      }
  
  }
  
  
  
  1.1                  jakarta-cactus/scratchpad/cactus2/framework/src/main/org/apache/cactus/framework/aspect/ClientInterceptionAspect.java
  
  Index: ClientInterceptionAspect.java
  ===================================================================
  /* 
   * ========================================================================
   * 
   * Copyright 2004 The Apache Software Foundation.
   *
   * Licensed 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.cactus.framework.aspect;
  
  import junit.framework.TestCase;
  
  import org.apache.cactus.framework.internal.ClientManager;
  import org.codehaus.aspectwerkz.attribdef.Pointcut;
  import org.codehaus.aspectwerkz.attribdef.aspect.Aspect;
  import org.codehaus.aspectwerkz.joinpoint.JoinPoint;
  
  /**
   * Intercepts client side JUnit tests.
   */
  public class ClientInterceptionAspect extends Aspect
  {
      /**
       * @Execution * *..TestCase+.test*()
       */
      private Pointcut interceptClientTest;
  
      /**
       * Has the Cactus system been already initialized? 
       */
      private boolean isInitialized = false;
      
      private ClientManager manager = new ClientManager();
      
      /**
       * @Around interceptClientTest
       */
      public synchronized Object intercept(JoinPoint joinPoint) 
          throws Throwable
      {
          if (!this.isInitialized)
          {
              manager.initialize();
              this.isInitialized = true;
          }
  
          manager.prepareTest((TestCase) joinPoint.getTargetInstance());
          
          return joinPoint.proceed();
      }
  }
  
  
  
  1.1                  jakarta-cactus/scratchpad/cactus2/framework/src/test/org/apache/cactus/framework/internal/orchestrator/OrchestratorClientTest.java
  
  Index: OrchestratorClientTest.java
  ===================================================================
  /* 
   * ========================================================================
   * 
   * Copyright 2004 The Apache Software Foundation.
   *
   * Licensed 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.cactus.framework.internal.orchestrator;
  
  import junit.framework.AssertionFailedError;
  import junit.framework.TestCase;
  
  public class OrchestratorClientTest extends TestCase
  {
      private OrchestratorClient client;
      private Orchestrator orchestrator;
      
      protected void setUp()
      {
          orchestrator = new Orchestrator(7777);
          client = new OrchestratorClient();
          try
          {
              orchestrator.start();
          }
          catch (Throwable t)
          {
              throw new AssertionFailedError("Failed to start orchestrator ["
                  + t.getMessage() + "]");
                      
          }
      }
  
      protected void tearDown()
      {
          try
          {
              orchestrator.stop();
          }
          catch (InterruptedException e)
          {
              throw new AssertionFailedError("Failed to stop orchestrator ["
                  + e.getMessage() + "]");                    
          }
      }
      
      public void testPrepareTestWhenOrchestratorStarted() throws Throwable
      {
          client.setTest("testXXX");
          assertEquals("test", client.getTest());
      }
  }
  
  
  
  1.2       +6 -0      jakarta-cactus/scratchpad/cactus2/framework/src/main/org/apache/cactus/framework/internal/orchestrator/handlers/GetResultHandler.java
  
  Index: GetResultHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/scratchpad/cactus2/framework/src/main/org/apache/cactus/framework/internal/orchestrator/handlers/GetResultHandler.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- GetResultHandler.java	21 Feb 2004 16:39:30 -0000	1.1
  +++ GetResultHandler.java	6 Mar 2004 21:01:29 -0000	1.2
  @@ -28,9 +28,15 @@
   
   public class GetResultHandler extends AbstractHttpHandler
   {
  +    public static String PATH_IN_CONTEXT = "/getresult";
  +
       public void handle(String pathInContext, String pathParams, 
           HttpRequest request, HttpResponse response) 
           throws HttpException, IOException
       {
  +        if (PATH_IN_CONTEXT.equals(pathInContext))
  +        {
  +            request.setHandled(true);
  +        }
       }
   }
  
  
  
  1.2       +6 -0      jakarta-cactus/scratchpad/cactus2/framework/src/main/org/apache/cactus/framework/internal/orchestrator/handlers/SetResultHandler.java
  
  Index: SetResultHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/scratchpad/cactus2/framework/src/main/org/apache/cactus/framework/internal/orchestrator/handlers/SetResultHandler.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SetResultHandler.java	21 Feb 2004 16:39:30 -0000	1.1
  +++ SetResultHandler.java	6 Mar 2004 21:01:29 -0000	1.2
  @@ -28,9 +28,15 @@
   
   public class SetResultHandler extends AbstractHttpHandler
   {
  +    public static String PATH_IN_CONTEXT = "/setresult";
  +
       public void handle(String pathInContext, String pathParams, 
           HttpRequest request, HttpResponse response) 
           throws HttpException, IOException
       {
  +        if (PATH_IN_CONTEXT.equals(pathInContext))
  +        {
  +            request.setHandled(true);
  +        }
       }
   }
  
  
  
  1.2       +25 -0     jakarta-cactus/scratchpad/cactus2/framework/src/main/org/apache/cactus/framework/internal/orchestrator/handlers/GetTestHandler.java
  
  Index: GetTestHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/scratchpad/cactus2/framework/src/main/org/apache/cactus/framework/internal/orchestrator/handlers/GetTestHandler.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- GetTestHandler.java	21 Feb 2004 16:39:30 -0000	1.1
  +++ GetTestHandler.java	6 Mar 2004 21:01:29 -0000	1.2
  @@ -20,17 +20,42 @@
   package org.apache.cactus.framework.internal.orchestrator.handlers;
   
   import java.io.IOException;
  +import java.io.OutputStream;
   
   import org.mortbay.http.HttpException;
  +import org.mortbay.http.HttpFields;
   import org.mortbay.http.HttpRequest;
   import org.mortbay.http.HttpResponse;
   import org.mortbay.http.handler.AbstractHttpHandler;
  +import org.mortbay.util.ByteArrayISO8859Writer;
   
   public class GetTestHandler extends AbstractHttpHandler
   {
  +    public static String PATH_IN_CONTEXT = "/gettest";
  +
  +    private SetTestHandler setTesthandler;
  +    
  +    public GetTestHandler(SetTestHandler handler)
  +    {
  +        this.setTesthandler = handler;
  +    }
  +    
       public void handle(String pathInContext, String pathParams, 
           HttpRequest request, HttpResponse response) 
           throws HttpException, IOException
       {
  +        if (PATH_IN_CONTEXT.equals(pathInContext))
  +        {
  +            String name = this.setTesthandler.getCurrentTestName();
  +            System.err.println("Gettest: name = [" + name + "]");
  +            
  +            OutputStream out = response.getOutputStream();
  +            ByteArrayISO8859Writer writer = new ByteArrayISO8859Writer();
  +            writer.write(name);
  +            writer.flush();
  +            response.setIntField(HttpFields.__ContentLength, writer.size());
  +            out.flush();
  +            request.setHandled(true);
  +        }
       }
   }
  
  
  
  1.2       +18 -0     jakarta-cactus/scratchpad/cactus2/framework/src/main/org/apache/cactus/framework/internal/orchestrator/handlers/SetTestHandler.java
  
  Index: SetTestHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/scratchpad/cactus2/framework/src/main/org/apache/cactus/framework/internal/orchestrator/handlers/SetTestHandler.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SetTestHandler.java	21 Feb 2004 16:39:30 -0000	1.1
  +++ SetTestHandler.java	6 Mar 2004 21:01:29 -0000	1.2
  @@ -28,9 +28,27 @@
   
   public class SetTestHandler extends AbstractHttpHandler
   {
  +    public static String PATH_IN_CONTEXT = "/settest";
  +
  +    private String currentTestName;
  +    
       public void handle(String pathInContext, String pathParams, 
           HttpRequest request, HttpResponse response) 
           throws HttpException, IOException
       {
  +        if (PATH_IN_CONTEXT.equals(pathInContext))
  +        {
  +            // TODO: use loggin subsystem
  +            System.err.println("Settest: name = [" 
  +                + request.getParameter("name") + "]");
  +
  +            this.currentTestName = request.getParameter("name");
  +            request.setHandled(true);
  +        }
  +    }
  +
  +    String getCurrentTestName()
  +    {
  +        return this.currentTestName;
       }
   }
  
  
  
  1.1                  jakarta-cactus/scratchpad/cactus2/framework/src/main/org/apache/cactus/framework/internal/ClientManager.java
  
  Index: ClientManager.java
  ===================================================================
  /* 
   * ========================================================================
   * 
   * Copyright 2004 The Apache Software Foundation.
   *
   * Licensed 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.cactus.framework.internal;
  
  import java.io.IOException;
  import java.net.MalformedURLException;
  
  import junit.framework.TestCase;
  
  import org.apache.cactus.framework.internal.orchestrator.Orchestrator;
  import org.apache.cactus.framework.internal.orchestrator.OrchestratorClient;
  import org.codehaus.aspectwerkz.attribdef.aspect.Aspect;
  
  public class ClientManager extends Aspect
  {    
      private OrchestratorClient orchestratorClient;
  
      public ClientManager()
      {
          this.orchestratorClient = new OrchestratorClient(); 
      }
      
      public void initialize() throws Throwable
      {
          // TODO: Create a Configuration component to externalize 
          // configuration data
          Orchestrator orchestrator = new Orchestrator(7777);
          orchestrator.start();
      }
   
      public void prepareTest(TestCase testCase) 
      	throws MalformedURLException, IOException
      {
          String name = testCase.getName();
          this.orchestratorClient.setTest(name);
      }   
  
  }
  
  
  
  1.5       +1 -1      jakarta-cactus/scratchpad/cactus2/framework/conf/aspectwerkz.xml
  
  Index: aspectwerkz.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/scratchpad/cactus2/framework/conf/aspectwerkz.xml,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- aspectwerkz.xml	22 Feb 2004 19:57:36 -0000	1.4
  +++ aspectwerkz.xml	6 Mar 2004 21:01:29 -0000	1.5
  @@ -1,3 +1,3 @@
   <?xml version="1.0" encoding="UTF-8"?>
   <!DOCTYPE aspectwerkz PUBLIC "-//AspectWerkz//DTD//EN" "http://aspectwerkz.codehaus.org/dtd/aspectwerkz.dtd">
  -<aspectwerkz>
  <system id="cactus">
    <package name="org.apache.cactus.framework.aspect">
      <use-aspect class="InitializationAspect"/>
    </package>
  </system>
</aspectwerkz>
  +<aspectwerkz>
  <system id="cactus">
    <package name="org.apache.cactus.framework.aspect">
      <use-aspect class="ClientInterceptionAspect"/>
    </package>
  </system>
</aspectwerkz>
  
  
  
  1.5       +1 -1      jakarta-cactus/scratchpad/cactus2/samples/servlet/conf/aspectwerkz.xml
  
  Index: aspectwerkz.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-cactus/scratchpad/cactus2/samples/servlet/conf/aspectwerkz.xml,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- aspectwerkz.xml	22 Feb 2004 19:57:36 -0000	1.4
  +++ aspectwerkz.xml	6 Mar 2004 21:01:29 -0000	1.5
  @@ -1,3 +1,3 @@
   <?xml version="1.0" encoding="UTF-8"?>
   <!DOCTYPE aspectwerkz PUBLIC "-//AspectWerkz//DTD//EN" "http://aspectwerkz.codehaus.org/dtd/aspectwerkz.dtd">
  -<aspectwerkz>
  <system id="cactus">
    <package name="org.apache.cactus.sample.servlet">
      <use-aspect class="TestSampleServletAspectWerkz$GetRequestParametersTestAdvice"/>
    </package>
    <package name="org.apache.cactus.framework.aspect">
      <use-aspect class="InitializationAspect"/>
    </package>
  </system>
</aspectwerkz>
  +<aspectwerkz>
  <system id="cactus">
    <package name="org.apache.cactus.sample.servlet">
      <use-aspect class="TestSampleServletAspectWerkz$GetRequestParametersTestAdvice"/>
    </package>
    <package name="org.apache.cactus.framework.aspect">
      <use-aspect class="ClientInterceptionAspect"/>
    </package>
  </system>
</aspectwerkz>
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: cactus-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: cactus-dev-help@jakarta.apache.org