Tag Archives: Spring

Spring C-notation

In a previous post, I talked about¬†Spring P-notation. ¬†In this blog post, I will give an example of the Spring C-notation for constructor arguments. The C-notation namespace needs to be added to your configuration file. All that is left is … Continue reading

Posted in Java | Tagged , , , , , , , , , | Leave a comment

Spring P-notation

Spring P-notation was made to make creating spring config files a little neater and shorter. Here is what a typical file would look like. Here is what it looks like once the P-notation is used.

Posted in Spring | Tagged , , , , , , | 1 Comment

How to run a JUnit test multiple times

I had a Spring-enabled JUnit test that I needed to run multiple times. I thought there used to be a JUnit annotation, but I couldn’t find it. I found and used the Spring @Repeat annotation. I used to set breakpoints … Continue reading

Posted in JUnit, Spring, Test Driven Development, Unit Tests | Tagged , , , , , | Leave a comment

Cucumber Spring Integration

I have a normal Spring-enabled project arranged as a Maven project. There were already JUnit tests in the project, along with the requisite Spring configuration. I needed to add Cucumber tests to the project. I started by adding a cucumber … Continue reading

Posted in Cucumber, Integration Tests, Java, JUnit, Spring, TDD, Test Driven Development, Unit Tests | Tagged , , , , , , , , , | Leave a comment

Injecting value from Spring Properties in Java

This is so easy, but I rarely use it and always forget how to use it. This is how you define a properties: The contents of the properties file is: To inject it into a class:

Posted in Java, Spring | Tagged , , | Leave a comment

Mocking Spring Security Principal for testing Spring MVC Controllers

How do you mock a Spring security principal for testing spring MVC controllers? Create a spring security principal Create a spring authentication Add the spring security authentication to the security context The last step should not be needed because MockMVC … Continue reading

Posted in Java, MockMVC, Spring, Spring MVC, Spring Security | Tagged , , , , , , , , , , , , , , | 2 Comments

Testing Spring MVC Rest controllers

Spring MVC 3.2 introduced the ability to test controllers via MockMVC. In this example, we will test a controller that returns JSON via @ResponseBody. Here are the dependencies that you will need. This is an example of the spring context. … Continue reading

Posted in Java, MockMVC, Spring, Spring MVC | Tagged , , , , , , , | Leave a comment

Get the active Spring profiles

Inject the Environment object The Environment object has getActiveProfiles that returns an array of active profiles. To get the first active profile, do…

Posted in Spring, Spring Profile | Tagged , , , | Leave a comment

Creating a list of strings in your Spring context

A friend of mine had to use this and I thought it was something worth remembering. He injected them with SpEl

Posted in Java, Spring | Tagged , , | Leave a comment

Expected exceptions in Junit

I had seen annotating a test class with @Test(expected = Exception.class) to test for exceptions before. In this case, we needed to test for Exception and the message was made the difference. This can be accomplished by @Rule

Posted in Integration Tests, Java, JUnit, Test Driven Development | Tagged , , , , , , , , , , | Leave a comment