Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "EclipseLink/Development/Testing/DBWS"

Line 7: Line 7:
 
just a bridge between OXM and ORM projects:
 
just a bridge between OXM and ORM projects:
 
<source lang="text" enclose="div">
 
<source lang="text" enclose="div">
Eclipselink Tree
+
Eclipselink SVN Tree
 
\---trunk
 
\---trunk
 
     |  about.html
 
     |  about.html
Line 89: Line 89:
 
<code>Map<QName, XMLDescriptor></code> of <code>descriptorsByQName</code>.
 
<code>Map<QName, XMLDescriptor></code> of <code>descriptorsByQName</code>.
  
The XR service is built by an <code>XRServiceFactory</code> thru the public API <code>public XRServiceAdapter buildService(XRServiceModel xrServiceModel)</code>
+
The XR service is built by an <code>XRServiceFactory</code> thru the API <code>public XRServiceAdapter buildService(XRServiceModel xrServiceModel)</code>:
 +
<source lang="java5">
 +
XRServiceFactory factory = new XRServiceFactory() {
 +
    @Override
 +
    public XRServiceAdapter buildService(XRServiceModel xrServiceModel) {
 +
parentClassLoader = this.getClass().getClassLoader();
 +
xrSchemaStream = new ByteArrayInputStream(KEYMAPPINGS_SCHEMA.getBytes());
 +
return super.buildService(xrServiceModel);
 +
    }
 +
...
 +
};
 +
XMLContext context = new XMLContext(new DBWSModelProject());
 +
XMLUnmarshaller unmarshaller = context.createUnmarshaller();
 +
DBWSModel model = (DBWSModel)unmarshaller.unmarshal(new StringReader(KEYMAPPINGS_DBWS));
 +
xrService = factory.buildService(model);
 +
</source>

Revision as of 14:03, 23 March 2009

Summary

DBWS has a number of test suites, all written using JUnit4. This page outlines the various testsuites and the types of testing in each suite.

DBWS core tests

In the SVN repository under the DBWS component's high-level directory, there is a project eclipselink.dbws.test
This project contains test classes that test DBWS in its XRM mode - no Web service deployment artifacts, no container -
just a bridge between OXM and ORM projects:

Eclipselink SVN Tree
\---trunk
    |   about.html
    |   ...
    |  
    +---dbws
    |   +---eclipselink.dbws.test
    |   |   |   .classpath
    |   |   |   .project
    |   |   |   build.properties
    |   |   |   build.xml
    |   |   |
    |   |   +---etc
    |   |   |       dbsetup_keymappings.sql
    |   |   |       dbsetup_relationships.sql
    |   |   |       dbteardown_keymappings.sql
    |   |   |       dbteardown_relationships.sql
    |   |   |
    |   |   \---src
    |   |       \---dbws
    |   |           \---testing
    |   |               |   DBWSTestHelper.java
    |   |               |   RootHelper.java
    |   |               |
    |   |               +---keymappings
    |   |               |       KeyMappingsTestSuite.java
    |   |               |
    |   |               \---relationships
    |   |                       RelationshipsAddress.java
    |   |                       RelationshipsEmployee.java
    |   |                       RelationshipsPhone.java
    |   |                       RelationshipsTestSuite.java


The setup required to run these tests is running the appropriately named dbsetup_xxx.sql script (and conversely dbteardown_xxx.sql -
where xxx = keymappings or relationships).

The test code is in the (related) xxxTestSuite class - let's look at KeyMappingsTestSuite:

public class KeyMappingsTestSuite {
 
    static final String KEYMAPPINGS_SCHEMA =
        "<?xml version='1.0' encoding='UTF-8'?>" +
        "<xsd:schema targetNamespace=\"urn:keymappings\" xmlns=\"urn:keymappings\" elementFormDefault=\"qualified\"\n" +
          "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"\n" +
          ">\n" +
          "<xsd:complexType name=\"phone\">\n" +
            "<xsd:sequence>\n" +
              "<xsd:element name=\"area-code\" type=\"xsd:string\" />\n" +
              "<xsd:element name=\"phone-number\" type=\"xsd:string\" />\n" +
              "<xsd:element name=\"type\" type=\"xsd:string\" />\n" +
            "</xsd:sequence>\n" +
            "<xsd:attribute name=\"phone-id\" type=\"xsd:int\" use=\"required\" />\n" +
            "<xsd:attribute name=\"owner-ref-id\" type=\"xsd:int\" use=\"required\" />\n" +
          "</xsd:complexType>\n" +
...
    // test fixtures
    public static XMLComparer comparer = new XMLComparer();
    public static XMLPlatform xmlPlatform = XMLPlatformFactory.getInstance().getXMLPlatform();
    public static XMLParser xmlParser = xmlPlatform.newXMLParser();
    public static XRServiceAdapter xrService = null;
    @BeforeClass
    public static void setUp() {
        final String username = System.getProperty(DATABASE_USERNAME_KEY);
        if (username == null) {
            fail("error retrieving database username");
        }


One of the notable things about this test class is the use of static Strings that contain all of the required XRM meta-data:
schema, ORM and OXM projects and the DBWS service descriptor file. For this test, these have been pre-built by hand and assembled
to follow the rules and styles of DBWS runtime processing. In fact, to be more accurate, these tests pre-date the existence of the
DBWSBuilder utility - that knows the rules and styles of DBWS runtime processing and produces meta-data to match.

We can see the static JUnit4 test fixtures for this testsuite: OX helper objects that will be used for comparing XML documents and an
xrService of type XRServiceAdapter. The XRServiceAdapter is a sub-class of XRServiceModel, the model object for the DBWS service descriptor
(fields: name, session-name and a Map<String, Operation> of operations). The XRServiceAdapter object has additional fields: schemaNamespace,
orSession (built from the ORM project), oxSession (built from the OXM project), xmlContext (built from the OXM project), schema and a
Map<QName, XMLDescriptor> of descriptorsByQName.

The XR service is built by an XRServiceFactory thru the API public XRServiceAdapter buildService(XRServiceModel xrServiceModel):

XRServiceFactory factory = new XRServiceFactory() {
    @Override
    public XRServiceAdapter buildService(XRServiceModel xrServiceModel) {
	parentClassLoader = this.getClass().getClassLoader();
	xrSchemaStream = new ByteArrayInputStream(KEYMAPPINGS_SCHEMA.getBytes());
	return super.buildService(xrServiceModel);
    }
 ...
};
XMLContext context = new XMLContext(new DBWSModelProject());
XMLUnmarshaller unmarshaller = context.createUnmarshaller();
DBWSModel model = (DBWSModel)unmarshaller.unmarshal(new StringReader(KEYMAPPINGS_DBWS));
xrService = factory.buildService(model);

Back to the top