Skip to content

Commit

Permalink
Automatically install spring-security-test when `spring-security-co…
Browse files Browse the repository at this point in the history
…re` is present (#2624)
  • Loading branch information
IlyaMuravjov authored Sep 29, 2023
1 parent d514a7b commit 7ce1752
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,21 @@ fun springBootTestLibraryDescriptor(versionInProject: Version?): ExternalLibrary
)
}

private const val MIN_SUPPORTED_SPRING_VERSION = "2.5"

fun springTestLibraryDescriptor(versionInProject: Version?): ExternalLibraryDescriptor {
val preferredVersion = if (versionInProject?.hasNumericOrEmptyPatch() == true) versionInProject?.plainText else "6.0.8"
val preferredVersion = if (versionInProject?.hasNumericOrEmptyPatch() == true) versionInProject.plainText else "6.0.8"
return ExternalLibraryDescriptor(
"org.springframework", "spring-test",
"2.5", null, preferredVersion
MIN_SUPPORTED_SPRING_VERSION, null, preferredVersion
)
}

fun springSecurityLibraryDescriptor(versionInProject: Version?): ExternalLibraryDescriptor {
val preferredVersion = if (versionInProject?.hasNumericOrEmptyPatch() == true) versionInProject.plainText else "6.0.8"
return ExternalLibraryDescriptor(
"org.springframework.security", "spring-security-test",
MIN_SUPPORTED_SPRING_VERSION, null, preferredVersion
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ import org.utbot.framework.codegen.domain.MockitoStaticMocking
import org.utbot.framework.codegen.domain.NoStaticMocking
import org.utbot.framework.codegen.domain.ParametrizedTestSource
import org.utbot.framework.codegen.domain.ProjectType
import org.utbot.framework.codegen.domain.SpringModule.SPRING_BEANS
import org.utbot.framework.codegen.domain.SpringModule.SPRING_BOOT
import org.utbot.framework.codegen.domain.SpringModule.*
import org.utbot.framework.codegen.domain.StaticsMocking
import org.utbot.framework.codegen.domain.TestFramework
import org.utbot.framework.codegen.domain.TestNg
Expand All @@ -112,6 +111,7 @@ import org.utbot.intellij.plugin.models.jUnit5ParametrizedTestsLibraryDescriptor
import org.utbot.intellij.plugin.models.mockitoCoreLibraryDescriptor
import org.utbot.intellij.plugin.models.packageName
import org.utbot.intellij.plugin.models.springBootTestLibraryDescriptor
import org.utbot.intellij.plugin.models.springSecurityLibraryDescriptor
import org.utbot.intellij.plugin.models.springTestLibraryDescriptor
import org.utbot.intellij.plugin.models.testNgNewLibraryDescriptor
import org.utbot.intellij.plugin.models.testNgOldLibraryDescriptor
Expand Down Expand Up @@ -1020,6 +1020,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
val libraryDescriptor = when (springModule) {
SPRING_BOOT -> springBootTestLibraryDescriptor(frameworkVersionInProject)
SPRING_BEANS -> springTestLibraryDescriptor(frameworkVersionInProject)
SPRING_SECURITY -> springSecurityLibraryDescriptor(frameworkVersionInProject)
}

model.preClasspathCollectionPromises += addDependency(model.testModule, libraryDescriptor)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ enum class SpringModule(
),
SPRING_BOOT(
testFrameworkDisplayName = "spring-boot-test",
),
SPRING_SECURITY(
testFrameworkDisplayName = "spring-security-test"
);

var isInstalled = false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package org.utbot.framework.plugin.api.utils

import org.utbot.framework.codegen.domain.SpringModule.SPRING_BEANS
import org.utbot.framework.codegen.domain.SpringModule.SPRING_BOOT
import org.utbot.framework.codegen.domain.SpringModule
import org.utbot.framework.codegen.domain.SpringModule.*

fun SpringModule.patterns(): Patterns {
val moduleLibraryPatterns = when (this) {
SPRING_BOOT -> springBootModulePatterns
SPRING_BEANS -> springBeansModulePatterns
SPRING_SECURITY -> springSecurityModulePatterns
}
val libraryPatterns = when (this) {
SPRING_BOOT -> springBootPatterns
SPRING_BEANS -> springBeansPatterns
SPRING_SECURITY -> springSecurityPatterns
}

return Patterns(moduleLibraryPatterns, libraryPatterns)
Expand All @@ -21,10 +22,12 @@ fun SpringModule.testPatterns(): Patterns {
val moduleLibraryPatterns = when (this) {
SPRING_BOOT -> springBootTestModulePatterns
SPRING_BEANS -> springBeansTestModulePatterns
SPRING_SECURITY -> springSecurityTestModulePatterns
}
val libraryPatterns = when (this) {
SPRING_BOOT -> springBootTestPatterns
SPRING_BEANS -> springBeansTestPatterns
SPRING_SECURITY -> springSecurityTestPatterns
}

return Patterns(moduleLibraryPatterns, libraryPatterns)
Expand Down Expand Up @@ -57,4 +60,18 @@ val SPRING_BOOT_TEST_MVN_PATTERN = Regex("org\\.springframework\\.boot:spring-bo
val springBootTestPatterns = listOf(SPRING_BOOT_TEST_JAR_PATTERN, SPRING_BOOT_TEST_MVN_PATTERN)

val SPRING_BOOT_TEST_BASIC_MODULE_PATTERN = Regex("spring-boot-test")
val springBootTestModulePatterns = listOf(SPRING_BOOT_TEST_BASIC_MODULE_PATTERN)
val springBootTestModulePatterns = listOf(SPRING_BOOT_TEST_BASIC_MODULE_PATTERN)

val SPRING_SECURITY_JAR_PATTERN = Regex("spring-security-core-([0-9]+)(\\.[0-9]+){1,2}")
val SPRING_SECURITY_MVN_PATTERN = Regex("org\\.springframework\\.security:spring-security-core:([0-9]+)(\\.[0-9]+){1,2}")
val springSecurityPatterns = listOf(SPRING_SECURITY_JAR_PATTERN, SPRING_SECURITY_MVN_PATTERN)

val SPRING_SECURITY_BASIC_MODULE_PATTERN = Regex("spring-security-core")
val springSecurityModulePatterns = listOf(SPRING_SECURITY_BASIC_MODULE_PATTERN)

val SPRING_SECURITY_TEST_JAR_PATTERN = Regex("spring-security-test-([0-9]+)(\\.[0-9]+){1,2}")
val SPRING_SECURITY_TEST_MVN_PATTERN = Regex("org\\.springframework\\.security:spring-security-test:([0-9]+)(\\.[0-9]+){1,2}")
val springSecurityTestPatterns = listOf(SPRING_SECURITY_TEST_JAR_PATTERN, SPRING_SECURITY_TEST_MVN_PATTERN)

val SPRING_SECURITY_TEST_BASIC_MODULE_PATTERN = Regex("spring-security-test")
val springSecurityTestModulePatterns = listOf(SPRING_SECURITY_TEST_BASIC_MODULE_PATTERN)

0 comments on commit 7ce1752

Please sign in to comment.