This project has retired. For details please refer to its
Attic page.
TestDbCriteria xref
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 at7 * 8 * http://www.apache.org/licenses/LICENSE-2.09 * 10 * Unless required by applicable law or agreed to in writing, software11 * 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 and14 * limitations under the License.15 */1617packageorg.apache.jetspeed.services.psmlmanager;
1819// Junit imports20import junit.framework.Test;
21import junit.framework.TestSuite;
222324import org.apache.turbine.util.TurbineConfig;
25import org.apache.turbine.util.StringUtils;
2627// Jetspeed imports28import org.apache.jetspeed.test.JetspeedTestCase;
29import org.apache.jetspeed.om.profile.ProfileLocator;
30import org.apache.jetspeed.om.profile.BaseProfile;
3132import org.apache.torque.util.Criteria;
3334/***35 * TestDbCriteria36 *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 */4041publicclassTestDbCriteriaextendsJetspeedTestCase {
424344/*** the column name for the PSML_ID field */45publicstaticfinal String PSML_ID;
46/*** the column name for the USER_NAME field */47publicstaticfinal String USER_NAME;
48/*** the column name for the MEDIA_TYPE field */49publicstaticfinal String MEDIA_TYPE;
50/*** the column name for the LANGUAGE field */51publicstaticfinal String LANGUAGE;
52/*** the column name for the COUNTRY field */53publicstaticfinal String COUNTRY;
54/*** the column name for the PAGE field */55publicstaticfinal String PAGE;
56/*** the column name for the PROFILE field */57publicstaticfinal String PROFILE;
5859static60 {
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 }
6970/***71 * Defines the testcase name for JUnit.72 *73 * @param name the testcase's name.74 */75publicTestDbCriteria( String name ) {
76super( name );
77 }
7879/***80 * Start the tests.81 *82 * @param args the arguments. Not used83 */84publicstaticvoid main(String args[]) {
85 junit.awtui.TestRunner.main( new String[] { TestDbCriteria.class.getName() } );
86 }
8788/***89 * Creates the test suite.90 *91 * @return a test suite (<code>TestSuite</code>) that includes all methods92 * starting with "test"93 */94publicstatic Test suite() {
95// All methods starting with "test" will be executed in the test suite.96returnnew TestSuite( TestDbCriteria.class );
97 }
9899100/***101 * Tests generating an SQL string from a profile locator102 * @throws Exception103 */104105publicvoid testLocatorCriteria() throws Exception
106 {
107108 ProfileLocator locator = new BaseProfile();
109 locator.setMediaType("html");
110 locator.setLanguage("en");
111 locator.setName("default.psml");
112113 Criteria criteria = new Criteria();
114115 String mediaType = locator.getMediaType();
116 String language = locator.getLanguage();
117 String country = locator.getCountry();
118 String pageName = locator.getName();
119 String userName = "anon";
120121 assertTrue(country == null);
122123if (userName != null && userName.length() > 0)
124 {
125 criteria.add(USER_NAME, userName) ;
126 }
127128if (pageName != null && pageName.length() > 0)
129 {
130 criteria.add(PAGE, pageName);
131 }
132133if (mediaType != null && mediaType.length() > 0)
134 {
135 criteria.add(MEDIA_TYPE, mediaType);
136 }
137138if (language != null && language.length() > 0)
139 {
140 criteria.add(LANGUAGE, language);
141 }
142143 criteria.add(COUNTRY, country);
144145 String sql = criteria.toString();
146 System.out.println("criteria = [" + criteria.toString() + "]");
147 assertTrue(sql.indexOf("JETSPEED_USER_PROFILE.COUNTRY IS NULL") > -1);
148 }
149150/*151 Configuration object to run Turbine outside a servlet container152 ( uses turbine.properties )153 */154privatestatic TurbineConfig config = null;
155156/***157 Sets up TurbineConfig using the system property:158 <pre>turbine.properties</pre>159 */160static161 {
162try163 {
164 config = new TurbineConfig( "webapp", "/WEB-INF/conf/TurbineResources.properties");
165 config.init();
166 }
167catch (Exception e)
168 {
169 fail(StringUtils.stackTrace(e));
170 }
171 }
172173 }