You can use a datapool from a Hyades test by making calls to the datapool API from a test's generated Java code.
The datapool you want to use must already exist.
The Java code for the test from which you want to use a datapool must exist. Generate code by right-clicking the test and selecting Generate.
The following excerpt, illustrating step 2, shows the import statements appearing at the beginning of a generated Hyades test. The lines in bold at the end are the datapool import statements that you must add to your test.
package test; import java.util.Random; import junit.extensions.RepeatedTest; import junit.framework.Test; import org.eclipse.hyades.test.common.junit.DefaultTestArbiter; import org.eclipse.hyades.test.common.junit.HyadesTestCase; import org.eclipse.hyades.test.common.junit.HyadesTestSuite; import org.eclipse.hyades.test.http.runner.HttpCookieCache; import org.eclipse.hyades.test.http.runner.HttpExecutor; import org.eclipse.hyades.test.http.runner.HttpHeader; import org.eclipse.hyades.test.http.runner.HttpRequest; import org.eclipse.hyades.test.http.runner.HttpResponse; import org.eclipse.hyades.test.http.runner.internal.util.HttpTestUtil; import org.eclipse.hyades.models.common.datapool.impl.Common_DatapoolFactoryImpl; import org.eclipse.hyades.execution.runtime.datapool.*;
The following excerpt, illustrating step 3, is taken from a generated test in which the tester went to www.amazon.com and searched for a book named atonement.
public void c8postwww_amazon_com() throws Exception {
HttpRequest request = new HttpRequest();
request.setMethod("POST");
request.setVersion("1.1");
request.setHost("www.amazon.com");
request.setPort(80);
request
.setAbsolutePath("/exec/obidos/search-handle-form/102-5005957-7048952");
request
.setBody("url=index%3Dstripbooks=atonement=10=6");
In the following excerpt, illustrating steps 4 and 5, the lines in bold show how to modify the generated test code such that a column named title in a datapool named books replaces the value atonement. In place of "pathname of books.datapool" in the second line, put the fully-qualified pathname of the books datapool.
public void c8postwww_amazon_com() throws Exception {
IDatapoolFactory dpFactory = new Common_DatapoolFactoryImpl();
IDatapool datapool = dpFactory.load(new File("pathname of books.datapool"), false); //false - nonshared
IDatapoolIterator iter = dpFactory.open(datapool,
"org.eclipse.hyades.datapool.DatapoolIteratorSequentialPrivate");
iter.dpInitialize(datapool, -1); //-1 - go through all ECs
while (!iter.dpDone())
{
HttpRequest request = new HttpRequest();
request.setMethod("POST");
request.setVersion("1.1");
request.setHost("www.amazon.com");
request.setPort(80);
request
.setAbsolutePath("/exec/obidos/search-handle-form/102-5005957-7048952");
// request
// .setBody("url=index%3Dstripbooks=atonement=10=6");
//new
String title = iter.dpCurrent().getCell("title").getStringValue();
iter.dpNext();
String body = "url=index%3Dstripbooks=" + title + " =10=6";
request.setBody(body);
//end new
// Lines from test ommitted ...
}// Close loop through datapool
Parent topic: Providing tests with variable data
Previous topic: Editing a datapool