Mobicents Summit 2012 - George Vagenas - Testing SIP Applications with Arquillian and SipUnit

Preview:

Citation preview

Testing SIP Applications with Arquillian and SipUnit

Annual Mobicents Community Summit

Rio de Janeiro, October 3-8, 2012

George VagenasCDI Telco Framework & SIP Testing project lead

Agenda

● Introduction

○ SipServlets applications testing

○ Arquillian extension for SipServlets

○ SipUnit

● Arquillian Extension for SipServlets○ Features

○ MSS Tomcat 6 & Tomcat 7 containers

● SipUnit

○ Features

Past year achievements

● Arquillian Extension for SipServlets 1.0.0.ALPHA1

● Telestax took over leadership of SipUnit● SipUnit 2.0.0

SipServlets applications testing

Requirements:● Manage SipServlets enabled container● Manage test archive● Integration with a testing framework (JUnit

or TestNG) ● SIP Client (UAC/UAS) to interact with the

SipServlet application

Arquillian Extension for SipServletsArquillian testing framework, seeks to minimize the burden on the developer to author integration tests by handling all aspects of test execution, including:● managing the lifecycle of the container (start/stop),● bundling the test class with dependent classes and

resources into a deployable archive,● enhancing the test class (e.g., resolving @Inject, @EJB

and @Resource injections),● deploying the archive to test (deploy/undeploy) and

capturing results and failures.

Arquillian Extension for SipServletsMobicents brings the Sip Servlets Arquillian container for testing converged applications.

Container is based on:● Tomcat 6.x● Tomcat 7.x

Arquillian Extension for SipServletsExtras● Annotations

○ @ContextParam○ @ContextParamMap○ @ConcurrencyControlMode

● Helper classes○ ContextParamTool○ SipStackTool

● Lifecycle extension to provide finer grained control over container's and test's lifecycle

Arquillian Extension for SipServlets● Finer grained control over the test's lifecycle

and the container's lifecycle● Override container configuration as needed● The integration is completely transparent,

which means you can launch the tests and get the test results using existing IDE, Ant and Maven test plugins without any add-ons.

Arquillian Extension for SipServlets● CTF can be optionally enabled in order to

enrich the test or the test archive.● On the same test we can have

○ Multiple test archives○ Multiple container configuration

Arquillian Extension for SipServlets

<container qualifier="mss-tomcat-embedded-6" default="true" mode="manual">

<configuration><property name="tomcatHome">target/mss-tomcat-embedded-

6</property><property name="workDir">work</property><property name="bindHttpPort">8888</property><property name="unpackArchive">true</property><property name="sipConnectors">:5070,:5070/TCP</property><property name="bindAddress">127.0.0.1</property><property name="sipApplicationRouterProviderClassName">org.

mobicents.servlet.sip.router.DefaultApplicationRouterProvider</property></configuration>

</container>

Arquillian Extension for SipServlets@RunWith(Arquillian.class)public class ShootistSipServletTest extends SipTestCase {@Deployment(name="simpleArchive", managed=false)

public static WebArchive createTestArchive(){WebArchive webArchive = ShrinkWrap.create(WebArchive.class,"shootistsipservlet.war");webArchive.addClasses(ShootistSipServlet.class);webArchive.addAsWebInfResource("in-container-sip.xml", "sip.xml");return webArchive;}

Arquillian Extension for SipServlets

@Test @ContextParam(name="cancel", value="true")public void testShootist() throws Exception {

SipStackTool sipStackTool = new SipStackTool();receiver = sipStackTool.initializeSipStack(SipStack.PROTOCOL_UDP,

"127.0.0.1", "5080", "127.0.0.1:5070");sipPhone = receiver.createSipPhone("127.0.0.1", SipStack.

PROTOCOL_UDP, 5070, "sip:LittleGuy@there.com");sipCall = sipPhone.createSipCall();sipCall.listenForIncomingCall();deployer.deploy("simpleArchive");assertTrue(sipCall.waitForIncomingCall(timeout));assertTrue(sipCall.sendIncomingCallResponse(Response.TRYING,"

Trying", timeout));

Arquillian Extension for SipServlets

What comes next:● Mobicents Sip Servlets AS7 container

SipUnit

SipUnit provides a test environment geared toward unit testing SIP applications.

The primary goal of SipUnit is to abstract the details of SIP messaging/call handling and facilitate free-flowing, sequential test code so that a test target can be exercised quickly and painlessly

SipUnit features

● Maven artifacts● Junit 4 support● TLS support● SIP UAC & UAS● uses the JAIN-SIP reference implementation as its

underlying SIP stack/engine● JUnit-like test development and execution environment

with SIP-specific assertions added ● Different levels of SIP handling abstraction depending

on test case needs. If you don't care how a setup call gets established, use the highest level - SipPhone.makeCall().

SipUnit features

● Support for registration and call handling with or without authentication

● Support for presence subscription handling (SUBSCRIBE/NOTIFY)

● CANCEL handling● Support for MESSAGE● REFER and associated subscription handling● Support for NAT traversal (STUN)● Support for testcase-specified timeouts● A test can act as more than one network element - ie, it

can act as both the caller and callee endpoints to test a network element between the two.

SipUnit example

b.listenForIncomingCall();

a.initiateOutgoingCall("sip:becky@nist.gov", null);

b.waitForIncomingCall(5000);

b.sendIncomingCallResponse(Response.RINGING, "Ringing", 0);

a.waitOutgoingCallResponse(10000);

b.sendIncomingCallResponse(Response.OK, "Answer - Hello world", 0);

a.waitOutgoingCallResponse(10000);

a.sendInviteOkAck();

SipUnit download

● Binary: http://code.google.com/p/commtesting/downloads/list

● Maven artifact <dependency> <groupId>org.cafesip.sipunit</groupId> <artifactId>sipunit</artifactId> <version>2.0.0</version></dependency><repository>

<id>mobicents-public-repository-group</id><name>Mobicens Public Maven Repository Group</name><url>https://oss.sonatype.org/content/groups/public</url><layout>default</layout><releases>

<enabled>true</enabled><updatePolicy>never</updatePolicy>

</releases><snapshots>

<enabled>true</enabled><updatePolicy>never</updatePolicy>

</snapshots></repository>

SipServletes Commtesting links

● Project site: http://code.google.com/p/commtesting/

● SipServlets Arquillian Extension Documentation: https://mobicents.ci.cloudbees.com/view/SIP%20Testing/job/sipservlets.arquillian/lastSuccessfulBuild/artifact/documentation/html_single/index.html

● SipUnit Documentation: https://mobicents.ci.cloudbees.com/job/SipUnit/lastSuccessfulBuild/artifact/sipunit/docs/jdocbook-mobicents/target/docbook/publish/en-US/html_single/index.html

Contact

George Vagenasgvagenas@gmail.com

Thank you