Skip to content

Commit

Permalink
fix: remove CorrelationHeaderProviders
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed May 24, 2024
1 parent 1a45764 commit 870aec2
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 177 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,19 @@

import be.vlaanderen.vip.magda.client.MagdaClient;
import be.vlaanderen.vip.magda.client.MagdaClientException;
import be.vlaanderen.vip.magda.client.correlation.CorrelationHeaderProvider;
import be.vlaanderen.vip.magda.client.correlation.NullCorrelationHeaderProvider;
import be.vlaanderen.vip.magda.client.diensten.GeefPersoonRequest;

import java.util.UUID;

public class MagdaClientGivePersonService implements GivePersonService {

private final MagdaClient service;
private final CorrelationHeaderProvider correlationHeaderProvider;

/**
* @deprecated remove the correlationHeaderProvider parameters, and for all the relevant requests, replace all uses of a CorrelationHeaderProvider with request.setCorrelationId(correlationId)`.
*/
@Deprecated(forRemoval = true)
public MagdaClientGivePersonService(
MagdaClient service,
CorrelationHeaderProvider correlationHeaderProvider) {
this.service = service;
this.correlationHeaderProvider = correlationHeaderProvider;
}

public MagdaClientGivePersonService(
MagdaClient service) {
this.service = service;
this.correlationHeaderProvider = NullCorrelationHeaderProvider.getInstance();
}

@Override
public Person getPerson(GeefPersoonRequest request) throws MagdaClientException {
correlationHeaderProvider.getXCorrelationId().ifPresent(xCorrelationId -> request.setCorrelationId(UUID.fromString(xCorrelationId))); // TODO abstract the correlation stuff somehow, maybe with a decorator pattern

return new MagdaResponsePerson(service.send(request));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,22 @@
import be.vlaanderen.vip.magda.client.MagdaClient;
import be.vlaanderen.vip.magda.client.MagdaClientException;
import be.vlaanderen.vip.magda.client.MagdaResponseWrapper;
import be.vlaanderen.vip.magda.client.correlation.CorrelationHeaderProvider;
import be.vlaanderen.vip.magda.client.correlation.NullCorrelationHeaderProvider;
import be.vlaanderen.vip.magda.client.diensten.RegistreerInschrijvingRequest;
import be.vlaanderen.vip.magda.client.domain.dto.INSZ;
import be.vlaanderen.vip.magda.client.domain.dto.RegisteredINSZ;
import be.vlaanderen.vip.magda.client.xml.node.Node;

import java.util.UUID;

public class MagdaClientRepertoriumRegistrationService implements RepertoriumRegistrationService {

private final MagdaClient service;
private final CorrelationHeaderProvider correlationHeaderProvider;

/**
* @deprecated remove the correlationHeaderProvider parameters, and for all the relevant requests, replace all uses of a CorrelationHeaderProvider with request.setCorrelationId(correlationId)`.
*/
public MagdaClientRepertoriumRegistrationService(
MagdaClient service,
CorrelationHeaderProvider correlationHeaderProvider) {
this.service = service;
this.correlationHeaderProvider = correlationHeaderProvider;
}

public MagdaClientRepertoriumRegistrationService(
MagdaClient service) {
this.service = service;
this.correlationHeaderProvider = NullCorrelationHeaderProvider.getInstance();
}

@Override
public RegisteredINSZ register(RegistreerInschrijvingRequest request) throws MagdaClientException {
correlationHeaderProvider.getXCorrelationId().ifPresent(xCorrelationId -> request.setCorrelationId(UUID.fromString(xCorrelationId)));

var response = service.send(request);
validateResponse(response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,19 @@

import be.vlaanderen.vip.magda.client.MagdaClient;
import be.vlaanderen.vip.magda.client.MagdaClientException;
import be.vlaanderen.vip.magda.client.correlation.CorrelationHeaderProvider;
import be.vlaanderen.vip.magda.client.correlation.NullCorrelationHeaderProvider;
import be.vlaanderen.vip.magda.client.diensten.GeefAanslagbiljetPersonenbelastingRequest;

import java.util.UUID;

public class MagdaClientTaxRecordService implements TaxRecordService {

private final MagdaClient service;
private final CorrelationHeaderProvider correlationHeaderProvider;

/**
* @deprecated remove the correlationHeaderProvider parameters, and for all the relevant requests, replace all uses of a CorrelationHeaderProvider with request.setCorrelationId(correlationId)`.
*/
public MagdaClientTaxRecordService(
MagdaClient service,
CorrelationHeaderProvider correlationHeaderProvider) {
this.service = service;
this.correlationHeaderProvider = correlationHeaderProvider;
}

public MagdaClientTaxRecordService(
MagdaClient service) {
this.service = service;
this.correlationHeaderProvider = NullCorrelationHeaderProvider.getInstance();
}

@Override
public TaxRecordList getTaxRecordList(GeefAanslagbiljetPersonenbelastingRequest request) throws MagdaClientException {
correlationHeaderProvider.getXCorrelationId().ifPresent(xCorrelationId -> request.setCorrelationId(UUID.fromString(xCorrelationId)));

return new MagdaResponseTaxRecordList(service.send(request));
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,39 @@

import be.vlaanderen.vip.magda.client.MagdaClient;
import be.vlaanderen.vip.magda.client.MagdaClientException;
import be.vlaanderen.vip.magda.client.correlation.CorrelationHeaderProvider;
import be.vlaanderen.vip.magda.client.diensten.GeefPersoonRequest;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
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 java.util.Optional;
import java.util.UUID;

import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
class MagdaClientGivePersonServiceTest {
@Mock private MagdaClient magdaClient;
@Mock private CorrelationHeaderProvider correlationHeaderProvider;

@InjectMocks
private MagdaClientGivePersonService service;

@Nested
class GetPerson {

@BeforeEach
void setup() {
when(correlationHeaderProvider.getXCorrelationId()).thenReturn(Optional.of("6469cd5e-e8ed-43f7-a91e-48fdfbb76e0f"));
}

@Test
void callsMagdaService() throws MagdaClientException {
service.getPerson(GeefPersoonRequest.builder()

var requestGeefPersoon = GeefPersoonRequest.builder()
.insz("insz")
.build());
.build();

requestGeefPersoon.setCorrelationId(UUID.fromString("6469cd5e-e8ed-43f7-a91e-48fdfbb76e0f"));

service.getPerson(requestGeefPersoon);

verify(magdaClient).send(argThat(r -> {
if(r instanceof GeefPersoonRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@
import be.vlaanderen.vip.magda.client.MagdaClient;
import be.vlaanderen.vip.magda.client.MagdaClientException;
import be.vlaanderen.vip.magda.client.MagdaResponseWrapper;
import be.vlaanderen.vip.magda.client.correlation.CorrelationHeaderProvider;
import be.vlaanderen.vip.magda.client.diensten.RegistreerInschrijvingRequest;
import be.vlaanderen.vip.magda.client.domain.dto.INSZ;
import be.vlaanderen.vip.magda.client.xml.node.Node;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -27,29 +25,27 @@
@ExtendWith(MockitoExtension.class)
class MagdaClientRepertoriumRegistrationServiceTest {
@Mock private MagdaClient magdaClient;
@Mock private CorrelationHeaderProvider correlationHeaderProvider;

@InjectMocks
private MagdaClientRepertoriumRegistrationService service;

@Nested
class Register {

@BeforeEach
void setup() {
when(correlationHeaderProvider.getXCorrelationId()).thenReturn(Optional.of("6469cd5e-e8ed-43f7-a91e-48fdfbb76e0f"));
}

@Test
void callsMagdaService() throws MagdaClientException {
mockResultResponse("1");
var insz = INSZ.of("00000000097");
var start = LocalDate.now();
var registeredInsz = service.register(RegistreerInschrijvingRequest.builder()

var requestRegister = RegistreerInschrijvingRequest.builder()
.insz(insz.getValue())
.startDate(start)
.build());
.build();

requestRegister.setCorrelationId(UUID.fromString("6469cd5e-e8ed-43f7-a91e-48fdfbb76e0f"));

var registeredInsz = service.register(requestRegister);

assertNotNull(registeredInsz);
assertEquals(insz, registeredInsz.insz());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import be.vlaanderen.vip.magda.client.MagdaClient;
import be.vlaanderen.vip.magda.client.MagdaClientException;
import be.vlaanderen.vip.magda.client.correlation.CorrelationHeaderProvider;
import be.vlaanderen.vip.magda.client.diensten.GeefAanslagbiljetPersonenbelastingRequest;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -13,39 +11,34 @@
import org.mockito.junit.jupiter.MockitoExtension;

import java.time.Year;
import java.util.Optional;
import java.util.UUID;

import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
class MagdaClientTaxRecordServiceTest {

@Mock
private MagdaClient magdaClient;

@Mock
private CorrelationHeaderProvider correlationHeaderProvider;

@InjectMocks
private MagdaClientTaxRecordService service;

@Nested
class GetTaxRecordListForIncomeYear {

@BeforeEach
void setup() {
when(correlationHeaderProvider.getXCorrelationId()).thenReturn(Optional.of("6469cd5e-e8ed-43f7-a91e-48fdfbb76e0f"));
}

@Test
void callsMagdaService() throws MagdaClientException {
service.getTaxRecordList(GeefAanslagbiljetPersonenbelastingRequest.builder2()

var requestGeefAanslag = GeefAanslagbiljetPersonenbelastingRequest.builder2()
.insz("insz")
.incomeYear(Year.of(2021))
.build());
.build();

requestGeefAanslag.setCorrelationId(UUID.fromString("6469cd5e-e8ed-43f7-a91e-48fdfbb76e0f"));

service.getTaxRecordList(requestGeefAanslag);

verify(magdaClient).send(argThat(r -> {
if(r instanceof GeefAanslagbiljetPersonenbelastingRequest request) {
Expand Down

0 comments on commit 870aec2

Please sign in to comment.