Fork me on GitHub
Subscribe to RSS Feed

Kit Plummer
Software Engineer :: Techitect :: Evangelist
kitplummer (AIM,Yahoo!IM,Gtalk,Skype)

To the top »

Please share:

Here’s my test class setup:

	public static void setUpServer() throws Exception {
		// Create a new Component.
		component = new Component();
		// Add a new HTTP server listening on port 8182.
		component.getServers().add(Protocol.HTTP, 8182);

		// Attach the sample application.
				new MyApplication(component.getContext()));
		// Create an application
		Application test = new Application(component.getContext()) {
		    public Restlet createRoot() {
		    	Reference rootUri = LocalReference.createFileReference(new File("./src/test/resources"));
		        return new Directory(getContext(), rootUri);
		component.getDefaultHost().attach("/test", test);
		// Start the component.

So, this takes files in ‘src/test/resources’ and makes them available through the spun up HTTP server. And, by taking advantage of the JUnit annotations we can ensure this only happens once, before any of the test code. Nice, eh? I’ve created a RFE at to provide direct support for non-absolute file paths, which the LocalReference works around (nicely).

Please comment:
blog comments powered by Disqus