Update of /cvsroot/ebxmlms/ebxmlms/src_junit/hk/hku/cecid/phoenix/test/message/handler
In directory sc8-pr-cvs1:/tmp/cvs-serv8706/src_junit/hk/hku/cecid/phoenix/test/message/handler
Modified Files:
Tag: b0931
FilePersistenceHandlerTest.java
Added Files:
Tag: b0931
ObjectStorePersistenceHandlerTest.java
RepositoryPersistenceHandlerTest.java
Log Message:
add test case for RepositoryPersistenceHandler
and ObjectStorePersistenceHandler
fix bug on RepositoryPersistenceHandler
--- NEW FILE: ObjectStorePersistenceHandlerTest.java ---
/*
* Copyright(c) 2002 Center for E-Commerce Infrastructure Development, The
* University of Hong Kong (HKU). All Rights Reserved.
*
* This software is licensed under the Academic Free License Version 1.0
*
* Academic Free License
* Version 1.0
*
* This Academic Free License applies to any software and associated
* documentation (the "Software") whose owner (the "Licensor") has placed the
* statement "Licensed under the Academic Free License Version 1.0" immediately
* after the copyright notice that applies to the Software.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of the Software (1) to use, copy, modify, merge, publish, perform,
* distribute, sublicense, and/or sell copies of the Software, and to permit
* persons to whom the Software is furnished to do so, and (2) under patent
* claims owned or controlled by the Licensor that are embodied in the Software
* as furnished by the Licensor, to make, use, sell and offer for sale the
* Software and derivative works thereof, subject to the following conditions:
*
* - Redistributions of the Software in source code form must retain all
* copyright notices in the Software as furnished by the Licensor, this list
* of conditions, and the following disclaimers.
* - Redistributions of the Software in executable form must reproduce all
* copyright notices in the Software as furnished by the Licensor, this list
* of conditions, and the following disclaimers in the documentation and/or
* other materials provided with the distribution.
* - Neither the names of Licensor, nor the names of any contributors to the
* Software, nor any of their trademarks or service marks, may be used to
* endorse or promote products derived from this Software without express
* prior written permission of the Licensor.
*
* DISCLAIMERS: LICENSOR WARRANTS THAT THE COPYRIGHT IN AND TO THE SOFTWARE IS
* OWNED BY THE LICENSOR OR THAT THE SOFTWARE IS DISTRIBUTED BY LICENSOR UNDER
* A VALID CURRENT LICENSE. EXCEPT AS EXPRESSLY STATED IN THE IMMEDIATELY
* PRECEDING SENTENCE, THE SOFTWARE IS PROVIDED BY THE LICENSOR, CONTRIBUTORS
* AND COPYRIGHT OWNERS "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* LICENSOR, CONTRIBUTORS OR COPYRIGHT OWNERS BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE.
*
* This license is Copyright (C) 2002 Lawrence E. Rosen. All rights reserved.
* Permission is hereby granted to copy and distribute this license without
* modification. This license may not be modified without the express written
* permission of its copyright owner.
*/
/* =====
*
* $Header: /cvsroot/ebxmlms/ebxmlms/src_junit/hk/hku/cecid/phoenix/test/message/handler/Attic/ObjectStorePersistenceHandlerTest.java,v 1.1.2.1 2004/01/03 09:53:41 bobpykoon Exp $
*
* Code authored by:
*
* pykoon [2004-01-05]
*
* Code reviewed by:
*
* username [YYYY-MM-DD]
*
* Remarks:
*
* =====
*/
package hk.hku.cecid.phoenix.test.message.handler;
import java.io.File;
import java.io.IOException;
import junit.framework.Test;
import junit.framework.TestSuite;
import hk.hku.cecid.phoenix.common.util.Property;
import hk.hku.cecid.phoenix.common.util.XMLProperty;
import hk.hku.cecid.phoenix.message.handler.Constants;
import hk.hku.cecid.phoenix.message.handler.FilePersistenceHandler;
import hk.hku.cecid.phoenix.message.handler.ObjectStorePersistenceHandler;
/**
* Test case for ObjectStorePersistenceHandler
* @author pykoon
* @version $Revision: 1.1.2.1 $
*/
public class ObjectStorePersistenceHandlerTest
extends FilePersistenceHandlerTest {
/**
* The system property key for prop.home, the one to load Property
*/
private static final String SYSTEM_PROP_HOME_KEY = "prop.home";
/**
* The file name to store the property
*/
private static final String PROPERTY_FILE_NAME = "msh.properties.xml";
/**
* The system property prop.home gotten
*/
private String systemPropHomeProperty = null;
/**
* Construct the test case
* @param name
*/
public ObjectStorePersistenceHandlerTest(String name) {
super(name);
}
/**
* get the test suite
* @return Test the test suite
*/
public static Test suite() {
return new TestSuite(RepositoryPersistenceHandlerTest.class);
}
/**
* create the repository persistence handler for testing
* @return the repository persistence handler
*/
protected FilePersistenceHandler createFilePersistenceHandler()
throws Exception {
systemPropHomeProperty = System.getProperty(SYSTEM_PROP_HOME_KEY);
return new ObjectStorePersistenceHandler();
}
/**
* method called when the test case is tear down
* @throws Exception thrown when error occur on tear down
*/
protected void tearDown() throws Exception {
super.tearDown();
if (systemPropHomeProperty != null) {
System.setProperty(SYSTEM_PROP_HOME_KEY, systemPropHomeProperty);
} else {
System.getProperties().remove(SYSTEM_PROP_HOME_KEY);
}
}
/**
* setup the Property which will be loaded by RepositoryPersistenceHandler
* @param maxFileNumber the max number of file in sub-directory
* @throws IOException thrown if there is exception in setting up the
* Property
*/
private void setupProperty() throws IOException {
Property property = new XMLProperty();
property.set(Constants.PROPERTY_MESSAGE_LISTENER_OBJECT_STORE,
TEST_PATH);
File propertyLocation = new File(TEST_PATH);
propertyLocation = new File(propertyLocation, PROPERTY_FILE_NAME);
String locationString = propertyLocation.getCanonicalPath();
property.save(locationString);
System.setProperty(SYSTEM_PROP_HOME_KEY, TEST_PATH);
}
}
--- NEW FILE: RepositoryPersistenceHandlerTest.java ---
/*
* Copyright(c) 2002 Center for E-Commerce Infrastructure Development, The
* University of Hong Kong (HKU). All Rights Reserved.
*
* This software is licensed under the Academic Free License Version 1.0
*
* Academic Free License
* Version 1.0
*
* This Academic Free License applies to any software and associated
* documentation (the "Software") whose owner (the "Licensor") has placed the
* statement "Licensed under the Academic Free License Version 1.0" immediately
* after the copyright notice that applies to the Software.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of the Software (1) to use, copy, modify, merge, publish, perform,
* distribute, sublicense, and/or sell copies of the Software, and to permit
* persons to whom the Software is furnished to do so, and (2) under patent
* claims owned or controlled by the Licensor that are embodied in the Software
* as furnished by the Licensor, to make, use, sell and offer for sale the
* Software and derivative works thereof, subject to the following conditions:
*
* - Redistributions of the Software in source code form must retain all
* copyright notices in the Software as furnished by the Licensor, this list
* of conditions, and the following disclaimers.
* - Redistributions of the Software in executable form must reproduce all
* copyright notices in the Software as furnished by the Licensor, this list
* of conditions, and the following disclaimers in the documentation and/or
* other materials provided with the distribution.
* - Neither the names of Licensor, nor the names of any contributors to the
* Software, nor any of their trademarks or service marks, may be used to
* endorse or promote products derived from this Software without express
* prior written permission of the Licensor.
*
* DISCLAIMERS: LICENSOR WARRANTS THAT THE COPYRIGHT IN AND TO THE SOFTWARE IS
* OWNED BY THE LICENSOR OR THAT THE SOFTWARE IS DISTRIBUTED BY LICENSOR UNDER
* A VALID CURRENT LICENSE. EXCEPT AS EXPRESSLY STATED IN THE IMMEDIATELY
* PRECEDING SENTENCE, THE SOFTWARE IS PROVIDED BY THE LICENSOR, CONTRIBUTORS
* AND COPYRIGHT OWNERS "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* LICENSOR, CONTRIBUTORS OR COPYRIGHT OWNERS BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE.
*
* This license is Copyright (C) 2002 Lawrence E. Rosen. All rights reserved.
* Permission is hereby granted to copy and distribute this license without
* modification. This license may not be modified without the express written
* permission of its copyright owner.
*/
/* =====
*
* $Header: /cvsroot/ebxmlms/ebxmlms/src_junit/hk/hku/cecid/phoenix/test/message/handler/Attic/RepositoryPersistenceHandlerTest.java,v 1.1.2.1 2004/01/03 09:53:41 bobpykoon Exp $
*
* Code authored by:
*
* pykoon [2004-01-03]
*
* Code reviewed by:
*
* username [YYYY-MM-DD]
*
* Remarks:
*
* =====
*/
package hk.hku.cecid.phoenix.test.message.handler;
import java.io.File;
import java.io.IOException;
import javax.activation.DataSource;
import hk.hku.cecid.phoenix.common.util.Property;
import hk.hku.cecid.phoenix.common.util.XMLProperty;
import hk.hku.cecid.phoenix.message.handler.Constants;
import hk.hku.cecid.phoenix.message.handler.FilePersistenceHandler;
import hk.hku.cecid.phoenix.message.handler.RepositoryPersistenceHandler;
import junit.framework.Test;
import junit.framework.TestSuite;
/**
* RepositoryPersistenceHandlerTest is the test for the class
* RepositoryPersistenceHandler
*
* @author pykoon
* @version $Revision: 1.1.2.1 $
*/
public class RepositoryPersistenceHandlerTest
extends FilePersistenceHandlerTest {
/**
* Construct the test case
* @param name the name
*/
public RepositoryPersistenceHandlerTest(String name) {
super(name);
}
/**
* The system property key for prop.home, the one to load Property
*/
private static final String SYSTEM_PROP_HOME_KEY = "prop.home";
/**
* The file name to store the property
*/
private static final String PROPERTY_FILE_NAME = "msh.properties.xml";
/**
* The max number of file per sub-directory
*/
private static final int MAX_NUM_FILE = 1;
/**
* The system property prop.home gotten
*/
private String systemPropHomeProperty = null;
/**
* get the test suite
* @return Test the test suite
*/
public static Test suite() {
return new TestSuite(RepositoryPersistenceHandlerTest.class);
}
/**
* create the repository persistence handler for testing
* @return the repository persistence handler
*/
protected FilePersistenceHandler createFilePersistenceHandler()
throws Exception {
systemPropHomeProperty = System.getProperty(SYSTEM_PROP_HOME_KEY);
setupProperty(MAX_NUM_FILE);
return new RepositoryPersistenceHandler();
}
/**
* method called when the test case is tear down
* @throws Exception thrown when error occur on tear down
*/
protected void tearDown() throws Exception {
super.tearDown();
if (systemPropHomeProperty != null) {
System.setProperty(SYSTEM_PROP_HOME_KEY, systemPropHomeProperty);
} else {
System.getProperties().remove(SYSTEM_PROP_HOME_KEY);
}
}
/**
* setup the Property which will be loaded by RepositoryPersistenceHandler
* @param maxFileNumber the max number of file in sub-directory
* @throws IOException thrown if there is exception in setting up the
* Property
*/
private void setupProperty(int maxFileNumber) throws IOException {
Property property = new XMLProperty();
property.set(Constants.PROPERTY_MESSAGE_REPOSITORY, TEST_PATH);
property.set(Constants.PROPERTY_MAX_FILE_IN_SUBDIRECTORY,
Integer.toString(maxFileNumber));
File propertyLocation = new File(TEST_PATH);
propertyLocation = new File(propertyLocation, PROPERTY_FILE_NAME);
String locationString = propertyLocation.getCanonicalPath();
property.save(locationString);
System.setProperty(SYSTEM_PROP_HOME_KEY, TEST_PATH);
}
/**
* test whether the Repository Persistence Handler can
* create R0000 directory, and also test whether it can create
* new directory when max number of file is reached.
*/
public void testCreateDirectory() {
DataSource dataSource1 = null;
DataSource dataSource2 = null;
try {
dataSource1 = createTestDataSource();
} catch (Exception e) {
fail("Cannot create data source : " + e.toString());
}
File testPathFile = new File(TEST_PATH);
File r0000Dir = new File(testPathFile, "R0000");
assertTrue(r0000Dir.exists());
assertTrue(r0000Dir.listFiles().length == 1);
try {
dataSource2 = createTestDataSource();
} catch (Exception e) {
fail("Cannot create data source : " + e.toString());
}
File r0001Dir = new File(testPathFile, "R0001");
assertTrue(r0001Dir.exists());
assertTrue(r0001Dir.listFiles().length == 1);
try {
handler.removeObject(dataSource1.getName());
handler.removeObject(dataSource2.getName());
} catch (Exception e) {
fail("Cannot remove data source");
}
}
/**
* test whether it is initialized successfully
* create R0000 directory
*/
public void testInitialize() {
RepositoryPersistenceHandler rHandler
= (RepositoryPersistenceHandler) handler;
int number = rHandler.getMaxNumberOfFileInSubDirectory();
assertTrue(number == MAX_NUM_FILE);
}
/**
* test whether it can remove directory if the file in the directory is
* deleted
*/
public void testRemoveDirectory() {
testCreateAndRemove();
File testPathFile = new File(TEST_PATH);
File r0000Dir = new File(testPathFile, "R0000");
assertFalse(r0000Dir.exists());
}
}
Index: FilePersistenceHandlerTest.java
===================================================================
RCS file: /cvsroot/ebxmlms/ebxmlms/src_junit/hk/hku/cecid/phoenix/test/message/handler/Attic/FilePersistenceHandlerTest.java,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -C2 -d -r1.1.2.1 -r1.1.2.2
*** FilePersistenceHandlerTest.java 31 Dec 2003 04:06:43 -0000 1.1.2.1
--- FilePersistenceHandlerTest.java 3 Jan 2004 09:53:41 -0000 1.1.2.2
***************
*** 83,107 ****
*/
public class FilePersistenceHandlerTest extends TestCase {
!
/**
The path used on testing the FilePersistenceHandler
*/
! private static final String TEST_PATH = "test/testFile";
!
/**
A sample content used to test on the FilePersistenceHandler
*/
! private static final int[] FILE_CONTENT = new int[]{0, 1, 2, 3};
!
! /**
! the dataSource used during testing
! */
! private DataSource dataSource;
!
/**
The file persistence handler used on testing
*/
! private FilePersistenceHandler handler;
!
/**
construct the FilePersistenceHandlerTest
--- 83,102 ----
*/
public class FilePersistenceHandlerTest extends TestCase {
!
/**
The path used on testing the FilePersistenceHandler
*/
! protected static final String TEST_PATH = "test/testFile";
!
/**
A sample content used to test on the FilePersistenceHandler
*/
! private static final int[] FILE_CONTENT = new int[] { 0, 1, 2, 3 };
!
/**
The file persistence handler used on testing
*/
! protected FilePersistenceHandler handler;
!
/**
construct the FilePersistenceHandlerTest
***************
*** 111,115 ****
super(name);
}
!
/**
get the test suite
--- 106,110 ----
super(name);
}
!
/**
get the test suite
***************
*** 119,123 ****
return new TestSuite(FilePersistenceHandlerTest.class);
}
!
/**
set up the test case.
--- 114,118 ----
return new TestSuite(FilePersistenceHandlerTest.class);
}
!
/**
set up the test case.
***************
*** 126,135 ****
protected void setUp() throws Exception {
File testPathFile = new File(TEST_PATH);
if (!testPathFile.exists()) {
testPathFile.mkdir();
}
! handler = new FilePersistenceHandler(new File(TEST_PATH));
}
/**
method called when the test case is tear down
--- 121,136 ----
protected void setUp() throws Exception {
File testPathFile = new File(TEST_PATH);
+ removeAllFiles(testPathFile);
if (!testPathFile.exists()) {
testPathFile.mkdir();
}
! handler = createFilePersistenceHandler();
}
+ protected FilePersistenceHandler createFilePersistenceHandler()
+ throws Exception {
+ return new FilePersistenceHandler(new File(TEST_PATH));
+ }
+
/**
method called when the test case is tear down
***************
*** 138,149 ****
protected void tearDown() throws Exception {
File testPathFile = new File(TEST_PATH);
! if (dataSource != null) {
! handler.removeObject(dataSource.getName());
! }
if (testPathFile.exists() && !testPathFile.delete()) {
testPathFile.deleteOnExit();
}
}
!
/**
create teh Test Data Source.
--- 139,162 ----
protected void tearDown() throws Exception {
File testPathFile = new File(TEST_PATH);
! removeAllFiles(testPathFile);
if (testPathFile.exists() && !testPathFile.delete()) {
testPathFile.deleteOnExit();
}
}
!
! /**
! * remove all the files in the specify directory
! * @param file
! * @throws IOException
! */
! protected static void removeAllFiles(File file) throws IOException {
! File[] files = file.listFiles();
! if (files != null) {
! for (int i = 0; i < files.length; i++) {
! removeAllFiles(files[i]);
! }
! }
! file.delete();
! }
/**
create teh Test Data Source.
***************
*** 151,160 ****
@throws Exception thrown when error occur on creating data source
*/
! private DataSource createTestDataSource() throws Exception {
DataSource dataSource = handler.createNewObject();
writeContent(dataSource);
return dataSource;
}
!
/**
write the content on DataSource
--- 164,173 ----
@throws Exception thrown when error occur on creating data source
*/
! protected DataSource createTestDataSource() throws Exception {
DataSource dataSource = handler.createNewObject();
writeContent(dataSource);
return dataSource;
}
!
/**
write the content on DataSource
***************
*** 169,173 ****
ostream.close();
}
!
/**
test to create a datasource and then remove from handler
--- 182,186 ----
ostream.close();
}
!
/**
test to create a datasource and then remove from handler
***************
*** 176,180 ****
String name = null;
try {
! dataSource = createTestDataSource();
name = dataSource.getName();
assertTrue(handler.getObject(name) != null);
--- 189,193 ----
String name = null;
try {
! DataSource dataSource = createTestDataSource();
name = dataSource.getName();
assertTrue(handler.getObject(name) != null);
***************
*** 185,189 ****
}
}
!
/**
test to create a data source, write data and then see if it
--- 198,202 ----
}
}
!
/**
test to create a data source, write data and then see if it
***************
*** 194,198 ****
InputStream istream = null;
try {
! dataSource = createTestDataSource();
name = dataSource.getName();
DataSource gotDataSource = handler.getObject(name);
--- 207,211 ----
InputStream istream = null;
try {
! DataSource dataSource = createTestDataSource();
name = dataSource.getName();
DataSource gotDataSource = handler.getObject(name);
|