Skip to content

Commit

Permalink
test caching of dockets in DefaultAsyncApiDocketServiceTest.java
Browse files Browse the repository at this point in the history
Took 6 hours 16 minutes
  • Loading branch information
tvahrst committed Oct 21, 2023
1 parent 7dc2e5e commit 70c9e35
Showing 1 changed file with 60 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
class DefaultAsyncApiDocketServiceTest {

@Test
void testConfigurationShouldMapAllPropertiesToTheDocket() {
void testServiceShouldMapAllPropertiesToTheDocket() {
// given
ConfigDocket configDocket = new ConfigDocket();
configDocket.setBasePackage("test-base-package");
Expand All @@ -40,9 +40,8 @@ void testConfigurationShouldMapAllPropertiesToTheDocket() {
properties.setDocket(configDocket);

// when
DefaultAsyncApiDocketService docketConfiguration =
new DefaultAsyncApiDocketService(Optional.empty(), properties);
AsyncApiDocket asyncApiDocket = docketConfiguration.getAsyncApiDocket();
DefaultAsyncApiDocketService docketService = new DefaultAsyncApiDocketService(Optional.empty(), properties);
AsyncApiDocket asyncApiDocket = docketService.getAsyncApiDocket();

// then
assertThat(asyncApiDocket.getDefaultContentType()).isEqualTo(configDocket.getDefaultContentType());
Expand All @@ -53,4 +52,61 @@ void testConfigurationShouldMapAllPropertiesToTheDocket() {
assertThat(asyncApiDocket.getInfo().getLicense()).isEqualTo(info.getLicense());
assertThat(asyncApiDocket.getInfo().getContact()).isEqualTo(info.getContact());
}

@Test
void docketServiceShouldDeliverCachedConfigDocketBean() {
// repeatable invocations of AsyncApiDocketService.getAsyncApiDocket() should return the same docket instance
// if a ConfigDocket @Bean is present.

// given
AsyncApiDocket customDocket = AsyncApiDocket.builder()
.basePackage("test-base-package")
.info(com.asyncapi.v2._6_0.model.info.Info.builder()
.title("some-title")
.version("some-version")
.build())
.build();

SpringwolfConfigProperties configProperties = new SpringwolfConfigProperties();

// when
AsyncApiDocketService docketService =
new DefaultAsyncApiDocketService(Optional.of(customDocket), configProperties);

// then
assertThat(docketService.getAsyncApiDocket()).isSameAs(customDocket);
// second invocation should again return same instance
assertThat(docketService.getAsyncApiDocket()).isSameAs(customDocket);
}

@Test
void docketServiceShouldDeliverCachedEnvironmentBasedDocket() {
// repeatable invocations of AsyncApiDocketService.getAsyncApiDocket() should return the same docket instance
// if docket is based on environment properties.

// given
ConfigDocket configDocket = new ConfigDocket();
configDocket.setBasePackage("test-base-package");
configDocket.setDefaultContentType("application/json");

Info info = new Info();
info.setTitle("some-title");
info.setVersion("some-version");
configDocket.setInfo(info);

Server server =
Server.builder().protocol("some-protocol").url("some-url").build();
configDocket.setServers(newHashMap("some-protocol", server));

SpringwolfConfigProperties configProperties = new SpringwolfConfigProperties();
configProperties.setDocket(configDocket);

// when
AsyncApiDocketService docketService = new DefaultAsyncApiDocketService(Optional.empty(), configProperties);
AsyncApiDocket asyncApiDocket = docketService.getAsyncApiDocket();

// then
// second invocation should again return same instance
assertThat(docketService.getAsyncApiDocket()).isSameAs(asyncApiDocket);
}
}

0 comments on commit 70c9e35

Please sign in to comment.