Skip to content

Commit

Permalink
Oppdatert kode for bestilling #deploy-test-dolly-backend
Browse files Browse the repository at this point in the history
  • Loading branch information
krharum committed Sep 19, 2023
1 parent 532c385 commit dd529c2
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ private Mono<SigrunstubResponse> deleteSkattegrunnlag(String ident, boolean oppr

private String getStatus(SigrunstubResponse response) {

log.info("Response fra Sigrunstub med data {} ", response);
return isNull(response.getErrorStatus()) ?
getStatus(response.getOpprettelseTilbakemeldingsListe()) :
ErrorStatusDecoder.encodeStatus(errorStatusDecoder.getErrorText(response.getErrorStatus(), response.getMelding()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public SigrunStubConsumer(
.build();
}

@Timed(name = "providers", tags = { "operation", "sigrun_deleteGrunnlag" })
@Timed(name = "providers", tags = {"operation", "sigrun_deleteGrunnlag"})
public Flux<SigrunstubResponse> deleteSkattegrunnlag(List<String> identer) {

return tokenService.exchange(serviceProperties)
Expand All @@ -55,14 +55,14 @@ public Flux<SigrunstubResponse> deleteSkattegrunnlag(List<String> identer) {
.flatMap(Flux::from));
}

@Timed(name = "providers", tags = { "operation", "sigrun_deleteGrunnlag" })
@Timed(name = "providers", tags = {"operation", "sigrun_deleteGrunnlag"})
public Mono<SigrunstubResponse> deleteSkattegrunnlag(String ident) {

return tokenService.exchange(serviceProperties)
.flatMap(token -> new SigrunstubDeleteCommand(webClient, ident, token.getTokenValue()).call());
}

@Timed(name = "providers", tags = { "operation", "sigrun_createGrunnlag" })
@Timed(name = "providers", tags = {"operation", "sigrun_createGrunnlag"})
public Mono<SigrunstubResponse> createSkattegrunnlag(List<OpprettSkattegrunnlag> request) {

log.info("Post til Sigrunstub med data {}", request);
Expand All @@ -71,7 +71,7 @@ public Mono<SigrunstubResponse> createSkattegrunnlag(List<OpprettSkattegrunnlag>
.flatMap(token -> new SigurunstubPostCommand(webClient, request, token.getTokenValue()).call());
}

@Timed(name = "providers", tags = { "operation", "sigrun_createPensjonsgivendeInntekt" })
@Timed(name = "providers", tags = {"operation", "sigrun_createPensjonsgivendeInntekt"})
public Mono<SigrunstubResponse> updatePensjonsgivendeInntekt(List<PensjonsgivendeForFolketrygden> request) {

log.info("Put til Sigrunstub med data {}", request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
public class SigurunstubPutCommand implements Callable<Mono<SigrunstubResponse>> {

private static final String CONSUMER = "Dolly";
private static final String SIGRUN_STUB_OPPRETT_GRUNNLAG = "/api/v1/pensjonsgivendeInntektforfolketrygden";
private static final String SIGRUN_STUB_OPPRETT_GRUNNLAG = "/api/v1/pensjonsgivendeinntektforfolketrygden";

private final WebClient webClient;
private final List<PensjonsgivendeForFolketrygden> request;
Expand All @@ -34,7 +34,7 @@ public class SigurunstubPutCommand implements Callable<Mono<SigrunstubResponse>>
@Override
public Mono<SigrunstubResponse> call() {

return webClient.post().uri(uriBuilder -> uriBuilder
return webClient.put().uri(uriBuilder -> uriBuilder
.path(SIGRUN_STUB_OPPRETT_GRUNNLAG)
.build())
.header(ACCEPT, APPLICATION_JSON_VALUE)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package no.nav.dolly.bestilling.sigrunstub.dto;

import com.fasterxml.jackson.databind.JsonNode;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

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

@Data
@Builder
@NoArgsConstructor
Expand All @@ -17,7 +15,7 @@ public class PensjonsgivendeForFolketrygden {

private String inntektsaar;
@Schema(description = "Liste av map som beskrevet i /api/v1/pensjonsgivendeinntektforfolketrygden/kodeverk")
private List<Map<String, Object>> pensjonsgivendeInntekt;
private JsonNode pensjonsgivendeInntekt;
private String personidentifikator;
private String testdataEier;
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,35 @@
package no.nav.dolly.bestilling.sigrunstub.mapper;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import ma.glasnost.orika.CustomMapper;
import ma.glasnost.orika.MapperFactory;
import ma.glasnost.orika.MappingContext;
import no.nav.dolly.bestilling.sigrunstub.dto.PensjonsgivendeForFolketrygden;
import no.nav.dolly.domain.resultset.sigrunstub.KodeverknavnGrunnlag;
import no.nav.dolly.domain.resultset.sigrunstub.OpprettSkattegrunnlag;
import no.nav.dolly.domain.resultset.sigrunstub.RsPensjonsgivendeForFolketrygden;
import no.nav.dolly.mapper.MappingStrategy;
import org.springframework.stereotype.Component;

import java.util.List;

import static java.lang.String.format;
import static no.nav.dolly.domain.resultset.sigrunstub.OpprettSkattegrunnlag.Tjeneste.BEREGNET_SKATT;
import static org.apache.commons.lang3.StringUtils.isNotBlank;

@Slf4j
@Component
@RequiredArgsConstructor
public class SigrunstubDataMapper implements MappingStrategy {

private static final String OPPGJOER_DATO_NAVN = "skatteoppgjoersdato";
private static final String OPPGJOER_DATO_VERDI = "%4d-05-01";

private final ObjectMapper objectMapper;

@Override
public void register(MapperFactory factory) {

Expand Down Expand Up @@ -49,5 +60,27 @@ private void addOppgjoersdato(List<KodeverknavnGrunnlag> spesifiktGrunnlag, Inte
})
.byDefault()
.register();

factory.classMap(RsPensjonsgivendeForFolketrygden.class, PensjonsgivendeForFolketrygden.class)
.customize(new CustomMapper<>() {
@Override
public void mapAtoB(RsPensjonsgivendeForFolketrygden kilde, PensjonsgivendeForFolketrygden destinasjon, MappingContext context) {

destinasjon.setPersonidentifikator((String) context.getProperty("ident"));

destinasjon.setTestdataEier(isNotBlank(kilde.getTestdataEier()) ? kilde.getTestdataEier() : "Dolly");

try {
destinasjon.setPensjonsgivendeInntekt(
objectMapper.readTree(
objectMapper.writeValueAsString(kilde.getPensjonsgivendeInntekt())));
} catch (JsonProcessingException e) {
log.error("Feilet å gjøre {} om til JSON", kilde.getPensjonsgivendeInntekt());
}
}
})
.exclude("pensjonsgivendeInntekt")
.byDefault()
.register();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import no.nav.dolly.domain.resultset.pdldata.PdlPersondata;
import no.nav.dolly.domain.resultset.pensjon.PensjonData;
import no.nav.dolly.domain.resultset.sigrunstub.OpprettSkattegrunnlag;
import no.nav.dolly.domain.resultset.sigrunstub.RsPensjonsgivendeForFolketrygden;
import no.nav.dolly.domain.resultset.skjerming.RsSkjerming;
import no.nav.dolly.domain.resultset.sykemelding.RsSykemelding;
import no.nav.dolly.domain.resultset.tpsmessagingservice.RsTpsMessaging;
Expand All @@ -42,6 +43,7 @@ public class BestilteKriterier {
private RsDigitalKontaktdata krrstub;
private RsUdiPerson udistub;
private List<OpprettSkattegrunnlag> sigrunstub;
private List<RsPensjonsgivendeForFolketrygden> sigrunstubPensjonsgivende;
private Arenadata arenaforvalter;
private PdlPersondata pdldata;
private List<RsInstdata> instdata;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import no.nav.dolly.domain.resultset.pdldata.PdlPersondata;
import no.nav.dolly.domain.resultset.pensjon.PensjonData;
import no.nav.dolly.domain.resultset.sigrunstub.OpprettSkattegrunnlag;
import no.nav.dolly.domain.resultset.sigrunstub.RsPensjonsgivendeForFolketrygden;
import no.nav.dolly.domain.resultset.skjerming.RsSkjerming;
import no.nav.dolly.domain.resultset.sykemelding.RsSykemelding;
import no.nav.dolly.domain.resultset.tpsmessagingservice.RsTpsMessaging;
Expand Down Expand Up @@ -88,6 +89,7 @@ public static class RsBestilling {
private List<RsInstdata> instdata;
private List<RsAareg> aareg;
private List<OpprettSkattegrunnlag> sigrunstub;
private List<RsPensjonsgivendeForFolketrygden> sigrunstubPensjonsgivende;
private InntektMultiplierWrapper inntektstub;
private Arenadata arenaforvalter;
private RsUdiPerson udistub;
Expand All @@ -104,4 +106,4 @@ public static class RsBestilling {
private RsSkjerming skjerming;
private ArbeidsplassenCVDTO arbeidsplassenCV;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import no.nav.dolly.domain.resultset.pdldata.PdlPersondata;
import no.nav.dolly.domain.resultset.pensjon.PensjonData;
import no.nav.dolly.domain.resultset.sigrunstub.OpprettSkattegrunnlag;
import no.nav.dolly.domain.resultset.sigrunstub.RsPensjonsgivendeForFolketrygden;
import no.nav.dolly.domain.resultset.skjerming.RsSkjerming;
import no.nav.dolly.domain.resultset.sykemelding.RsSykemelding;
import no.nav.dolly.domain.resultset.tpsmessagingservice.RsTpsMessaging;
Expand Down Expand Up @@ -82,6 +83,7 @@ public static class RsBestilling {
private List<RsInstdata> instdata;
private List<RsAareg> aareg;
private List<OpprettSkattegrunnlag> sigrunstub;
private List<RsPensjonsgivendeForFolketrygden> sigrunstubPensjonsgivende;
private InntektMultiplierWrapper inntektstub;
private Arenadata arenaforvalter;
private RsUdiPerson udistub;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public void mapAtoB(Bestilling bestilling, RsBestillingStatus bestillingStatus,
.instdata(bestillingRequest.getInstdata())
.inntektstub(bestillingRequest.getInntektstub())
.sigrunstub(bestillingRequest.getSigrunstub())
.sigrunstubPensjonsgivende(bestillingRequest.getSigrunstubPensjonsgivende())
.udistub(bestillingRequest.getUdistub())
.pensjonforvalter(bestillingRequest.getPensjonforvalter())
.inntektsmelding(bestillingRequest.getInntektsmelding())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,13 +383,6 @@ public void slettBestillingByTestIdent(String ident) {
});
}

public List<Long> fetchBestillingerByTestident(String ident) {

var bestillinger = bestillingRepository.findBestillingerByIdent(ident);
return bestillinger.stream().map(Bestilling::getId).toList();
}


@Transactional
public void swapIdent(String oldIdent, String newIdent) {
bestillingRepository.swapIdent(oldIdent, newIdent);
Expand All @@ -401,6 +394,7 @@ public String getBestKriterier(RsDollyBestilling request) {
.krrstub(request.getKrrstub())
.udistub(request.getUdistub())
.sigrunstub(request.getSigrunstub())
.sigrunstubPensjonsgivende(request.getSigrunstubPensjonsgivende())
.arenaforvalter(request.getArenaforvalter())
.pdldata(request.getPdldata())
.instdata(request.getInstdata())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;

import java.util.List;

import static java.util.Collections.singletonList;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
Expand Down Expand Up @@ -91,7 +93,7 @@ void gjenopprett_sigrunstub_feiler() {
.assertNext(status -> {
verify(transactionHelperService, times(1))
.persister(any(BestillingProgress.class), any(), statusCaptor.capture());
assertThat(statusCaptor.getValue(), Matchers.is(equalTo("Feil:")));
assertThat(statusCaptor.getValue(), Matchers.is(equalTo("SIGRUN_LIGNET:Feil=")));
})
.verifyComplete();
}
Expand All @@ -106,7 +108,9 @@ void gjenopprett_sigrunstub_ok() {
.thenReturn(request.getSigrunstub());

when(sigrunStubConsumer.createSkattegrunnlag(anyList())).thenReturn(Mono.just(SigrunstubResponse.builder()
.errorStatus(HttpStatus.OK)
.opprettelseTilbakemeldingsListe(List.of(SigrunstubResponse.OpprettelseTilbakemelding.builder()
.status(200)
.build()))
.build()));

when(sigrunStubConsumer.deleteSkattegrunnlag(IDENT)).thenReturn(Mono.just(new SigrunstubResponse()));
Expand All @@ -117,7 +121,7 @@ void gjenopprett_sigrunstub_ok() {
.assertNext(status -> {
verify(transactionHelperService, times(1))
.persister(any(BestillingProgress.class), any(), statusCaptor.capture());
assertThat(statusCaptor.getValue(), Matchers.is(equalTo("OK")));
assertThat(statusCaptor.getValue(), Matchers.is(equalTo("SIGRUN_LIGNET:OK")));
})
.verifyComplete();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.tomakehurst.wiremock.client.WireMock;
import no.nav.dolly.bestilling.sigrunstub.dto.PensjonsgivendeForFolketrygden;
import no.nav.dolly.bestilling.sigrunstub.dto.SigrunstubResponse;
import no.nav.dolly.config.credentials.SigrunstubProxyProperties;
import no.nav.dolly.domain.resultset.sigrunstub.OpprettSkattegrunnlag;
import no.nav.dolly.errorhandling.ErrorStatusDecoder;
import no.nav.testnav.libs.securitycore.domain.AccessToken;
import no.nav.testnav.libs.standalone.servletsecurity.exchange.TokenExchange;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -31,6 +31,7 @@
import static com.github.tomakehurst.wiremock.client.WireMock.matching;
import static com.github.tomakehurst.wiremock.client.WireMock.ok;
import static com.github.tomakehurst.wiremock.client.WireMock.post;
import static com.github.tomakehurst.wiremock.client.WireMock.put;
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
import static com.github.tomakehurst.wiremock.client.WireMock.urlPathMatching;
import static java.util.Collections.singletonList;
Expand All @@ -48,14 +49,13 @@ class SigrunStubConsumerTest {
@MockBean
private TokenExchange tokenService;

@MockBean
private ErrorStatusDecoder errorStatusDecoder;

@Autowired
private SigrunStubConsumer sigrunStubConsumer;

private OpprettSkattegrunnlag skattegrunnlag;

private PensjonsgivendeForFolketrygden pensjonsgivendeForFolketrygden;

private static String asJsonString(final Object object) throws JsonProcessingException {
return new ObjectMapper().writeValueAsString(object);
}
Expand All @@ -70,20 +70,42 @@ void setup() {
skattegrunnlag = OpprettSkattegrunnlag.builder()
.inntektsaar("1978")
.build();

pensjonsgivendeForFolketrygden = PensjonsgivendeForFolketrygden.builder()
.inntektsaar("1978")
.build();
}

@Test
void createSkattegrunnlag() {

stubOpprettSkattegrunnlagOK();

StepVerifier.create(sigrunStubConsumer.createSkattegrunnlag(singletonList(this.skattegrunnlag)))
StepVerifier.create(sigrunStubConsumer.createSkattegrunnlag(singletonList(skattegrunnlag)))
.expectNext(SigrunstubResponse.builder()
.errorStatus(HttpStatus.OK)
.opprettelseTilbakemeldingsListe(List.of(SigrunstubResponse.OpprettelseTilbakemelding.builder()
.inntektsaar("1978")
.status(200)
.build()))
.build())
.verifyComplete();
}

@Test
void createPensjonsgivendeOK() {

stubOpprettPensjongivendeOK();

StepVerifier.create(sigrunStubConsumer.updatePensjonsgivendeInntekt(singletonList(pensjonsgivendeForFolketrygden)))
.expectNext(SigrunstubResponse.builder()
.opprettelseTilbakemeldingsListe(List.of(SigrunstubResponse.OpprettelseTilbakemelding.builder()
.inntektsaar("1978")
.status(200)
.build()))
.build())
.verifyComplete();
}

@Test
void createSkattegrunnlag_kasterSigrunExceptionHvisKallKasterClientException() throws Exception {

Expand Down Expand Up @@ -114,7 +136,15 @@ private void stubOpprettSkattegrunnlagOK() {

stubFor(post(urlPathMatching("(.*)/sigrunstub/api/v1/lignetinntekt"))
.willReturn(ok()
.withBody("{}")
.withBody("{\"opprettelseTilbakemeldingsListe\":[{\"status\":200}]}")
.withHeader("Content-Type", "application/json")));
}

private void stubOpprettPensjongivendeOK() {

stubFor(put(urlPathMatching("(.*)/sigrunstub/api/v1/pensjonsgivendeinntektforfolketrygden"))
.willReturn(ok()
.withBody("{\"opprettelseTilbakemeldingsListe\":[{\"status\":200}]}")
.withHeader("Content-Type", "application/json")));
}

Expand Down

0 comments on commit dd529c2

Please sign in to comment.