Skip to content

Commit

Permalink
upgrade open-api generator, fix mockmvc itests
Browse files Browse the repository at this point in the history
  • Loading branch information
zambrovski committed Oct 11, 2023
1 parent 9ce7e38 commit 8e02810
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ class TaskResource(
return ResponseEntity.noContent().build()
}

private fun getAuthorizedTask(taskId: String, user: User): Task = taskServiceGateway.getTask(taskId)
private fun getAuthorizedTask(taskId: String, user: User): Task = taskServiceGateway
.getTask(taskId)
.apply {
if (!isAuthorized(this, user)) {
// if the user is not allowed to access, behave if the task is not found
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,23 @@ package io.holunda.polyflow.example.tasklist.adapter.rest.impl

import com.fasterxml.jackson.databind.ObjectMapper
import io.holunda.camunda.taskpool.api.task.*
import io.holunda.polyflow.example.tasklist.adapter.rest.Rest.REQUEST_PATH
import io.holunda.polyflow.example.tasklist.itest.ITestApplication
import io.holunda.polyflow.example.tasklist.itest.ITestApplication.Companion.ITEST
import io.holunda.polyflow.example.tasklist.adapter.rest.Rest.REQUEST_PATH
import io.holunda.polyflow.view.Task
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.mockito.kotlin.any
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.boot.test.mock.mockito.MockBean
import org.springframework.http.MediaType
import org.springframework.test.context.ActiveProfiles
import org.springframework.test.web.servlet.MockMvc
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post
import org.springframework.test.web.servlet.result.MockMvcResultMatchers.status
import org.springframework.test.web.servlet.setup.MockMvcBuilders
import org.springframework.web.context.WebApplicationContext
import java.time.Instant
import java.time.OffsetDateTime
import java.time.ZoneOffset.UTC
Expand All @@ -29,27 +27,18 @@ import java.util.*

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = [ITestApplication::class])
@ActiveProfiles(ITEST)
@AutoConfigureMockMvc
internal class TaskResourceIT {

@Autowired
private lateinit var mockMvc: MockMvc

@MockBean
private lateinit var taskServiceGateway: TaskServiceGateway

@Autowired
private lateinit var webApplicationContext: WebApplicationContext

@Autowired
private lateinit var resource: TaskResource

@Autowired
private lateinit var objectMapper: ObjectMapper

@BeforeEach
fun setup() {
this.mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build()
}

@Test
fun `should not allow to claim without the user header`() {
val taskId = UUID.randomUUID().toString()
Expand All @@ -59,7 +48,7 @@ internal class TaskResourceIT {
this.mockMvc
.perform(
post("${REQUEST_PATH}/task/{taskId}/claim", taskId)
.servletPath(REQUEST_PATH)
.contentType(MediaType.APPLICATION_JSON)
)
.andExpect(status().isBadRequest)
}
Expand All @@ -73,8 +62,8 @@ internal class TaskResourceIT {
this.mockMvc
.perform(
post("${REQUEST_PATH}/task/{taskId}/claim", taskId)
.contentType(MediaType.APPLICATION_JSON)
.header("X-Current-User-ID", "id1")
.servletPath(REQUEST_PATH)
)
.andExpect(status().isNotFound)
}
Expand All @@ -91,8 +80,8 @@ internal class TaskResourceIT {
this.mockMvc
.perform(
post("${REQUEST_PATH}/task/{taskId}/claim", taskId)
.contentType(MediaType.APPLICATION_JSON)
.header("X-Current-User-ID", "id1")
.servletPath(REQUEST_PATH)
)
.andExpect(status().isNoContent)

Expand All @@ -110,8 +99,8 @@ internal class TaskResourceIT {
this.mockMvc
.perform(
post("${REQUEST_PATH}/task/{taskId}/unclaim", taskId)
.contentType(MediaType.APPLICATION_JSON)
.header("X-Current-User-ID", "id1")
.servletPath(REQUEST_PATH)
)
.andExpect(status().isNoContent)

Expand All @@ -132,7 +121,6 @@ internal class TaskResourceIT {
.perform(
post("${REQUEST_PATH}/task/{taskId}/defer", taskId)
.header("X-Current-User-ID", "id1")
.servletPath(REQUEST_PATH)
.contentType(MediaType.APPLICATION_JSON)
.content(json)
)
Expand All @@ -152,8 +140,8 @@ internal class TaskResourceIT {
this.mockMvc
.perform(
post("${REQUEST_PATH}/task/{taskId}/undefer", taskId)
.contentType(MediaType.APPLICATION_JSON)
.header("X-Current-User-ID", "id1")
.servletPath(REQUEST_PATH)
)
.andExpect(status().isNoContent)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ logging:
level:
root: INFO
org.springframework.test.util.ReflectionTestUtils: INFO
# org.springframework.web: TRACE
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@
<!-- Open API generator -->
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>6.5.0</version>
<version>7.0.1</version>
</plugin>

<plugin>
Expand Down

0 comments on commit 8e02810

Please sign in to comment.