JBoss Community Archive (Read Only)

Scribble

QA

There are two types of QA that are performed as part of
the project:

  1. Local test cases
    Unit tests would be used to test the individual classes
    within the specific implementation of an interface.

  2. Integration tests
    Where multiple implementations of a particular module could
    exist, an integration test strategy may be useful to ensure that
    all implementations of the same interface behaviour in the
    same way.
    This section will discuss the second type of QA, aimed at
    ensuring multiple implementations behaviour in the same way.

Protocol Conformance Test Kit (CTK)

Parser

This part of the project structure provides a set of
tests to check that the parser (being tested) processes
the supplied set of test 'protocol' descriptions, and
returns the correct object model.

The test protocol descriptions are stored in the
src/test/resources/tests folder.
The global sub-folder provides
the global representation of the protocols, with the
local representation of these protocols (for all of the
relevant roles) being defined in the local
sub-folder.

Each test is accompanied by a junit test, defined in
the class org.scribble.protocol.parser.ctk.
For example:

	@org.junit.Test
	public void testSingleInteraction() {
		TestJournal logger=new TestJournal();
		
		ProtocolModel model=CTKUtil.getModel("tests/protocol/global/SingleInteraction.spr", logger);
		
		assertNotNull(model);
		
		assertTrue(logger.getErrorCount() == 0);
		
		// Build expected model
		ProtocolModel expected=new ProtocolModel();
		
		ImportList imp=new ImportList();
		TypeImport t=new TypeImport();
		t.setName("Order");
		imp.getTypeImports().add(t);
		expected.getImports().add(imp);
		
		Protocol protocol=new Protocol();
		expected.setProtocol(protocol);
		
		protocol.setName("SingleInteraction");
		
		RoleList rl=new RoleList();
		Role buyer=new Role();
		buyer.setName("Buyer");
		rl.getRoles().add(buyer);
		Role seller=new Role();
		seller.setName("Seller");
		rl.getRoles().add(seller);
		
		protocol.getBlock().add(rl);
		
		Interaction interaction=new Interaction();
		
		MessageSignature ms=new MessageSignature();
		TypeReference tref=new TypeReference();
		tref.setName("Order");
		ms.getTypeReferences().add(tref);
		interaction.setMessageSignature(ms);
		interaction.setFromRole(buyer);
		interaction.getToRoles().add(seller);
		
		protocol.getBlock().add(interaction);
		
		CTKUtil.verify(model, expected);
	}

The CTKUtil.getModel() method retrieves the
protocol description from a named file, and invokes the
parser implementation being tested.

The parser implementation is defined using the
scribble.protocol.parser system property.
If this property is not set, then it will default to the
ANTLR based implementation.

Once the model has been retrieved using the parser, the
unit test will construct an 'expected' object model.

The final step in the unit test is to invoke the
CTKUtil.verify() method to compare the
model retrieved against the 'expected' version.

To perform the verification, each model is flattened
to produce a list of 'model objects'. Then the
verification mechanism iterates through the list,
checking that the same entry in each list is
identical - first checking they are the same class,
and then invoking a 'comparator' implementation for
that class.

The 'comparator' implementations are defined in the
org.scribble.protocol.parser.ctk.comparators
package. The comparator implementations are
registered in the static initializer for the
org.scribble.protocol.parser.ctk.ProtocolParserTest
class.

Projection

As with the parser, the CTK provides a set of tests that can be
used to test the projection implementation.

The projector implementation is defined using the
scribble.protocol.projector system property.
If this property is not set, then it will use the default
implementation.

The tests are performed by initially retrieving the global
representation of a Protocol, and then the local representation
that is associated with the particular role that will be
projected. This local representation effectively becomes the
'expected' projection.

The project is then invoked, for the required role, which will
produce another local representation. All that is then left
to do is verify that the projected local representation is
identical to the local representation loaded from the
file.

An example of a projection test is shown below, where the global
model is being projected to the Buyer role:

	@org.junit.Test
	public void testSingleInteractionAtBuyer() {
		TestJournal logger=new TestJournal();
		
		ProtocolModel model=CTKUtil.getModel("tests/protocol/global/SingleInteraction.spr", logger);
		
		assertNotNull(model);
		
		assertTrue(logger.getErrorCount() == 0);
		
		ProtocolModel expected=CTKUtil.getModel("tests/protocol/local/SingleInteraction@Buyer.spr", logger);
		
		assertNotNull(expected);
		
		assertTrue(logger.getErrorCount() == 0);
		
		// Produce projection of model to buyer
		Role role=new Role("Buyer");
		ProtocolModel projected=CTKUtil.project(model, role, logger);
		
		CTKUtil.verify(projected, expected);
	}

Monitor

The monitoring CTK tests are based on simulating a set of events
against the local representation of protocols, as defined in the
tests/protocol/local sub-folder.

The JUnit tests are structured as follows:

	@org.junit.Test
	public void testSingleInteractionXSDImportAtBuyer() {
		testMonitor("tests/protocol/local/SingleInteractionXSDImport@Buyer.spr",
				"tests/monitor/SingleInteractionXSDImport@Buyer.events", false);
	}	

They simply specify the location of the local protocol representation
that will be monitored, and the location of the file containing the
list of events to be simulated. The final parameter indicates whether
the test (or simulation) is expected to fail.

The event file has the same structure as used with the
simulate command line function. For example,

receiveMessage,Order
sendChoice,validProduct
sendMessage,Order
receiveChoice,_Confirmation
receiveMessage,Confirmation
sendMessage,Confirmation
JBoss.org Content Archive (Read Only), exported from JBoss Community Documentation Editor at 2020-03-13 09:37:58 UTC, last content change 2011-05-24 08:36:13 UTC.