Skip to content

Commit d468e4d

Browse files
committed
TS-38628 API changing settings, artifactory dump, cucumber maven
1 parent 938c861 commit d468e4d

13 files changed

Lines changed: 256 additions & 244 deletions

File tree

system-tests/api-changing-settings-should-dump/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
plugins {
2+
com.teamscale.`kotlin-convention`
23
com.teamscale.`system-test-convention`
34
}
45

system-tests/api-changing-settings-should-dump/src/main/java/systemundertest/SystemUnderTest.java

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package systemundertest
2+
3+
/** Fake system under test to generate some coverage. */
4+
class SystemUnderTest {
5+
fun foo() = 12
6+
7+
fun bar() = 13
8+
}

system-tests/api-changing-settings-should-dump/src/test/java/com/teamscale/tia/client/ApiChangingSettingsShouldDumpSystemTest.java

Lines changed: 0 additions & 40 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.teamscale.tia.client
2+
3+
import com.teamscale.client.EReportFormat
4+
import com.teamscale.test.commons.SystemTestUtils
5+
import com.teamscale.test.commons.SystemTestUtils.changePartition
6+
import com.teamscale.test.commons.TeamscaleMockServer
7+
import org.assertj.core.api.Assertions
8+
import org.assertj.core.api.Assertions.assertThat
9+
import org.junit.jupiter.api.Test
10+
import systemundertest.SystemUnderTest
11+
12+
/**
13+
* Runs the system under test and then changes the partition of the agent. This should cause a dump to our
14+
* [TeamscaleMockServer].
15+
*/
16+
class ApiChangingSettingsShouldDumpSystemTest {
17+
@Test
18+
@Throws(Exception::class)
19+
fun systemTest() {
20+
System.setProperty("org.eclipse.jetty.util.log.class", "org.eclipse.jetty.util.log.StdErrLog")
21+
System.setProperty("org.eclipse.jetty.LEVEL", "OFF")
22+
23+
val teamscaleMockServer = TeamscaleMockServer(SystemTestUtils.TEAMSCALE_PORT).acceptingReportUploads()
24+
25+
SystemUnderTest().foo()
26+
changePartition(SystemTestUtils.AGENT_PORT, "some_other_value")
27+
28+
val session = teamscaleMockServer.onlySession
29+
assertThat(session.partition).isEqualTo("partition_before_change")
30+
assertThat(session.getOnlyReport(EReportFormat.JACOCO)).contains(
31+
"<line nr=\"$METHOD_FOO_COVERABLE_LINE\" mi=\"0\""
32+
)
33+
}
34+
35+
companion object {
36+
private const val METHOD_FOO_COVERABLE_LINE = 4
37+
}
38+
}

system-tests/artifactory-git-properties-detection/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
plugins {
2+
com.teamscale.`kotlin-convention`
23
com.teamscale.`system-test-convention`
34
}
45

system-tests/artifactory-git-properties-detection/src/test/java/com/teamscale/client/ArtifactoryGitPropertiesDetectionTest.java

Lines changed: 0 additions & 39 deletions
This file was deleted.

system-tests/artifactory-git-properties-detection/src/test/java/com/teamscale/client/ArtifactoryMockServer.java

Lines changed: 0 additions & 74 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.teamscale.client
2+
3+
import com.teamscale.test.commons.SystemTestUtils
4+
import com.teamscale.test.commons.SystemTestUtils.dumpCoverage
5+
import org.assertj.core.api.Assertions
6+
import org.assertj.core.api.Assertions.assertThat
7+
import org.conqat.lib.commons.collections.Pair
8+
import org.junit.jupiter.api.AfterEach
9+
import org.junit.jupiter.api.BeforeEach
10+
import org.junit.jupiter.api.Test
11+
import systemundertest.SystemUnderTest
12+
13+
class ArtifactoryGitPropertiesDetectionTest {
14+
private lateinit var artifactoryMockServer: ArtifactoryMockServer
15+
16+
@BeforeEach
17+
fun startFakeTeamscaleServer() {
18+
artifactoryMockServer = ArtifactoryMockServer(FAKE_ARTIFACTORY_PORT)
19+
}
20+
21+
@AfterEach
22+
fun shutdownFakeTeamscaleServer() {
23+
artifactoryMockServer.shutdown()
24+
}
25+
26+
@Test
27+
@Throws(Exception::class)
28+
fun systemTest() {
29+
SystemUnderTest.foo()
30+
31+
dumpCoverage(SystemTestUtils.AGENT_PORT)
32+
33+
assertThat(artifactoryMockServer.uploadedReports).hasSize(1)
34+
val reports = artifactoryMockServer.uploadedReports
35+
assertThat(reports).hasSize(1)
36+
// Ensure infos from src/main/resources/git.properties are picked up
37+
assertThat(reports.getFirst(0))
38+
.startsWith("uploads/master/1645713803000-86f9d655bf8a204d98bc3542e0d15cea38cc7c74/")
39+
}
40+
41+
companion object {
42+
private val FAKE_ARTIFACTORY_PORT = Integer.getInteger("artifactoryPort")
43+
}
44+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package com.teamscale.client
2+
3+
import org.conqat.lib.commons.collections.PairList
4+
import spark.*
5+
import java.io.ByteArrayInputStream
6+
import java.io.ByteArrayOutputStream
7+
import java.io.IOException
8+
import java.io.InputStream
9+
import java.util.function.BiConsumer
10+
import java.util.zip.ZipEntry
11+
import java.util.zip.ZipInputStream
12+
import javax.servlet.http.HttpServletResponse
13+
14+
/**
15+
* Mocks a Artifactory server: stores all uploaded reports so tests can run assertions on them.
16+
*/
17+
class ArtifactoryMockServer(port: Int) {
18+
/** All reports uploaded to this Teamscale instance. */
19+
val uploadedReports = PairList<String, String>()
20+
private val service = Service.ignite()
21+
22+
init {
23+
service.port(port)
24+
service.put(":path", ::handleReport)
25+
service.exception<Exception>(Exception::class.java) { exception, _, response ->
26+
response.status(HttpServletResponse.SC_INTERNAL_SERVER_ERROR)
27+
response.body("Exception: ${exception.message}")
28+
}
29+
service.notFound { request, response ->
30+
response.status(HttpServletResponse.SC_INTERNAL_SERVER_ERROR)
31+
"Unexpected request: ${request.requestMethod()} ${request.uri()}"
32+
}
33+
service.awaitInitialization()
34+
}
35+
36+
@Throws(IOException::class)
37+
private fun handleReport(request: Request, response: Response): String {
38+
processZipEntries(ByteArrayInputStream(request.bodyAsBytes())) { entry, content ->
39+
if (!entry.isDirectory) {
40+
uploadedReports.add("${request.params("path")} -> ${entry.getName()}", content.toString())
41+
}
42+
}
43+
return "success"
44+
}
45+
46+
/**
47+
* Shuts down the mock server and waits for it to be stopped.
48+
*/
49+
fun shutdown() {
50+
service.stop()
51+
service.awaitStop()
52+
}
53+
54+
companion object {
55+
@Throws(IOException::class)
56+
private fun processZipEntries(
57+
zipStream: InputStream,
58+
entryConsumer: (ZipEntry, ByteArrayOutputStream) -> Unit
59+
) {
60+
val bufferSize = 1024
61+
ZipInputStream(zipStream).use { zipInput ->
62+
while (true) {
63+
val zipEntry = zipInput.nextEntry ?: break
64+
val entryContent = ByteArrayOutputStream()
65+
val buffer = ByteArray(bufferSize)
66+
var bytesRead: Int
67+
while (zipInput.read(buffer).also { bytesRead = it } != -1) {
68+
entryContent.write(buffer, 0, bytesRead)
69+
}
70+
entryConsumer(zipEntry, entryContent)
71+
}
72+
}
73+
}
74+
}
75+
}

0 commit comments

Comments
 (0)