Concordion > Annotations >

ConcordionResources Annotation

Since Concordion 2.0.0

The ConcordionResources annotation can be used to apply a new theme to your specifications, tweak the existing styling, or add new css, javascript, images, or other resources.

The ConcordionResources annotation is applied to the fixture class corresponding to the specification. It can be applied to all classes in the fixture's class hierarchy - each class will be inspected in turn (parent first) for the annotation. Each annotation will be processed in isolation to others so they will operate independently. You will need to ensure that there are no conflicts.

The annotation has the following options:

valueOne or more files to add to the generated specification:
  • File name starting with '/' is relative to the root folder
  • File not starting with '/' is relative to the class the annotation is applied to
  • Supports wild card characters ("/images/*.png", "/css/*.*")
  • If no file is found an exception will be thrown
  • Will inspect the HTML and remove any links from the head section that contain "concordion.css" or any of the CSS or JavaScript files that have been added
  • CSS and JS files are treated a little differently than other files:
    • the specifications html will be updated with the correct link (if linked) or content (if embedded)
    • CSS is appended to the end of the head section so that any styling will override the default Concordion styles
    • any existing links to the resource file will be removed
    All other file types must be added to the specification at design time by whomever is writing the specification.
insertTypeEMBEDDED or LINKED - applies to css and js files only
includeDefaultStylingInclude or remove the default concordion css styling

Example: Linked Resource - relative to the fixture

Executing the following fixture:

package resources.test;

import org.concordion.api.ConcordionResources;
import org.concordion.integration.junit4.ConcordionRunner;
import org.junit.runner.RunWith;

@RunWith(ConcordionRunner.class)
@ConcordionResources( { "resources.js", "subfolder/resources with space.js", "../../resources.css" } )
public class ResourcesDemoTest {
    
}
		

will include a link to the resources resources.js, subfolder/resources with space.js and ../../resources.css in the generated specification and leave the default CSS in the generated specification.

Example: Linked Resource - relative to the root folder

Executing the following fixture:

package resources.test;

import org.concordion.api.ConcordionResources;
import org.concordion.integration.junit4.ConcordionRunner;
import org.junit.runner.RunWith;

@RunWith(ConcordionRunner.class)
@ConcordionResources( { "/resources.css", "/resources/test/resources.js" } )
public class ConcordionResourcesDemoTest {
    
}
		

will include a link to the resources ../../resources.css and resources.js into the generated specification and leave the default CSS in the generated specification.

Example: Wildcard Search

Executing the following fixture:

package resources.test;

import org.concordion.api.ConcordionResources;
import org.concordion.integration.junit4.ConcordionRunner;
import org.junit.runner.RunWith;

@RunWith(ConcordionRunner.class)
@ConcordionResources( value = { "resources.*", "/resource?.c??" } )
public class ConcordionResourcesDemoTest {
    
}
		

Will add the following resources to the generated specification:
Added Resources
resources.js
resources.txt
../../resources.css

Example: Embedded Resource

Executing the following fixture:

package resources.test;

import org.concordion.api.ConcordionResources;
import org.concordion.api.ConcordionResources.InsertType;
import org.concordion.integration.junit4.ConcordionRunner;
import org.junit.runner.RunWith;

@RunWith(ConcordionRunner.class)
@ConcordionResources( value = "/resources.css", insertType = InsertType.EMBEDDED )
public class ConcordionResourcesDemoTest {
    
}
		

will embed the resource resources.css into the generated specification.

Example: Remove Default CSS

Executing the following fixture:

package resources.test;

import org.concordion.api.ConcordionResources;
import org.concordion.api.ConcordionResources.InsertType;
import org.concordion.integration.junit4.ConcordionRunner;
import org.junit.runner.RunWith;

@RunWith(ConcordionRunner.class)
@ConcordionResources( value = "/resources.css", includeDefaultStyling = false )
public class ConcordionResourcesDemoTest {
    
}
		

will include a link to the resource ../../resources.css and remove the default CSS from the generated specification.

Example: Missing Resource File Throws Exception

Executing the following fixture:

package resources.test;

import org.concordion.api.ConcordionResources;
import org.concordion.api.ConcordionResources.InsertType;
import org.concordion.integration.junit4.ConcordionRunner;
import org.junit.runner.RunWith;

@RunWith(ConcordionRunner.class)
@ConcordionResources( "im-not-here.txt" )
public class ConcordionResourcesDemoTest {
    
}
		

will throw an exception containing the text "No file found".

Example: Annotations In Parent Class

Executing the following fixture:

package resources.test;

import org.concordion.api.ConcordionResources;

@ConcordionResources( "resources.js" )
public class ConcordionResourcesDemoTest extends ConcordionResourcesDemoParent {
    
}
		

And parent class:

	
package resources.test;

import org.concordion.api.ConcordionResources;
import org.concordion.integration.junit4.ConcordionRunner;
import org.junit.runner.RunWith;

@RunWith(ConcordionRunner.class)
@ConcordionResources( value = "/resources.css", includeDefaultStyling = false )
public class ConcordionResourcesDemoParent {
    
}
		

will include a link to the resources ../../resources.css and resources.js, and will remove the default CSS from the generated specification.

Example: Remove Developer Added Link and Script Elements

Executing the following fixture:

package resources.test;

import org.concordion.api.ConcordionResources;
import org.concordion.integration.junit4.ConcordionRunner;
import org.junit.runner.RunWith;

@RunWith(ConcordionRunner.class)
@ConcordionResources( value = {  "/resources.css", "resources.js" }, includeDefaultStyling = false )
public class ConcordionResourcesDemoTest {
    
}
		

With the following specification:

<head>
	<link href="../../concordion.css" rel="stylesheet" type="text/css" />
	<link href="resources.css" rel="stylesheet" type="text/css" />
	<link href="unknown.css" rel="stylesheet" type="text/css" />
	<script type="text/javascript" src="../resources.js"></script>
</head>
		

Will update the generated specification:

ConcordionResources Path Normalization

The specified resources path is normalized to determine if the specified resource exists. This fixes issue #286, which occurred when the target resources folder corresponding to the current source folder did not exist.

Example: Linked Resource - relative to the fixture

Executing the following fixture:

package resources.test.missingresourcesfolder;

import org.concordion.api.ConcordionResources;
import org.concordion.integration.junit4.ConcordionRunner;
import org.junit.runner.RunWith;

@RunWith(ConcordionRunner.class)
@ConcordionResources( { "../../../resources.css" } )
public class ResourcesDemoTest {

}
        

will include a link to the resource ../../resources.css in the generated specification.