Skip to content

Commit

Permalink
Added OpenApi Test
Browse files Browse the repository at this point in the history
  • Loading branch information
slaurenz committed Mar 17, 2022
1 parent 29f1588 commit 555b5bf
Show file tree
Hide file tree
Showing 3 changed files with 178 additions and 2 deletions.
23 changes: 21 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<lombok.version>1.18.22</lombok.version>
<springdoc.version>1.6.0</springdoc.version>
<mapstruct.version>1.4.2.Final</mapstruct.version>
<junit.version>5.8.1</junit.version>
<junit.jupiter.version>5.8.2</junit.jupiter.version>
<mockito.version>4.1.0</mockito.version>
<bcpkix.version>1.70</bcpkix.version>
<okhttp.version>4.9.1</okhttp.version>
Expand Down Expand Up @@ -144,6 +144,13 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>io.zonky.test.postgres</groupId>
<artifactId>embedded-postgres-binaries-bom</artifactId>
<version>9.6.16</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down Expand Up @@ -195,7 +202,7 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -301,6 +308,18 @@
<version>0.11.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>io.zonky.test</groupId>
<artifactId>embedded-database-spring-test</artifactId>
<version>2.1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.zonky.test</groupId>
<artifactId>embedded-postgres</artifactId>
<version>1.2.10</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*-
* ---license-start
* eu-digital-green-certificates / dgca-businessrule-service
* ---
* Copyright (C) 2021 T-Systems International GmbH and all other contributors
* ---
* 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.
* ---license-end
*/

package eu.europa.ec.dgc.revocationdistribution;


import eu.europa.ec.dgc.gateway.connector.DgcGatewayCountryListDownloadConnector;
import eu.europa.ec.dgc.gateway.connector.DgcGatewayValidationRuleDownloadConnector;
import eu.europa.ec.dgc.gateway.connector.DgcGatewayValueSetDownloadConnector;
import eu.europa.ec.dgc.gateway.connector.client.DgcGatewayConnectorRestClientConfig;
import eu.europa.ec.dgc.revocationdistribution.client.IssuanceDgciRestClient;
import io.zonky.test.db.AutoConfigureEmbeddedDatabase;
import java.io.BufferedInputStream;
import java.io.FileOutputStream;
import java.net.URL;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;

import static io.zonky.test.db.AutoConfigureEmbeddedDatabase.DatabaseProvider.ZONKY;

@Slf4j
@SpringBootTest(
properties = {
"server.port=8080",
"springdoc.api-docs.enabled=true",
"springdoc.api-docs.path=/openapi",
"dgc.gateway.connector.enabled=false"
},
webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT
)
@AutoConfigureEmbeddedDatabase(provider = ZONKY)
class OpenApiTest {

@MockBean
DgcGatewayConnectorRestClientConfig dgcGatewayConnectorRestClientConfig;

@MockBean
IssuanceDgciRestClient issuanceDgciRestClient;
@MockBean
DgcGatewayValidationRuleDownloadConnector dgcGatewayValidationRuleDownloadConnector;

@MockBean
DgcGatewayValueSetDownloadConnector dgcGatewayValueSetDownloadConnector;

@MockBean
DgcGatewayCountryListDownloadConnector dgcGatewayCountryListDownloadConnector;

@Test
void apiDocs() {
try (BufferedInputStream in = new BufferedInputStream(new URL("http://localhost:8080/openapi").openStream());
FileOutputStream out = new FileOutputStream("target/openapi.json")) {
byte[] buffer = new byte[1024];
int read;
while ((read = in.read(buffer, 0, buffer.length)) != -1) {
out.write(buffer, 0, read);
}
} catch (Exception e) {
log.error("Failed to download openapi specification.", e);
Assertions.fail();
}
}
}
75 changes: 75 additions & 0 deletions src/test/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
logging:
level:
default: TRACE
org.hibernate.SQL: INFO
org.hibernate.type.descriptor.sql: INFO
server:
port: 8080
spring:
application:
name: dgca-revocation-distribution-service
datasource:
driver-class-name: org.postgresql.Driver
url: jdbc:postgresql://localhost:5432/postgres
username: postgres
password: postgres
jpa:
database-platform: org.hibernate.dialect.PostgreSQLDialect
hibernate:
ddl-auto: validate
liquibase:
change-log: classpath:db/changelog.xml
database-change-log-table: RD_CHANGELOG
database-change-log-lock-table: RD_CHANGELOG_LOCK
h2:
console:
enabled: false
path: /h2-console
task:
scheduling:
pool:
size: 5
management:
server:
ssl:
enabled: false
port: 8081
endpoint:
info:
enabled: true
health:
enabled: true
endpoints:
enabled-by-default: false
web:
exposure:
include: info,health
jmx:
exposure:
include: info,health
health:
probes:
enabled: true

info:
name: ${spring.application.name}
profiles: ${spring.profiles.active}
springdoc:
api-docs:
path: /api/docs
enabled: true
swagger-ui:
path: /swagger

dgc:
revocationListDownload:
timeInterval: 1800000
lockLimit: 3600000
bloomFilter:
enabled: true
type: Bloom
version: 1.0
probRate: 0.000000000001f
issuance:
dgci:
endpoint: ${DGC_ISSUANCE_DGCI_ENDPOINT}

0 comments on commit 555b5bf

Please sign in to comment.