JPropertIEsTest.Java文件
package com.kindani.test;
import junit.framework.*;
import com.kindani.JPropertIEs;
//import Javax.servlet.ServletContext;
import Java.util.PropertIEs;
public class JPropertIEsTest extends TestCase {
JProperties jPropertIEs;
String key = "helloworld.title";
String value = "Hello World!";
public void testLoadPropertIEs() throws Exception {
String name = null;
Properties p = new PropertIEs();
name = "C:IDEAPPropertIEs4Methodssrccom
kindanitestLocalStrings.propertIEs";
p = JProperties.loadProperties(name, JProperties.BY_PROPERTIES);
assertEquals(value, p.getProperty(key));
name = "com.kindani.test.LocalStrings";
p = JProperties.loadProperties(name,JPropertIEs.BY_RESOURCEBUNDLE);
assertEquals(value, p.getProperty(key));
assertEquals(value,((JPropertIEs.ResourceBundleAdapter)p).getString(key));
name = "C:IDEAPPropertIEs4Methodssrccom
kindanitestLocalStrings.propertIEs";
p = JProperties.loadProperties(name, JPropertIEs.BY_PROPERTYRESOURCEBUNDLE);
assertEquals(value, p.getProperty(key));
assertEquals(value,((JPropertIEs.ResourceBundleAdapter)p).getString(key));
name = "comkindanitestLocalStrings.propertIEs";
p = JProperties.loadProperties(name, JPropertIEs.BY_SYSTEM_CLASSLOADER);
assertEquals(value, p.getProperty(key));
name = "comkindanitestLocalStrings.propertIEs";
p = JProperties.loadProperties(name, JPropertIEs.BY_CLASSLOADER);
assertEquals(value, p.getProperty(key));
name = "testLocalStrings.propertIEs";
p = JProperties.loadProperties(name, JPropertIEs.BY_CLASS);
assertEquals(value, p.getProperty(key));
}
/*
public void testLoadPropertIEs2() throws Exception {
ServletContext context = null;
String path = null;
PropertIEs p = null;
path = "/WEB-INF/classes/LocalStrings.propertIEs";
p = JProperties.loadPropertIEs(context, path);
assertEquals(value, p.getProperty(key));
}
*/
}
properties文件與JPropertIEsTest.Java文件相同的目錄下
LocalStrings.propertIEs文件
# $Id: LocalStrings.propertIEs,v 1.1 2000/08/17 00:57:52 horwat Exp $
# Default localized resources for example servlets
# This locale is en_US
helloworld.title=Hello World!
requestinfo.title=Request Information Example
requestinfo.label.method=Method:
requestinfo.label.requesturi=Request URI:
requestinfo.label.protocol=Protocol:
requestinfo.label.pathinfo=Path Info:
requestinfo.label.remoteaddr=Remote Address:
requestheader.title=Request Header Example
requestparams.title=Request Parameters Example
requestparams.params-in-req=Parameters in this request:
requestparams.no-params=No Parameters, Please enter some
requestparams.firstname=First Name:
requestparams.lastname=Last Name:
cookies.title=CookIEs Example
cookies.cookies=Your browser is sending the following cookIEs:
cookies.no-cookies=Your browser isn't sending any cookIEs
cookies.make-cookie=Create a cookIE to send to your browser
cookIEs.name=Name:
cookIEs.value=Value:
cookies.set=You just sent the following cookIE to your browser:
sessions.title=Sessions Example
sessions.id=Session ID:
sessions.created=Created:
sessions.lastaccessed=Last Accessed:
sessions.data=The following data is in your session:
sessions.adddata=Add data to your session
sessions.dataname=Name of Session Attribute:
sessions.datavalue=Value of Session Attribute: