In the Spring test, you can use: @ActiveProfiles to activate some profile (but this is not a layout)
@RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("test.xml") @ActiveProfiles("myProfile") public class ProfileTest { @Autowired MyService myService @Test public void demo() { assertTrue(myService.env.acceptsProfiles("myProfile")); } }
But I need a layout, then write your own or use a mocking structure (Mokito or JMock). Environment has an AbstractEnvironment sublayer, where you just need to override the customizePropertySources(MutablePropertySources propertySources) method
@Override protected void customizePropertySources(MutablePropertySources propertySources) { Properties properties = .... propertySources.addLast(new MockPropertySource(properties)); }
Ralph
source share