Skip to content

Commit

Permalink
WIP: add integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
bhuism committed Nov 25, 2024
1 parent e6bf419 commit 88a462d
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 37 deletions.
11 changes: 7 additions & 4 deletions src/main/java/nl/ictu/controller/v1/ExchangeToken.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package nl.ictu.controller.v1;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -23,16 +24,18 @@ public class ExchangeToken implements ExchangeTokenApi, VersionOneController {

private final TokenConverter tokenConverter;

private final ObjectMapper objectMapper;

@Override
@SneakyThrows
public ResponseEntity<WsExchangeTokenForIdentifier200Response> exchangeTokenForIdentifier(final String callerOIN, final WsExchangeTokenForIdentifierRequest wsExchangeTokenForIdentifierRequest) {

final String encodedToken = cryptographer.decrypt(wsExchangeTokenForIdentifierRequest.getToken());

log.info("Received token: " + encodedToken);

final Token token = tokenConverter.decode(encodedToken);

log.info("Received token: {}", objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(token));

if (!callerOIN.equals(token.getRecipientOIN())) {
throw new RuntimeException("Sink OIN not the same");
}
Expand All @@ -41,8 +44,8 @@ public ResponseEntity<WsExchangeTokenForIdentifier200Response> exchangeTokenForI

final WsIdentifier wsIdentifier = new WsIdentifier();

wsIdentifier.setIdentifierType(WsIdentifierTypes.fromValue(token.getIdentifier().getType()));
wsIdentifier.setIdentifierValue(token.getIdentifier().getValue());
wsIdentifier.setType(WsIdentifierTypes.fromValue(token.getIdentifier().getType()));
wsIdentifier.setValue(token.getIdentifier().getValue());

wsExchangeTokenForIdentifier200Response.setIdentifier(wsIdentifier);

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/nl/ictu/controller/v1/GetToken.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public ResponseEntity<WsGetToken200Response> getToken(final String callerOIN, Ws

token.setCreationDate(new Date(System.currentTimeMillis()));
token.setRecipientOIN(wsGetTokenRequest.getRecipientOIN());
token.getIdentifier().setType(wsGetTokenRequest.getIdentifier().getIdentifierType().name());
token.getIdentifier().setValue(wsGetTokenRequest.getIdentifier().getIdentifierValue());
token.getIdentifier().setType(wsGetTokenRequest.getIdentifier().getType().name());
token.getIdentifier().setValue(wsGetTokenRequest.getIdentifier().getValue());

final String plainTextToken = tokenConverter.encode(token);

Expand Down
28 changes: 0 additions & 28 deletions src/main/java/nl/ictu/controller/v1/IdentifierHelper.java

This file was deleted.

4 changes: 2 additions & 2 deletions src/main/resources/public/v1/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ components:
identifier:
type: object
properties:
identifierValue:
value:
type: string
identifierType:
type:
$ref: '#/components/schemas/identifierTypes'
identifierTypes:
type: string
Expand Down
29 changes: 28 additions & 1 deletion src/test/java/nl/ictu/TestingWebApplicationTests.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
package nl.ictu;

import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.util.CollectionUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static java.util.Map.of;
import static org.assertj.core.api.Assertions.assertThat;

@Slf4j
@ActiveProfiles("test")
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
class TestingWebApplicationTests {
Expand All @@ -28,11 +41,25 @@ public void contextLoads() {
}

@Test
public void testActuatorHealthEndpoint() throws Exception {
public void testActuatorHealthEndpoint() {
assertThat(
restTemplate
.getForObject("http://localhost:" + actuatorPort + "/actuator/health", String.class)
).contains("{\"status\":\"UP\"}");
}

@Test
public void testIntegration() {

final Map body = Map.of("recipientOIN", "54321543215432154321", "identifier", Map.of("type", "BSN", "value", "012345679"));

final HttpEntity httpEntity = new HttpEntity(body, new HttpHeaders(CollectionUtils.toMultiValueMap(of("callerOIN", List.of("0912345012345012345012345")))));

ResponseEntity<Map> exchange = restTemplate.exchange("http://localhost:" + port + "/v1/getToken", HttpMethod.POST, httpEntity, Map.class);

log.info("map: " + exchange.getBody());

assertThat(exchange.getStatusCode()).isEqualTo(HttpStatus.OK);
}

}

0 comments on commit 88a462d

Please sign in to comment.