Skip to content

Automatically install spring-security-test when spring-security-core is present #2624

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)