@@ -63,6 +63,7 @@ import com.intellij.ui.components.panels.OpaquePanel
6363import com.intellij.ui.dsl.builder.Align
6464import com.intellij.ui.layout.ComboBoxPredicate
6565import com.intellij.ui.dsl.builder.panel
66+ import com.intellij.ui.layout.selected
6667import com.intellij.util.IncorrectOperationException
6768import com.intellij.util.lang.JavaVersion
6869import com.intellij.util.ui.JBUI
@@ -152,7 +153,7 @@ import org.utbot.intellij.plugin.util.findSdkVersion
152153import java.io.File
153154import java.time.LocalDateTime
154155import java.time.format.DateTimeFormatter
155- import java.util.*
156+ import javax.swing.JTextField
156157import kotlin.io.path.notExists
157158
158159private const val RECENTS_KEY = " org.utbot.recents"
@@ -162,6 +163,7 @@ private const val SAME_PACKAGE_LABEL = "same as for sources"
162163private const val WILL_BE_INSTALLED_LABEL = " (will be installed)"
163164
164165private const val NO_SPRING_CONFIGURATION_OPTION = " No configuration"
166+ private const val DEFAULT_SPRING_PROFILE_NAME = " default"
165167
166168private const val ACTION_GENERATE = " Generate Tests"
167169private const val ACTION_GENERATE_AND_RUN = " Generate and Run"
@@ -192,10 +194,13 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
192194 private val javaConfigurationHelper = SpringConfigurationsHelper (" ." )
193195 private val xmlConfigurationHelper = SpringConfigurationsHelper (File .separator)
194196
195- private val springConfig = createComboBoxWithSeparatorsForSpringConfigs(shortenConfigurationNames())
196-
197197 private val mockStrategies = createComboBox(MockStrategyApi .values())
198198 private val staticsMocking = JCheckBox (" Mock static methods" )
199+
200+ private val springConfig = createComboBoxWithSeparatorsForSpringConfigs(shortenConfigurationNames())
201+ private val selectProfile = JCheckBox (" Select active profiles" )
202+ private val profileExpression = JTextField (DEFAULT_SPRING_PROFILE_NAME , 23 )
203+
199204 private val timeoutSpinner =
200205 JBIntSpinner (TimeUnit .MILLISECONDS .toSeconds(model.timeout).toInt(), 1 , Int .MAX_VALUE , 1 ).also {
201206 when (val editor = it.editor) {
@@ -388,17 +393,33 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
388393 row(" Spring configuration:" ) {
389394 cell(springConfig)
390395 contextHelp(
391- " 100% Symbolic execution mode.\n " +
396+ " 100% Symbolic execution mode.<br> " +
392397 " Classes defined in Spring configuration will be used instead " +
393- " of interfaces and abstract classes.\n " +
398+ " of interfaces and abstract classes.<br> " +
394399 " Mocks will be used when necessary."
395400 )
396401 }
402+ row {
403+ cell(selectProfile)
404+ contextHelp(
405+ " Only selected profile will be active.<br>" +
406+ " Otherwise, profile from the configuration class or default one is used."
407+ )
408+ }
409+ indent {
410+ row(" Profile name(s):" ) {
411+ cell(profileExpression).align(Align .FILL )
412+ contextHelp(
413+ " Profile name or expression like \" prod|web\" may be passed here.<br>" +
414+ " If expression is incorrect, default profile will be used"
415+ )
416+ }.enabledIf(selectProfile.selected)
417+ }
397418 }
398419 row(" Mocking strategy:" ) {
399420 cell(mockStrategies)
400421 contextHelp(
401- " Mock everything around the target class or the whole package except the system classes. " +
422+ " Mock everything around the target class or the whole package except the system classes.<br> " +
402423 " Otherwise, mock nothing. Mockito will be installed, if you don't have one."
403424 )
404425 }.enabledIf(ComboBoxPredicate (springConfig) {
@@ -638,6 +659,7 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
638659 TypeReplacementApproach .ReplaceIfPossible (fullConfigName)
639660 }
640661 }
662+ model.profileExpression = profileExpression.text
641663
642664 val settings = model.project.service<Settings >()
643665 with (settings) {
@@ -1034,16 +1056,26 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
10341056 mockStrategies.item = MockStrategyApi .springDefaultItem
10351057 mockStrategies.isEnabled = false
10361058 updateMockStrategyListForConfigGuidedTypeReplacements()
1059+
1060+ selectProfile.isEnabled = true
1061+ selectProfile.isSelected = false
10371062 } else {
10381063 mockStrategies.item = when (model.projectType) {
10391064 ProjectType .Spring -> MockStrategyApi .springDefaultItem
10401065 else -> MockStrategyApi .defaultItem
10411066 }
10421067 mockStrategies.isEnabled = true
10431068 updateMockStrategyList()
1069+
1070+ selectProfile.isEnabled = false
1071+ selectProfile.isSelected = false
10441072 }
10451073 }
10461074
1075+ selectProfile.addActionListener { _ ->
1076+ profileExpression.text = if (selectProfile.isSelected) " " else DEFAULT_SPRING_PROFILE_NAME
1077+ }
1078+
10471079 cbSpecifyTestPackage.addActionListener {
10481080 val testPackageName = findTestPackageComboValue()
10491081 val packageNameIsNeeded = testPackageField.isEnabled || testPackageName != SAME_PACKAGE_LABEL
@@ -1120,6 +1152,8 @@ class GenerateTestsDialogWindow(val model: GenerateTestsModel) : DialogWrapper(m
11201152 private fun updateSpringConfigurationEnabled () {
11211153 // We check for > 1 because there is already extra-dummy NO_SPRING_CONFIGURATION_OPTION option
11221154 springConfig.isEnabled = model.projectType == ProjectType .Spring && springConfig.itemCount > 1
1155+ selectProfile.isEnabled = false
1156+ selectProfile.isSelected = false
11231157 }
11241158
11251159 private fun staticsMockingConfigured (): Boolean {
0 commit comments