Skip to content

Commit

Permalink
Fiks tester
Browse files Browse the repository at this point in the history
  • Loading branch information
ugur93 committed Oct 13, 2023
1 parent f6538c2 commit b100912
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 53 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

<!-- dependent versions other than from spring-boot -->
<apache-avro-version>1.11.2</apache-avro-version>
<bidrag-commons.version>20230816111838_f404b39</bidrag-commons.version>
<bidrag-commons.version>20231013111728_2a4d649</bidrag-commons.version>
<bidrag-commons-test.version>1.20230503150725_3c2c77b</bidrag-commons-test.version>
<bidrag-transport.version>20231010134706_52d8d27</bidrag-transport.version>
<bidrag-dokument-dto.version>1.6.41</bidrag-dokument-dto.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ import no.nav.bidrag.commons.security.service.SecurityTokenService
import no.nav.bidrag.commons.security.service.StsTokenService
import no.nav.bidrag.commons.web.CorrelationIdFilter
import no.nav.bidrag.commons.web.DefaultCorsFilter
import no.nav.bidrag.commons.web.EnhetFilter
import no.nav.bidrag.commons.web.HttpHeaderRestTemplate
import no.nav.bidrag.commons.web.MdcFilter
import no.nav.bidrag.commons.web.UserMdcFilter
import no.nav.bidrag.dokument.arkiv.aop.AspectExceptionLogger
import no.nav.bidrag.dokument.arkiv.aop.HttpStatusRestControllerAdvice
import no.nav.bidrag.dokument.arkiv.consumer.BidragOrganisasjonConsumer
import no.nav.bidrag.dokument.arkiv.consumer.DokarkivConsumer
Expand Down Expand Up @@ -291,15 +289,6 @@ class BidragDokumentArkivConfig {
return BidragOrganisasjonConsumer(httpHeaderRestTemplate)
}

@Bean
fun exceptionLogger(): ExceptionLogger {
return ExceptionLogger(
BidragDokumentArkiv::class.java.simpleName,
AspectExceptionLogger::class.java,
HttpStatusRestControllerAdvice::class.java
)
}

@Bean
fun environmentProperties(
@Value("\${DOKARKIV_URL}") dokarkivUrl: String,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package no.nav.bidrag.dokument.arkiv.aop

import com.fasterxml.jackson.databind.exc.MismatchedInputException
import com.fasterxml.jackson.module.kotlin.MissingKotlinParameterException
import no.nav.bidrag.commons.util.hentForespørselValideringsfeil
import no.nav.bidrag.dokument.arkiv.model.HttpStatusException
import no.nav.bidrag.dokument.arkiv.model.JournalIkkeFunnetException
import no.nav.bidrag.dokument.arkiv.model.JournalpostIkkeFunnetException
Expand All @@ -11,16 +14,37 @@ import no.nav.bidrag.dokument.arkiv.model.UgyldigAvvikException
import no.nav.bidrag.dokument.arkiv.model.ViolationException
import no.nav.security.token.support.spring.validation.interceptor.JwtTokenUnauthorizedException
import org.slf4j.LoggerFactory
import org.springframework.core.convert.ConversionFailedException
import org.springframework.http.HttpHeaders
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.http.converter.HttpMessageNotReadableException
import org.springframework.web.bind.annotation.ExceptionHandler
import org.springframework.web.bind.annotation.ResponseBody
import org.springframework.web.bind.annotation.RestControllerAdvice
import org.springframework.web.client.HttpStatusCodeException
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException

@RestControllerAdvice
class HttpStatusRestControllerAdvice {
@ResponseBody
@ExceptionHandler(value = [IllegalArgumentException::class, MethodArgumentTypeMismatchException::class, ConversionFailedException::class, HttpMessageNotReadableException::class])
fun handleInvalidValueExceptions(exception: Exception): ResponseEntity<*> {
val valideringsFeil = hentForespørselValideringsfeil(exception)
LOGGER.warn(
"Forespørselen inneholder ugyldig verdi: ${valideringsFeil ?: "ukjent feil"}",
exception
)

return ResponseEntity
.status(HttpStatus.BAD_REQUEST)
.header(
HttpHeaders.WARNING,
valideringsFeil ?: exception.message
)
.build<Any>()
}

@ResponseBody
@ExceptionHandler(PersonException::class)
fun handleTechnicalException(exception: Exception): ResponseEntity<*> {
Expand Down Expand Up @@ -68,17 +92,6 @@ class HttpStatusRestControllerAdvice {
.build<Any>()
}

@ResponseBody
@ExceptionHandler
fun handleIllegalArgumentException(
illegalArgumentException: IllegalArgumentException
): ResponseEntity<*> {
LOGGER.warn(illegalArgumentException.message)
return ResponseEntity.status(HttpStatus.BAD_REQUEST)
.header(HttpHeaders.WARNING, illegalArgumentException.message)
.build<Any>()
}

@ResponseBody
@ExceptionHandler
fun handleHttpStatusException(httpStatusException: HttpStatusException): ResponseEntity<*> {
Expand All @@ -89,7 +102,11 @@ class HttpStatusRestControllerAdvice {
}

@ResponseBody
@ExceptionHandler(KnyttTilSakManglerTemaException::class, OppdaterJournalpostFeiletFunksjoneltException::class, UgyldigAvvikException::class)
@ExceptionHandler(
KnyttTilSakManglerTemaException::class,
OppdaterJournalpostFeiletFunksjoneltException::class,
UgyldigAvvikException::class
)
fun ugyldigInput(exception: Exception): ResponseEntity<*> {
LOGGER.warn(exception.message)
return ResponseEntity.status(HttpStatus.BAD_REQUEST)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ import no.nav.bidrag.transport.dokument.JournalpostType
import no.nav.bidrag.transport.dokument.MottakUtsendingKanal
import no.nav.bidrag.transport.dokument.OpprettDokumentDto
import no.nav.bidrag.transport.dokument.OpprettJournalpostResponse
import org.intellij.lang.annotations.Language
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test
import org.springframework.http.HttpEntity
import org.springframework.http.HttpHeaders
import org.springframework.http.HttpMethod
import org.springframework.http.HttpStatus
import org.springframework.http.MediaType
import java.time.LocalDateTime
import java.util.*

Expand Down Expand Up @@ -489,20 +492,55 @@ internal class OpprettJournalpostControllerTest : AbstractControllerTest() {
inner class Feilhåndtering {
@Test
fun `skal feile hvis journalpost opprettet uten journalposttype`() {
val request =
createOpprettJournalpostRequest().copy(journalposttype = JournalpostType.INNGÅENDE)
@Language("json")
val request = """
{
"skalFerdigstilles": false,
"gjelderIdent": "12345678910",
"avsenderMottaker": {
"navn": null,
"ident": "12345678910",
"type": "FNR",
"adresse": null
},
"dokumenter": [
{
"tittel": "Tittel på hoveddokument",
"fysiskDokument": "SW5uaG9sZCBww6UgZG9rdW1lbnRldA=="
},
{
"tittel": "Tittel på vedlegg",
"fysiskDokument": "SW5uaG9sZCBww6UgZG9rdW1lbnRldCB2ZWRsZWdn"
}
],
"tilknyttSaker": [],
"behandlingstema": "BEHTEMA",
"datoMottatt": [
2022,
11,
29,
16,
0
],
"kanal": "DIGITALT",
"tema": "BID",
"referanseId": "REFID"
}
""".trimIndent()

val nyJpId = 123123123L
stubs.mockDokarkivOpprettRequest(
nyJpId,
ferdigstill = false,
dokumentList = request.dokumenter.map { DokumentInfo("DOK_ID_${it.tittel}") }
)

val header = HttpHeaders()
header.contentType = MediaType.APPLICATION_JSON

val response = httpHeaderTestRestTemplate.exchange(
initUrl() + "/journalpost",
HttpMethod.POST,
HttpEntity(request),
HttpEntity(request, header),
OpprettJournalpostResponse::class.java
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal class EndreJournalpostValidationTest {
journalpost.antallRetur = 1
val endreJournalpostCommand = createEndreJournalpostCommand()
.copy(
skalJournalfores = true,
skalJournalfores = false,
endreReturDetaljer = emptyList()
)
Assertions.assertDoesNotThrow {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import no.nav.bidrag.dokument.arkiv.stubs.createOpprettJournalpostRequest
import no.nav.bidrag.transport.dokument.AvsenderMottakerDto
import no.nav.bidrag.transport.dokument.JournalpostType
import no.nav.bidrag.transport.dokument.OpprettDokumentDto
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test

class OpprettJournalpostValidatorTest {

@Test
@Disabled
fun `Validering skal feile hvis journalposttype er tom`() {
val request =
createOpprettJournalpostRequest().copy(journalposttype = JournalpostType.INNGÅENDE)
Expand Down

0 comments on commit b100912

Please sign in to comment.