1 16 17 package org.apache.jetspeed.services.psmlmanager; 18 19 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 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 40 41 public class TestDbCriteria extends JetspeedTestCase { 42 43 44 45 public static final String PSML_ID; 46 47 public static final String USER_NAME; 48 49 public static final String MEDIA_TYPE; 50 51 public static final String LANGUAGE; 52 53 public static final String COUNTRY; 54 55 public static final String PAGE; 56 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 75 public TestDbCriteria( String name ) { 76 super( name ); 77 } 78 79 84 public static void main(String args[]) { 85 junit.awtui.TestRunner.main( new String [] { TestDbCriteria.class.getName() } ); 86 } 87 88 94 public static Test suite() { 95 return new TestSuite( TestDbCriteria.class ); 97 } 98 99 100 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 154 private static TurbineConfig config = null; 155 156 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 } 174 | Popular Tags |