Skip to content

Commit

Permalink
Merge pull request #643 from DanielFran/maven-version_springdoc-openapi
Browse files Browse the repository at this point in the history
Springdoc-openapi: use get version, managed by dependabot
  • Loading branch information
pascalgrimaud authored Feb 3, 2022
2 parents 3bcb967 + c3383ee commit f27ed16
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

public class SpringDoc {

private static final String SPRING_DOC_VERSION = "1.6.4";

private SpringDoc() {}

public static Dependency springDocDependency() {
Expand All @@ -16,8 +14,4 @@ public static Dependency springDocDependency() {
.version("\\${springdoc-openapi-ui.version}")
.build();
}

public static String springDocVersion() {
return SPRING_DOC_VERSION;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
import tech.jhipster.lite.error.domain.GeneratorException;
import tech.jhipster.lite.generator.buildtool.generic.domain.BuildToolService;
import tech.jhipster.lite.generator.project.domain.Project;
import tech.jhipster.lite.generator.project.domain.ProjectRepository;
Expand Down Expand Up @@ -49,8 +50,16 @@ public void initWithSecurityJWT(Project project) {

@Override
public void addSpringDocDependency(Project project) {
buildToolService.addProperty(project, "springdoc-openapi-ui.version", SpringDoc.springDocVersion());
buildToolService.addDependency(project, SpringDoc.springDocDependency());
this.buildToolService.getVersion(project, "springdoc-openapi")
.ifPresentOrElse(
version -> {
buildToolService.addProperty(project, "springdoc-openapi-ui.version", version);
buildToolService.addDependency(project, SpringDoc.springDocDependency());
},
() -> {
throw new GeneratorException("Springdoc Openapi version not found");
}
);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/generator/dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<problem-spring.version>0.27.0</problem-spring.version>
<spring-boot.version>2.6.3</spring-boot.version>
<spring-cloud.version>2021.0.0</spring-cloud.version>
<springdoc-openapi.version.version>1.6.4</springdoc-openapi.version.version>
<springdoc-openapi.version>1.6.5</springdoc-openapi.version>
<testcontainers.version>1.16.2</testcontainers.version>
</properties>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,13 @@
import tech.jhipster.lite.TestUtils;
import tech.jhipster.lite.generator.project.domain.DefaultConfig;
import tech.jhipster.lite.generator.project.domain.Project;
import tech.jhipster.lite.generator.server.springboot.mvc.springdoc.domain.SpringDoc;

public class SpringDocAssert {

public static final String SPRING_DOC_CONFIG_JAVA_FILE_NAME = "SpringDocConfiguration.java";

public static void assertDependencies(Project project) {
TestUtils.assertFileContent(
project,
POM_XML,
List.of("<springdoc-openapi-ui.version>" + SpringDoc.springDocVersion() + "</springdoc-openapi-ui.version>")
);
TestUtils.assertFileContent(project, POM_XML, List.of("<springdoc-openapi-ui.version>"));
TestUtils.assertFileContent(
project,
POM_XML,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
package tech.jhipster.lite.generator.server.springboot.mvc.springdoc.domain;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.*;
import static tech.jhipster.lite.TestUtils.tmpProject;
import static tech.jhipster.lite.generator.server.springboot.mvc.springdoc.domain.SpringDocConstants.*;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import tech.jhipster.lite.UnitTest;
import tech.jhipster.lite.error.domain.GeneratorException;
import tech.jhipster.lite.generator.buildtool.generic.domain.BuildToolService;
import tech.jhipster.lite.generator.buildtool.generic.domain.Dependency;
import tech.jhipster.lite.generator.project.domain.Project;
Expand Down Expand Up @@ -44,10 +46,11 @@ void shouldInitWithDefaultValues() {
Project project = tmpProject();

// When
when(buildToolService.getVersion(project, "springdoc-openapi")).thenReturn(Optional.of("0.0.0"));
springDocDomainService.init(project);

// Then
verify(buildToolService).addProperty(project, "springdoc-openapi-ui.version", "1.6.4");
verify(buildToolService).addProperty(project, "springdoc-openapi-ui.version", "0.0.0");
ArgumentCaptor<Dependency> dependencyArgCaptor = ArgumentCaptor.forClass(Dependency.class);
verify(buildToolService).addDependency(eq(project), dependencyArgCaptor.capture());
assertThat(dependencyArgCaptor.getValue()).usingRecursiveComparison().isEqualTo(getExpectedDependency());
Expand Down Expand Up @@ -89,10 +92,11 @@ void shouldInitWithAdditionalConfigFromProject() {
project.getConfig().putAll(projectConfig);

// When
when(buildToolService.getVersion(project, "springdoc-openapi")).thenReturn(Optional.of("0.0.0"));
springDocDomainService.init(project);

// Then
verify(buildToolService).addProperty(project, "springdoc-openapi-ui.version", "1.6.4");
verify(buildToolService).addProperty(project, "springdoc-openapi-ui.version", "0.0.0");
ArgumentCaptor<Dependency> dependencyArgCaptor = ArgumentCaptor.forClass(Dependency.class);
verify(buildToolService).addDependency(eq(project), dependencyArgCaptor.capture());
assertThat(dependencyArgCaptor.getValue()).usingRecursiveComparison().isEqualTo(getExpectedDependency());
Expand All @@ -113,6 +117,13 @@ void shouldInitWithAdditionalConfigFromProject() {
assertThat(project.getConfig()).containsAllEntriesOf(projectConfig);
}

@Test
void shouldNotAddSpringDocDependency() {
Project project = tmpProject();

assertThatThrownBy(() -> springDocDomainService.addSpringDocDependency(project)).isExactlyInstanceOf(GeneratorException.class);
}

private static Dependency getExpectedDependency() {
return Dependency
.builder()
Expand Down

0 comments on commit f27ed16

Please sign in to comment.