generated from micronaut-projects/micronaut-project-template
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use the client builders as a parameter to clients to allow users to configure the builders. When they are used as parameters, the builder singleton becomes requires and therefore can be configured with bean creation event listener.
- Loading branch information
1 parent
860b15b
commit 7418a44
Showing
4 changed files
with
81 additions
and
11 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
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
66 changes: 66 additions & 0 deletions
66
oraclecloud-sdk/src/test/java/io/micronaut/oraclecloud/database/DatabaseFactoryTest.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,66 @@ | ||
package io.micronaut.oraclecloud.database; | ||
|
||
import com.oracle.bmc.database.DatabaseAsyncClient; | ||
import com.oracle.bmc.database.DatabaseClient; | ||
import io.micronaut.context.event.BeanCreatedEvent; | ||
import io.micronaut.context.event.BeanCreatedEventListener; | ||
import io.micronaut.core.annotation.NonNull; | ||
import io.micronaut.test.extensions.junit5.annotation.MicronautTest; | ||
import jakarta.inject.Singleton; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
@MicronautTest | ||
public class DatabaseFactoryTest { | ||
|
||
public static final String ENDPOINT = "http://my_endpoint"; | ||
public static final String ASYNC_ENDPOINT = "http://my_endpoint_async"; | ||
private final DatabaseClient databaseClient; | ||
private final DatabaseAsyncClient databaseAsyncClient; | ||
|
||
public DatabaseFactoryTest( | ||
DatabaseClient databaseClient, | ||
DatabaseAsyncClient databaseAsyncClient | ||
) { | ||
this.databaseClient = databaseClient; | ||
this.databaseAsyncClient = databaseAsyncClient; | ||
} | ||
|
||
@Test | ||
void testDataBaseClientConfiguration() { | ||
assertEquals(ENDPOINT, databaseClient.getEndpoint()); | ||
} | ||
|
||
@Test | ||
void testDataBaseAsyncClientConfiguration() { | ||
assertEquals(ASYNC_ENDPOINT, databaseAsyncClient.getEndpoint()); | ||
} | ||
|
||
@Singleton | ||
static class DatabaseClientBuilderListener | ||
implements BeanCreatedEventListener<DatabaseClient.Builder> { | ||
@Override | ||
public DatabaseClient.Builder onCreated( | ||
@NonNull BeanCreatedEvent<DatabaseClient.Builder> event | ||
) { | ||
DatabaseClient.Builder builder = event.getBean(); | ||
builder.endpoint(DatabaseFactoryTest.ENDPOINT); | ||
return builder; | ||
} | ||
} | ||
|
||
@Singleton | ||
static class DatabaseAsyncClientBuilderListener | ||
implements BeanCreatedEventListener<DatabaseAsyncClient.Builder> { | ||
@Override | ||
public DatabaseAsyncClient.Builder onCreated( | ||
@NonNull BeanCreatedEvent<DatabaseAsyncClient.Builder> event | ||
) { | ||
DatabaseAsyncClient.Builder builder = event.getBean(); | ||
builder.endpoint(DatabaseFactoryTest.ASYNC_ENDPOINT); | ||
return builder; | ||
} | ||
} | ||
|
||
} |