Skip to content
This repository has been archived by the owner on May 25, 2022. It is now read-only.

Commit

Permalink
feat(scan): output the test nodes json, feature analyser can take it …
Browse files Browse the repository at this point in the history
…as the input (contract test)
  • Loading branch information
Andong Liao committed Apr 23, 2022
1 parent 46b214f commit 406c3e7
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 0 deletions.
1 change: 1 addition & 0 deletions analyser_sourcecode/lang_kotlin/.gitignore
@@ -0,0 +1 @@
structs_*.json
Expand Up @@ -4,10 +4,16 @@ import io.mockk.every
import io.mockk.just
import io.mockk.mockk
import io.mockk.runs
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import org.archguard.scanner.core.client.ArchGuardClient
import org.archguard.scanner.core.sourcecode.SourceCodeContext
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test
import java.io.File
import java.nio.file.Paths

internal class KotlinAnalyserTest {
private val mockClient = mockk<ArchGuardClient> {
Expand All @@ -26,4 +32,15 @@ internal class KotlinAnalyserTest {
assertThat(result).hasSize(2)
assertThat(result[0].FilePath.replace("\\", "/")).endsWith("resources/test/kotlin/Hello.kt")
}

// print these files and copy to analyser [feat_apicalls/backend] to finish the contract tests
@Nested
inner class PrintFilesForApiAnalyserContract {
@Test
fun identRestTemplateCall() {
every { mockContext.path } returns this.javaClass.classLoader.getResource("spring").path
val nodes = KotlinAnalyser(mockContext).analyse()
File("structs_kotlin.json").writeText(Json.encodeToString(nodes))
}
}
}
@@ -0,0 +1,16 @@
package kotlin

import com.thoughtworks.archguard.report.domain.qualitygate.CouplingQualityGate
import com.thoughtworks.archguard.report.domain.qualitygate.QualityGateClient
import org.springframework.beans.factory.annotation.Value
import org.springframework.stereotype.Component
import org.springframework.web.client.RestTemplate


@Component
class QualityGateClientImpl(@Value("\${client.host}") val baseUrl: String) : QualityGateClient {
override fun getQualityGate(qualityGateName: String): CouplingQualityGate {
val couplingQualityGate = RestTemplate().getForObject("$baseUrl/api/quality-gate-profile/$qualityGateName", CouplingQualityGate::class.java)
return couplingQualityGate ?: CouplingQualityGate(null, qualityGateName, emptyList(), null, null)
}
}
1 change: 1 addition & 0 deletions analyser_sourcecode/lang_typescript/.gitignore
@@ -0,0 +1 @@
structs_*.json
Expand Up @@ -4,10 +4,14 @@ import io.mockk.every
import io.mockk.just
import io.mockk.mockk
import io.mockk.runs
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import org.archguard.scanner.core.client.ArchGuardClient
import org.archguard.scanner.core.sourcecode.SourceCodeContext
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test
import java.io.File

internal class TypeScriptAnalyserTest {
private val mockClient = mockk<ArchGuardClient> {
Expand All @@ -25,4 +29,36 @@ internal class TypeScriptAnalyserTest {

assertThat(result).hasSize(16)
}

// print these files and copy to analyser [feat_apicalls/frontend] to finish the contract tests
@Nested
inner class PrintFilesForApiAnalyserContract {
@Test
fun shouldSupportIdentifyComponentApi() {
every { mockContext.path } returns this.javaClass.classLoader.getResource("ts/apicall").path
val nodes = TypeScriptAnalyser(mockContext).analyse()
File("structs_apicall.json").writeText(Json.encodeToString(nodes))
}

@Test
internal fun shouldCorrectComponentName() {
every { mockContext.path } returns this.javaClass.classLoader.getResource("ts/interface-error").path
val nodes = TypeScriptAnalyser(mockContext).analyse()
File("structs_interface-error.json").writeText(Json.encodeToString(nodes))
}

@Test
internal fun shouldSaveApiAdapter() {
every { mockContext.path } returns this.javaClass.classLoader.getResource("ts/api-adapter").path
val nodes = TypeScriptAnalyser(mockContext).analyse()
File("structs_api-adapter.json").writeText(Json.encodeToString(nodes))
}

@Test
internal fun testForUmi() {
every { mockContext.path } returns this.javaClass.classLoader.getResource("ts/js-umi-request").path
val nodes = TypeScriptAnalyser(mockContext).analyse()
File("structs_js-umi-request.json").writeText(Json.encodeToString(nodes))
}
}
}
Expand Up @@ -5,6 +5,9 @@ import org.archguard.scanner.core.client.dto.ContainerService

// client of the archguard, scanner can communicate to server via this client with limited functions
interface ArchGuardClient {
// File("structs.json").writeText(Json.encodeToString(dataStructs))
fun saveDataStructure(dataStructure: List<CodeDataStruct>)

// File("apis.json").writeText(Json.encodeToString(apiCalls))
fun saveApi(api: List<ContainerService>)
}

0 comments on commit 406c3e7

Please sign in to comment.