'How to get values from test.properties or application-test.properties
I'm trying to get value either from a test.properties or application-test.properties. My goal is to get some value from testprofile key, and then activate profiles from the values I read.
RunWith(SpringJUnit4ClassRunner.class)
@ActiveProfiles("test")
@SpringBootTest(classes = CustomActiveProfilesResolver.class)
@TestPropertySource(locations = "classpath:application-test.properties")
@EnableConfigurationProperties
@Configuration
public class CustomActiveProfilesResolver implements ActiveProfilesResolver
{
@Value("${testprofile}")
private String testprofile;
@Override
public String[] resolve(final Class<?> aClass)
{
System.out.println("profile" + testprofile);
String[] profileFound;
Pattern laPatternSeparVirgule = Pattern.compile("[,]");
if (testprofile == null)
{
throw new ProgrammationException(
"You have to define profiles");
}
else
{
List<String> listeDeStrings = new ArrayList<>();
String[] sousChaines = laPatternSeparVirgule.split(testprofile);
for (String chaine : sousChaines)
{
listeDeStrings.add(chaine);
System.out.println(chaine);
}
profileFound = new String[listeDeStrings.size()];
listeDeStrings.toArray(profileFound);
}
return profileFound;
}
}
No matter what I do, I can't reach testprofile=batch,postgres,hibernate.
I tried putting alternatively my application-test.properties in /src/main/resources and in /src/test/resources.
Could you please tell me what I've missed?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
