Skip to content

Commit

Permalink
fix: generate KafkaConfiguration when init
Browse files Browse the repository at this point in the history
  • Loading branch information
fdelbrayelle committed May 1, 2022
1 parent af50f31 commit 7e521e2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ private void addConfiguration(final Project project) {

projectRepository.template(project, SOURCE, "KafkaProperties.java", getPath(MAIN_JAVA, packageNamePath, configKafkaPath));
projectRepository.template(project, SOURCE, "KafkaPropertiesTest.java", getPath(TEST_JAVA, packageNamePath, configKafkaPath));

projectRepository.template(
project,
SOURCE,
"KafkaConfiguration.java",
getPath(MAIN_JAVA, packageNamePath, TECHNICAL_INFRASTRUCTURE_CONFIG + "/kafka")
);
}

@Override
Expand All @@ -77,12 +84,6 @@ public void addDummyProducerConsumer(final Project project) {
projectRepository.template(project, SOURCE, "DummyProducer.java", getPath(MAIN_JAVA, packageNamePath, DUMMY_PRODUCER_PATH));
projectRepository.template(project, SOURCE, "DummyProducerTest.java", getPath(TEST_JAVA, packageNamePath, DUMMY_PRODUCER_PATH));
projectRepository.template(project, SOURCE, "DummyProducerIT.java", getPath(TEST_JAVA, packageNamePath, DUMMY_PRODUCER_PATH));
projectRepository.template(
project,
SOURCE,
"KafkaConfiguration.java",
getPath(MAIN_JAVA, packageNamePath, TECHNICAL_INFRASTRUCTURE_CONFIG + "/kafka")
);

projectRepository.template(project, SOURCE, "AbstractConsumer.java", getPath(MAIN_JAVA, packageNamePath, DUMMY_CONSUMER_PATH));
projectRepository.template(project, SOURCE, "DummyConsumer.java", getPath(MAIN_JAVA, packageNamePath, DUMMY_CONSUMER_PATH));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,13 @@ void shouldInit() {
String kafkaPropertiesTestPath = getPath("com/mycompany/myapp/technical/infrastructure/config/kafka");
assertFileExist(project, getPath(TEST_JAVA, kafkaPropertiesTestPath, "KafkaPropertiesTest.java"));
assertFileContent(project, getPath(TEST_JAVA, kafkaPropertiesTestPath, "KafkaPropertiesTest.java"), "class KafkaPropertiesTest");

assertFileExist(project, getPath(MAIN_JAVA, configKafkaPath, "KafkaConfiguration.java"));
assertFileContent(project, getPath(MAIN_JAVA, configKafkaPath, "KafkaConfiguration.java"), "public class KafkaConfiguration");
}

@Test
void shouldAddProducer() {
void shouldAddProducerConsumer() {
Project project = tmpProject();
initApplicationService.init(project);
mavenApplicationService.addPomXml(project);
Expand All @@ -76,9 +79,6 @@ void shouldAddProducer() {

String configKafkaPath = getPath("com/mycompany/myapp/technical/infrastructure/config/kafka");

assertFileExist(project, getPath(MAIN_JAVA, configKafkaPath, "KafkaConfiguration.java"));
assertFileContent(project, getPath(MAIN_JAVA, configKafkaPath, "KafkaConfiguration.java"), "public class KafkaConfiguration");

String dummyProducerPath = getPath("com/mycompany/myapp/dummy/infrastructure/secondary/kafka/producer");
assertFileExist(project, getPath(MAIN_JAVA, dummyProducerPath, "DummyProducer.java"));
assertFileContent(project, getPath(MAIN_JAVA, dummyProducerPath, "DummyProducer.java"), "public class DummyProducer");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,22 @@ void shouldInit() {
verify(buildToolService, times(2)).addDependency(any(Project.class), any(Dependency.class));
verify(dockerService, times(2)).getImageNameWithVersion(anyString());
verify(projectRepository).template(any(Project.class), anyString(), anyString(), anyString(), anyString());
verify(projectRepository, times(3)).template(any(Project.class), anyString(), anyString(), anyString());
verify(projectRepository, times(4)).template(any(Project.class), anyString(), anyString(), anyString());
verify(springBootCommonService, times(9)).addProperties(any(Project.class), anyString(), any());
verify(springBootCommonService, times(9)).addPropertiesTest(any(Project.class), anyString(), any());
verify(springBootCommonService).updateIntegrationTestAnnotation(any(Project.class), anyString());
}

@Test
void shouldAddProducer() {
void shouldAddProducerConsumer() {
Project project = tmpProjectWithPomXml();

when(springBootCommonService.getProperty(any(Project.class), anyString())).thenReturn(Optional.empty());
kafkaDomainService.addDummyProducerConsumer(project);

verify(springBootCommonService).addProperties(any(Project.class), anyString(), any());
verify(springBootCommonService).addPropertiesTest(any(Project.class), anyString(), any());
verify(projectRepository, times(8)).template(any(Project.class), anyString(), anyString(), anyString());
verify(projectRepository, times(7)).template(any(Project.class), anyString(), anyString(), anyString());
}

@Test
Expand All @@ -81,7 +81,7 @@ void shouldAddAkhq() {
}

@Test
void shouldNotAddProducer() {
void shouldNotAddProducerConsumer() {
Project project = tmpProjectWithPomXml();

when(springBootCommonService.getProperty(any(Project.class), anyString())).thenReturn(Optional.of("queue.jhipster.dummy"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,11 @@ void shouldInitKafka() throws Exception {
assertFileExist(projectPath, MAIN_DOCKER + "/" + KAFKA_DOCKER_COMPOSE_FILE);
assertFileExist(projectPath, "src/main/java/tech/jhipster/chips/technical/infrastructure/config/kafka/KafkaProperties.java");
assertFileExist(projectPath, "src/test/java/tech/jhipster/chips/technical/infrastructure/config/kafka/KafkaPropertiesTest.java");
assertFileExist(projectPath, "src/main/java/tech/jhipster/chips/technical/infrastructure/config/kafka/KafkaConfiguration.java");
}

@Test
void shouldAddProducer() throws Exception {
void shouldAddProducerConsumer() throws Exception {
ProjectDTO projectDTO = TestUtils.readFileToObject("json/chips.json", ProjectDTO.class).folder(tmpDirForTest());
if (projectDTO == null) {
throw new GeneratorException("Error when reading file");
Expand Down

0 comments on commit 7e521e2

Please sign in to comment.