-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CNFT1-2846] Configurable logo (#1927)
* favicon * logo * sonar
- Loading branch information
1 parent
170085b
commit ff90e6f
Showing
14 changed files
with
232 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,7 +56,7 @@ nbs: | |
- /expired | ||
|
||
logging: | ||
file.name: | ||
file: | ||
path: ./log/ | ||
|
||
spring: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
apps/nbs-gateway/src/main/java/gov/cdc/nbs/gateway/favicon/FaviconEndpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package gov.cdc.nbs.gateway.favicon; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.io.Resource; | ||
import org.springframework.web.reactive.function.server.RouterFunction; | ||
import org.springframework.web.reactive.function.server.ServerResponse; | ||
|
||
import static org.springframework.web.reactive.function.server.RequestPredicates.GET; | ||
import static org.springframework.web.reactive.function.server.RouterFunctions.route; | ||
import static org.springframework.web.reactive.function.server.ServerResponse.ok; | ||
|
||
@Configuration | ||
class FaviconEndpoint { | ||
|
||
@Bean | ||
RouterFunction<ServerResponse> favicon( | ||
@Value("classpath:favicon.ico") Resource favicon | ||
) { | ||
return route(GET("/favicon.ico"), request -> ok().bodyValue(favicon)); | ||
} | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
apps/nbs-gateway/src/main/java/gov/cdc/nbs/gateway/logo/LogoConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package gov.cdc.nbs.gateway.logo; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
class LogoConfiguration { | ||
|
||
@Bean | ||
LogoSettings logoSettings( | ||
@Value("${nbs.gateway.logo.path:/images/nedssLogo.jpg}") final String path, | ||
@Value("${nbs.gateway.logo.file:}") final String file | ||
) { | ||
return new LogoSettings(path, file); | ||
} | ||
|
||
} |
26 changes: 26 additions & 0 deletions
26
apps/nbs-gateway/src/main/java/gov/cdc/nbs/gateway/logo/LogoEndpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package gov.cdc.nbs.gateway.logo; | ||
|
||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.io.FileSystemResource; | ||
import org.springframework.web.reactive.function.server.RouterFunction; | ||
import org.springframework.web.reactive.function.server.ServerResponse; | ||
|
||
import static org.springframework.web.reactive.function.server.RequestPredicates.GET; | ||
import static org.springframework.web.reactive.function.server.RouterFunctions.route; | ||
import static org.springframework.web.reactive.function.server.ServerResponse.ok; | ||
|
||
@Configuration | ||
@ConditionalOnProperty(prefix = "nbs.gateway.logo", name = "file") | ||
class LogoEndpoint { | ||
|
||
@Bean | ||
RouterFunction<ServerResponse> logo( | ||
final LogoSettings settings | ||
) { | ||
FileSystemResource logo = new FileSystemResource(settings.file()); | ||
return route(GET(settings.path()), request -> ok().bodyValue(logo)); | ||
} | ||
|
||
} |
4 changes: 4 additions & 0 deletions
4
apps/nbs-gateway/src/main/java/gov/cdc/nbs/gateway/logo/LogoSettings.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package gov.cdc.nbs.gateway.logo; | ||
|
||
record LogoSettings(String path, String file) { | ||
} |
34 changes: 34 additions & 0 deletions
34
apps/nbs-gateway/src/main/java/gov/cdc/nbs/gateway/logo/NBS6LogoRouteConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package gov.cdc.nbs.gateway.logo; | ||
|
||
import gov.cdc.nbs.gateway.classic.NBSClassicService; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.cloud.gateway.route.RouteLocator; | ||
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
/** | ||
* Configures the routing for the NBS Logo at {@code GET} requests to {@code /images/nedssLogo.jpg} to use the NBS6 | ||
* service to resolve the logo. This route becomes active if the property {@code nbs.gateway.logo.location} is not | ||
* present. | ||
*/ | ||
@Configuration | ||
@ConditionalOnProperty(prefix = "nbs.gateway.logo", name = "file", matchIfMissing = true) | ||
class NBS6LogoRouteConfiguration { | ||
|
||
@Bean | ||
RouteLocator nbsLogoRouteLocator( | ||
final RouteLocatorBuilder builder, | ||
final NBSClassicService service, | ||
final LogoSettings settings | ||
) { | ||
return builder.routes() | ||
.route( | ||
"nbs6-logo", | ||
route -> route.path(settings.path()) | ||
.uri(service.uri()) | ||
) | ||
.build(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
26 changes: 26 additions & 0 deletions
26
apps/nbs-gateway/src/test/java/gov/cdc/nbs/gateway/favicon/FaviconEndpointTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package gov.cdc.nbs.gateway.favicon; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.web.reactive.server.WebTestClient; | ||
|
||
@SpringBootTest( | ||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT | ||
) | ||
class FaviconEndpointTest { | ||
|
||
@Autowired | ||
WebTestClient webClient; | ||
|
||
@Test | ||
void should_route_to_favicon() { | ||
|
||
webClient | ||
.get().uri("/favicon.ico") | ||
.exchange() | ||
.expectStatus() | ||
.isOk(); | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
apps/nbs-gateway/src/test/java/gov/cdc/nbs/gateway/logo/LogoEndpointTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package gov.cdc.nbs.gateway.logo; | ||
|
||
import com.github.tomakehurst.wiremock.junit5.WireMockExtension; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.web.reactive.server.WebTestClient; | ||
|
||
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; | ||
import static com.github.tomakehurst.wiremock.matching.RequestPatternBuilder.allRequests; | ||
|
||
@SpringBootTest( | ||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, | ||
properties = { | ||
"nbs.gateway.classic=http://localhost:10000", | ||
"nbs.gateway.logo.file=src/test/resources/80x32.png" | ||
} | ||
) | ||
class LogoEndpointTest { | ||
|
||
@RegisterExtension | ||
static WireMockExtension classic = WireMockExtension.newInstance() | ||
.options(wireMockConfig().port(10000)) | ||
.build(); | ||
|
||
@Autowired | ||
WebTestClient webClient; | ||
|
||
@Test | ||
void should_route_to_file_based_logo_() { | ||
|
||
webClient | ||
.get().uri("/images/nedssLogo.jpg") | ||
.exchange() | ||
.expectStatus() | ||
.isOk(); | ||
|
||
classic.verify(0, allRequests()); | ||
} | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
apps/nbs-gateway/src/test/java/gov/cdc/nbs/gateway/logo/NBS6LogoRouteConfigurationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package gov.cdc.nbs.gateway.logo; | ||
|
||
import com.github.tomakehurst.wiremock.junit5.WireMockExtension; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.web.reactive.server.WebTestClient; | ||
|
||
import static com.github.tomakehurst.wiremock.client.WireMock.get; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.ok; | ||
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig; | ||
|
||
@SpringBootTest( | ||
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, | ||
properties = { | ||
"nbs.gateway.classic=http://localhost:10000" | ||
} | ||
) | ||
class NBS6LogoRouteConfigurationTest { | ||
|
||
@RegisterExtension | ||
static WireMockExtension classic = WireMockExtension.newInstance() | ||
.options(wireMockConfig().port(10000)) | ||
.build(); | ||
|
||
@Autowired | ||
WebTestClient webClient; | ||
|
||
@Test | ||
void should_route_logo_path_to_nbs6() { | ||
classic.stubFor(get("/images/nedssLogo.jpg").willReturn(ok())); | ||
|
||
webClient | ||
.get().uri("/images/nedssLogo.jpg") | ||
.exchange() | ||
.expectStatus() | ||
.isOk(); | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.