What is the Apache James MTP?

Apache James Mail Protocol Tester (MTP) is a library providing a framework for the scritable functional testing of ASCII based line protocols.

This contains a lightweight scripting framework suitable for the functional testing of the ASCII line based protocols common in mail. A script contains a list of client requests and templated server responses. The framework runs the client lines against a host system and then compares the server lines received in response against the template responses.

Using MPT

Host System

MPT is a lightweight, flexible framework which is capable of being used in a variety of ways. HostSystem is pivotal, defining the interface between the framework and the server system under test.

  • The ExternalHostSystem implementation connects to a port on a server. This is typically used to test a complete running server (including the sockets). MPT AntLib provides an Ant task suitable for this use case.
  • When performing in-JVM testing (without a live server socket) a custom implementation must be created connecting the framework to the components under test. This use case is typically developed as a JUnit test case.

With JUnit

In-JVM JUnit testing is a typical use case. The framework provides abstract superclasses which setup up appropriate fixtures.

Script Features

Basic Syntax

MPT scripts are line based plain text files. The initial letter of each line determines it's type:
Line Prefix Description
# A comment: the rest of the line will be ignored
C: A client request: the rest of the line will be sent to the server
S: A server response: the framework will read one line of response from the server, and compare it to the rest of the line (see regex matching)


# This script is a basic SMTP HELO.
S: 220 localhost. SMTP Server \(JAMES SMTP Server .*
C: HELO example.org
S: 250 localhost. Hello example.org .*
S: 221 2.0.0 localhost. Service closing transmission channel

Regex Matching Of Server Responses

The server responses in the script support regex matching. Java Pattern is used for the regex comparison and so the syntax is identical.

Variable Substitution

Variables of form ${variable-name} may be substituted by values passed into the script builder before interpretation.