Skip to content

Commit

Permalink
Fix tests, adding proper default spring profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
blacelle committed Sep 11, 2024
1 parent 3a5714a commit bca2b3e
Show file tree
Hide file tree
Showing 12 changed files with 65 additions and 35 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
# kumite
# kumite

This projects enables defining Games, to create contests between Bots/Algorithms.

# Contributing

If you'd like to contribute to the project, see our [CONTRIBUTING.MD](https://github.com/solven-eu/kumite/blob/master/CONTRIBUTING.MD)
6 changes: 4 additions & 2 deletions monolith/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ spring:
profiles:
group:
default:
# Renamed to enable merging in monolith
# Renamed to enable merging in monolith
- "default_player"
- "default_server"
- "default_server"
- "server"
- "fake_player"
11 changes: 10 additions & 1 deletion player/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>eu.solven.kumite</groupId>
Expand All @@ -17,8 +18,16 @@
</dependency>

<dependency>
<!-- WebClient-->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
<exclusions>
<!-- Do not expore any API -->
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-reactor-netty</artifactId>
</exclusion>
</exclusions>
</dependency>

<!-- https://github.com/cowtowncoder/java-uuid-generator -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
@Configuration
@Import({

KumiteRandomConfiguration.class,
KumitePlayerRandomConfiguration.class,

})
@Slf4j
Expand All @@ -47,6 +47,7 @@ public Void playTicTacToe(IKumiteServer kumiteServer, Environment env) {

Stream.of("Travelling Salesman Problem", "Tic-Tac-Toe").forEach(gameTitle -> {
ses.scheduleWithFixedDelay(() -> {
log.info("Looking for interesting contests for game LIKE `{}`", gameTitle);
kumiteServer.searchGames(GameSearchParameters.builder().titleRegex(Optional.of(gameTitle)).build())
.flatMap(game -> kumiteServer.searchContests(
ContestSearchParameters.builder().gameId(Optional.of(game.getGameId())).build()))
Expand All @@ -64,8 +65,11 @@ public Void playTicTacToe(IKumiteServer kumiteServer, Environment env) {
kumiteServer.joinContest(playerId, contestId);
}

})
.subscribe(view -> {
log.info("View: {}", view);
});
}, 1, 1, TimeUnit.MINUTES);
}, 1, 60, TimeUnit.SECONDS);
});

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

@Configuration
@Slf4j
public class KumiteRandomConfiguration {
public class KumitePlayerRandomConfiguration {

@Bean
RandomGenerator randomGenerator(Environment env) {
RandomGenerator playerRandomGenerator(Environment env) {
String rawSeed = env.getProperty("kumite.random.seed", "random");
RandomGenerator r;
if ("random".equals(rawSeed)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public Flux<GameMetadata> searchGames(GameSearchParameters search) {
RequestHeadersSpec<?> spec = webClient.get()
.uri(uriBuilder -> uriBuilder.path("/api/games")
.queryParamIfPresent("game_id", search.getGameId())
.queryParamIfPresent("title", search.getTitleRegex())
.queryParamIfPresent("title_regex", search.getTitleRegex())
.build());

return spec.exchangeToFlux(r -> {
Expand Down
17 changes: 9 additions & 8 deletions player/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
spring:
application.name: kumite-player
# https://stackoverflow.com/questions/26105061/spring-boot-without-the-web-server
main.web-application-type: NONE
profiles:
group:
default:
# Renamed to enable merging in monolith
- "default_player"
- "fake_player"
- "inject_default_games"

logging:
level:
Expand All @@ -13,11 +22,3 @@ kumite.server:
access_token: "NEEDS_A_PROPER_VALUE"


spring:
profiles:
group:
default:
# Renamed to enable merging in monolith
- "default_player"
- "fake_player"
- "inject_default_games"
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package eu.solven.kumite.app;

public interface IKumiteSpringProfiles {
//
String P_SERVER = "server";

// The default profile, activated when no other profile is defined. Typically useful for local runs.
String P_DEFAULT = "default";
// This will provide reasonable default for a fast+non_prod run
Expand Down
17 changes: 17 additions & 0 deletions server/src/main/resources/application-server.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
spring:
application.name: kumite-server
security:
oauth2:
client:
registration:
github:
clientId: ${kumite.login.oauth2.github.clientId}
clientSecret: ${kumite.login.oauth2.github.clientSecret}
google:
client-id: google-client-id
client-secret: google-client-secret
graphql:
graphiql:
enabled: true

springdoc.show-actuator: true
19 changes: 2 additions & 17 deletions server/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
spring:
application.name: kumite-server
security:
oauth2:
client:
registration:
github:
clientId: ${kumite.login.oauth2.github.clientId}
clientSecret: ${kumite.login.oauth2.github.clientSecret}
google:
client-id: google-client-id
client-secret: google-client-secret
graphql:
graphiql:
enabled: true

profiles:
include: server
group:
default:
# - server
- default_server
- fake_player

Expand All @@ -27,5 +14,3 @@ logging:

kumite.login:
signing-key: 'NEEDS_TO_BE_DEFINED'

springdoc.show-actuator: true
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.security.test.web.reactive.server.SecurityMockServerConfigurers;
import org.springframework.security.test.web.reactive.server.SecurityMockServerConfigurers.OAuth2LoginMutator;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.web.reactive.server.StatusAssertions;
import org.springframework.test.web.reactive.server.WebTestClient;

import eu.solven.kumite.account.KumiteUserRaw;
import eu.solven.kumite.account.login.KumiteOAuth2UserService;
import eu.solven.kumite.account.login.SocialWebFluxSecurity;
import eu.solven.kumite.app.IKumiteSpringProfiles;
import eu.solven.kumite.app.controllers.KumiteLoginController;
import eu.solven.kumite.app.greeting.GreetingHandler;
import eu.solven.kumite.scenario.TestTSPLifecycle;
Expand All @@ -37,6 +39,7 @@
// We create a `@SpringBootTest`, starting an actual server on a `RANDOM_PORT`
@SpringBootTest(classes = KumiteServerSecurityApplication.class,
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@ActiveProfiles({ IKumiteSpringProfiles.P_DEFAULT_SERVER })
@Slf4j
// https://stackoverflow.com/questions/73881370/mocking-oauth2-client-with-webtestclient-for-servlet-applications-results-in-nul
@AutoConfigureWebTestClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@Slf4j
// https://stackoverflow.com/questions/73881370/mocking-oauth2-client-with-webtestclient-for-servlet-applications-results-in-nul
@ActiveProfiles(IKumiteSpringProfiles.P_DEFAULT_SERVER)
@ActiveProfiles({IKumiteSpringProfiles.P_DEFAULT_SERVER})
@AutoConfigureWebTestClient
public class TestSecurity_WithoutAuth {

Expand Down

0 comments on commit bca2b3e

Please sign in to comment.