Skip to content

Instantly share code, notes, and snippets.

@kinow
Created October 24, 2011 00:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kinow/1308128 to your computer and use it in GitHub Desktop.
Save kinow/1308128 to your computer and use it in GitHub Desktop.
TestLink Java API BaseTest for TestNG tests
package br.eti.kinoshita.testlinkjavaapi;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import org.apache.commons.io.FileUtils;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
public class BaseTest
{
protected TestLinkAPI api;
protected HttpTestServer server;
/**
* Set up method that creates the instance of the TestLink API.
*/
@BeforeClass
protected void setUp()
throws Exception
{
this.server = new HttpTestServer();
this.loadXMLRPCMockData( "tl.checkDevKey.xml" );
this.server.start();
this.api = new TestLinkAPI(new URL("http://localhost:"+this.server.getPort()+"/testlink/lib/api/xmlrpc.php"), "devKey");
}
public void loadXMLRPCMockData( String xmlFile )
{
URL url = getClass().getResource( "/br/eti/kinoshita/testlinkjavaapi/testdata/" + xmlFile );
String filePath = url.getFile();
File file = new File(filePath);
String mockXml;
try
{
mockXml = FileUtils.readFileToString(file);
} catch (IOException e)
{
throw new RuntimeException(e);
}
this.server.setMockResponseBody(mockXml);
}
@AfterClass(alwaysRun=true)
public void tearDown()
throws Exception
{
this.server.stop();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment