1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.services.psmlmanager;
18
19
20 import junit.framework.Test;
21 import junit.framework.TestSuite;
22
23
24 import org.apache.turbine.util.TurbineConfig;
25 import org.apache.turbine.util.StringUtils;
26
27
28 import org.apache.jetspeed.test.JetspeedTestCase;
29 import org.apache.jetspeed.om.profile.ProfileLocator;
30 import org.apache.jetspeed.om.profile.BaseProfile;
31
32 import org.apache.torque.util.Criteria;
33
34 /***
35 * TestDbCriteria
36 *
37 * @author <a href="taylor@apache.org">David Sean Taylor</a>
38 * @version $Id: TestDbCriteria.java,v 1.1 2004/04/07 22:02:42 jford Exp $
39 */
40
41 public class TestDbCriteria extends JetspeedTestCase {
42
43
44 /*** the column name for the PSML_ID field */
45 public static final String PSML_ID;
46 /*** the column name for the USER_NAME field */
47 public static final String USER_NAME;
48 /*** the column name for the MEDIA_TYPE field */
49 public static final String MEDIA_TYPE;
50 /*** the column name for the LANGUAGE field */
51 public static final String LANGUAGE;
52 /*** the column name for the COUNTRY field */
53 public static final String COUNTRY;
54 /*** the column name for the PAGE field */
55 public static final String PAGE;
56 /*** the column name for the PROFILE field */
57 public static final String PROFILE;
58
59 static
60 {
61 PSML_ID = "JETSPEED_USER_PROFILE.PSML_ID";
62 USER_NAME = "JETSPEED_USER_PROFILE.USER_NAME";
63 MEDIA_TYPE = "JETSPEED_USER_PROFILE.MEDIA_TYPE";
64 LANGUAGE = "JETSPEED_USER_PROFILE.LANGUAGE";
65 COUNTRY = "JETSPEED_USER_PROFILE.COUNTRY";
66 PAGE = "JETSPEED_USER_PROFILE.PAGE";
67 PROFILE = "JETSPEED_USER_PROFILE.PROFILE";
68 }
69
70 /***
71 * Defines the testcase name for JUnit.
72 *
73 * @param name the testcase's name.
74 */
75 public TestDbCriteria( String name ) {
76 super( name );
77 }
78
79 /***
80 * Start the tests.
81 *
82 * @param args the arguments. Not used
83 */
84 public static void main(String args[]) {
85 junit.awtui.TestRunner.main( new String[] { TestDbCriteria.class.getName() } );
86 }
87
88 /***
89 * Creates the test suite.
90 *
91 * @return a test suite (<code>TestSuite</code>) that includes all methods
92 * starting with "test"
93 */
94 public static Test suite() {
95
96 return new TestSuite( TestDbCriteria.class );
97 }
98
99
100 /***
101 * Tests generating an SQL string from a profile locator
102 * @throws Exception
103 */
104
105 public void testLocatorCriteria() throws Exception
106 {
107
108 ProfileLocator locator = new BaseProfile();
109 locator.setMediaType("html");
110 locator.setLanguage("en");
111 locator.setName("default.psml");
112
113 Criteria criteria = new Criteria();
114
115 String mediaType = locator.getMediaType();
116 String language = locator.getLanguage();
117 String country = locator.getCountry();
118 String pageName = locator.getName();
119 String userName = "anon";
120
121 assertTrue(country == null);
122
123 if (userName != null && userName.length() > 0)
124 {
125 criteria.add(USER_NAME, userName) ;
126 }
127
128 if (pageName != null && pageName.length() > 0)
129 {
130 criteria.add(PAGE, pageName);
131 }
132
133 if (mediaType != null && mediaType.length() > 0)
134 {
135 criteria.add(MEDIA_TYPE, mediaType);
136 }
137
138 if (language != null && language.length() > 0)
139 {
140 criteria.add(LANGUAGE, language);
141 }
142
143 criteria.add(COUNTRY, country);
144
145 String sql = criteria.toString();
146 System.out.println("criteria = [" + criteria.toString() + "]");
147 assertTrue(sql.indexOf("JETSPEED_USER_PROFILE.COUNTRY IS NULL") > -1);
148 }
149
150
151
152
153
154 private static TurbineConfig config = null;
155
156 /***
157 Sets up TurbineConfig using the system property:
158 <pre>turbine.properties</pre>
159 */
160 static
161 {
162 try
163 {
164 config = new TurbineConfig( "webapp", "/WEB-INF/conf/TurbineResources.properties");
165 config.init();
166 }
167 catch (Exception e)
168 {
169 fail(StringUtils.stackTrace(e));
170 }
171 }
172
173 }