KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jetspeed > services > profiler > TestProfilerService


1 /*
2  * Copyright 2000-2001,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
17 package org.apache.jetspeed.services.profiler;
18
19 import java.io.File JavaDoc;
20
21 // Junit imports
22
import junit.framework.Test;
23 import junit.framework.TestSuite;
24
25 // Jetspeed imports
26
import org.apache.jetspeed.test.JetspeedTestCase;
27 import org.apache.jetspeed.om.profile.*;
28 import org.apache.jetspeed.om.profile.psml.*;
29
30 import org.apache.jetspeed.services.Profiler;
31
32 import org.apache.turbine.util.TurbineConfig;
33 import org.apache.turbine.util.StringUtils;
34
35 /**
36  * TestProfilerService
37  *
38  * @author <a HREF="taylor@apache.org">David Sean Taylor</a>
39  * @version $Id: TestProfilerService.java,v 1.1 2004/04/07 22:02:42 jford Exp $
40  */

41
42 public class TestProfilerService extends JetspeedTestCase {
43
44     /**
45      * Defines the testcase name for JUnit.
46      *
47      * @param name the testcase's name.
48      */

49     public TestProfilerService( String JavaDoc name ) {
50         super( name );
51     }
52
53     /**
54      * Start the tests.
55      *
56      * @param args the arguments. Not used
57      */

58     public static void main(String JavaDoc args[]) {
59         junit.awtui.TestRunner.main( new String JavaDoc[] { TestProfilerService.class.getName() } );
60     }
61
62     public void setup() {
63         System.out.println("Setup: Testing categories of Profiler Service");
64      }
65     /**
66      * Creates the test suite.
67      *
68      * @return a test suite (<code>TestSuite</code>) that includes all methods
69      * starting with "test"
70      */

71     public static Test suite() {
72         // All methods starting with "test" will be executed in the test suite.
73
return new TestSuite( TestProfilerService.class );
74     }
75
76     /**
77      * Tests categories
78      * @throws Exception
79      */

80     public void testCreateProfile() throws Exception JavaDoc
81     {
82         try
83         {
84             ProfileLocator locator = Profiler.createLocator();
85             locator.setGroupByName("apache");
86             locator.setName("create-test");
87
88             Portlets portlets = new PsmlPortlets();
89             Control control = new PsmlControl();
90             Controller controller = new PsmlController();
91             control.setName("BoxControl");
92             controller.setName("GridPortletController");
93             portlets.setControl(control);
94             portlets.setController(controller);
95             Profile profile = Profiler.createProfile(locator, portlets);
96             PSMLDocument doc = profile.getDocument();
97
98             System.out.println("doc = " + doc.getName());
99
100             // this only works with the default configuration (Castor/Filebased)
101
File JavaDoc file = new File JavaDoc(doc.getName());
102             assertTrue(file.exists());
103             //file.delete();
104
}
105         catch (Exception JavaDoc e)
106         {
107             String JavaDoc errmsg = "Error in Profiler Service: " + e.toString();
108             e.printStackTrace();
109             assertNotNull(errmsg, null);
110         }
111     }
112
113     /*
114       Configuration object to run Turbine outside a servlet container
115       ( uses turbine.properties )
116     */

117     private static TurbineConfig config = null;
118
119     /*
120       Sets up TurbineConfig using the system property:
121       <pre>turbine.properties</pre>
122     */

123     static
124     {
125         try
126         {
127            config = new TurbineConfig( "webapp", "/WEB-INF/conf/TurbineResources.properties");
128            config.init();
129         }
130         catch (Exception JavaDoc e)
131         {
132             fail(StringUtils.stackTrace(e));
133         }
134     }
135 }
136
137
Popular Tags