-
-
Notifications
You must be signed in to change notification settings - Fork 217
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set preset in Spring Config #10610
Set preset in Spring Config #10610
Conversation
pascalgrimaud
commented
Aug 19, 2024
- fix preset.json in spring config #10553
...n/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemProjectsRepository.java
Outdated
Show resolved
Hide resolved
...n/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemProjectsRepository.java
Outdated
Show resolved
Hide resolved
...n/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemProjectsRepository.java
Outdated
Show resolved
Hide resolved
...n/java/tech/jhipster/lite/project/infrastructure/secondary/FileSystemProjectsRepository.java
Outdated
Show resolved
Hide resolved
@pascalgrimaud : A error was detected with This must be done in this same PR. |
@renanfranca : I tested locally jhlite custom with the following code here and it works, as I used default override mechanism by Spring, so the property will be set with the default value preset.json |
b9a5881
to
21da0d8
Compare
Nice! Thanks! @pascalgrimaud : If you change the property at the line to change:from: to: The class without and with the change:from: ackage tech.jhipster.lite.project.infrastructure.secondary;
import java.nio.charset.StandardCharsets;
import org.mockito.Mockito;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import tech.jhipster.lite.module.infrastructure.secondary.FileSystemProjectFiles;
@TestConfiguration
public class FakedFileSystemProjectFilesConfiguration {
@Bean
@Primary
FileSystemProjectFiles fileSystemProjectFiles() {
FileSystemProjectFiles fileSystemProjectFiles = Mockito.spy(new FileSystemProjectFiles());
mockPresetJson(fileSystemProjectFiles);
return fileSystemProjectFiles;
}
private static void mockPresetJson(FileSystemProjectFiles fileSystemProjectFiles) {
String presetJsonContent =
"""
{
"presets": [
{
"name": "test preset one",
"modules": ["test-module-one", "test-module-two"]
},
{
"name": "test preset two",
"modules": ["test-module-three", "test-module-four"]
}
]
}
""";
Mockito.doReturn(presetJsonContent.getBytes(StandardCharsets.UTF_8)).when(fileSystemProjectFiles).readBytes("/preset.json");
}
} to: package tech.jhipster.lite.project.infrastructure.secondary;
import static org.mockito.ArgumentMatchers.*;
import java.nio.charset.StandardCharsets;
import org.mockito.Mockito;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import tech.jhipster.lite.module.infrastructure.secondary.FileSystemProjectFiles;
@TestConfiguration
public class FakedFileSystemProjectFilesConfiguration {
@Bean
@Primary
FileSystemProjectFiles fileSystemProjectFiles() {
FileSystemProjectFiles fileSystemProjectFiles = Mockito.spy(new FileSystemProjectFiles());
mockPresetJson(fileSystemProjectFiles);
return fileSystemProjectFiles;
}
private static void mockPresetJson(FileSystemProjectFiles fileSystemProjectFiles) {
String presetJsonContent =
"""
{
"presets": [
{
"name": "test preset one",
"modules": ["test-module-one", "test-module-two"]
},
{
"name": "test preset two",
"modules": ["test-module-three", "test-module-four"]
}
]
}
""";
Mockito.doReturn(presetJsonContent.getBytes(StandardCharsets.UTF_8)).when(fileSystemProjectFiles).readBytes(anyString());
}
} |
@renanfranca : nice catch and thanks. See my last commit, we should not need to apply this additional code about Cucumber |
@pascalgrimaud : please, hold on. Don't implement that change, it will break a lot of other tests and won't fix the problem when the I don't have a solution right now from the top of my head. |
@pascalgrimaud : Greate! Thanks for the solution, I didn't see that option implement the code in my head 😅 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @pascalgrimaud for your work! 😃