Category Archives: Uncategorized

Jersey Tests with Authentication

When I tested my REST-interface, which I implemented with Jersey, I also wanted to write Unit tests for an easy test. Since I spent some time to get authentication and autorisation working, I stood before another problem, when logging in and check access to my resources.

The problem that occured was that with each request a new session id was generated, which makes my authentication worthless. But I found a way around it:

So the secret is to save the cookie of the response and append it to each following request!

Posted in Uncategorized | 1 Comment

OJB: Can’t read repository file ‘repository.xml’

When getting this error when trying to access a database configured with OJB, then check the XML-files referenced by the repository.xml file. If you find a XML-header then remove it and it should work fine again.

I had the problem when I wanted to dynamically change the repository_database.xml file and then tried to access the MetadataManager, which accessed the configuration file(s).  When I wrote the XML file with the TransformerFactory I had to do the following to remove the header:

Posted in Uncategorized | Leave a comment

Spring: Attribute “xmlns” must be declared for element type “beans”

This happens if you add ‘xmlns’ tags into your application-context file where you define your beans. Also other spring configurations might lead to a similar error. The solution for this is to remove the document type of the xml-file, which should look like this:

Afterwards the error should be gone, since the file is not checked against another definition.

Posted in Uncategorized | 1 Comment

Spring Injection in JUnit4 – Testcases

If you use maven then you should make sure to have the following dependencies within your pom:

Your test class should look like this:

The ContextConfiguration has to be setup with the spring configuration file, which contains all the beans that can be used for injection.

If you get initialization errors or ClassNotFoundExceptions then you should make sure to have the correct version of your dependencies installed. For JUnit it’s recommended to stick with version 4.4 since the newer versions throw a ClassNotFoundException if you combine your tests with Spring Injection.

Posted in Uncategorized | 1 Comment