Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Testcontainers Service Connection in examples #63

Merged
merged 2 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions examples/servlet/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,9 @@ To use a different FGA server, update `src/main/resources/application.yaml` acco

## Usage

### Start OpenFGA server

In a terminal, start the OpenFGA Server:

```bash
docker pull openfga/openfga:latest
docker run --rm -e OPENFGA_HTTP_ADDR=0.0.0.0:4000 -p 4000:4000 -p 8081:8081 -p 3000:3000 openfga/openfga run
```

### Start the example application:

In a separate terminal, start the application:
In a terminal, start the application:

```bash
./gradlew bootRun
Expand Down
3 changes: 3 additions & 0 deletions examples/servlet/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-resource-server'
implementation 'dev.openfga:openfga-spring-boot-starter:0.0.1'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.boot:spring-boot-testcontainers'
testImplementation 'org.testcontainers:openfga:1.20.0'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package dev.openfga.example;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.testcontainers.openfga.OpenFGAContainer;

public class TestServletApp {

public static void main(String[] args) {
SpringApplication.from(ServletApp::main)
.with(TestConfig.class)
.run(args);
}

@TestConfiguration(proxyBeanMethods = false)
static class TestConfig {

@Bean
OpenFGAContainer container(DynamicPropertyRegistry registry) {
OpenFGAContainer container = new OpenFGAContainer("openfga/openfga:v1.4.3");
registry.add("openfga.api-url", container::getHttpEndpoint);
return container;
}

}
}
16 changes: 16 additions & 0 deletions examples/servlet/src/test/resources/logback-test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<configuration>

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} %-5level %logger - %msg%n</pattern>
</encoder>
</appender>

<root level="INFO">
<appender-ref ref="STDOUT"/>
</root>

<logger name="org.testcontainers" level="INFO"/>
</configuration>
Loading