Skip to content
This repository was archived by the owner on Mar 30, 2025. It is now read-only.

Commit 6b9daf0

Browse files
committed
also accept 204 as upload status code
1 parent 3f4838c commit 6b9daf0

2 files changed

Lines changed: 29 additions & 7 deletions

File tree

adapter/src/main/kotlin/org/railwaystations/rsapi/adapter/task/WebDavSyncTask.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ class WebDavSyncTask(
155155
}
156156
}
157157

158+
private val positiveUploadStatusCodes = listOf(HttpStatus.CREATED.value(), HttpStatus.NO_CONTENT.value())
159+
158160
@Throws(IOException::class, InterruptedException::class)
159161
private fun uploadToProcess(toProcessPath: Path) {
160162
log.info("Uploading $toProcessPath")
@@ -165,7 +167,7 @@ class WebDavSyncTask(
165167
.build()
166168
val response = client.send(request, HttpResponse.BodyHandlers.ofString())
167169
log.info("Upload response " + response.statusCode())
168-
if (response.statusCode() != HttpStatus.CREATED.value()) {
170+
if (!positiveUploadStatusCodes.contains(response.statusCode())) {
169171
throw RuntimeException("Failed Upload, statusCode=" + response.statusCode())
170172
}
171173
}

adapter/src/test/kotlin/org/railwaystations/rsapi/adapter/task/WebDavSyncTaskTest.kt

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import com.github.tomakehurst.wiremock.junit5.WireMockTest
2626
import com.github.tomakehurst.wiremock.matching.RequestPatternBuilder
2727
import io.mockk.every
2828
import io.mockk.mockk
29-
import org.assertj.core.api.Assertions
29+
import org.assertj.core.api.Assertions.assertThat
3030
import org.junit.jupiter.api.BeforeEach
3131
import org.junit.jupiter.api.Test
3232
import org.railwaystations.rsapi.adapter.db.InboxAdapter
@@ -99,7 +99,7 @@ internal class WebDavSyncTaskTest {
9999
}
100100

101101
@Test
102-
fun shouldUploadToProcessFile(wmRuntimeInfo: WireMockRuntimeInfo) {
102+
fun shouldUploadToProcessFileCreated(wmRuntimeInfo: WireMockRuntimeInfo) {
103103
val task = createWebDavSyncTask(wmRuntimeInfo)
104104
val toProcessPath1 = createFile(tempdir)
105105
every { photoStoragePort.getInboxToProcessFile(FILENAME) } returns toProcessPath1
@@ -115,7 +115,27 @@ internal class WebDavSyncTaskTest {
115115
.withRequestBody(binaryEqualTo(FILENAME.toByteArray(StandardCharsets.UTF_8)))
116116
)
117117

118-
Assertions.assertThat(Files.exists(toProcessPath1)).isFalse()
118+
assertThat(Files.exists(toProcessPath1)).isFalse()
119+
}
120+
121+
@Test
122+
fun shouldUploadToProcessFileNoContent(wmRuntimeInfo: WireMockRuntimeInfo) {
123+
val task = createWebDavSyncTask(wmRuntimeInfo)
124+
val toProcessPath1 = createFile(tempdir)
125+
every { photoStoragePort.getInboxToProcessFile(FILENAME) } returns toProcessPath1
126+
every { photoStoragePort.getInboxProcessedFile(FILENAME) } returns tempdir.resolve(FILENAME)
127+
128+
stubFor(put(TO_PROCESS_PATH_FILE).willReturn(noContent()))
129+
stubPropfindEmpty()
130+
131+
task.syncWebDav()
132+
133+
verify(
134+
putRequestedFor(urlEqualTo(TO_PROCESS_PATH_FILE))
135+
.withRequestBody(binaryEqualTo(FILENAME.toByteArray(StandardCharsets.UTF_8)))
136+
)
137+
138+
assertThat(Files.exists(toProcessPath1)).isFalse()
119139
}
120140

121141
@Test
@@ -139,7 +159,7 @@ internal class WebDavSyncTaskTest {
139159
)
140160
)
141161

142-
Assertions.assertThat(Files.exists(toProcessPath)).isTrue()
162+
assertThat(Files.exists(toProcessPath)).isTrue()
143163
}
144164

145165
@Test
@@ -159,7 +179,7 @@ internal class WebDavSyncTaskTest {
159179
verify(getRequestedFor(urlEqualTo(PROCESSED_PATH_FILE)))
160180
verify(deleteRequestedFor(urlEqualTo(PROCESSED_PATH_FILE)))
161181

162-
Assertions.assertThat(Files.exists(processedPath)).isTrue()
182+
assertThat(Files.exists(processedPath)).isTrue()
163183
}
164184

165185
private fun verifyPropfindRequest() {
@@ -245,7 +265,7 @@ internal class WebDavSyncTaskTest {
245265
verify(getRequestedFor(urlEqualTo(PROCESSED_PATH_FILE)))
246266
verify(0, deleteRequestedFor(urlEqualTo(PROCESSED_PATH_FILE)))
247267

248-
Assertions.assertThat(Files.exists(processedPath)).isFalse()
268+
assertThat(Files.exists(processedPath)).isFalse()
249269
}
250270

251271
private fun createWebDavSyncTask(wmRuntimeInfo: WireMockRuntimeInfo): WebDavSyncTask {

0 commit comments

Comments
 (0)