1   /*
2    * Copyright 2000-2004 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.apache.jetspeed.services.forward;
17  
18  import java.util.Collection;
19  import java.util.Map;
20  import java.util.Iterator;
21  
22  // Junit imports
23  import junit.framework.Test;
24  import junit.framework.TestSuite;
25  
26  
27  import org.apache.jetspeed.test.HeadlessBaseTest;
28  import org.apache.jetspeed.util.ServiceUtil;
29  
30  import org.apache.jetspeed.services.forward.configuration.Forward;
31  import org.apache.jetspeed.services.forward.configuration.PortletForward;
32  import org.apache.jetspeed.services.forward.configuration.Page;
33  import org.apache.jetspeed.services.forward.configuration.Pane;
34  import org.apache.jetspeed.services.forward.configuration.Portlet;
35  import org.apache.jetspeed.services.forward.configuration.QueryParam;
36  
37  /***
38   * Test Forward service basics.
39   *
40   * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
41   * @version $Id: TestForwardService.java,v 1.1 2004/04/07 22:02:42 jford Exp $
42   */
43  
44  public class TestForwardService extends HeadlessBaseTest
45  {
46      /***
47       * Defines the testcase name for JUnit.
48       *
49       * @param name the testcase's name.
50       */
51      public TestForwardService( String name ) {
52          super( name );
53      }
54  
55      /***
56       * Start the tests.
57       *
58       * @param args the arguments. Not used
59       */
60      public static void main(String args[]) {
61          junit.awtui.TestRunner.main( new String[] { TestForwardService.class.getName() } );
62      }
63  
64      public void setup() {
65          System.out.println("Setup: Testing TestForwardService");
66       }
67  
68      public static Test suite()
69      {
70          // All methods starting with "test" will be executed in the test suite.
71          return new TestSuite( TestForwardService.class );
72      }
73  
74  
75        ///////////////////////////////////////////////////////////////////////////
76  
77      public void testConfiguration() throws Exception
78      {
79          try
80          {
81              System.out.println("Running TestForwardService");
82              ForwardService fs = (ForwardService)ServiceUtil.getServiceByName("ForwardService");
83              assertNotNull(fs);
84              Collection forwards = fs.getForwards();
85              Iterator it = forwards.iterator();
86              while (it.hasNext())
87              {
88                  System.out.println("-------------------------------------------");
89  
90                  Forward forward = (Forward)it.next();
91                  System.out.println("forward = " + forward.getName());
92                  Page page = forward.getPage();
93                  Pane pane = forward.getPane();
94                  Portlet portlet = forward.getPortlet();
95                  if (page != null)
96                  {
97                      System.out.println("page = " + page.getName() + ", user = " + page.getUser());
98                  }
99                  if (pane != null)
100                 {
101                     System.out.println("pane = " + pane.getId());
102                 }
103                 if (portlet != null)
104                 {
105                     System.out.println("portlet = " + portlet.getId() + ", action = " + portlet.getAction());
106                 }
107                 printQueryParams(forward.getQueryParams());
108             }
109             Collection pfs = fs.getPortletForwards();
110             it = pfs.iterator();
111             while (it.hasNext())
112             {
113                 System.out.println("-------------------------------------------");
114 
115                 PortletForward pf = (PortletForward)it.next();
116                 System.out.println("PF: portlet = " + pf.getPortlet() + ", forward = " + pf.getForward() + ", target = " + pf.getTarget());
117                 printQueryParams(pf.getQueryParams());
118             }
119 
120             System.out.println("End Run TestForwardService");
121         }
122         catch (Throwable t)
123         {
124             t.printStackTrace();
125         }
126     }
127 
128     private void printQueryParams(Map qparams)
129     {
130         Iterator it = qparams.values().iterator();
131         while (it.hasNext())
132         {
133             QueryParam qp = (QueryParam)it.next();
134             System.out.println("QP: name = " + qp.getName() + ", value = " + qp.getValue());
135         }
136 
137     }
138 
139         
140 }