4. Basic API overview
4.1. API Overview
All test cases should extend tigase.tests.AbstractTest
class, which offers a couple of handy methods that makes writing a test case easier. The most useful and basic are following:
handling user/admin account/connection:
createAccount()
- returnsAccountBuilder
allowing adjusting settings of particular user account;getAdminAccount()
andgetJaxmppAdmin()
- get eitherAccount
object related to admin account orJaxmpp
object directly.removeUserAccount(Jaxmpp jaxmpp)
- delete particular user account
vhost management:
addVhost(Jaxmpp adminJaxmpp, String prefix)
removeVhost(Jaxmpp adminJaxmpp, String VHost)
user basic xmpp functionality methods:
changePresenceAndWait(Jaxmpp from, Jaxmpp to, Presence.Show p)
sendAndFail(Jaxmpp from, Jaxmpp to)
sendAndWait(Jaxmpp j, IQ iq, AsyncCallback asyncCallback)
sendAndWait(Jaxmpp from, Jaxmpp to, Message message)
sendAndWait(Jaxmpp from, Jaxmpp to, String message)
testSendAndWait(Jaxmpp from, Jaxmpp to)
testSubscribeAndWait(Jaxmpp from, Jaxmpp to)
utility and configuration
getDomain()
- returns random domain from the list of available domains from the list of available domains (see Test Configuration)getDomain(int i)
- returns i-th domain from the list of available domains from the list of available domains (see Test Configuration)getInstanceHostname()
- returns random machine hostname from the list of available hostnames from the list of available domains (see Test Configuration)getInstanceHostnames()
- returns i-th machine hostname from the list of available hostnames from the list of available domains (see Test Configuration)getApiKey()
- returns configured HTTP-API keygetHttpPort()
- returns configured HTTP-API portgetBoshURI()
- returns BOSH URI based on configuration in Test ConfigurationgetWebSocketURI()
- returns WebSocket URI based on configuration in Test Configuration
In addition tigase.tests.utils.AccountBuilder
class allows:
setUsername(String username)
- set username/local part name of particular accountsetDomain(String domain)
- set domain name of particular accountsetPassword(String password)
- set password of particular accountsetEmail(String email)
- set e-mail address of particular accountsetLogPrefix(String logPrefix)
- allows to customize log prefix for log entries for this particular accountsetRegister(boolean register)
- specify whether account should be registered automatically
For the purpose of testing delayed response tigase.tests.Mutex
can be used: * waitFor(long timeout, String… items)
- instruct Mutex to wait for the particular items during configured timeout
* notify(String… itemName)
- upon receiving desired response notify Mutex about it * isItemNotified(String item)
- can be used to verify whether particular item was received (useful in asserts)
4.2. Creating simple test
As an example we will use src/test/java/tigase/tests/ExampleJaxmppTest.java
test case. Followings steps should be taken:
extend
AbstractTest
class:public class ExampleJaxmppTest extends AbstractTest {}
create test method and annote it with
@Test
. In addition specify test group and provide short description@Test(groups = { "examples" }, description = "Simple test verifying logging in by the user") public void SimpleLoginTest() {}
create an Account object, configure it, later build Jaxmpp object from it and connect to the server
Account userAccount = createAccount().setLogPrefix("test_user" ).build(); Jaxmpp jaxmpp = userAccount.createJaxmpp().build(); jaxmpp.login( true );
check whether the connection was successful
assertTrue(createJaxmpp.isConnected(), "contact was not connected" );
4.3. Adding test to suite
As described in TTS-NF Configuration, each test case must be included in Test Suite configuration.
create new xml file under
src/test/resources/
, for exampleexample.xml
in the created xml file add new test case as follows, creating new Suite (specifying name) with a list of tests (specifying names), and each test can contain multiple classes (for details please refer to TestNG documentation)
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd" > <suite name="Tigase Various Tests" verbose="1"> <test name="Example Tests"> <classes> <class name="tigase.tests.ExampleJaxmppTest" /> </classes> </test> </suite>
include created xml file in the Test Suite (see TTS-NF Configuration)