Compare commits
2 commits
2a05564ec3
...
5ac8f910b5
Author | SHA1 | Date | |
---|---|---|---|
5ac8f910b5 | |||
37517a2845 |
9 changed files with 34 additions and 44 deletions
4
.github/workflows/bld.yml
vendored
4
.github/workflows/bld.yml
vendored
|
@ -13,8 +13,8 @@ jobs:
|
|||
|
||||
strategy:
|
||||
matrix:
|
||||
java-version: [17, 21, 22]
|
||||
kotlin-version: [1.9.24, 2.0.20]
|
||||
java-version: [17, 21, 23]
|
||||
kotlin-version: [1.9.24, 2.1.0]
|
||||
|
||||
steps:
|
||||
- name: Checkout source repository
|
||||
|
|
4
.idea/kotlinc.xml
generated
4
.idea/kotlinc.xml
generated
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="KotlinJpsPluginSettings">
|
||||
<option name="version" value="1.9.10" />
|
||||
<option name="version" value="2.1.0" />
|
||||
</component>
|
||||
</project>
|
||||
</project>
|
||||
|
|
9
.idea/runConfigurations/Run Tests.xml
generated
9
.idea/runConfigurations/Run Tests.xml
generated
|
@ -1,9 +0,0 @@
|
|||
<component name="ProjectRunConfigurationManager">
|
||||
<configuration default="false" name="Run Tests" type="Application" factoryName="Application" nameIsGenerated="true">
|
||||
<option name="MAIN_CLASS_NAME" value="net.thauvin.erik.JokeapiTest" />
|
||||
<module name="app" />
|
||||
<method v="2">
|
||||
<option name="Make" enabled="true" />
|
||||
</method>
|
||||
</configuration>
|
||||
</component>
|
|
@ -1,5 +1,5 @@
|
|||
[](https://opensource.org/licenses/BSD-3-Clause)
|
||||
[](https://kotlinlang.org/)
|
||||
[](https://kotlinlang.org/)
|
||||
[](https://rife2.com/bld)
|
||||
[](https://github.com/ethauvin/jokeapi/releases/latest)
|
||||
[](https://central.sonatype.com/artifact/net.thauvin.erik/jokeapi)
|
||||
|
|
|
@ -2,9 +2,9 @@ bld.downloadExtensionJavadoc=false
|
|||
bld.downloadExtensionSources=true
|
||||
bld.downloadLocation=
|
||||
bld.extension-detekt=com.uwyn.rife2:bld-detekt:0.9.7
|
||||
bld.extension-dokka=com.uwyn.rife2:bld-dokka:1.0.1
|
||||
bld.extension-dokka=com.uwyn.rife2:bld-dokka:1.0.2
|
||||
bld.extension-jacoco=com.uwyn.rife2:bld-jacoco-report:0.9.8
|
||||
bld.extension-kotlin=com.uwyn.rife2:bld-kotlin:1.0.2
|
||||
bld.extension-kotlin=com.uwyn.rife2:bld-kotlin:1.0.3
|
||||
bld.repositories=MAVEN_LOCAL,MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
|
||||
bld.sourceDirectories=
|
||||
bld.version=2.1.0
|
||||
|
|
4
pom.xml
4
pom.xml
|
@ -18,7 +18,7 @@
|
|||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib</artifactId>
|
||||
<version>2.0.0</version>
|
||||
<version>2.1.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
@ -30,7 +30,7 @@
|
|||
<dependency>
|
||||
<groupId>net.thauvin.erik.urlencoder</groupId>
|
||||
<artifactId>urlencoder-lib-jvm</artifactId>
|
||||
<version>1.5.0</version>
|
||||
<version>1.6.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
|
|
@ -67,15 +67,15 @@ public class JokeApiBuild extends Project {
|
|||
autoDownloadPurge = true;
|
||||
repositories = List.of(MAVEN_LOCAL, MAVEN_CENTRAL);
|
||||
|
||||
final var kotlin = version(2, 0, 20);
|
||||
final var kotlin = version(2, 1, 0);
|
||||
scope(compile)
|
||||
.include(dependency("org.jetbrains.kotlin", "kotlin-stdlib", kotlin))
|
||||
.include(dependency("org.json", "json", "20240303"))
|
||||
.include(dependency("net.thauvin.erik.urlencoder", "urlencoder-lib-jvm", version(1, 5, 0)));
|
||||
.include(dependency("net.thauvin.erik.urlencoder", "urlencoder-lib-jvm", version(1, 6, 0)));
|
||||
scope(test)
|
||||
.include(dependency("org.jetbrains.kotlin", "kotlin-test-junit5", kotlin))
|
||||
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 11, 0)))
|
||||
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 11, 0)))
|
||||
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 11, 4)))
|
||||
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 11, 4)))
|
||||
.include(dependency("com.willowtreeapps.assertk", "assertk-jvm", version(0, 28, 1)));
|
||||
|
||||
publishOperation()
|
||||
|
|
|
@ -59,15 +59,15 @@ internal fun fetchUrl(url: String, auth: String = ""): String {
|
|||
connection.setRequestProperty("Authentication", auth)
|
||||
}
|
||||
|
||||
if (connection.responseCode in 200..399) {
|
||||
val body = connection.inputStream.bufferedReader().use { it.readText() }
|
||||
if (JokeApi.logger.isLoggable(Level.FINE)) {
|
||||
JokeApi.logger.fine(body)
|
||||
}
|
||||
return body
|
||||
} else {
|
||||
val stream = if (connection.responseCode in 200..399) connection.inputStream else connection.errorStream
|
||||
val body = stream.bufferedReader().use { it.readText() }
|
||||
if (body.isBlank()) {
|
||||
throw httpError(connection.responseCode)
|
||||
}
|
||||
if (JokeApi.logger.isLoggable(Level.FINE)) {
|
||||
JokeApi.logger.fine(body)
|
||||
}
|
||||
return body
|
||||
} finally {
|
||||
connection.disconnect()
|
||||
}
|
||||
|
|
|
@ -41,8 +41,6 @@ import net.thauvin.erik.jokeapi.models.Category
|
|||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.assertThrows
|
||||
import org.junit.jupiter.api.extension.ExtendWith
|
||||
import org.junit.jupiter.params.ParameterizedTest
|
||||
import org.junit.jupiter.params.provider.ValueSource
|
||||
|
||||
@ExtendWith(BeforeAllTests::class)
|
||||
internal class ExceptionsTest {
|
||||
|
@ -63,19 +61,20 @@ internal class ExceptionsTest {
|
|||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(ints = [400, 404, 403, 413, 414, 429, 500, 523, 666])
|
||||
fun `Validate HTTP Exceptions`(code: Int) {
|
||||
val e = assertThrows<HttpErrorException> {
|
||||
fetchUrl("https://httpstat.us/$code")
|
||||
}
|
||||
assertThat(e, "fetchUrl($code)").all {
|
||||
prop(HttpErrorException::statusCode).isEqualTo(code)
|
||||
prop(HttpErrorException::message).isNotNull().isNotEmpty()
|
||||
if (code < 600)
|
||||
prop(HttpErrorException::cause).isNotNull().assertThat(Throwable::message).isNotNull()
|
||||
else
|
||||
prop(HttpErrorException::cause).isNull()
|
||||
@Test
|
||||
fun `Validate HTTP Exceptions`() {
|
||||
val locs = ArrayList<Pair<String, Int>>()
|
||||
locs.add(Pair("https://apichallenges.herokuapp.com/secret/note", 401))
|
||||
locs.add(Pair("https://apichallenges.herokuapp.com/todo", 404))
|
||||
|
||||
for ((url, code) in locs) {
|
||||
val e = assertThrows<HttpErrorException> {
|
||||
fetchUrl(url)
|
||||
}
|
||||
assertThat(e, "fetchUrl($code)").all {
|
||||
prop(HttpErrorException::statusCode).isEqualTo(code)
|
||||
prop(HttpErrorException::message).isNotNull().isNotEmpty()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue