loading table of contents...

Content Application Developer Manual / Version 2310

Table Of Contents Example - Testing Link Schemes

This example demonstrates how to set up an infrastructure that can be used for testing project link schemes. In the project's bean declaration myproject-linkschemes-beans.xml several link schemes are defined, as well as some CAE basic infrastructure such as the LinkFormatter bean. It is very useful to load exactly this file into a test application context, in order to...

  1. test the contents of the file itself, for example detect whether there a syntactical or wiring problems

  2. test the service instances with a configuration that is (nearly) equal to the configuration used in the project

  3. test the service (in this example: the links scheme) in interaction with similar services, for example make sure that a certain link scheme is addressed for certain parameters and not a different link scheme instance.

Use the configuration pattern to construct the application context with the desired configuration:

class MyTest {
  @Configuration(proxyBeanMethods = false)
          value = {
                  "classpath:/com/mycompany" +
          reader = ResourceAwareXmlBeanDefinitionReader.class
  public static class LocalConfig {
    public static final String PROFILE = "MyTest";

  // ...

Using a local test-only profile is recommended if you are using component scan to find your beans. If not using the ActiveProfile, Profile annotation pair LocalConfig classes of other tests might be found through component scan.

Now you can just inject the LinkFormatter and use it as in production code:

LinkFormatter linkFormatter;

String link = linkFormatter.formatLink(
        new MyPage(123),
        new MockHttpServletRequest(),
        new MockHttpServletResponse(),


Search Results

Table Of Contents

Your Internet Explorer is no longer supported.

Please use Mozilla Firefox, Google Chrome, or Microsoft Edge.