Sip Servlets – Extension to Arquillian


The Mobicents Sip Servlet extension to Arquillian 1.0.0-CR1 release introduces two Maven archetypes to help you quickly setup a test project.

This tutorial will walk you through the basic steps to create a testing project.

First pick one on of the Mobicent Sip Servlet Arquillian containers depending on your needs:

  • For embedded Tomcat 6 container based on Mobicents Sip Servlets 1.7.0 (Java Servlets 2.5) create a maven project using the following maven archetype:
    mvn archetype:generate -DartifactId=my-sipapp-test -Dversion=1.0-SNAPSHOT -DarchetypeArtifactId=mss-testing-embeddedTomcat6-archetype -DarchetypeGroupId=org.mobicents.servlet.sip.archetypes -DarchetypeVersion=1.0
  • For embedded Tomcat 7 container based on Mobicents Sip Servlets 2.0.0 (Java Servlets 3.0) create a maven project using the following maven archetype:
    mvn archetype:generate -DartifactId=my-sipapp-test -Dversion=1.0-SNAPSHOT -DarchetypeArtifactId=mss-testing-embeddedTomcat7-archetype -DarchetypeGroupId=org.mobicents.servlet.sip.archetypes -DarchetypeVersion=1.0

The created project will contain everything you need to get started:

  • The required dependencies
  • Mobicents Sip Servlet Arquillian container
  • SipUnit
  • A SIP servlet class
  • The test class

Create the project

So lets get started:

  • Open a console window and issue the command:
    mvn archetype:generate -DartifactId=my-sipapp-test -Dversion=1.0-SNAPSHOT -DarchetypeArtifactId=mss-testing-embeddedTomcat6-archetype -DarchetypeGroupId=org.mobicents.servlet.sip.archetypes -DarchetypeVersion=1.0
  • Once the Maven Archetype plugin creates the project, change to the my-sipapp-test directory
  • You can quickly check that everything is setup correctly by running the test using the command: mvn test
  • Now lets prepare the project for import to Eclipse with the command: mvn clean eclipse:clean eclipse:eclipse
  • Next go to Eclipse and import the project to the workspace

Project Structure

The structure of the created project will be:

Project Structure

Project Structure

  • The folder src/test/java contains the test class.
  • The folder src/test/resources contains the required fot the test, configuration and resource files.
  • The folder src/main/java contains the SIP servlet class. This is the actual SIP Servlet application we need to test.

Next lets discus each of the folder’s contents.

SIP Servlet application

The class is the SIP Servlet application that we need to test.


The application will handle INVITE, ACK and BYE messages.

When a new INVITE message arrives, the application will send 100 TRYING, 180 RINGING and finally 200 OK responses. When a BYE received, the application will send a 200 OK response.

This is the behavior that we will assert later in the test method.

Test resources and configuration

  • arquillian.xml: Arquillian controlled containers, such as Mobicents Sip Servlet Arquillian Embedded Tomcat 6 container, need arquillian.xml in order to configure parts of the server such as HTTP and SIP connectors ports and the IP Address that the connectors will bind to.
  • log4j.xml: This is the configuration for Log4J. You can change the loglevel here
  • in-container-sip.xml: The sip.xml deployment descriptor that will be used to created test archive.
  • The configuration needed for the Sip Servlet Application Router.

Test class

The is the test class of the project. Here we assembly the test archive, we setup and tear down the pre-requisite components for the test , such as the SIP client, and we define the test methods.



Lets go through the important parts of the test class:

  • We need to annotate our test class with @RunWith(Arquillian.class) in order Arquillian to pick up the test
  • Using JUnit 4 @Before, @After and @BeforeClass annotations, we setup the SipUnit, the SIP client that will be used in our test method later
  • The methods createTestArchive() that is annotated with @Deployment, will be called by Arquillian to get the test archive and deploy it. In this method:
    • We create a test archive with name simplesipservlet.war archive:
      WebArchive webArchive = ShrinkWrap.create(WebArchive.class, “simplesipservlet.war”);
    • We add the SIP servlet SimpleSipServlet.class class:
    • We add the required SIP Servlets deployment descriptor sip.xml:
      webArchive.addAsWebInfResource(“in-container-sip.xml”, “sip.xml”);
    • And finally we return the test archive:
      return webArchive;
  • Last is the test method annotated with JUnit 4 @Test. Here SipUnit will interact with the SIP Servlet application and will assert the results.
    • SipUnit will initiate a call to the application
      assertTrue(sipUnitCall.initiateOutgoingCall(toUri, null));
    • Then will wait for an answer and will check that the answer is a 200 OK
      assertEquals(SipServletResponse.SC_OK, sipUnitCall.getLastReceivedResponse().getStatusCode());
    • Next will send an ACK
    • And finally will disconnect this call:


Running the test

Now we are ready to run the test.

Right click on the and choose Run As -> JUnit test. You will see a lot of messages in the console and finally the GREEN bar of the JUnit result:

JUnit Result

JUnit Result

You can also run the test from the console using Maven surefire plugin. Just open a console in the project’s directory and run the test with the command: mvn test.


0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply