Hello I have a springboot app and there are two possible spring profiles, one environment config related (dev,prod,staging...) and one with mocked some remote service, let's call it remoteServiceMock. So I have origin service that marked with :
@Profile("!remoteServiceMock")
And mock bean:
@Profile("remoteServiceMock")
Everything, except test are fine , when I run application with :
install -Dspring.profiles.active=dev,remoteServiceMock
or
install -Dspring.profiles.active=dev
So corresponding beans are loaded. But I got problems with testing. My test class:
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class)
@Category({IntegrationTest.class})
@TestPropertySource("classpath:test.properties")
@IfProfileValue(name = "spring.profiles.active",
values = "remoteServiceMock")
public class DeltaServiceMockTest {
@Autowired
private RemoteService remoteService;
@Test
public void shouldIntiService() throws Exception {
assertNotNull(remoteService);
}
@Test
public void shouldGetMockDelta() throws Exception {
RemoteData remoteDate = remoteService.getData(new Date(), new Date());
assertEquals(15,remoteDate.getActivity().size());
}
}
The problem that tests are being executed only if spring.profiles.active exactly match . So tests will run only if I will write:
@IfProfileValue(name = "spring.profiles.active", = "dev,remoteServiceMock")
The question are:
1) Is it possible to write some kind of extension for IfProfileValue with "contains"/"not contains" profile feature
2) Is the any other better solution for my goal ? (So I want to mock one (in feature there are several will be) of remote service and deploy my app to staging env).
Thanks
Aucun commentaire:
Enregistrer un commentaire