1
+ package org .springdoc .core .configuration ;
2
+
3
+ import org .junit .jupiter .api .Test ;
4
+ import org .springdoc .core .customizers .GlobalOpenApiCustomizer ;
5
+ import org .springdoc .core .customizers .OpenApiHateoasLinksCustomizer ;
6
+ import org .springdoc .core .properties .SpringDocConfigProperties ;
7
+ import org .springframework .boot .autoconfigure .AutoConfigurations ;
8
+ import org .springframework .boot .autoconfigure .web .servlet .WebMvcAutoConfiguration ;
9
+ import org .springframework .boot .test .context .runner .WebApplicationContextRunner ;
10
+ import org .springframework .hateoas .config .HateoasConfiguration ;
11
+
12
+ import static org .assertj .core .api .Assertions .assertThat ;
13
+ import static org .mockito .Mockito .mock ;
14
+ import static org .springdoc .core .utils .Constants .LINKS_SCHEMA_CUSTOMISER ;
15
+
16
+ class SpringDocHateoasConfigurationTest {
17
+
18
+ @ Test
19
+ void linksSchemaCustomizerShouldBeRegistered () {
20
+ new WebApplicationContextRunner ()
21
+ .withPropertyValues (
22
+ "springdoc.api-docs.enabled=true" ,
23
+ "springdoc.enable-hateoas=true"
24
+ )
25
+ .withConfiguration (AutoConfigurations .of (
26
+ WebMvcAutoConfiguration .class ,
27
+ HateoasConfiguration .class ,
28
+ SpringDocConfiguration .class ,
29
+ SpringDocConfigProperties .class ,
30
+ SpringDocHateoasConfiguration .class
31
+ ))
32
+ .run (context -> {
33
+ assertThat (context ).getBeanNames (GlobalOpenApiCustomizer .class )
34
+ .hasSize (1 )
35
+ .containsExactly (LINKS_SCHEMA_CUSTOMISER );
36
+ assertThat (context .getBean (LINKS_SCHEMA_CUSTOMISER )).isExactlyInstanceOf (OpenApiHateoasLinksCustomizer .class );
37
+ });
38
+ }
39
+
40
+ @ Test
41
+ void linksSchemaCustomizerShouldBeRegisteredWithMultipleGlobalOpenApiCustomizer () {
42
+ new WebApplicationContextRunner ()
43
+ .withPropertyValues (
44
+ "springdoc.api-docs.enabled=true" ,
45
+ "springdoc.enable-hateoas=true"
46
+ )
47
+ .withConfiguration (AutoConfigurations .of (
48
+ WebMvcAutoConfiguration .class ,
49
+ HateoasConfiguration .class ,
50
+ SpringDocConfiguration .class ,
51
+ SpringDocConfigProperties .class ,
52
+ SpringDocHateoasConfiguration .class
53
+ ))
54
+ .withBean ("globalOpenApiCustomizer" , GlobalOpenApiCustomizer .class , () -> mock (GlobalOpenApiCustomizer .class ))
55
+ .run (context -> {
56
+ assertThat (context ).getBeanNames (GlobalOpenApiCustomizer .class )
57
+ .hasSize (2 )
58
+ .containsExactlyInAnyOrder (LINKS_SCHEMA_CUSTOMISER , "globalOpenApiCustomizer" );
59
+ });
60
+ }
61
+
62
+ @ Test
63
+ void linksSchemaCustomizerShouldNotBeRegisteredIfBeanWithSameNameAlreadyExists () {
64
+ new WebApplicationContextRunner ()
65
+ .withPropertyValues (
66
+ "springdoc.api-docs.enabled=true" ,
67
+ "springdoc.enable-hateoas=true"
68
+ )
69
+ .withConfiguration (AutoConfigurations .of (
70
+ WebMvcAutoConfiguration .class ,
71
+ HateoasConfiguration .class ,
72
+ SpringDocConfiguration .class ,
73
+ SpringDocConfigProperties .class ,
74
+ SpringDocHateoasConfiguration .class
75
+ ))
76
+ .withBean (LINKS_SCHEMA_CUSTOMISER , GlobalOpenApiCustomizer .class , () -> mock (GlobalOpenApiCustomizer .class ))
77
+ .run (context -> {
78
+ assertThat (context ).getBeanNames (GlobalOpenApiCustomizer .class )
79
+ .hasSize (1 )
80
+ .containsExactly (LINKS_SCHEMA_CUSTOMISER );
81
+ assertThat (context .getBean (LINKS_SCHEMA_CUSTOMISER )).isNotExactlyInstanceOf (OpenApiHateoasLinksCustomizer .class );
82
+ });
83
+ }
84
+ }
0 commit comments