diff --git a/README.md b/README.md index 8892c1c..2a90e18 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,11 @@ # Golden Samples for Projects Golden Samples for Customer Success Projects specific use cases. -## Backbase OpenAPI Plugin -Typical use cases explained in detail on how to use Boat in your projects are available [here](boat-example). +## Backbase OpenAPI Plugin +Typical use cases explained in detail on how to use Boat in your projects are available [here](https://github.com/Backbase/boat-examples). ## Quarkus with OpenAPI Plugin -Typical use cases explained in detail on how to generate OpenAPI clients compatible with Identity in your projects are available [here](openapi-with-quarkus). +Typical use cases explained in detail on how to generate OpenAPI clients compatible with Identity in your projects are available [here](https://github.com/Backbase/openapi-with-quarkus). ## Local Development Setup You can find [here](development) instructions on how to set up a minimal local environment in your laptop. diff --git a/boat-example/README.md b/boat-example/README.md deleted file mode 100644 index c9a2178..0000000 --- a/boat-example/README.md +++ /dev/null @@ -1,188 +0,0 @@ -# BOAT Golden Example - -This example consists of three modules: - -- [Server](server): This service provides a greeting message based on the received name -- [Client](client): This service registers a user and calls the [Server](server) service to get a greeting message -- [Api](api): The OpenAPI specification for the greeting services are stored in this module. - -**Note**: It's important to keep your specifications in a separate module to prevent duplicating it in the server and -client. - -## API - -This module will package the OpenAPI specs using `maven-assembly-plugin`. Take a look at -the [api.xml](api/assembly/api.xml) file to see how it's configured.
-For validating and bundling the spec file we can use `boat-maven-plugin`. Take a look at the executions of the plugin. - -## Server - -The server uses the api dependency to generate the rest controller interfaces.
-First we need to unpack the API dependency using the `maven-dependency-plugin` in the [POM file](server/pom.xml): - -```xml - - - org.apache.maven.plugins - maven-dependency-plugin - - - unpack - generate-sources - - unpack - - - - - com.backbase - boat-example-api - 1.0.0 - api - ${project.build.directory}/yaml - zip - true - - - **/*.yaml, **/*.json - - - - -``` - -Then we can generate required DTOs and interfaces using `boat-maven-plugin`: - -```xml - - - com.backbase.oss - boat-maven-plugin - ${boat-maven-plugin.version} - - - generate-client-api-code - - generate-spring-boot-embedded - - generate-sources - - ${project.build.directory}/yaml/boat-example-api/greeting-api-v1.0.0.yaml - - com.backbase.greeting.api.service.v1 - com.backbase.greeting.api.service.v1.model - - OffsetDateTime=java.time.ZonedDateTime - - - - - -``` - -Notice the `generate-spring-boot-embedded` which generates required files for server implementation. - -## Client - -The client also uses the API dependency to generate required DTOs and client files.
-First we need to unpack the API dependency using the `maven-dependency-plugin` like the server config.
-Then we can generate required DTOs and client using `boat-maven-plugin`: - -```xml - - - com.backbase.oss - boat-maven-plugin - ${boat-maven-plugin.version} - - - boat-example-api - generate-sources - - generate-rest-template-embedded - - - ${project.build.directory}/yaml/boat-example-api/greeting-api-v1.0.0.yaml - - com.backbase.greeting.api.service.v1 - com.backbase.greeting.api.service.v1.model - - OffsetDateTime=java.time.ZonedDateTime - - - - - -``` - -Notice the `generate-rest-template-embedded` which generates required files for client implementation. - -### Client config - -We need to create and configure api beans: - -```java - -@Configuration -public class GreetingClientConfiguration { - @Value("${backbase.example.greeting-base-url}") - private String greetingBasePath; - - @Bean - public ApiClient greetingApiClient(@Qualifier(INTER_SERVICE_REST_TEMPLATE_BEAN_NAME) RestTemplate restTemplate) { - ApiClient apiClient = new ApiClient(restTemplate); - apiClient.setBasePath(this.greetingBasePath); - apiClient.addDefaultHeader(HttpCommunicationConfiguration.INTERCEPTORS_ENABLED_HEADER, Boolean.TRUE.toString()); - return apiClient; - } - - @Bean - public GreetingApi createConfirmationApi(@Qualifier("greetingApiClient") ApiClient greetingApiClient) { - return new GreetingApi(greetingApiClient); - } -} -``` - -If we want to call a service-api, we need to provide a client-credential token which is created by the Token Converter -service. We can use the rest template that is provided by the SSDK communication library which will automatically inject -the -client credential token in the request using `@Qualifier(INTER_SERVICE_REST_TEMPLATE_BEAN_NAME)`.
-For more information you can read the HTTP -communication [here](https://community.backbase.com/documentation/ServiceSDK/latest/http_service_to_service_communication) -.
- -The `INTERCEPTORS_ENABLED_HEADER` header enables the `ApiErrorExceptionInterceptor` class of the SSDK communication -library to intercept errors. -For more info about client configuration you can read -the [community doc](https://community.backbase.com/documentation/ServiceSDK/latest/generate_clients_from_openapi). - -### Enabling logging - -We can enable request and response logging in api client using debug option: - -```java - @Bean -public ApiClient greetingApiClient(){ - ApiClient apiClient=new ApiClient(new RestTemplate()); - apiClient.setBasePath(this.greetingBasePath); - apiClient.addDefaultHeader(HttpCommunicationConfiguration.INTERCEPTORS_ENABLED_HEADER,Boolean.TRUE.toString()); - apiClient.setDebugging(true); - return apiClient; - } -``` - -## Writing tests - -In the client for writing tests, we can mock the server's API like this: - -```java - //mock server's response - GreetingPostResponse greetingPostResponse=new GreetingPostResponse(); - greetingPostResponse.setMessage(HELLO_USERNAME); - when(greetingApi.postGreeting(any())).thenReturn(greetingPostResponse); -``` - -You can check the whole test class [here](client/src/test/java/com/example/RegisterControllerIT.java) - -For more info you can read -the [boat documentation](https://github.com/Backbase/backbase-openapi-tools/blob/main/boat-maven-plugin/README.md) \ No newline at end of file diff --git a/boat-example/api/.gitignore b/boat-example/api/.gitignore deleted file mode 100644 index 8fcb18f..0000000 --- a/boat-example/api/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -/target -.DS_Store -.idea -*.iml -/src/main/java -/src/main/resources/lib -node_modules -fe-dist diff --git a/boat-example/api/README.md b/boat-example/api/README.md deleted file mode 100644 index 567e4d9..0000000 --- a/boat-example/api/README.md +++ /dev/null @@ -1,27 +0,0 @@ -# Boat example Service API Spec - -> _Fill out this file with some information about your OpenAPI spec._ - -To build this spec, use: - -``` -mvn clean install -``` - -The spec is also validated as part of the build. - -## Community Documentation - -Add links to documentation including setup, config, etc. - -## Jira Project - -Add link to Jira project. - -## Confluence Links - -Links to relevant confluence pages (design etc). - -## Support - -Slack, Email, Jira etc. \ No newline at end of file diff --git a/boat-example/api/assembly/api.xml b/boat-example/api/assembly/api.xml deleted file mode 100644 index e9ee18d..0000000 --- a/boat-example/api/assembly/api.xml +++ /dev/null @@ -1,18 +0,0 @@ - - api - - zip - - false - - - ${project.build.directory} - ${artifactId} - - *.yaml - - - - \ No newline at end of file diff --git a/boat-example/api/pom.xml b/boat-example/api/pom.xml deleted file mode 100644 index aa5ba3b..0000000 --- a/boat-example/api/pom.xml +++ /dev/null @@ -1,105 +0,0 @@ - - - 4.0.0 - - - com.backbase.buildingblocks - backbase-openapi-spec-starter-parent - 14.1.0 - - - - com.backbase - boat-example-api - 1.0.0 - Backbase :: boat-example-api - - - - - - - - 0.15.5 - - - - - - com.backbase.oss - boat-maven-plugin - ${boat-maven-plugin.version} - - - boat-validation - generate-sources - - validate - - - ${project.basedir}/src/main/resources/greeting-api-v1.yaml - true - - - - - boat-bundle - generate-sources - - bundle - - - ${project.basedir}/src/main/resources - ${project.build.directory} - true - - - - - boat-bundle-unversioned - generate-sources - - bundle - - - ${project.basedir}/src/main/resources - ${project.build.directory}/unversioned - false - - - - boat-docs - package - - generate - - - ${project.build.directory}/unversioned/greeting-api-v1.yaml - ${project.build.directory}/generated-docs - html2 - true - - - - - - maven-assembly-plugin - - - assemble-api-zip - - single - - package - - - assembly/api.xml - - - - - - - - diff --git a/boat-example/api/src/main/resources/examples/body/greeting-get-response.json b/boat-example/api/src/main/resources/examples/body/greeting-get-response.json deleted file mode 100644 index 09d621b..0000000 --- a/boat-example/api/src/main/resources/examples/body/greeting-get-response.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "message": "Hello there!" -} \ No newline at end of file diff --git a/boat-example/api/src/main/resources/examples/body/greeting-post-request.json b/boat-example/api/src/main/resources/examples/body/greeting-post-request.json deleted file mode 100644 index ce3fa1d..0000000 --- a/boat-example/api/src/main/resources/examples/body/greeting-post-request.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "username": "Alex" -} \ No newline at end of file diff --git a/boat-example/api/src/main/resources/examples/body/greeting-post-response.json b/boat-example/api/src/main/resources/examples/body/greeting-post-response.json deleted file mode 100644 index 33f2d50..0000000 --- a/boat-example/api/src/main/resources/examples/body/greeting-post-response.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "message": "Hello Alex!" -} \ No newline at end of file diff --git a/boat-example/api/src/main/resources/greeting-api-v1.yaml b/boat-example/api/src/main/resources/greeting-api-v1.yaml deleted file mode 100644 index 78c946f..0000000 --- a/boat-example/api/src/main/resources/greeting-api-v1.yaml +++ /dev/null @@ -1,89 +0,0 @@ -openapi: 3.0.3 -info: - title: Boat Example service - version: 1.0.0 - description: Sends greetings to users -servers: - - description: Prism mock server - url: http://localhost:8080 -tags: - - name: confirmations -paths: - /client-api/v1/greeting: - get: - tags: - - greeting - summary: sends a generic greetings - description: This endpoint returns a generic greetings. - operationId: getGreeting - responses: - "200": - description: A successful operation. Greeting is returned. - content: - application/json: - schema: - $ref: '#/components/schemas/GreetingGetResponse' - examples: - greetingGetResponse: - $ref: '#/components/examples/GreetingGetResponse' - - post: - tags: - - greeting - summary: sends a greeting - description: This endpoint returns a greeting containing received user's name. - operationId: postGreeting - requestBody: - required: true - description: Send user's name - content: - application/json: - schema: - $ref: '#/components/schemas/GreetingPostRequest' - examples: - greetingPostRequest: - $ref: '#/components/examples/GreetingPostRequest' - responses: - "200": - description: A successful operation. Greeting is returned. - content: - application/json: - schema: - $ref: '#/components/schemas/GreetingPostResponse' - examples: - greetingPostResponse: - $ref: '#/components/examples/GreetingPostResponse' - "400": - description: The request was bad. - content: - application/json: - schema: - $ref: '#/components/schemas/BadRequestError' - examples: - badRequestError: - $ref: '#/components/examples/BadRequestError' - -components: - schemas: - GreetingGetResponse: - $ref: 'schemas/body/greeting-get-response.json' - GreetingPostRequest: - $ref: 'schemas/body/greeting-post-request.json' - GreetingPostResponse: - $ref: 'schemas/body/greeting-post-response.json' - BadRequestError: - $ref: 'lib/schemas/bad-request-error.yaml' - - examples: - GreetingGetResponse: - value: - $ref: 'examples/body/greeting-get-response.json' - GreetingPostResponse: - value: - $ref: 'examples/body/greeting-post-response.json' - GreetingPostRequest: - value: - $ref: 'examples/body/greeting-post-request.json' - BadRequestError: - value: - $ref: 'lib/examples/bad-request-validation-error.json' \ No newline at end of file diff --git a/boat-example/api/src/main/resources/schemas/body/greeting-get-response.json b/boat-example/api/src/main/resources/schemas/body/greeting-get-response.json deleted file mode 100644 index 5a89735..0000000 --- a/boat-example/api/src/main/resources/schemas/body/greeting-get-response.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "additionalProperties": false, - "type": "object", - "properties": { - "message": { - "description": "The greeting message", - "type": "string" - } - } -} \ No newline at end of file diff --git a/boat-example/api/src/main/resources/schemas/body/greeting-post-request.json b/boat-example/api/src/main/resources/schemas/body/greeting-post-request.json deleted file mode 100644 index 794c601..0000000 --- a/boat-example/api/src/main/resources/schemas/body/greeting-post-request.json +++ /dev/null @@ -1,16 +0,0 @@ -{ - "additionalProperties": false, - "description": "Sends greeting with user's name", - "type": "object", - "properties": { - "username": { - "type": "string", - "description": "The user's name", - "minLength": 1, - "maxLength": 50 - } - }, - "required": [ - "username" - ] -} diff --git a/boat-example/api/src/main/resources/schemas/body/greeting-post-response.json b/boat-example/api/src/main/resources/schemas/body/greeting-post-response.json deleted file mode 100644 index 965ed30..0000000 --- a/boat-example/api/src/main/resources/schemas/body/greeting-post-response.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "additionalProperties": false, - "type": "object", - "properties": { - "message": { - "description": "The greeting message containing the user name", - "type": "string" - } - }, - "required": [ - "message" - ] -} \ No newline at end of file diff --git a/boat-example/client/.gitignore b/boat-example/client/.gitignore deleted file mode 100644 index 07f7fb1..0000000 --- a/boat-example/client/.gitignore +++ /dev/null @@ -1,26 +0,0 @@ -**/*.iml -**/*.ipr -**/*.iws -**/*.log -**/.classpath -**/.idea/ -**/.project -**/.settings -**/target/ -**/*.class - -# General -.DS_Store -.AppleDouble -.LSOverride - - -.vscode/* -!.vscode/settings.json -!.vscode/tasks.json -!.vscode/launch.json -!.vscode/extensions.json -*.code-workspace - -# Local History for Visual Studio Code -.history/ \ No newline at end of file diff --git a/boat-example/client/README.md b/boat-example/client/README.md deleted file mode 100644 index 16a796b..0000000 --- a/boat-example/client/README.md +++ /dev/null @@ -1,49 +0,0 @@ -# boat-example-client - -_Fill out this file with some information about your Service._ - -#Getting Started - -* [Extend and build](https://community.backbase.com/documentation/ServiceSDK/latest/extend_and_build) - -## Dependencies - -Requires a running Eureka registry, by default on port 8080. - -## Configuration - -Service configuration is under `src/main/resources/application.yaml`. - -## Running - -To run the service in development mode, use: - -- `mvn spring-boot:run` - -To run the service from the built binaries, use: - -- `java -jar target/boat-example-client-1.0.0-SNAPSHOT.jar` - -## Authorization - -Requests to this service are authorized with a Backbase Internal JWT, therefore you must access this service via the -Backbase Gateway after authenticating with the authentication service. - -For local development, an internal JWT can be created from http://jwt.io, entering `JWTSecretKeyDontUseInProduction!` -as the secret in the signature to generate a valid signed JWT. - -## Community Documentation - -Add links to documentation including setup, config, etc. - -## Jira Project - -Add link to Jira project. - -## Confluence Links - -Links to relevant confluence pages (design etc). - -## Support - -The official boat-example-client support room is [#s-boat-example-client](https://todo). diff --git a/boat-example/client/pom.xml b/boat-example/client/pom.xml deleted file mode 100644 index b51608f..0000000 --- a/boat-example/client/pom.xml +++ /dev/null @@ -1,116 +0,0 @@ - - 4.0.0 - - - - com.backbase.buildingblocks - 14.1.0 - service-sdk-starter-core - - - - com.backbase - boat-example-client - 1.0.0 - war - Backbase :: boat-example-client - - - 11 - - 0.15.5 - - - - - com.backbase.buildingblocks - service-sdk-starter-test - test - - - com.backbase.buildingblocks - communication - - - io.swagger - swagger-annotations - 1.6.6 - - - com.google.code.findbugs - jsr305 - 3.0.2 - - - org.projectlombok - lombok - 1.18.22 - provided - - - com.backbase.buildingblocks - api - - - - - - - org.apache.maven.plugins - maven-dependency-plugin - - - unpack - generate-sources - - unpack - - - - - com.backbase - boat-example-api - 1.0.0 - api - ${project.build.directory}/yaml - zip - true - - - **/*.yaml, **/*.json - - - - - - com.backbase.oss - boat-maven-plugin - ${boat-maven-plugin.version} - - - boat-example-api - generate-sources - - generate-rest-template-embedded - - - ${project.build.directory}/yaml/boat-example-api/greeting-api-v1.0.0.yaml - - com.backbase.greeting.api.service.v1 - com.backbase.greeting.api.service.v1.model - - OffsetDateTime=java.time.ZonedDateTime - - - - - - - - - diff --git a/boat-example/client/src/main/java/com/example/BoatExampleClientApplication.java b/boat-example/client/src/main/java/com/example/BoatExampleClientApplication.java deleted file mode 100644 index 976ae91..0000000 --- a/boat-example/client/src/main/java/com/example/BoatExampleClientApplication.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.example; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; -import org.springframework.cloud.client.discovery.EnableDiscoveryClient; - -@SpringBootApplication(excludeName = "ApiClient") -@EnableDiscoveryClient -public class BoatExampleClientApplication extends SpringBootServletInitializer { - - public static void main(final String[] args) { - SpringApplication.run(BoatExampleClientApplication.class, args); - } - -} \ No newline at end of file diff --git a/boat-example/client/src/main/java/com/example/config/GreetingClientConfiguration.java b/boat-example/client/src/main/java/com/example/config/GreetingClientConfiguration.java deleted file mode 100644 index 7ddcc92..0000000 --- a/boat-example/client/src/main/java/com/example/config/GreetingClientConfiguration.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.example.config; - -import com.backbase.buildingblocks.communication.http.HttpCommunicationConfiguration; -import com.backbase.greeting.api.service.ApiClient; -import com.backbase.greeting.api.service.v1.GreetingApi; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.client.RestTemplate; - -import static com.backbase.buildingblocks.communication.http.HttpCommunicationConfiguration.INTER_SERVICE_REST_TEMPLATE_BEAN_NAME; - -@Configuration -public class GreetingClientConfiguration { - @Value("${backbase.example.greeting-base-url}") - private String greetingBasePath; - - @Bean - public ApiClient greetingApiClient(@Qualifier(INTER_SERVICE_REST_TEMPLATE_BEAN_NAME) RestTemplate restTemplate) { - ApiClient apiClient = new ApiClient(restTemplate); - apiClient.setBasePath(this.greetingBasePath); - apiClient.addDefaultHeader(HttpCommunicationConfiguration.INTERCEPTORS_ENABLED_HEADER, Boolean.TRUE.toString()); - apiClient.setDebugging(true); - return apiClient; - } - - @Bean - public GreetingApi createGreetingApi(@Qualifier("greetingApiClient") ApiClient greetingApiClient) { - return new GreetingApi(greetingApiClient); - } -} diff --git a/boat-example/client/src/main/java/com/example/dto/RegisterUserRequestDTO.java b/boat-example/client/src/main/java/com/example/dto/RegisterUserRequestDTO.java deleted file mode 100644 index a071519..0000000 --- a/boat-example/client/src/main/java/com/example/dto/RegisterUserRequestDTO.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.example.dto; - -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import lombok.ToString; - -import javax.validation.constraints.NotEmpty; - -@NoArgsConstructor -@ToString -@Getter -@Setter -public class RegisterUserRequestDTO { - @NotEmpty - private String username; - private String email; -} diff --git a/boat-example/client/src/main/java/com/example/dto/RegisterUserResponseDTO.java b/boat-example/client/src/main/java/com/example/dto/RegisterUserResponseDTO.java deleted file mode 100644 index 999d6c4..0000000 --- a/boat-example/client/src/main/java/com/example/dto/RegisterUserResponseDTO.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.example.dto; - -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; -import lombok.ToString; - -import javax.validation.constraints.NotEmpty; - -@NoArgsConstructor -@ToString -@Getter -@Setter -public class RegisterUserResponseDTO { - @NotEmpty - private String message; -} diff --git a/boat-example/client/src/main/java/com/example/rest/RegisterController.java b/boat-example/client/src/main/java/com/example/rest/RegisterController.java deleted file mode 100644 index 1078212..0000000 --- a/boat-example/client/src/main/java/com/example/rest/RegisterController.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.example.rest; - -import com.example.dto.RegisterUserRequestDTO; -import com.example.dto.RegisterUserResponseDTO; -import com.example.service.GreetingService; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RestController; - -import javax.validation.Valid; - -@Slf4j -@RestController -@RequiredArgsConstructor -public class RegisterController { - - private final GreetingService greetingService; - - @PostMapping("/client-api/register") - public ResponseEntity registerUser(@RequestBody @Valid RegisterUserRequestDTO registerUserRequestDTO) { - log.info("registering user"); - //Do register business logic here - return ResponseEntity.ok(greetingService.fetchGreeting(registerUserRequestDTO.getUsername())); - } - -} diff --git a/boat-example/client/src/main/java/com/example/service/GreetingService.java b/boat-example/client/src/main/java/com/example/service/GreetingService.java deleted file mode 100644 index 169e286..0000000 --- a/boat-example/client/src/main/java/com/example/service/GreetingService.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.example.service; - -import com.example.dto.RegisterUserResponseDTO; - -public interface GreetingService { - RegisterUserResponseDTO fetchGreeting(String username); -} diff --git a/boat-example/client/src/main/java/com/example/service/impl/GreetingServiceImpl.java b/boat-example/client/src/main/java/com/example/service/impl/GreetingServiceImpl.java deleted file mode 100644 index 0cf5398..0000000 --- a/boat-example/client/src/main/java/com/example/service/impl/GreetingServiceImpl.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.example.service.impl; - -import com.backbase.greeting.api.service.v1.GreetingApi; -import com.backbase.greeting.api.service.v1.model.GreetingPostRequest; -import com.example.dto.RegisterUserResponseDTO; -import com.example.service.GreetingService; -import lombok.RequiredArgsConstructor; -import org.springframework.stereotype.Service; - -@RequiredArgsConstructor -@Service -public class GreetingServiceImpl implements GreetingService { - - private final GreetingApi greetingApi; - - @Override - public RegisterUserResponseDTO fetchGreeting(String username) { - String message = greetingApi.postGreeting(new GreetingPostRequest().username(username)).getMessage(); - RegisterUserResponseDTO registerUserResponseDTO = new RegisterUserResponseDTO(); - registerUserResponseDTO.setMessage(message); - return registerUserResponseDTO; - } -} diff --git a/boat-example/client/src/main/resources/application.yaml b/boat-example/client/src/main/resources/application.yaml deleted file mode 100644 index b6b499e..0000000 --- a/boat-example/client/src/main/resources/application.yaml +++ /dev/null @@ -1,32 +0,0 @@ -server: - port: 9917 - -# API Registry client configuration -eureka: - instance: - metadata-map: - public: true - role: live - client: - serviceUrl: - defaultZone: http://localhost:8080/registry/eureka/ - enabled: false - -# Configure Internal JWT handler -sso: - jwt: - internal: - signature: - key: - type: ENV - value: SIG_SECRET_KEY - -# Spring health monitoring -management: - health: - jms: - enabled: false - -backbase: - example: - greeting-base-url: 'http://localhost:9915' \ No newline at end of file diff --git a/boat-example/client/src/main/resources/banner.txt b/boat-example/client/src/main/resources/banner.txt deleted file mode 100644 index 3e84197..0000000 --- a/boat-example/client/src/main/resources/banner.txt +++ /dev/null @@ -1,9 +0,0 @@ - ________ ________ ________ ___ __ ________ ________ ________ _______ -|\ __ \|\ __ \|\ ____\|\ \|\ \ |\ __ \|\ __ \|\ ____\|\ ___ \ -\ \ \|\ /\ \ \|\ \ \ \___|\ \ \/ /|\ \ \|\ /\ \ \|\ \ \ \___|\ \ __/| - \ \ __ \ \ __ \ \ \ \ \ ___ \ \ __ \ \ __ \ \_____ \ \ \_|/__ - \ \ \|\ \ \ \ \ \ \ \____\ \ \\ \ \ \ \|\ \ \ \ \ \|____|\ \ \ \_|\ \ - \ \_______\ \__\ \__\ \_______\ \__\\ \__\ \_______\ \__\ \__\____\_\ \ \_______\ - \|_______|\|__|\|__|\|_______|\|__| \|__|\|_______|\|__|\|__|\_________\|_______| - \|_________| - diff --git a/boat-example/client/src/main/resources/bootstrap.yaml b/boat-example/client/src/main/resources/bootstrap.yaml deleted file mode 100644 index e7e4e8d..0000000 --- a/boat-example/client/src/main/resources/bootstrap.yaml +++ /dev/null @@ -1,3 +0,0 @@ -spring: - application: - name: boat-example-client diff --git a/boat-example/client/src/test/java/com/example/RegisterControllerIT.java b/boat-example/client/src/test/java/com/example/RegisterControllerIT.java deleted file mode 100644 index c23915c..0000000 --- a/boat-example/client/src/test/java/com/example/RegisterControllerIT.java +++ /dev/null @@ -1,65 +0,0 @@ -package com.example; - -import com.backbase.buildingblocks.test.http.TestRestTemplateConfiguration; -import com.backbase.greeting.api.service.v1.GreetingApi; -import com.backbase.greeting.api.service.v1.model.GreetingPostResponse; -import com.example.dto.RegisterUserRequestDTO; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.http.HttpHeaders; -import org.springframework.http.MediaType; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.annotation.DirtiesContext.ClassMode; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.web.servlet.MockMvc; - -import static org.hamcrest.Matchers.equalTo; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.when; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; - -@SpringBootTest(classes = BoatExampleClientApplication.class) -@DirtiesContext(classMode = ClassMode.AFTER_CLASS) -@AutoConfigureMockMvc -@ActiveProfiles("it") -class RegisterControllerIT { - - private static final String HELLO_USERNAME = "Hello username!"; - @Autowired - private MockMvc mvc; - @Autowired - private ObjectMapper objectMapper; - @MockBean - private GreetingApi greetingApi; - - @Test - void exampleTest() throws Exception { - //mock server's response - GreetingPostResponse greetingPostResponse = new GreetingPostResponse(); - greetingPostResponse.setMessage(HELLO_USERNAME); - when(greetingApi.postGreeting(any())).thenReturn(greetingPostResponse); - //create test request - RegisterUserRequestDTO registerUserRequestDTO = new RegisterUserRequestDTO(); - registerUserRequestDTO.setUsername("username"); - registerUserRequestDTO.setEmail("test@test.com"); - String requestAsString = objectMapper.writeValueAsString(registerUserRequestDTO); - - mvc.perform( - post("/client-api/register") - .header("Authorization", TestRestTemplateConfiguration.TEST_SERVICE_TOKEN) - .content(requestAsString) - .contentType(MediaType.APPLICATION_JSON) - ) - .andDo(print()) - .andExpect(status().isOk()) - .andExpect(header().string(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$.message").value(equalTo(HELLO_USERNAME))); - } -} diff --git a/boat-example/pom.xml b/boat-example/pom.xml deleted file mode 100644 index 986defc..0000000 --- a/boat-example/pom.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - 4.0.0 - com.backbase - boat-example - 1.0.0 - - pom - - - 11 - 11 - - - - api - server - client - - - diff --git a/boat-example/server/.gitignore b/boat-example/server/.gitignore deleted file mode 100644 index 07f7fb1..0000000 --- a/boat-example/server/.gitignore +++ /dev/null @@ -1,26 +0,0 @@ -**/*.iml -**/*.ipr -**/*.iws -**/*.log -**/.classpath -**/.idea/ -**/.project -**/.settings -**/target/ -**/*.class - -# General -.DS_Store -.AppleDouble -.LSOverride - - -.vscode/* -!.vscode/settings.json -!.vscode/tasks.json -!.vscode/launch.json -!.vscode/extensions.json -*.code-workspace - -# Local History for Visual Studio Code -.history/ \ No newline at end of file diff --git a/boat-example/server/README.md b/boat-example/server/README.md deleted file mode 100644 index 5fedf7b..0000000 --- a/boat-example/server/README.md +++ /dev/null @@ -1,49 +0,0 @@ -# boat-example-server - -_Fill out this file with some information about your Service._ - -#Getting Started - -* [Extend and build](https://community.backbase.com/documentation/ServiceSDK/latest/extend_and_build) - -## Dependencies - -Requires a running Eureka registry, by default on port 8080. - -## Configuration - -Service configuration is under `src/main/resources/application.yaml`. - -## Running - -To run the service in development mode, use: - -- `mvn spring-boot:run` - -To run the service from the built binaries, use: - -- `java -jar target/boat-example-server-1.0.0-SNAPSHOT.jar` - -## Authorization - -Requests to this service are authorized with a Backbase Internal JWT, therefore you must access this service via the -Backbase Gateway after authenticating with the authentication service. - -For local development, an internal JWT can be created from http://jwt.io, entering `JWTSecretKeyDontUseInProduction!` -as the secret in the signature to generate a valid signed JWT. - -## Community Documentation - -Add links to documentation including setup, config, etc. - -## Jira Project - -Add link to Jira project. - -## Confluence Links - -Links to relevant confluence pages (design etc). - -## Support - -The official boat-example-server support room is [#s-boat-example-server](https://todo). diff --git a/boat-example/server/pom.xml b/boat-example/server/pom.xml deleted file mode 100644 index 3752cfc..0000000 --- a/boat-example/server/pom.xml +++ /dev/null @@ -1,110 +0,0 @@ - - 4.0.0 - - - - com.backbase.buildingblocks - 14.1.0 - service-sdk-starter-core - - - - com.backbase - boat-example-server - 1.0.0 - war - Backbase :: boat-example-server - - - 11 - - 0.15.5 - - - - - com.backbase.buildingblocks - service-sdk-starter-test - test - - - io.swagger - swagger-annotations - 1.6.6 - - - org.openapitools - jackson-databind-nullable - 0.2.2 - - - com.backbase.buildingblocks - communication - - - com.backbase.buildingblocks - api - - - - - - - org.apache.maven.plugins - maven-dependency-plugin - - - unpack - generate-sources - - unpack - - - - - com.backbase - boat-example-api - 1.0.0 - api - ${project.build.directory}/yaml - zip - true - - - **/*.yaml, **/*.json - - - - - - com.backbase.oss - boat-maven-plugin - ${boat-maven-plugin.version} - - - generate-client-api-code - - generate-spring-boot-embedded - - generate-sources - - ${project.build.directory}/yaml/boat-example-api/greeting-api-v1.0.0.yaml - - com.backbase.greeting.api.service.v1 - com.backbase.greeting.api.service.v1.model - - OffsetDateTime=java.time.ZonedDateTime - - - - - - - - - diff --git a/boat-example/server/src/main/java/com/example/BoatExampleServerApplication.java b/boat-example/server/src/main/java/com/example/BoatExampleServerApplication.java deleted file mode 100644 index 890244f..0000000 --- a/boat-example/server/src/main/java/com/example/BoatExampleServerApplication.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.example; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; -import org.springframework.cloud.client.discovery.EnableDiscoveryClient; - -@SpringBootApplication -@EnableDiscoveryClient -public class BoatExampleServerApplication extends SpringBootServletInitializer { - - public static void main(final String[] args) { - SpringApplication.run(BoatExampleServerApplication.class, args); - } - -} \ No newline at end of file diff --git a/boat-example/server/src/main/java/com/example/rest/GreetingController.java b/boat-example/server/src/main/java/com/example/rest/GreetingController.java deleted file mode 100644 index 39e73b5..0000000 --- a/boat-example/server/src/main/java/com/example/rest/GreetingController.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.example.rest; - -import com.backbase.greeting.api.service.v1.GreetingApi; -import com.backbase.greeting.api.service.v1.model.GreetingGetResponse; -import com.backbase.greeting.api.service.v1.model.GreetingPostRequest; -import com.backbase.greeting.api.service.v1.model.GreetingPostResponse; -import org.springframework.http.ResponseEntity; -import org.springframework.web.bind.annotation.RestController; - -import javax.validation.Valid; - -@RestController -public class GreetingController implements GreetingApi { - - private static final String GREETING_MESSAGE_FORMAT = "Hello %s!"; - private static final String GENERIC_GREETING_MESSAGE = "Hello there!"; - - @Override - public ResponseEntity getGreeting() { - GreetingGetResponse response = new GreetingGetResponse().message(GENERIC_GREETING_MESSAGE); - return ResponseEntity.ok(response); - } - - @Override - public ResponseEntity postGreeting(@Valid GreetingPostRequest greetingPostRequest) { - GreetingPostResponse response = new GreetingPostResponse().message(String.format(GREETING_MESSAGE_FORMAT, greetingPostRequest.getUsername())); - return ResponseEntity.ok(response); - } - -} diff --git a/boat-example/server/src/main/resources/application.yaml b/boat-example/server/src/main/resources/application.yaml deleted file mode 100644 index cff3d76..0000000 --- a/boat-example/server/src/main/resources/application.yaml +++ /dev/null @@ -1,28 +0,0 @@ -server: - port: 9915 - -# API Registry client configuration -eureka: - instance: - metadata-map: - public: true - role: live - client: - serviceUrl: - defaultZone: http://localhost:8080/registry/eureka/ - enabled: false - -# Configure Internal JWT handler -sso: - jwt: - internal: - signature: - key: - type: ENV - value: SIG_SECRET_KEY - -# Spring health monitoring -management: - health: - jms: - enabled: false \ No newline at end of file diff --git a/boat-example/server/src/main/resources/banner.txt b/boat-example/server/src/main/resources/banner.txt deleted file mode 100644 index 3e84197..0000000 --- a/boat-example/server/src/main/resources/banner.txt +++ /dev/null @@ -1,9 +0,0 @@ - ________ ________ ________ ___ __ ________ ________ ________ _______ -|\ __ \|\ __ \|\ ____\|\ \|\ \ |\ __ \|\ __ \|\ ____\|\ ___ \ -\ \ \|\ /\ \ \|\ \ \ \___|\ \ \/ /|\ \ \|\ /\ \ \|\ \ \ \___|\ \ __/| - \ \ __ \ \ __ \ \ \ \ \ ___ \ \ __ \ \ __ \ \_____ \ \ \_|/__ - \ \ \|\ \ \ \ \ \ \ \____\ \ \\ \ \ \ \|\ \ \ \ \ \|____|\ \ \ \_|\ \ - \ \_______\ \__\ \__\ \_______\ \__\\ \__\ \_______\ \__\ \__\____\_\ \ \_______\ - \|_______|\|__|\|__|\|_______|\|__| \|__|\|_______|\|__|\|__|\_________\|_______| - \|_________| - diff --git a/boat-example/server/src/main/resources/bootstrap.yaml b/boat-example/server/src/main/resources/bootstrap.yaml deleted file mode 100644 index 6d6d0c7..0000000 --- a/boat-example/server/src/main/resources/bootstrap.yaml +++ /dev/null @@ -1,3 +0,0 @@ -spring: - application: - name: boat-example-server diff --git a/boat-example/server/src/test/java/com/example/GreetingControllerIT.java b/boat-example/server/src/test/java/com/example/GreetingControllerIT.java deleted file mode 100644 index ab15d3f..0000000 --- a/boat-example/server/src/test/java/com/example/GreetingControllerIT.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.example; - -import com.backbase.buildingblocks.test.http.TestRestTemplateConfiguration; -import com.backbase.greeting.api.service.v1.model.GreetingPostRequest; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.http.HttpHeaders; -import org.springframework.http.MediaType; -import org.springframework.test.annotation.DirtiesContext; -import org.springframework.test.annotation.DirtiesContext.ClassMode; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.web.servlet.MockMvc; - -import static org.hamcrest.Matchers.equalTo; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; - -@SpringBootTest(classes = BoatExampleServerApplication.class) -@DirtiesContext(classMode = ClassMode.AFTER_CLASS) -@AutoConfigureMockMvc -@ActiveProfiles("it") -class GreetingControllerIT { - - @Autowired - private MockMvc mvc; - @Autowired - private ObjectMapper objectMapper; - - @Test - void getGreetingTest() throws Exception { - mvc.perform(get("/client-api/v1/greeting") - .header("Authorization", TestRestTemplateConfiguration.TEST_SERVICE_TOKEN)) - .andDo(print()) - .andExpect(status().isOk()) - .andExpect(header().string(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$.message").value(equalTo("Hello there!"))) - .andReturn(); - } - - @Test - void postGreetingTest() throws Exception { - GreetingPostRequest greetingPostRequest = new GreetingPostRequest(); - greetingPostRequest.setUsername("Alex"); - mvc.perform(post("/client-api/v1/greeting") - .header("Authorization", TestRestTemplateConfiguration.TEST_SERVICE_TOKEN) - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(greetingPostRequest)) - ) - .andDo(print()) - .andExpect(status().isOk()) - .andExpect(header().string(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$.message").value(equalTo("Hello Alex!"))) - .andReturn(); - } -} diff --git a/openapi-with-quarkus/.gitignore b/openapi-with-quarkus/.gitignore deleted file mode 100644 index d336c87..0000000 --- a/openapi-with-quarkus/.gitignore +++ /dev/null @@ -1,43 +0,0 @@ -#Maven -target/ -pom.xml.tag -pom.xml.releaseBackup -pom.xml.versionsBackup -release.properties -mvnw.cmd -mvnw - -# Eclipse -.project -.classpath -.settings/ -bin/ - -# IntelliJ -.idea -*.ipr -*.iml -*.iws - -# NetBeans -nb-configuration.xml - -# Visual Studio Code -.vscode -.factorypath - -# OSX -.DS_Store -.dockerignore - -# Vim -*.swp -*.swo - -# patch -*.orig -*.rej - -# Local environment -.env -/.mvn/ diff --git a/openapi-with-quarkus/README.md b/openapi-with-quarkus/README.md deleted file mode 100644 index bec3cb8..0000000 --- a/openapi-with-quarkus/README.md +++ /dev/null @@ -1,312 +0,0 @@ -# OpenApi Generator Usage on Sample Quarkus Application - -This example covers the approach adopted on the Natwest Identity project when generating API clients with Resteasy for -**Identity Service Provider Interfaces** which they are using Quarkus native libraries. - -For **Spring**, with the help of the **boat-plugin**, we have the default configuration to use open-api-generator with -Spring. It's already documented and is well known in Backbase. - -Also, multi-tenancy (while creating api-client) and aspects of tracing will be covered with the examples. - -> **_NOTE:_** Please take a look at -> the [BOAT Golden Example](https://github.com/Backbase/project-golden-samples/tree/main/boat) -> to understand how to use boat-plugin. - -For **Quarkus**, to use openapi-generator the plugin must be configured. - -## Configuration of OpenApiGenerator Plugin - -The input spec of this sample application can be -found [here](https://raw.githubusercontent.com/redhat-appdev-practice/todo-api/trunk/openapi.yml). - -```xml - - - org.openapitools - openapi-generator-maven-plugin - - - todo-api - - generate - - - ${project.basedir}/src/main/resources/todo.yaml - - org.quarkus.openapi.todo.model - org.quarkus.openapi.todo.api - - - - - - ${codegen.openapi.generated-sources-dir} - java - false - false - false - false - - resteasy - java8 - false - org.quarkus.openapi.todo.api - - - -``` - -```resteasy``` - -The resteasy library is used to generate resteasy client. - -```java8``` - -Java8 date library is used. - -```false``` - -OpenAPI Jackson Nullable library is disabled. - -```org.quarkus.openapi.todo.api``` - -Root package for generated code - -## Config Class for API(s) -We have TodoApiConfig class, by using this config class, the API(s) usage is/are can be easy. At this example, we only have one API, - -if we would have multiple API's, the new API Clients would be created in the **TodoApiConfigFactory** class and would be ready to use by any service calling the **TodosApiConfig**. - -In **TodoApiConfig** class, we are simply adding the generated TodosApi. - -***TodoApiConfig*** -```java -public class TodoApiConfig { - private final TodosApi todosApi; - - public TodoApiConfig(TodosApi todosApi) { - this.todosApi = todosApi; - } - - public TodosApi getTodosApi() { - return todosApi; - } -} -``` - -In **TodoApiConfigFactory** class, we have simply one method for creating **TodoApiConfig** which **TodosApi** will be created for the Config class. - -***TodoApiConfigFactory*** - -```java -public class TodoApiConfigFactory { - - /** - * Create Todo Api Config without tenant data. - * - * @return {@link TodoApiConfig} - */ - public static TodoApiConfig createTodoApiConfig() { - return createTodoApiConfig(null); - } - - /** - * Create Todo Api Config for a given tenant. - * Global scope is used to get base url. - * - * @return {@link TodoApiConfig} - */ - public static TodoApiConfig createTodoApiConfig(Tenant tenant) { - Config.Scope scope = ConfigUtils.getGlobalScope(); - - Optional tenantId = Optional.ofNullable(tenant).map(Tenant::getId); - - TodosApi todosApi = - createTodoApi(tenantId.orElse(null), scope.get(TODO_API_BASE_URL_KEY)); - - if (Objects.isNull(todosApi)) { - log.error("Can't initialize Todos api for tenant: {}", tenantId.orElse("")); - return null; - } - - return new TodoApiConfig(todosApi); - } - - private static TodosApi createTodoApi(String tenantId, String baseUrl) { - if (Objects.isNull(baseUrl)) { - log.error("TodoApi base url is null"); - return null; - } - - return new TodosApi(ApiClientFactory.createTenantApiClient(tenantId, baseUrl)); - } -``` - -## Tracing -It’s becoming more important than ever before to be able to see what’s going on inside our requests as they span across multiple microservices. - -As a first step, we need to create **ApiClient** with the base path. After that, we can register our newly created ApiClient to the **OpenTracing.** - -We are using **JAXRS Default Client Builder** to create **JAXRS** Client. -OpenTracing's **Global Tracer** is used for this sample quarkus application. - - -If any logger is defined for debugging in ApiClient class, the logger class will be registered while creating **JAXRS** Client. -Last step is setting the HttpClient. An HttpClient can be used to send requests and retrieve their responses. An HttpClient is created through a builder. - -(Since we are going to create a new **JAX-RS - Client**, we used **JAX-RS - Client Builder**) - -```java - /** - * Getting ApiClient configured for given tenant. - */ - public static ApiClient createTraceApiClient(String basePath) { - ApiClient apiClient = new ApiClient().setBasePath(basePath); - Tracer tracer = GlobalTracer.get(); - ClientBuilder clientBuilder = ClientBuilder.newBuilder() - .executorService(new TracedExecutorService(Executors.newCachedThreadPool(), tracer)) - .register(new SmallRyeClientTracingFeature(tracer)) - .register(apiClient.getJSON()); - - if (LoggerFactory.getLogger(ApiClient.class).isDebugEnabled()) { - clientBuilder.register(Logger.class); - } - - return apiClient.setHttpClient(clientBuilder.build()); - } -``` - -## Multi-tenancy - -Each time an API request is performed, we need to know to tenant identifier to correctly route the persistence -operations. - -There are around three most common ways to provide tenant identifier. - -1. Providing the tenant identifier as a **URL Part** -2. Using a custom **HTTP Request header** -3. Using JWTs to provide the tenant identifier as a JSON token claim - -For this sample-app, second option through a custom HTTP header called **'X-TID'** is used. - - -```java - public class ApiClientFactory { - - private ApiClientFactory() { - } - - /** - * Getting ApiClient configured for given tenant. - */ - public static ApiClient createTraceApiClient(String basePath) { - ApiClient apiClient = new ApiClient().setBasePath(basePath); - Tracer tracer = GlobalTracer.get(); - ClientBuilder clientBuilder = ClientBuilder.newBuilder() - .executorService(new TracedExecutorService(Executors.newCachedThreadPool(), tracer)) - .register(new SmallRyeClientTracingFeature(tracer)) - .register(apiClient.getJSON()); - - if (LoggerFactory.getLogger(ApiClient.class).isDebugEnabled()) { - clientBuilder.register(Logger.class); - } - - return apiClient.setHttpClient(clientBuilder.build()); - } - - /** - * Getting ApiClient configured for given tenant (or without tenant if tenantId is null). - */ - public static ApiClient createTenantApiClient(String tenantId, String basePath) { - ApiClient apiClient = createTraceApiClient(basePath); - if (Objects.isNull(tenantId)) { - return apiClient; - } - - return apiClient.addDefaultHeader("X-TID", tenantId); - } -} -``` - -After the trace api client is created, the custom **HTTP request header** (**X-TID**) is added. - -## Tests -We have basic tests for Factory classes, TodoApiConfig and Provider class to ensure that our ApiClient and ApiConfig are initialized correctly. - -**TodoApiConfigTest** -```java - @ExtendWith(MockitoExtension.class) - class TodoApiConfigTest { - - @Mock - private TodosApi todosApi; - - @InjectMocks - private TodoApiConfig todoApiConfig; - - @Test - void shouldReturnAllApis() { - assertNotNull(todoApiConfig.getTodosApi()); - } -} -``` -For factory class tests: there are different methods to verify the **ApiClient** is created correctly. - -Detailed test can be found (creating **ApiConfig** with the tenant/without tenant) on [TodoApiConfigFactoryTest](src/test/java/org/quarkus/openapi/generator/config/TodoApiConfigFactoryTest.java) class. - -## Running the application in dev mode - -You can run your application in dev mode that enables live coding using: - -```shell script -./mvnw compile quarkus:dev -``` - -> **_NOTE:_** Quarkus now ships with a Dev UI, which is available in dev mode only at http://localhost:8080/q/dev/. - -## Packaging and running the application - -The application can be packaged using: - -```shell script -./mvnw package -``` - -It produces the `quarkus-run.jar` file in the `target/quarkus-app/` directory. -Be aware that it’s not an _über-jar_ as the dependencies are copied into the `target/quarkus-app/lib/` directory. - -The application is now runnable using `java -jar target/quarkus-app/quarkus-run.jar`. - -If you want to build an _über-jar_, execute the following command: - -```shell script -./mvnw package -Dquarkus.package.type=uber-jar -``` - -The application, packaged as an _über-jar_, is now runnable using `java -jar target/*-runner.jar`. - -## Creating a native executable - -You can create a native executable using: - -```shell script -./mvnw package -Pnative -``` - -Or, if you don't have GraalVM installed, you can run the native executable build in a container using: - -```shell script -./mvnw package -Pnative -Dquarkus.native.container-build=true -``` - -You can then execute your native executable with: `./target/code-with-quarkus-1.0.0-SNAPSHOT-runner` - -If you want to learn more about building native executables, please consult https://quarkus.io/guides/maven-tooling. - -## Provided Code - -### RESTEasy Reactive - -Easily start your Reactive RESTful Web Services - -[Related guide section...](https://quarkus.io/guides/getting-started-reactive#reactive-jax-rs-resources) diff --git a/openapi-with-quarkus/pom.xml b/openapi-with-quarkus/pom.xml deleted file mode 100644 index 3fe5051..0000000 --- a/openapi-with-quarkus/pom.xml +++ /dev/null @@ -1,268 +0,0 @@ - - - 4.0.0 - org.quarkus.openapi.generator - openapi-with-quarkus - 1.0.0-SNAPSHOT - - ${generated-sources-dir}/openapi - 3.8.1 - ${project.build.directory}/generated-sources - 18.0.0 - true - 11 - 11 - UTF-8 - UTF-8 - quarkus-bom - io.quarkus.platform - 2.2.3.Final - true - 3.0.0-M5 - - - - - ${quarkus.platform.group-id} - ${quarkus.platform.artifact-id} - ${quarkus.platform.version} - pom - import - - - - - - org.keycloak - keycloak-server-spi - ${keycloak-dependency.version} - - - org.keycloak - keycloak-server-spi-private - ${keycloak-dependency.version} - - - org.keycloak - keycloak-services - ${keycloak-dependency.version} - - - io.swagger - swagger-annotations - 1.6.3 - - - com.squareup.okhttp3 - logging-interceptor - 3.12.1 - - - javax.validation - validation-api - 2.0.1.Final - - - org.openapitools - jackson-databind-nullable - 0.2.1 - - - com.fasterxml.jackson.module - jackson-module-parameter-names - - - com.fasterxml.jackson.datatype - jackson-datatype-jdk8 - - - io.opentracing - opentracing-api - 0.33.0 - - - io.opentracing - opentracing-noop - 0.33.0 - - - com.google.code.findbugs - jsr305 - 3.0.0 - - - com.fasterxml.jackson.datatype - jackson-datatype-jsr310 - - - io.quarkus - quarkus-smallrye-opentracing - - - org.junit.jupiter - junit-jupiter - 5.8.1 - test - - - org.mockito - mockito-junit-jupiter - 4.6.0 - test - - - org.mockito - mockito-inline - 4.6.0 - test - - - org.jboss.resteasy - resteasy-client - 4.7.2.Final - - - org.jboss.resteasy - resteasy-multipart-provider - 4.5.12.Final - - - org.projectlombok - lombok - 1.18.24 - - - io.quarkus - quarkus-resteasy-jsonb - - - io.quarkus - quarkus-smallrye-openapi - - - io.quarkus - quarkus-resteasy - - - - com.google.code.gson - gson - 2.8.9 - compile - - - io.quarkus - quarkus-arc - - - io.quarkus - quarkus-junit5 - test - - - io.rest-assured - rest-assured - test - - - - ${project.artifactId} - - - ${quarkus.platform.group-id} - quarkus-maven-plugin - ${quarkus.platform.version} - true - - - - build - generate-code - generate-code-tests - - - - - - maven-compiler-plugin - ${compiler-plugin.version} - - ${maven.compiler.parameters} - - - - maven-shade-plugin - - - - shade - - - - - - maven-compiler-plugin - ${compiler-plugin.version} - - - -parameters - - - - - org.jacoco - jacoco-maven-plugin - 0.8.7 - - - maven-surefire-plugin - ${surefire-plugin.version} - - - org.jboss.logmanager.LogManager - ${maven.home} - - - - - org.openapitools - openapi-generator-maven-plugin - - - todo-api - - generate - - - ${project.basedir}/src/main/resources/todo.yaml - - org.quarkus.openapi.todo.model - org.quarkus.openapi.todo.api - - - - - - ${codegen.openapi.generated-sources-dir} - java - false - false - false - false - - resteasy - java8 - false - false - org.quarkus.openapi.todo.api - - - - - maven-checkstyle-plugin - - - - diff --git a/openapi-with-quarkus/src/main/docker/Dockerfile.jvm b/openapi-with-quarkus/src/main/docker/Dockerfile.jvm deleted file mode 100644 index 63d045e..0000000 --- a/openapi-with-quarkus/src/main/docker/Dockerfile.jvm +++ /dev/null @@ -1,94 +0,0 @@ -#### -# This Dockerfile is used in order to build a container that runs the Quarkus application in JVM mode -# -# Before building the container image run: -# -# ./mvnw package -# -# Then, build the image with: -# -# docker build -f src/main/docker/Dockerfile.jvm -t quarkus/code-with-quarkus-jvm . -# -# Then run the container using: -# -# docker run -i --rm -p 8080:8080 quarkus/code-with-quarkus-jvm -# -# If you want to include the debug port into your docker image -# you will have to expose the debug port (default 5005) like this : EXPOSE 8080 5005 -# -# Then run the container using : -# -# docker run -i --rm -p 8080:8080 quarkus/code-with-quarkus-jvm -# -# This image uses the `run-java.sh` script to run the application. -# This scripts computes the command line to execute your Java application, and -# includes memory/GC tuning. -# You can configure the behavior using the following environment properties: -# - JAVA_OPTS: JVM options passed to the `java` command (example: "-verbose:class") -# - JAVA_OPTS_APPEND: User specified Java options to be appended to generated options -# in JAVA_OPTS (example: "-Dsome.property=foo") -# - JAVA_MAX_MEM_RATIO: Is used when no `-Xmx` option is given in JAVA_OPTS. This is -# used to calculate a default maximal heap memory based on a containers restriction. -# If used in a container without any memory constraints for the container then this -# option has no effect. If there is a memory constraint then `-Xmx` is set to a ratio -# of the container available memory as set here. The default is `50` which means 50% -# of the available memory is used as an upper boundary. You can skip this mechanism by -# setting this value to `0` in which case no `-Xmx` option is added. -# - JAVA_INITIAL_MEM_RATIO: Is used when no `-Xms` option is given in JAVA_OPTS. This -# is used to calculate a default initial heap memory based on the maximum heap memory. -# If used in a container without any memory constraints for the container then this -# option has no effect. If there is a memory constraint then `-Xms` is set to a ratio -# of the `-Xmx` memory as set here. The default is `25` which means 25% of the `-Xmx` -# is used as the initial heap size. You can skip this mechanism by setting this value -# to `0` in which case no `-Xms` option is added (example: "25") -# - JAVA_MAX_INITIAL_MEM: Is used when no `-Xms` option is given in JAVA_OPTS. -# This is used to calculate the maximum value of the initial heap memory. If used in -# a container without any memory constraints for the container then this option has -# no effect. If there is a memory constraint then `-Xms` is limited to the value set -# here. The default is 4096MB which means the calculated value of `-Xms` never will -# be greater than 4096MB. The value of this variable is expressed in MB (example: "4096") -# - JAVA_DIAGNOSTICS: Set this to get some diagnostics information to standard output -# when things are happening. This option, if set to true, will set -# `-XX:+UnlockDiagnosticVMOptions`. Disabled by default (example: "true"). -# - JAVA_DEBUG: If set remote debugging will be switched on. Disabled by default (example: -# true"). -# - JAVA_DEBUG_PORT: Port used for remote debugging. Defaults to 5005 (example: "8787"). -# - CONTAINER_CORE_LIMIT: A calculated core limit as described in -# https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt. (example: "2") -# - CONTAINER_MAX_MEMORY: Memory limit given to the container (example: "1024"). -# - GC_MIN_HEAP_FREE_RATIO: Minimum percentage of heap free after GC to avoid expansion. -# (example: "20") -# - GC_MAX_HEAP_FREE_RATIO: Maximum percentage of heap free after GC to avoid shrinking. -# (example: "40") -# - GC_TIME_RATIO: Specifies the ratio of the time spent outside the garbage collection. -# (example: "4") -# - GC_ADAPTIVE_SIZE_POLICY_WEIGHT: The weighting given to the current GC time versus -# previous GC times. (example: "90") -# - GC_METASPACE_SIZE: The initial metaspace size. (example: "20") -# - GC_MAX_METASPACE_SIZE: The maximum metaspace size. (example: "100") -# - GC_CONTAINER_OPTIONS: Specify Java GC to use. The value of this variable should -# contain the necessary JRE command-line options to specify the required GC, which -# will override the default of `-XX:+UseParallelGC` (example: -XX:+UseG1GC). -# - HTTPS_PROXY: The location of the https proxy. (example: "myuser@127.0.0.1:8080") -# - HTTP_PROXY: The location of the http proxy. (example: "myuser@127.0.0.1:8080") -# - NO_PROXY: A comma separated lists of hosts, IP addresses or domains that can be -# accessed directly. (example: "foo.example.com,bar.example.com") -# -### -FROM registry.access.redhat.com/ubi8/openjdk-11:1.11 - -ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en' - - -# We make four distinct layers so if there are application changes the library layers can be re-used -COPY --chown=185 target/quarkus-app/lib/ /deployments/lib/ -COPY --chown=185 target/quarkus-app/*.jar /deployments/ -COPY --chown=185 target/quarkus-app/app/ /deployments/app/ -COPY --chown=185 target/quarkus-app/quarkus/ /deployments/quarkus/ - -EXPOSE 8080 -USER 185 -ENV AB_JOLOKIA_OFF="" -ENV JAVA_OPTS="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager" -ENV JAVA_APP_JAR="/deployments/quarkus-run.jar" - diff --git a/openapi-with-quarkus/src/main/docker/Dockerfile.legacy-jar b/openapi-with-quarkus/src/main/docker/Dockerfile.legacy-jar deleted file mode 100644 index 7169565..0000000 --- a/openapi-with-quarkus/src/main/docker/Dockerfile.legacy-jar +++ /dev/null @@ -1,90 +0,0 @@ -#### -# This Dockerfile is used in order to build a container that runs the Quarkus application in JVM mode -# -# Before building the container image run: -# -# ./mvnw package -Dquarkus.package.type=legacy-jar -# -# Then, build the image with: -# -# docker build -f src/main/docker/Dockerfile.legacy-jar -t quarkus/code-with-quarkus-legacy-jar . -# -# Then run the container using: -# -# docker run -i --rm -p 8080:8080 quarkus/code-with-quarkus-legacy-jar -# -# If you want to include the debug port into your docker image -# you will have to expose the debug port (default 5005) like this : EXPOSE 8080 5005 -# -# Then run the container using : -# -# docker run -i --rm -p 8080:8080 quarkus/code-with-quarkus-legacy-jar -# -# This image uses the `run-java.sh` script to run the application. -# This scripts computes the command line to execute your Java application, and -# includes memory/GC tuning. -# You can configure the behavior using the following environment properties: -# - JAVA_OPTS: JVM options passed to the `java` command (example: "-verbose:class") -# - JAVA_OPTS_APPEND: User specified Java options to be appended to generated options -# in JAVA_OPTS (example: "-Dsome.property=foo") -# - JAVA_MAX_MEM_RATIO: Is used when no `-Xmx` option is given in JAVA_OPTS. This is -# used to calculate a default maximal heap memory based on a containers restriction. -# If used in a container without any memory constraints for the container then this -# option has no effect. If there is a memory constraint then `-Xmx` is set to a ratio -# of the container available memory as set here. The default is `50` which means 50% -# of the available memory is used as an upper boundary. You can skip this mechanism by -# setting this value to `0` in which case no `-Xmx` option is added. -# - JAVA_INITIAL_MEM_RATIO: Is used when no `-Xms` option is given in JAVA_OPTS. This -# is used to calculate a default initial heap memory based on the maximum heap memory. -# If used in a container without any memory constraints for the container then this -# option has no effect. If there is a memory constraint then `-Xms` is set to a ratio -# of the `-Xmx` memory as set here. The default is `25` which means 25% of the `-Xmx` -# is used as the initial heap size. You can skip this mechanism by setting this value -# to `0` in which case no `-Xms` option is added (example: "25") -# - JAVA_MAX_INITIAL_MEM: Is used when no `-Xms` option is given in JAVA_OPTS. -# This is used to calculate the maximum value of the initial heap memory. If used in -# a container without any memory constraints for the container then this option has -# no effect. If there is a memory constraint then `-Xms` is limited to the value set -# here. The default is 4096MB which means the calculated value of `-Xms` never will -# be greater than 4096MB. The value of this variable is expressed in MB (example: "4096") -# - JAVA_DIAGNOSTICS: Set this to get some diagnostics information to standard output -# when things are happening. This option, if set to true, will set -# `-XX:+UnlockDiagnosticVMOptions`. Disabled by default (example: "true"). -# - JAVA_DEBUG: If set remote debugging will be switched on. Disabled by default (example: -# true"). -# - JAVA_DEBUG_PORT: Port used for remote debugging. Defaults to 5005 (example: "8787"). -# - CONTAINER_CORE_LIMIT: A calculated core limit as described in -# https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt. (example: "2") -# - CONTAINER_MAX_MEMORY: Memory limit given to the container (example: "1024"). -# - GC_MIN_HEAP_FREE_RATIO: Minimum percentage of heap free after GC to avoid expansion. -# (example: "20") -# - GC_MAX_HEAP_FREE_RATIO: Maximum percentage of heap free after GC to avoid shrinking. -# (example: "40") -# - GC_TIME_RATIO: Specifies the ratio of the time spent outside the garbage collection. -# (example: "4") -# - GC_ADAPTIVE_SIZE_POLICY_WEIGHT: The weighting given to the current GC time versus -# previous GC times. (example: "90") -# - GC_METASPACE_SIZE: The initial metaspace size. (example: "20") -# - GC_MAX_METASPACE_SIZE: The maximum metaspace size. (example: "100") -# - GC_CONTAINER_OPTIONS: Specify Java GC to use. The value of this variable should -# contain the necessary JRE command-line options to specify the required GC, which -# will override the default of `-XX:+UseParallelGC` (example: -XX:+UseG1GC). -# - HTTPS_PROXY: The location of the https proxy. (example: "myuser@127.0.0.1:8080") -# - HTTP_PROXY: The location of the http proxy. (example: "myuser@127.0.0.1:8080") -# - NO_PROXY: A comma separated lists of hosts, IP addresses or domains that can be -# accessed directly. (example: "foo.example.com,bar.example.com") -# -### -FROM registry.access.redhat.com/ubi8/openjdk-11:1.11 - -ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en' - - -COPY target/lib/* /deployments/lib/ -COPY target/*-runner.jar /deployments/quarkus-run.jar - -EXPOSE 8080 -USER 185 -ENV AB_JOLOKIA_OFF="" -ENV JAVA_OPTS="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager" -ENV JAVA_APP_JAR="/deployments/quarkus-run.jar" diff --git a/openapi-with-quarkus/src/main/docker/Dockerfile.native b/openapi-with-quarkus/src/main/docker/Dockerfile.native deleted file mode 100644 index b932d86..0000000 --- a/openapi-with-quarkus/src/main/docker/Dockerfile.native +++ /dev/null @@ -1,27 +0,0 @@ -#### -# This Dockerfile is used in order to build a container that runs the Quarkus application in native (no JVM) mode. -# -# Before building the container image run: -# -# ./mvnw package -Pnative -# -# Then, build the image with: -# -# docker build -f src/main/docker/Dockerfile.native -t quarkus/code-with-quarkus . -# -# Then run the container using: -# -# docker run -i --rm -p 8080:8080 quarkus/code-with-quarkus -# -### -FROM registry.access.redhat.com/ubi8/ubi-minimal:8.5 -WORKDIR /work/ -RUN chown 1001 /work \ - && chmod "g+rwX" /work \ - && chown 1001:root /work -COPY --chown=1001:root target/*-runner /work/application - -EXPOSE 8080 -USER 1001 - -CMD ["./application", "-Dquarkus.http.host=0.0.0.0"] diff --git a/openapi-with-quarkus/src/main/docker/Dockerfile.native-micro b/openapi-with-quarkus/src/main/docker/Dockerfile.native-micro deleted file mode 100644 index 691cfe3..0000000 --- a/openapi-with-quarkus/src/main/docker/Dockerfile.native-micro +++ /dev/null @@ -1,30 +0,0 @@ -#### -# This Dockerfile is used in order to build a container that runs the Quarkus application in native (no JVM) mode. -# It uses a micro base image, tuned for Quarkus native executables. -# It reduces the size of the resulting container image. -# Check https://quarkus.io/guides/quarkus-runtime-base-image for further information about this image. -# -# Before building the container image run: -# -# ./mvnw package -Pnative -# -# Then, build the image with: -# -# docker build -f src/main/docker/Dockerfile.native-micro -t quarkus/code-with-quarkus . -# -# Then run the container using: -# -# docker run -i --rm -p 8080:8080 quarkus/code-with-quarkus -# -### -FROM quay.io/quarkus/quarkus-micro-image:1.0 -WORKDIR /work/ -RUN chown 1001 /work \ - && chmod "g+rwX" /work \ - && chown 1001:root /work -COPY --chown=1001:root target/*-runner /work/application - -EXPOSE 8080 -USER 1001 - -CMD ["./application", "-Dquarkus.http.host=0.0.0.0"] diff --git a/openapi-with-quarkus/src/main/java/org/quarkus/openapi/generator/GreetingResource.java b/openapi-with-quarkus/src/main/java/org/quarkus/openapi/generator/GreetingResource.java deleted file mode 100644 index a1dc1d0..0000000 --- a/openapi-with-quarkus/src/main/java/org/quarkus/openapi/generator/GreetingResource.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.quarkus.openapi.generator; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; - -@Path("/hello") -public class GreetingResource { - - @GET - @Produces(MediaType.TEXT_PLAIN) - public String hello() { - return "Hello from RESTEasy Reactive"; - } -} \ No newline at end of file diff --git a/openapi-with-quarkus/src/main/java/org/quarkus/openapi/generator/authenticator/Utils.java b/openapi-with-quarkus/src/main/java/org/quarkus/openapi/generator/authenticator/Utils.java deleted file mode 100644 index cacc6ac..0000000 --- a/openapi-with-quarkus/src/main/java/org/quarkus/openapi/generator/authenticator/Utils.java +++ /dev/null @@ -1,44 +0,0 @@ -package org.quarkus.openapi.generator.authenticator; - -import java.util.Objects; -import org.eclipse.microprofile.config.ConfigProvider; -import org.keycloak.models.KeycloakSession; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public final class Utils { - - private static final Logger log = LoggerFactory.getLogger(Utils.class); - private static final String WARN_MESSAGE_NOT_DEFINED_PROPERTY = - "Property {} is not defined; Default value `{}` is used"; - - /** - * Retrieve configuration property by name. Default value is null - */ - public static String retrieveConfigProperty(String propertyName) { - return retrieveConfigProperty(propertyName, null); - } - - /** - * Retrieve configuration property by name. If property is not defined default value will be used. - */ - public static String retrieveConfigProperty(String propertyName, String defaultValue) { - try { - String value = ConfigProvider.getConfig().getValue(propertyName, String.class); - if (Objects.isNull(value)) { - log.warn(WARN_MESSAGE_NOT_DEFINED_PROPERTY, propertyName, defaultValue); - return defaultValue; - } - return value; - } catch (Exception e) { - log.warn(WARN_MESSAGE_NOT_DEFINED_PROPERTY, propertyName, defaultValue); - return defaultValue; - } - } - - public static String getRealmId(KeycloakSession keycloakSession) { - return keycloakSession.getContext().getRealm().getId(); - } - private Utils() {} - -} diff --git a/openapi-with-quarkus/src/main/java/org/quarkus/openapi/generator/common/RealmSessionCountFunction.java b/openapi-with-quarkus/src/main/java/org/quarkus/openapi/generator/common/RealmSessionCountFunction.java deleted file mode 100644 index 424b6ed..0000000 --- a/openapi-with-quarkus/src/main/java/org/quarkus/openapi/generator/common/RealmSessionCountFunction.java +++ /dev/null @@ -1,45 +0,0 @@ -package org.quarkus.openapi.generator.common; - -import java.util.Map; -import java.util.function.ToDoubleFunction; -import org.keycloak.models.KeycloakSession; -import org.keycloak.models.RealmModel; -import org.keycloak.services.resources.KeycloakApplication; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class RealmSessionCountFunction implements ToDoubleFunction { - - private static final Logger log = LoggerFactory.getLogger(RealmSessionCountFunction.class); - - @Override - public double applyAsDouble(String realmName) { - double sessionCount = 0.0; - KeycloakSession session = null; - - try { - session = KeycloakApplication.getSessionFactory().create(); - RealmModel realm = session.realms().getRealmByName(realmName); - - Map activeClientSessionStats = session.sessions() - .getActiveClientSessionStats(realm, false); - - sessionCount = activeClientSessionStats.values() - .stream() - .mapToDouble(Long::doubleValue) - .sum(); - - } catch (IllegalStateException ex) { - log.warn("Can't calculate total sessions count for realm: {}", realmName); - // Found this can occur when metrics are collected before any sessions are established, presumably as - // There are no active transactions nothing works. Once one person has logged in it doesn't happen. - // Recommend just squelching this as will return 0 sessions anyway. - } finally { - if (session != null) { - session.close(); - } - } - - return sessionCount; - } -} diff --git a/openapi-with-quarkus/src/main/java/org/quarkus/openapi/generator/config/ConfigUtils.java b/openapi-with-quarkus/src/main/java/org/quarkus/openapi/generator/config/ConfigUtils.java deleted file mode 100644 index 2dcb583..0000000 --- a/openapi-with-quarkus/src/main/java/org/quarkus/openapi/generator/config/ConfigUtils.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.quarkus.openapi.generator.config; - -import static org.quarkus.openapi.generator.config.api.global.GlobalConfigConstants.BACKBASE_SCOPE; - -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.keycloak.Config; - -@Slf4j -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class ConfigUtils { - - /** - * Mehtod to get backbase global properties. - * - * @return {@link Config.Scope} - */ - public static Config.Scope getGlobalScope() { - return Config.scope(BACKBASE_SCOPE); - } - -} diff --git a/openapi-with-quarkus/src/main/java/org/quarkus/openapi/generator/config/TodoApiConfig.java b/openapi-with-quarkus/src/main/java/org/quarkus/openapi/generator/config/TodoApiConfig.java deleted file mode 100644 index 4d37acd..0000000 --- a/openapi-with-quarkus/src/main/java/org/quarkus/openapi/generator/config/TodoApiConfig.java +++ /dev/null @@ -1,19 +0,0 @@ -package org.quarkus.openapi.generator.config; - -import org.quarkus.openapi.todo.api.TodosApi; - -public class TodoApiConfig { - - private final TodosApi todosApi; - - /** - * Todos Api config. - */ - public TodoApiConfig(TodosApi todosApi) { - this.todosApi = todosApi; - } - - public TodosApi getTodosApi() { - return todosApi; - } -} diff --git a/openapi-with-quarkus/src/main/java/org/quarkus/openapi/generator/config/api/factory/ApiClientFactory.java b/openapi-with-quarkus/src/main/java/org/quarkus/openapi/generator/config/api/factory/ApiClientFactory.java deleted file mode 100644 index d107a86..0000000 --- a/openapi-with-quarkus/src/main/java/org/quarkus/openapi/generator/config/api/factory/ApiClientFactory.java +++ /dev/null @@ -1,55 +0,0 @@ -package org.quarkus.openapi.generator.config.api.factory; - -import io.opentracing.Tracer; -import io.opentracing.contrib.concurrent.TracedExecutorService; -import io.opentracing.util.GlobalTracer; -import io.smallrye.opentracing.SmallRyeClientTracingFeature; -import java.util.Objects; -import java.util.concurrent.Executors; -import javax.ws.rs.client.ClientBuilder; -import org.jboss.logging.Logger; -import org.quarkus.openapi.todo.api.ApiClient; -import org.slf4j.LoggerFactory; - -public class ApiClientFactory { - - private ApiClientFactory() { - } - - /** - * Getting ApiClient configured for given tenant. - * - * @param basePath url path to given resource - * @return {@link ApiClient} - */ - public static ApiClient createTraceApiClient(String basePath) { - ApiClient apiClient = new ApiClient().setBasePath(basePath); - Tracer tracer = GlobalTracer.get(); - ClientBuilder clientBuilder = ClientBuilder.newBuilder() - .executorService(new TracedExecutorService(Executors.newCachedThreadPool(), tracer)) - .register(new SmallRyeClientTracingFeature(tracer)) - .register(apiClient.getJSON()); - - if (LoggerFactory.getLogger(ApiClient.class).isDebugEnabled()) { - clientBuilder.register(Logger.class); - } - - return apiClient.setHttpClient(clientBuilder.build()); - } - - /** - * Getting ApiClient configured for given tenant (or without tenant if tenantId is null). - * - * @param tenantId id of given tenant - * @param basePath url path to given resource - * @return {@link ApiClient} - */ - public static ApiClient createTenantApiClient(String tenantId, String basePath) { - ApiClient apiClient = createTraceApiClient(basePath); - if (Objects.isNull(tenantId)) { - return apiClient; - } - - return apiClient.addDefaultHeader("X-TID", tenantId); - } -} diff --git a/openapi-with-quarkus/src/main/java/org/quarkus/openapi/generator/config/api/factory/TodoApiConfigFactory.java b/openapi-with-quarkus/src/main/java/org/quarkus/openapi/generator/config/api/factory/TodoApiConfigFactory.java deleted file mode 100644 index 7cd2369..0000000 --- a/openapi-with-quarkus/src/main/java/org/quarkus/openapi/generator/config/api/factory/TodoApiConfigFactory.java +++ /dev/null @@ -1,59 +0,0 @@ -package org.quarkus.openapi.generator.config.api.factory; - -import static org.quarkus.openapi.generator.config.api.global.GlobalConfigConstants.TODO_API_BASE_URL_KEY; - -import java.util.Objects; -import java.util.Optional; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.keycloak.Config; -import org.quarkus.openapi.generator.config.ConfigUtils; -import org.quarkus.openapi.generator.config.TodoApiConfig; -import org.quarkus.openapi.generator.models.Tenant; -import org.quarkus.openapi.todo.api.TodosApi; - -@Slf4j -@NoArgsConstructor(access = AccessLevel.PRIVATE) -public class TodoApiConfigFactory { - - /** - * Create Todo Api Config without tenant data. - * - * @return {@link TodoApiConfig} - */ - public static TodoApiConfig createTodoApiConfig() { - return createTodoApiConfig(null); - } - - /** - * Create Todo Api Config for a given tenant. - * Global scope is used to get base url. - * - * @return {@link TodoApiConfig} - */ - public static TodoApiConfig createTodoApiConfig(Tenant tenant) { - Config.Scope scope = ConfigUtils.getGlobalScope(); - - Optional tenantId = Optional.ofNullable(tenant).map(Tenant::getId); - - TodosApi todosApi = - createTodoApi(tenantId.orElse(null), scope.get(TODO_API_BASE_URL_KEY)); - - if (Objects.isNull(todosApi)) { - log.error("Can't initialize Todos api for tenant: {}", tenantId.orElse("")); - return null; - } - - return new TodoApiConfig(todosApi); - } - - private static TodosApi createTodoApi(String tenantId, String baseUrl) { - if (Objects.isNull(baseUrl)) { - log.error("TodoApi base url is null"); - return null; - } - - return new TodosApi(ApiClientFactory.createTenantApiClient(tenantId, baseUrl)); - } -} diff --git a/openapi-with-quarkus/src/main/java/org/quarkus/openapi/generator/config/api/global/GlobalConfigConstants.java b/openapi-with-quarkus/src/main/java/org/quarkus/openapi/generator/config/api/global/GlobalConfigConstants.java deleted file mode 100644 index 0264486..0000000 --- a/openapi-with-quarkus/src/main/java/org/quarkus/openapi/generator/config/api/global/GlobalConfigConstants.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.quarkus.openapi.generator.config.api.global; - -import org.quarkus.openapi.generator.config.TodoApiConfig; - -public class GlobalConfigConstants { - - private GlobalConfigConstants() { - } - - public static final String BACKBASE_SCOPE = "backbase"; - /** - * TodoApi Base URL / not added to configuration, just a illustration. - * - * @return {@link TodoApiConfig} - */ - public static final String TODO_API_BASE_URL_KEY = "custom.todoApi.url"; -} diff --git a/openapi-with-quarkus/src/main/java/org/quarkus/openapi/generator/models/Tenant.java b/openapi-with-quarkus/src/main/java/org/quarkus/openapi/generator/models/Tenant.java deleted file mode 100644 index 8c54580..0000000 --- a/openapi-with-quarkus/src/main/java/org/quarkus/openapi/generator/models/Tenant.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.quarkus.openapi.generator.models; - -import java.util.HashSet; -import java.util.Objects; -import java.util.Set; - -public class Tenant { - private String id; - private String name; - private Set realms = new HashSet(); - - public Tenant() { - } - - public String getId() { - return this.id; - } - - public Tenant setId(String id) { - this.id = id; - return this; - } - - public String getName() { - return this.name; - } - - public Tenant setName(String name) { - this.name = name; - return this; - } - - public Set getRealms() { - return this.realms; - } - - public Tenant setRealms(Set realms) { - this.realms = realms; - return this; - } - - public boolean equals(Object o) { - if (this == o) { - return true; - } else if (o != null && this.getClass() == o.getClass()) { - Tenant tenant = (Tenant)o; - return Objects.equals(this.id, tenant.id) && Objects.equals(this.name, tenant.name) && Objects.equals(this.realms, tenant.realms); - } else { - return false; - } - } - - public int hashCode() { - return Objects.hash(new Object[]{this.id, this.name, this.realms}); - } -} diff --git a/openapi-with-quarkus/src/main/java/org/quarkus/openapi/generator/spi/ApiClientProviderSpi.java b/openapi-with-quarkus/src/main/java/org/quarkus/openapi/generator/spi/ApiClientProviderSpi.java deleted file mode 100644 index 8b93bac..0000000 --- a/openapi-with-quarkus/src/main/java/org/quarkus/openapi/generator/spi/ApiClientProviderSpi.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.quarkus.openapi.generator.spi; - -import org.keycloak.provider.Provider; -import org.keycloak.provider.ProviderFactory; -import org.keycloak.provider.Spi; -import org.quarkus.openapi.generator.spi.factory.ApiClientProviderFactory; -import org.quarkus.openapi.generator.spi.provider.ApiClientProvider; - -public class ApiClientProviderSpi implements Spi { - - @Override - public boolean isInternal() { - return false; - } - - @Override - public String getName() { - return "api-client-provider-spi"; - } - - @Override - public Class getProviderClass() { - return ApiClientProvider.class; - } - - @Override - public Class getProviderFactoryClass() { - return ApiClientProviderFactory.class; - } -} diff --git a/openapi-with-quarkus/src/main/java/org/quarkus/openapi/generator/spi/InitProviderSpi.java b/openapi-with-quarkus/src/main/java/org/quarkus/openapi/generator/spi/InitProviderSpi.java deleted file mode 100644 index ed8431f..0000000 --- a/openapi-with-quarkus/src/main/java/org/quarkus/openapi/generator/spi/InitProviderSpi.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.quarkus.openapi.generator.spi; - -import org.keycloak.provider.Provider; -import org.keycloak.provider.ProviderFactory; -import org.keycloak.provider.Spi; -import org.quarkus.openapi.generator.spi.factory.InitProviderFactory; -import org.quarkus.openapi.generator.spi.provider.InitProvider; - -public class InitProviderSpi implements Spi { - - @Override - public boolean isInternal() { - return false; - } - - @Override - public String getName() { - return "init-provider-spi"; - } - - @Override - public Class getProviderClass() { - return InitProvider.class; - } - - @Override - public Class getProviderFactoryClass() { - return InitProviderFactory.class; - } -} diff --git a/openapi-with-quarkus/src/main/java/org/quarkus/openapi/generator/spi/factory/ApiClientProviderFactory.java b/openapi-with-quarkus/src/main/java/org/quarkus/openapi/generator/spi/factory/ApiClientProviderFactory.java deleted file mode 100644 index 5a4944a..0000000 --- a/openapi-with-quarkus/src/main/java/org/quarkus/openapi/generator/spi/factory/ApiClientProviderFactory.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.quarkus.openapi.generator.spi.factory; - -import org.keycloak.provider.ProviderFactory; -import org.quarkus.openapi.generator.spi.provider.ApiClientProvider; - -public interface ApiClientProviderFactory extends ProviderFactory { -} diff --git a/openapi-with-quarkus/src/main/java/org/quarkus/openapi/generator/spi/factory/InitProviderFactory.java b/openapi-with-quarkus/src/main/java/org/quarkus/openapi/generator/spi/factory/InitProviderFactory.java deleted file mode 100644 index 0d6d475..0000000 --- a/openapi-with-quarkus/src/main/java/org/quarkus/openapi/generator/spi/factory/InitProviderFactory.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.quarkus.openapi.generator.spi.factory; - -import org.keycloak.provider.ProviderFactory; -import org.quarkus.openapi.generator.spi.provider.InitProvider; - -public interface InitProviderFactory extends ProviderFactory { -} diff --git a/openapi-with-quarkus/src/main/java/org/quarkus/openapi/generator/spi/provider/ApiClientProvider.java b/openapi-with-quarkus/src/main/java/org/quarkus/openapi/generator/spi/provider/ApiClientProvider.java deleted file mode 100644 index f49faa6..0000000 --- a/openapi-with-quarkus/src/main/java/org/quarkus/openapi/generator/spi/provider/ApiClientProvider.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.quarkus.openapi.generator.spi.provider; - -import org.keycloak.provider.Provider; -import org.quarkus.openapi.generator.config.TodoApiConfig; - -public class ApiClientProvider implements Provider { - - private final TodoApiConfig apiConfig; - - public ApiClientProvider(TodoApiConfig apiConfig) { - this.apiConfig = apiConfig; - } - - public TodoApiConfig getApiConfig() { - return apiConfig; - } - - @Override - public void close() { - } -} diff --git a/openapi-with-quarkus/src/main/java/org/quarkus/openapi/generator/spi/provider/InitProvider.java b/openapi-with-quarkus/src/main/java/org/quarkus/openapi/generator/spi/provider/InitProvider.java deleted file mode 100644 index 54dc9d1..0000000 --- a/openapi-with-quarkus/src/main/java/org/quarkus/openapi/generator/spi/provider/InitProvider.java +++ /dev/null @@ -1,11 +0,0 @@ -package org.quarkus.openapi.generator.spi.provider; - -import org.keycloak.provider.Provider; - -public class InitProvider implements Provider { - - @Override - public void close() { - // No action needed - } -} diff --git a/openapi-with-quarkus/src/main/resources/META-INF/resources/index.html b/openapi-with-quarkus/src/main/resources/META-INF/resources/index.html deleted file mode 100644 index dd04b5d..0000000 --- a/openapi-with-quarkus/src/main/resources/META-INF/resources/index.html +++ /dev/null @@ -1,277 +0,0 @@ - - - - - code-with-quarkus - 1.0.0-SNAPSHOT - - - -
-
-
- - - - - quarkus_logo_horizontal_rgb_1280px_reverse - - - - - - - - - - - - - - - - - - -
-
-
- -
-
-
-

This page is served by Quarkus.

- Visit the Dev UI -

This page: src/main/resources/META-INF/resources/index.html

-

App configuration: src/main/resources/application.properties

-

Static assets: src/main/resources/META-INF/resources/

-

Code: src/main/java

-

Generated starter code:

-
    -
  • - RESTEasy Reactive Easily start your Reactive RESTful Web Services -
    @Path: /hello -
    Related guide -
  • - -
-
-
-
Documentation
-

Practical step-by-step guides to help you achieve a specific goal. Use them to help get your work - done.

-
Set up your IDE
-

Everyone has a favorite IDE they like to use to code. Learn how to configure yours to maximize your - Quarkus productivity.

-
-
-
- - diff --git a/openapi-with-quarkus/src/main/resources/META-INF/resources/org.keycloak.provider.Spi b/openapi-with-quarkus/src/main/resources/META-INF/resources/org.keycloak.provider.Spi deleted file mode 100755 index 02f293e..0000000 --- a/openapi-with-quarkus/src/main/resources/META-INF/resources/org.keycloak.provider.Spi +++ /dev/null @@ -1,19 +0,0 @@ -# -# Copyright 2016 Red Hat, Inc. and/or its affiliates -# and other contributors as indicated by the @author tags. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -org.quarkus.openapi.generator.spi.ApiClientProviderSpi -org.quarkus.openapi.generator.spi.InitProviderSpi diff --git a/openapi-with-quarkus/src/main/resources/META-INF/resources/org.quarkus.openapi.generator.spi.factory.ApiClientProviderFactory b/openapi-with-quarkus/src/main/resources/META-INF/resources/org.quarkus.openapi.generator.spi.factory.ApiClientProviderFactory deleted file mode 100644 index b5d40aa..0000000 --- a/openapi-with-quarkus/src/main/resources/META-INF/resources/org.quarkus.openapi.generator.spi.factory.ApiClientProviderFactory +++ /dev/null @@ -1 +0,0 @@ -org.quarkus.openapi.generator.spi.factory.TenantAwareApiClientFactory \ No newline at end of file diff --git a/openapi-with-quarkus/src/main/resources/META-INF/resources/org.quarkus.openapi.generator.spi.factory.InitProviderFactory b/openapi-with-quarkus/src/main/resources/META-INF/resources/org.quarkus.openapi.generator.spi.factory.InitProviderFactory deleted file mode 100644 index 4896521..0000000 --- a/openapi-with-quarkus/src/main/resources/META-INF/resources/org.quarkus.openapi.generator.spi.factory.InitProviderFactory +++ /dev/null @@ -1 +0,0 @@ -org.quarkus.openapi.generator.spi.factory.MicrometerCustomMetricsInit \ No newline at end of file diff --git a/openapi-with-quarkus/src/main/resources/application.properties b/openapi-with-quarkus/src/main/resources/application.properties deleted file mode 100644 index e69de29..0000000 diff --git a/openapi-with-quarkus/src/main/resources/todo.yaml b/openapi-with-quarkus/src/main/resources/todo.yaml deleted file mode 100644 index dd0e6d8..0000000 --- a/openapi-with-quarkus/src/main/resources/todo.yaml +++ /dev/null @@ -1,205 +0,0 @@ ---- -openapi: 3.0.2 -info: - title: Todo - version: 1.0.0 - description: My Todo list API - contact: - url: "http://localhost:8080/api/v1" - email: deven.phillips@redhat.com - license: - name: Apache 2.0 - url: "https://www.apache.org/licenses/LICENSE-2.0" -servers: - - url: "http://{domain}:{port}/api/v1" - description: "Local Dev" - variables: - domain: - default: keycloak - port: - default: 4180 -tags: - - name: todos - - name: user -paths: - /todos: - summary: Path used to manage the list of todos. - description: >- - The REST endpoint/path used to list and create zero or more `Todo` entities. This path contains a - `GET` and `POST` operation to perform the list and create tasks, respectively. - get: - responses: - "200": - content: - application/json: - schema: - type: array - items: - $ref: "#/components/schemas/Todo" - description: Successful response - returns an array of `Todo` entities. - operationId: gettodos - tags: - - todos - summary: List All todos - description: Gets a list of all `Todo` entities. - post: - requestBody: - description: A new `Todo` to be created. - content: - application/json: - schema: - $ref: "#/components/schemas/Todo" - required: true - responses: - "200": - description: Successful response. - content: - application/json: - schema: - $ref: "#/components/schemas/Todo" - operationId: createTodo - tags: - - todos - summary: Create a Todo - description: Creates a new instance of a `Todo`. - "/todos/{todoId}": - summary: Path used to manage a single Todo. - description: >- - The REST endpoint/path used to get, update, and delete single instances of an `Todo`. This path - contains `GET`, `PUT`, and `DELETE` operations used to perform the get, update, and delete tasks, - respectively. - get: - responses: - "200": - content: - application/json: - schema: - $ref: "#/components/schemas/Todo" - description: Successful response - returns a single `Todo`. - security: - - KeyCloak: [] - operationId: getTodo - tags: - - todos - summary: Get a Todo - description: Gets the details of a single instance of a `Todo`. - put: - requestBody: - description: Updated `Todo` information. - content: - application/json: - schema: - $ref: "#/components/schemas/Todo" - required: true - responses: - "200": - description: Successful response. - content: - application/json: - schema: - $ref: "#/components/schemas/Todo" - operationId: updateTodo - tags: - - todos - summary: Update a Todo - description: Updates an existing `Todo`. - delete: - responses: - "204": - description: Successful response. - operationId: deleteTodo - tags: - - todos - summary: Delete a Todo - description: Deletes an existing `Todo`. - parameters: - - name: todoId - description: A unique identifier for a `Todo`. - schema: - format: uuid - type: string - in: path - required: true - /user: - summary: Get the currently logged on user's profile data - description: Return user profile based on authenticated user's OAuth2 Access Token - get: - responses: - "200": - description: The user profile information - content: - application/json: - schema: - $ref: "#/components/schemas/User" - operationId: getUserProfile - description: Return the current user profile - tags: - - user -components: - schemas: - User: - title: User - description: User information - properties: - family_name: - type: string - given_name: - type: string - name: - type: string - preferred_username: - type: string - Todo: - title: Todo - description: A Todo list item - required: - - title - type: object - properties: - id: - format: uuid - type: string - x-java-field-annotations: - - '@javax.persistence.Id' - - '@javax.persistence.GeneratedValue(generator = "UUID")' - - '@org.hibernate.annotations.GenericGenerator(name = "UUID", strategy = "org.hibernate.id.UUIDGenerator")' - - '@javax.persistence.Column(name = "id", updatable = false, nullable = false)' - title: - type: string - description: - type: string - x-java-field-annotations: - - '@javax.persistence.Column(columnDefinition = "TEXT")' - created: - format: date-time - type: string - readOnly: true - x-java-field-annotations: - - '@org.hibernate.annotations.CreationTimestamp' - - '@javax.persistence.Column(name = "created", updatable = false, nullable = false)' - dueDate: - format: date-time - type: string - complete: - type: boolean - author: - type: string - readOnly: true - example: - id: ec3b48dc-938d-11ea-8877-c7ea413b00cb - title: Example Todo - description: This is a Todo entity with a description - created: "2020-05-14T09:00:00.000Z" - dueDate: "2020-05-20T09:00:00.000Z" - complete: false - x-java-class-annotations: - - "@javax.persistence.Entity" - - '@javax.persistence.Table(name = "todos")' - securitySchemes: - KeyCloak: - openIdConnectUrl: "http://todo:8080/auth/realms/todo/.well-known/openid-configuration" - type: openIdConnect -security: - - KeyCloak: - - user - - admin \ No newline at end of file diff --git a/openapi-with-quarkus/src/test/java/org/quarkus/openapi/generator/api/TodoApiConfigTest.java b/openapi-with-quarkus/src/test/java/org/quarkus/openapi/generator/api/TodoApiConfigTest.java deleted file mode 100644 index 5fd9c33..0000000 --- a/openapi-with-quarkus/src/test/java/org/quarkus/openapi/generator/api/TodoApiConfigTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.quarkus.openapi.generator.api; - -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; -import org.quarkus.openapi.generator.config.TodoApiConfig; -import org.quarkus.openapi.todo.api.TodosApi; - -@ExtendWith(MockitoExtension.class) -class TodoApiConfigTest { - - @Mock - private TodosApi todosApi; - - @InjectMocks - private TodoApiConfig todoApiConfig; - - @Test - void shouldReturnAllApis() { - assertNotNull(todoApiConfig.getTodosApi()); - } -} diff --git a/openapi-with-quarkus/src/test/java/org/quarkus/openapi/generator/config/ApiClientFactoryTest.java b/openapi-with-quarkus/src/test/java/org/quarkus/openapi/generator/config/ApiClientFactoryTest.java deleted file mode 100644 index 3a8e973..0000000 --- a/openapi-with-quarkus/src/test/java/org/quarkus/openapi/generator/config/ApiClientFactoryTest.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.quarkus.openapi.generator.config; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import org.junit.jupiter.api.Test; -import org.quarkus.openapi.generator.config.api.factory.ApiClientFactory; -import org.quarkus.openapi.todo.api.ApiClient; - -class ApiClientFactoryTest { - - @Test - void shouldCreateApiClient() { - String basePath = "path"; - - ApiClient traceApiClient = ApiClientFactory.createTraceApiClient(basePath); - - assertNotNull(traceApiClient); - assertEquals(basePath, traceApiClient.getBasePath()); - } - - @Test - void shouldCreateTenantAwareApiClient() { - String basePath = "path"; - String tenantId = "tenantId"; - - ApiClient traceApiClient = ApiClientFactory.createTenantApiClient(tenantId, basePath); - - assertNotNull(traceApiClient); - assertEquals(basePath, traceApiClient.getBasePath()); - } - - @Test - void shouldCreateApiClientWithoutTenantId() { - String basePath = "path"; - - ApiClient traceApiClient = ApiClientFactory.createTenantApiClient(null, basePath); - - assertNotNull(traceApiClient); - assertEquals(basePath, traceApiClient.getBasePath()); - } - -} \ No newline at end of file diff --git a/openapi-with-quarkus/src/test/java/org/quarkus/openapi/generator/config/TodoApiConfigFactoryTest.java b/openapi-with-quarkus/src/test/java/org/quarkus/openapi/generator/config/TodoApiConfigFactoryTest.java deleted file mode 100644 index 74b1b98..0000000 --- a/openapi-with-quarkus/src/test/java/org/quarkus/openapi/generator/config/TodoApiConfigFactoryTest.java +++ /dev/null @@ -1,82 +0,0 @@ -package org.quarkus.openapi.generator.config; - -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.Mockito.mockStatic; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.when; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.keycloak.Config; -import org.mockito.Mock; -import org.mockito.MockedStatic; -import org.mockito.junit.jupiter.MockitoExtension; -import org.quarkus.openapi.generator.config.api.factory.ApiClientFactory; -import org.quarkus.openapi.generator.config.api.factory.TodoApiConfigFactory; -import org.quarkus.openapi.generator.models.Tenant; -import org.quarkus.openapi.todo.api.ApiClient; - -@ExtendWith(MockitoExtension.class) -class TodoApiConfigFactoryTest { - - @Mock - private Config.Scope mockScope; - - @Mock - private ApiClient mockApiClient; - - @Mock - private Tenant mockTenant; - - @Test - void shouldNotCreateTodoConfigWhenBasePathIsMissing() { - try (MockedStatic mockedConfigUtils = mockStatic(ConfigUtils.class)) { - mockedConfigUtils.when(ConfigUtils::getGlobalScope).thenReturn(mockScope); - when(mockScope.get(any())).thenReturn(null); - - TodoApiConfig todoApiConfig = TodoApiConfigFactory.createTodoApiConfig(); - - assertNull(todoApiConfig); - } - } - - @Test - void shouldCreateTodoApiConfigWithoutTenant() { - try (MockedStatic mockedConfigUtils = mockStatic(ConfigUtils.class)) { - mockedConfigUtils.when(ConfigUtils::getGlobalScope).thenReturn(mockScope); - when(mockScope.get(any())).thenReturn("basePath"); - - try (MockedStatic mockedApiClientFactory = mockStatic(ApiClientFactory.class)) { - mockedApiClientFactory.when(() -> ApiClientFactory.createTenantApiClient(null, "basePath")) - .thenReturn(mockApiClient); - - TodoApiConfig todoApiConfig = TodoApiConfigFactory.createTodoApiConfig(); - - assertNotNull(todoApiConfig); - mockedApiClientFactory.verify(() -> ApiClientFactory.createTenantApiClient(null, "basePath"), times(1)); - } - } - } - - @Test - void shouldCreateTodoConfigWithTenant() { - try (MockedStatic mockedConfigUtils = mockStatic(ConfigUtils.class)) { - mockedConfigUtils.when(ConfigUtils::getGlobalScope).thenReturn(mockScope); - when(mockScope.get(any())).thenReturn("basePath"); - when(mockTenant.getId()).thenReturn("tenantId"); - try (MockedStatic mockedApiClientFactory = mockStatic(ApiClientFactory.class)) { - mockedApiClientFactory.when(() -> ApiClientFactory.createTenantApiClient("tenantId", "basePath")) - .thenReturn(mockApiClient); - - TodoApiConfig todoApiConfig = TodoApiConfigFactory.createTodoApiConfig(mockTenant); - - assertNotNull(todoApiConfig); - mockedApiClientFactory.verify(() -> ApiClientFactory.createTenantApiClient("tenantId", "basePath"), - times(1)); - } - } - } - -} diff --git a/openapi-with-quarkus/src/test/java/org/quarkus/openapi/generator/spi/ApiClientProviderSpiTest.java b/openapi-with-quarkus/src/test/java/org/quarkus/openapi/generator/spi/ApiClientProviderSpiTest.java deleted file mode 100644 index d836dd7..0000000 --- a/openapi-with-quarkus/src/test/java/org/quarkus/openapi/generator/spi/ApiClientProviderSpiTest.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.quarkus.openapi.generator.spi; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; - -import org.junit.jupiter.api.Test; -import org.keycloak.provider.Provider; -import org.keycloak.provider.ProviderFactory; -import org.quarkus.openapi.generator.spi.factory.ApiClientProviderFactory; -import org.quarkus.openapi.generator.spi.provider.ApiClientProvider; - -class ApiClientProviderSpiTest { - - private ApiClientProviderSpi spi = new ApiClientProviderSpi(); - - @Test - void shouldNotBeInternalProvider() { - boolean internal = spi.isInternal(); - assertFalse(internal); - } - - @Test - void shouldReturnValidName() { - String name = spi.getName(); - assertEquals("api-client-provider-spi", name); - } - - @Test - void shouldReturnValidProviderClass() { - Class providerClass = spi.getProviderClass(); - assertEquals(ApiClientProvider.class, providerClass); - } - - @Test - void shouldReturnValidFactoryClass() { - Class providerFactoryClass = spi.getProviderFactoryClass(); - assertEquals(ApiClientProviderFactory.class, providerFactoryClass); - } - -} \ No newline at end of file diff --git a/openapi-with-quarkus/src/test/java/org/quarkus/openapi/generator/spi/InitProviderSpiTest.java b/openapi-with-quarkus/src/test/java/org/quarkus/openapi/generator/spi/InitProviderSpiTest.java deleted file mode 100644 index e3edee8..0000000 --- a/openapi-with-quarkus/src/test/java/org/quarkus/openapi/generator/spi/InitProviderSpiTest.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.quarkus.openapi.generator.spi; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; - -import org.junit.jupiter.api.Test; -import org.keycloak.provider.Provider; -import org.keycloak.provider.ProviderFactory; -import org.quarkus.openapi.generator.spi.factory.InitProviderFactory; -import org.quarkus.openapi.generator.spi.provider.InitProvider; - -class InitProviderSpiTest { - - private final InitProviderSpi initProviderSpi = new InitProviderSpi(); - - @Test - void shouldNotBeInternal() { - boolean resultInternalFlag = initProviderSpi.isInternal(); - assertFalse(resultInternalFlag); - } - - @Test - void shouldReturnName() { - String resultName = initProviderSpi.getName(); - assertEquals("init-provider-spi", resultName); - } - - @Test - void shouldReturnProviderClass() { - Class resultProviderClass = initProviderSpi.getProviderClass(); - assertEquals(InitProvider.class, resultProviderClass); - } - - @Test - void shouldReturnProviderFactoryClass() { - Class resultProviderFactoryClass = initProviderSpi.getProviderFactoryClass(); - assertEquals(InitProviderFactory.class, resultProviderFactoryClass); - } - -} \ No newline at end of file diff --git a/openapi-with-quarkus/src/test/java/org/quarkus/openapi/generator/spi/provider/ApiClientProviderTest.java b/openapi-with-quarkus/src/test/java/org/quarkus/openapi/generator/spi/provider/ApiClientProviderTest.java deleted file mode 100644 index 3cbf4b1..0000000 --- a/openapi-with-quarkus/src/test/java/org/quarkus/openapi/generator/spi/provider/ApiClientProviderTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.quarkus.openapi.generator.spi.provider; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; -import org.quarkus.openapi.generator.config.TodoApiConfig; - -@ExtendWith(MockitoExtension.class) -class ApiClientProviderTest { - - @Mock - private TodoApiConfig mockTodoApiConfig; - - @InjectMocks - private ApiClientProvider provider; - - @Test - void shouldGetValidConfig() { - TodoApiConfig apiConfig = provider.getApiConfig(); - assertEquals(mockTodoApiConfig, apiConfig); - } -}