Calling 2 tests, first is successfull, second consecutive test fails over. Problem is I assume with creating model second time. Trying to distroy first model calling tearDown(); or shutDown() does not help.
Second test gets executed correctly when called as single test.
Code below:
import java.io.IOException;
import java.util.*;
import junit.framework.Test;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
import com.mrt.common.PropertiesHelper;
import com.mrt.merlin.unit.AbstractMerlinTestCase;
import com.mrt.vend.desktop.command.employee.*;
import com.mrt.vend.desktop.model.*;
/**
* @author jerzy.graca
*/
public class EmployeeDAOServiceTest extends AbstractMerlinTestCase {
private Properties properites;
private EmployeeFactory employeeFactory;
public EmployeeDAOServiceTest(String name) {
super(name);
// this.properites = properites;
}
public static void main(String[] argv) throws IOException {
TestRunner.run(suite());
}
public static Test suite() throws IOException {
TestSuite suite = new TestSuite();
// Properties props = PropertiesHelper.loadPrefixedProperties("build.properties","client.");
suite.addTest(new EmployeeDAOServiceTest("createEmployees"));
suite.addTest(new EmployeeDAOServiceTest("selectEmployees"));
return suite;
}
public void createEmployees() throws Exception {
CreateEmployeeCommand DAO1 =
(CreateEmployeeCommand) resolve("/mrt-vend-client/CreateEmployeeCommandImpl");
assertNotNull("CreateEmployeeCommandImpl null", DAO1);
for(int i=0; i<2; i++) {
DAO1.setEmployee(EmployeeFactory.getEmployee());
DAO1.execute();
}
tearDown();
}
public void selectEmployees() throws Exception {
super.setUp();
GetEmployeeRefListCommand DAO2 =
(GetEmployeeRefListCommand) resolve("/mrt-vend-client/GetEmployeeRefListCommandImpl");
assertNotNull("employee-GetEmployeeRefListCommand null", DAO2);
DAO2.execute();
List lst = DAO2.getEmployeeRefList();
assertNotNull("list is null", lst);
assertEquals(lst.size(), 2);
tearDown();
}
/*
* (non-Javadoc)
*
* @see org.apache.avalon.merlin.unit.AbstractMerlinTestCase#getDeployment()
*/
protected String[] getDeployment() {
return new String[] { "src/tests/conf/block-employeedao-test.xml" };
}
}
Result is below:
Hibernate: insert into employees (emp_reg_id, emp_server_login, emp_mobile_phone_id, emp_mobile_new_phone_id, emp_firstname, emp_lastname, emp_system_id, emp_opr_number, emp_opr_new_number, emp_active, emp_id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
[DEBUG ] (mrt-vend-client.employee-dao): About to close current session
[DEBUG ] (mrt-vend-client.hibernate-service): About to close Hibernate session joined with current thread
[DEBUG ] (mrt-vend-client.hibernate-service): Closing hibernate session joined with current thread
[DEBUG ] (mrt-vend-client.employee-dao): About to open hibernate session
[DEBUG ] (mrt-vend-client.hibernate-service): Opening new Hibernate session
[DEBUG ] (mrt-vend-client.hibernate-service): Joining hibernate session with current thread
[DEBUG ] (mrt-vend-client.hibernate-service): Returning new hibernate session, joined with current thread
[DEBUG ] (mrt-vend-client.employee-dao): About to begin transaction
[DEBUG ] (mrt-vend-client.hibernate-service): Returning existing hibernate session, joined with current thread
Hibernate: insert into employees (emp_reg_id, emp_server_login, emp_mobile_phone_id, emp_mobile_new_phone_id, emp_firstname, emp_lastname, emp_system_id, emp_opr_number, emp_opr_new_number, emp_active, emp_id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
[DEBUG ] (mrt-vend-client.employee-dao): About to close current session
[DEBUG ] (mrt-vend-client.hibernate-service): About to close Hibernate session joined with current thread
[DEBUG ] (mrt-vend-client.hibernate-service): Closing hibernate session joined with current thread
[DEBUG ] (kernel): state: stopping
[DEBUG ] (kernel): state: decommissioning
[DEBUG ] (): decommissioning
[DEBUG ] (mrt-vend-client): decommissioning
[DEBUG ] (mrt-vend-client.CreateEmployeeCommandImpl.lifecycle): etherialization
[DEBUG ] (mrt-vend-client.employee-dao.lifecycle): etherialization
[DEBUG ] (mrt-vend-client.location-dao.lifecycle): etherialization
[DEBUG ] (mrt-vend-client.hibernate-service.lifecycle): etherialization
[DEBUG ] (kernel): state: stopped
[DEBUG ] (kernel.logger): logging system established
[DEBUG ] (kernel.logger): adding category [kernel]
[DEBUG ] (kernel): logging system established
[DEBUG ] (kernel): repository established: C:\Documents and Settings\jerzy.graca\.maven\repository,
http://www.dpml.net/,
http://www.ibiblio.org/maven/
[DEBUG ] (kernel.logger): adding category [kernel]
[INFO ] (kernel): info report
-----------------------------------------------------------
Merlin Kernel Environment Listing
-----------------------------------------------------------
${user.dir} == C:\projekty\mrt-vend2
${user.home} == C:\Documents and Settings\jerzy.graca
${avalon.repository.cache} == C:\Documents and Settings\jerzy.graca\.maven\repository
${avalon.repository.online} == true
${avalon.repository.hosts} ==
http://www.dpml.net,http://www.ibiblio.org/maven
${merlin.lang} == null
${merlin.home} == C:\merlin
${merlin.system} == C:\merlin\system
${merlin.config} == C:\merlin\config
${merlin.kernel} == file:/C:/merlin/config/kernel.xml
${merlin.logging.implementation} == artifact:avalon-logging/avalon-logging-logkit-impl#1.0.0
${merlin.logging.config} == null
${merlin.runtime} == artifact:avalon-activation/avalon-activation-impl#2.0.0
${merlin.override} == null
${merlin.dir} == C:\projekty\mrt-vend2
${merlin.temp} == C:\DOCUME~1\jerzy.graca\Ustawienia lokalne\Temp
${merlin.context} == C:\projekty\mrt-vend2\target
${merlin.anchor} == C:\projekty\mrt-vend2
${merlin.info} == true
${merlin.debug} == true
${merlin.audit} == false
${merlin.server} == true
${merlin.autostart} == true
${merlin.code.security.enabled} == false
${merlin.deployment.timeout} == 0
${merlin.repository} == C:\Documents and Settings\jerzy.graca\.maven\repository
${merlin.repository.hosts} ==
http://www.dpml.net/,http://www.ibiblio.org/maven/
${merlin.deployment} == file:/${merlin.dir}/src/tests/conf/block-employeedao-test.xml
-----------------------------------------------------------
[DEBUG ] (kernel): building application model
[DEBUG ] (kernel.logger): adding root category
[DEBUG ] (kernel.logger): adding root category
[DEBUG ] (kernel.logger): adding root category
---- exception report ----------------------------------------------------------
Exception: org.apache.avalon.composition.model.ModelException
Message: Unable to construct a new containment model: untitled.
---- cause ---------------------------------------------------------------------
Exception: org.apache.avalon.composition.model.ModelException
Message: Unable to construct a new containment model: untitled.
---- cause ---------------------------------------------------------------------
Exception: java.lang.LinkageError
Message: loader constraints violated when linking org/apache/avalon/extension/manager/ExtensionManager class
---- stack trace ---------------------------------------------------------------
java.lang.LinkageError: loader constraints violated when linking org/apache/avalon/extension/manager/ExtensionManager class
org.apache.avalon.composition.model.impl.DefaultModelFactory.createRootContainmentContext(DefaultModelFactory.java:368)
org.apache.avalon.composition.model.impl.DefaultModelFactory.createRootContainmentModel(DefaultModelFactory.java:287)
org.apache.avalon.merlin.impl.DefaultFactory.createApplicationModel(DefaultFactory.java:479)
org.apache.avalon.merlin.impl.DefaultFactory.create(DefaultFactory.java:244)
com.mrt.merlin.unit.AbstractMerlinTestCase.setUp(AbstractMerlinTestCase.java:159)
junit.framework.TestCase.runBare(TestCase.java:125)
junit.framework.TestResult$1.protect(TestResult.java:106)
junit.framework.TestResult.runProtected(TestResult.java:124)
junit.framework.TestResult.run(TestResult.java:109)
junit.framework.TestCase.run(TestCase.java:118)
junit.framework.TestSuite.runTest(TestSuite.java:208)
junit.framework.TestSuite.run(TestSuite.java:203)
org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:289)
org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:523)
--------------------------------------------------------------------------------