Skip to content

Commit

Permalink
chore: linter fix
Browse files Browse the repository at this point in the history
  • Loading branch information
MikAoJk committed Oct 7, 2024
1 parent 5450844 commit 8630f8f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 89 deletions.
4 changes: 1 addition & 3 deletions src/test/kotlin/no/nav/pdfgen/ApplicationTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import io.ktor.http.*
import io.ktor.server.routing.*
import io.ktor.server.testing.*
import no.nav.pdfgen.application.api.nais.registerNaisApi
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test

internal class ApplicationTest {

Expand All @@ -26,7 +26,6 @@ internal class ApplicationTest {

assertEquals(HttpStatusCode.OK, response.status)
assertEquals("I'm alive", response.bodyAsText())

}
}

Expand Down Expand Up @@ -82,6 +81,5 @@ internal class ApplicationTest {
assertEquals(HttpStatusCode.InternalServerError, response.status)
assertEquals("Please wait! I'm not ready :(", response.bodyAsText())
}

}
}
134 changes: 48 additions & 86 deletions src/test/kotlin/no/nav/pdfgen/PdfGenITest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,8 @@ internal class PdfGenITest {
@Test
internal fun post_to_api_v1_genpdf_applicationName_templateName() {
testApplication {
environment {
connector {
port = randomApplicationPort
}
}
application {
module()
}
environment { connector { port = randomApplicationPort } }
application { module() }
// api path /api/v1/genpdf/{applicationName}/{templateName}
templates
.map { it.key }
Expand All @@ -48,19 +42,18 @@ internal class PdfGenITest {
?.toString(Charsets.UTF_8)
?: "{}"

val response =
runBlocking {
client.post(
"http://0.0.0.0:$randomApplicationPort/api/v1/genpdf/$applicationName/$templateName",
) {
setBody(
TextContent(
json,
contentType = ContentType.Application.Json,
),
)
}
val response = runBlocking {
client.post(
"http://0.0.0.0:$randomApplicationPort/api/v1/genpdf/$applicationName/$templateName",
) {
setBody(
TextContent(
json,
contentType = ContentType.Application.Json,
),
)
}
}
assertEquals(true, response.status.isSuccess())
val bytes = runBlocking { response.readBytes() }
assertNotEquals(null, bytes)
Expand All @@ -71,22 +64,14 @@ internal class PdfGenITest {
println(document.documentInformation.title)
document.close()
}

}

}

@Test
internal fun `Generate sample PDFs using test data`() {
testApplication {
environment {
connector {
port = randomApplicationPort
}
}
application {
module()
}
environment { connector { port = randomApplicationPort } }
application { module() }
templates
.map { it.key }
.forEach {
Expand Down Expand Up @@ -123,16 +108,12 @@ internal class PdfGenITest {
@Test
internal fun `Using the HTML convert endpoint should render a document using default HTML`() {
testApplication {
environment {
connector {
port = randomApplicationPort
}
}
application {
module()
}
environment { connector { port = randomApplicationPort } }
application { module() }
val response = runBlocking {
client.post("http://0.0.0.0:$randomApplicationPort/api/v1/genpdf/html/integration-test") {
client.post(
"http://0.0.0.0:$randomApplicationPort/api/v1/genpdf/html/integration-test"
) {
setBody(testTemplateIncludedFonts)
}
}
Expand Down Expand Up @@ -184,28 +165,22 @@ internal class PdfGenITest {
@Test
internal fun `Using the image convert endpoint Should render a document using input image`() {
testApplication {
environment {
connector {
port = randomApplicationPort
}
}
application {
module()
}
environment { connector { port = randomApplicationPort } }
application { module() }
mapOf(
ByteArrayContent(testJpg, ContentType.Image.JPEG) to "jpg.pdf",
ByteArrayContent(testPng, ContentType.Image.PNG) to "png.pdf",
)
ByteArrayContent(testJpg, ContentType.Image.JPEG) to "jpg.pdf",
ByteArrayContent(testPng, ContentType.Image.PNG) to "png.pdf",
)
.forEach { (payload, outputFile) ->
println("Should render a document using input image, $outputFile")
runBlocking {
runBlocking {
client.preparePost(
"http://0.0.0.0:$randomApplicationPort/api/v1/genpdf/image/integration-test",
) {
setBody(payload)
client.preparePost(
"http://0.0.0.0:$randomApplicationPort/api/v1/genpdf/image/integration-test",
) {
setBody(payload)
}
}
}
.execute { response ->
assertEquals(true, response.status.isSuccess())
val bytes = response.readBytes()
Expand All @@ -225,20 +200,14 @@ internal class PdfGenITest {
@Test
internal fun `Calls to unknown endpoints should respond with helpful information`() {
testApplication {
environment {
connector {
port = randomApplicationPort
}
}
application {
module()
}
environment { connector { port = randomApplicationPort } }
application { module() }
runBlocking {
runBlocking {
client
.config { expectSuccess = false }
.preparePost("http://0.0.0.0:$randomApplicationPort/whodis")
}
client
.config { expectSuccess = false }
.preparePost("http://0.0.0.0:$randomApplicationPort/whodis")
}
.execute { response ->
assertEquals(404, response.status.value)
val text = runBlocking { response.bodyAsText() }
Expand All @@ -251,14 +220,8 @@ internal class PdfGenITest {
@Test
internal fun `Simple performance test full multiple-threads`() {
testApplication {
environment {
connector {
port = randomApplicationPort
}
}
application {
module()
}
environment { connector { port = randomApplicationPort } }
application { module() }
val passes = 20

val context = Executors.newFixedThreadPool(8).asCoroutineDispatcher()
Expand Down Expand Up @@ -290,7 +253,8 @@ internal class PdfGenITest {
setBody(
TextContent(
json,
contentType = ContentType.Application.Json,
contentType =
ContentType.Application.Json,
),
)
}
Expand All @@ -312,26 +276,24 @@ internal class PdfGenITest {
@Test
internal fun `Simple performance test full single-thread`() {
testApplication {
environment {
connector {
port = randomApplicationPort
}
}
application {
module()
}
environment { connector { port = randomApplicationPort } }
application { module() }
val passes = 40

templates
.map { it.key }
.forEach { (applicationName, templateName) ->
println("$templateName for $applicationName performs fine with single-thread load")
println(
"$templateName for $applicationName performs fine with single-thread load"
)
val startTime = System.currentTimeMillis()
runBlocking {
for (i in 1..passes) {
val json =
javaClass
.getResourceAsStream("/data/$applicationName/$templateName.json")
.getResourceAsStream(
"/data/$applicationName/$templateName.json"
)
?.use { IOUtils.toByteArray(it).toString(Charsets.UTF_8) }
?: "{}"

Expand Down

0 comments on commit 8630f8f

Please sign in to comment.