Skip to content

Commit

Permalink
fixup! HAI-1873 Remove explicit produces tags
Browse files Browse the repository at this point in the history
  • Loading branch information
corvidian committed Aug 31, 2023
1 parent 95b0b02 commit 653cd55
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -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"))
Expand Down Expand Up @@ -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]))
Expand Down Expand Up @@ -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()))

Expand Down Expand Up @@ -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))

Expand All @@ -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()) }
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -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"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"))

Expand All @@ -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"))

Expand All @@ -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) }
Expand All @@ -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) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -263,15 +262,19 @@ 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."
)
@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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ interface ControllerTest {
fun get(
url: String,
resultType: MediaType = MediaType.APPLICATION_JSON,
accept: Array<MediaType> = 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))
}

Expand Down

0 comments on commit 653cd55

Please sign in to comment.