diff --git a/services/hanke-service/src/integrationTest/kotlin/fi/hel/haitaton/hanke/HankeControllerITests.kt b/services/hanke-service/src/integrationTest/kotlin/fi/hel/haitaton/hanke/HankeControllerITests.kt index d736170d6..ecca3082f 100644 --- a/services/hanke-service/src/integrationTest/kotlin/fi/hel/haitaton/hanke/HankeControllerITests.kt +++ b/services/hanke-service/src/integrationTest/kotlin/fi/hel/haitaton/hanke/HankeControllerITests.kt @@ -28,7 +28,6 @@ import org.junit.jupiter.api.Test import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest import org.springframework.context.annotation.Import -import org.springframework.http.MediaType import org.springframework.security.test.context.support.WithAnonymousUser import org.springframework.security.test.context.support.WithMockUser import org.springframework.security.test.web.servlet.response.SecurityMockMvcResultMatchers @@ -105,7 +104,6 @@ class HankeControllerITests(@Autowired override val mockMvc: MockMvc) : Controll get(url) .andExpect(status().isOk) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.nimi").value("Hämeentien perusparannus ja katuvalot")) .andExpect(jsonPath("$.status").value(HankeStatus.DRAFT.name)) @@ -151,7 +149,6 @@ class HankeControllerITests(@Autowired override val mockMvc: MockMvc) : Controll // we check that we get the two hankeTunnus we expect get(url) .andExpect(status().isOk) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$[2]").doesNotExist()) .andExpect(jsonPath("$[0].hankeTunnus").value(HANKE_TUNNUS)) .andExpect(jsonPath("$[1].hankeTunnus").value("hanketunnus2")) @@ -188,7 +185,6 @@ class HankeControllerITests(@Autowired override val mockMvc: MockMvc) : Controll // we check that we get the two hankeTunnus and geometriat we expect get("$url/?geometry=true") .andExpect(status().isOk) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$[0].hankeTunnus").value(HANKE_TUNNUS)) .andExpect(jsonPath("$[1].hankeTunnus").value("hanketunnus2")) .andExpect(jsonPath("$[0].id").value(hankeIds[0])) @@ -322,7 +318,6 @@ class HankeControllerITests(@Autowired override val mockMvc: MockMvc) : Controll post(url, hankeToBeCreated) .andExpect(status().isOk) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.hankeTunnus").value(HANKE_TUNNUS)) .andExpect(content().json(createdHanke.toJsonString())) @@ -362,7 +357,6 @@ class HankeControllerITests(@Autowired override val mockMvc: MockMvc) : Controll post(url, hankeToBeMocked) .andExpect(status().isOk) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(content().json(expectedContent)) .andExpect(jsonPath("$.hankeTunnus").value(HANKE_TUNNUS)) @@ -379,7 +373,6 @@ class HankeControllerITests(@Autowired override val mockMvc: MockMvc) : Controll post(url, hanke) .andExpect(status().isInternalServerError) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(hankeError(HankeError.HAI0002)) verifySequence { hankeService.createHanke(any()) } @@ -423,7 +416,6 @@ class HankeControllerITests(@Autowired override val mockMvc: MockMvc) : Controll // Call it and check results post(url, hankeToBeMocked) .andExpect(status().isOk) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(content().json(expectedContent)) // These might be redundant, but at least it is clear what we're checking here: .andExpect(jsonPath("$.alkuPvm").value(expectedDateAlkuJson)) @@ -483,7 +475,6 @@ class HankeControllerITests(@Autowired override val mockMvc: MockMvc) : Controll put(url, hankeToBeUpdated) .andExpect(status().isOk) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.nimi").value(HankeFactory.defaultNimi)) .andExpect(jsonPath("$.status").value(HankeStatus.PUBLIC.name)) @@ -533,7 +524,6 @@ class HankeControllerITests(@Autowired override val mockMvc: MockMvc) : Controll put(url, hankeToBeUpdated) .andExpect(status().isOk) - .andExpect(content().contentType(MediaType.APPLICATION_JSON)) .andExpect(content().json(expectedContent)) // These might be redundant, but at least it is clear what we're checking here: .andExpect(jsonPath("$.tyomaaKatuosoite").value("Testikatu 1")) diff --git a/services/hanke-service/src/integrationTest/kotlin/fi/hel/haitaton/hanke/application/ApplicationControllerITest.kt b/services/hanke-service/src/integrationTest/kotlin/fi/hel/haitaton/hanke/application/ApplicationControllerITest.kt index 1b525591c..32dc3b0a6 100644 --- a/services/hanke-service/src/integrationTest/kotlin/fi/hel/haitaton/hanke/application/ApplicationControllerITest.kt +++ b/services/hanke-service/src/integrationTest/kotlin/fi/hel/haitaton/hanke/application/ApplicationControllerITest.kt @@ -37,7 +37,6 @@ import org.junit.jupiter.api.Test import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest import org.springframework.context.annotation.Import -import org.springframework.http.MediaType.APPLICATION_JSON import org.springframework.http.MediaType.APPLICATION_PDF import org.springframework.security.test.context.support.WithMockUser import org.springframework.test.context.ActiveProfiles @@ -695,9 +694,8 @@ class ApplicationControllerITest(@Autowired override val mockMvc: MockMvc) : Con val id = 11L every { applicationService.getApplicationById(id) } throws ApplicationNotFoundException(id) - get("$BASE_URL/$id/paatos", accept = arrayOf(APPLICATION_PDF, APPLICATION_JSON)) + get("$BASE_URL/$id/paatos") .andExpect(status().isNotFound) - .andExpect(content().contentType(APPLICATION_JSON)) .andExpect(jsonPath("errorCode").value("HAI2001")) .andExpect(jsonPath("errorMessage").value("Application not found")) @@ -715,9 +713,8 @@ class ApplicationControllerITest(@Autowired override val mockMvc: MockMvc) : Con every { applicationService.downloadDecision(id, USERNAME) } throws ApplicationDecisionNotFoundException("Decision not found in Allu. alluid=23") - get("$BASE_URL/11/paatos", accept = arrayOf(APPLICATION_PDF, APPLICATION_JSON)) + get("$BASE_URL/11/paatos") .andExpect(status().isNotFound) - .andExpect(content().contentType(APPLICATION_JSON)) .andExpect(jsonPath("errorCode").value("HAI2006")) .andExpect(jsonPath("errorMessage").value("Application decision not found")) @@ -737,14 +734,9 @@ class ApplicationControllerITest(@Autowired override val mockMvc: MockMvc) : Con every { applicationService.downloadDecision(11, USERNAME) } returns Pair("JS230001", pdfBytes) - get( - "$BASE_URL/11/paatos", - resultType = APPLICATION_PDF, - accept = arrayOf(APPLICATION_PDF, APPLICATION_JSON) - ) + get("$BASE_URL/11/paatos", resultType = APPLICATION_PDF) .andExpect(status().isOk) .andExpect(header().string("Content-Disposition", "inline; filename=JS230001.pdf")) - .andExpect(content().contentType(APPLICATION_PDF)) .andExpect(content().bytes(pdfBytes)) verify { applicationService.getApplicationById(11) } @@ -761,8 +753,7 @@ class ApplicationControllerITest(@Autowired override val mockMvc: MockMvc) : Con AlluDataFactory.createApplication(id = id, hankeTunnus = HANKE_TUNNUS) every { permissionService.hasPermission(42, USERNAME, VIEW) } returns false - get("$BASE_URL/$id/paatos", accept = arrayOf(APPLICATION_PDF, APPLICATION_JSON)) - .andExpect(status().isNotFound) + get("$BASE_URL/$id/paatos").andExpect(status().isNotFound) verify { applicationService.getApplicationById(id) } verify { permissionService.hasPermission(42, USERNAME, VIEW) } diff --git a/services/hanke-service/src/integrationTest/kotlin/fi/hel/haitaton/hanke/attachment/hanke/HankeAttachmentControllerITests.kt b/services/hanke-service/src/integrationTest/kotlin/fi/hel/haitaton/hanke/attachment/hanke/HankeAttachmentControllerITests.kt index 74c8ec2d3..d2cb2da41 100644 --- a/services/hanke-service/src/integrationTest/kotlin/fi/hel/haitaton/hanke/attachment/hanke/HankeAttachmentControllerITests.kt +++ b/services/hanke-service/src/integrationTest/kotlin/fi/hel/haitaton/hanke/attachment/hanke/HankeAttachmentControllerITests.kt @@ -100,7 +100,6 @@ class HankeAttachmentControllerITests(@Autowired override val mockMvc: MockMvc) getAttachmentContent(attachmentId = liiteId) .andExpect(status().isOk) .andExpect(header().string(CONTENT_DISPOSITION, "attachment; filename=$FILE_NAME_PDF")) - .andExpect(content().contentType(APPLICATION_PDF)) .andExpect(content().bytes(dummyData)) verifyOrder { diff --git a/services/hanke-service/src/main/kotlin/fi/hel/haitaton/hanke/application/ApplicationController.kt b/services/hanke-service/src/main/kotlin/fi/hel/haitaton/hanke/application/ApplicationController.kt index 544a419f2..643414e8f 100644 --- a/services/hanke-service/src/main/kotlin/fi/hel/haitaton/hanke/application/ApplicationController.kt +++ b/services/hanke-service/src/main/kotlin/fi/hel/haitaton/hanke/application/ApplicationController.kt @@ -22,7 +22,6 @@ import io.swagger.v3.oas.annotations.security.SecurityRequirement import mu.KotlinLogging import org.springframework.http.HttpHeaders import org.springframework.http.HttpStatus -import org.springframework.http.MediaType.APPLICATION_JSON_VALUE import org.springframework.http.MediaType.APPLICATION_PDF import org.springframework.http.MediaType.APPLICATION_PDF_VALUE import org.springframework.http.ResponseEntity @@ -263,7 +262,7 @@ class ApplicationController( return service.sendApplication(id, currentUserId()) } - @GetMapping("/{id}/paatos", produces = [APPLICATION_PDF_VALUE, APPLICATION_JSON_VALUE]) + @GetMapping("/{id}/paatos") @Operation( summary = "Download a decision", description = "Downloads a decision for this application from Allu." @@ -271,7 +270,11 @@ class ApplicationController( @ApiResponses( value = [ - ApiResponse(description = "The decision PDF", responseCode = "200"), + ApiResponse( + description = "The decision PDF", + responseCode = "200", + content = [Content(mediaType = APPLICATION_PDF_VALUE)] + ), ApiResponse( description = "An application was not found with the given id or the application didn't have a decision", diff --git a/services/hanke-service/src/test/kotlin/fi/hel/haitaton/hanke/ControllerTest.kt b/services/hanke-service/src/test/kotlin/fi/hel/haitaton/hanke/ControllerTest.kt index cf04b1541..d9896ca26 100644 --- a/services/hanke-service/src/test/kotlin/fi/hel/haitaton/hanke/ControllerTest.kt +++ b/services/hanke-service/src/test/kotlin/fi/hel/haitaton/hanke/ControllerTest.kt @@ -15,10 +15,9 @@ interface ControllerTest { fun get( url: String, resultType: MediaType = MediaType.APPLICATION_JSON, - accept: Array = arrayOf(MediaType.APPLICATION_JSON) ): ResultActions { return mockMvc - .perform(MockMvcRequestBuilders.get(url).accept(*accept)) + .perform(MockMvcRequestBuilders.get(url).accept(MediaType.APPLICATION_JSON)) .andExpect(content().contentType(resultType)) }