Skip to content

Conversation

@sofurihafe
Copy link
Member

@sofurihafe sofurihafe commented Jun 30, 2023

Description

This PR adds support for user-defined configurations and profiles in Spring integration tests

Also, this PR has fixes for inner class Spring configurations.

Fixes #2292, #2338

How to test

Manual tests

Checking annotations in integration tests:

  1. (optional) Open spring-boot-testing-main project.
  2. Choose OrderService.getOrders() method for test generation with selected 100% fuzzer option, selected OrderServiceApplication configuration and any profile and selected integration test generation option.
  3. Verify that class under test has two annotations: @activeprofiles(...) and @ContextConfiguration(...):
@ActiveProfiles(profiles = {"dev", "test"})
@ContextConfiguration(classes = {OrderServiceApplication.class})
@ExtendWith(SpringExtension.class)
@BootstrapWith(SpringBootTestContextBootstrapper.class)
@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD)
@Transactional
@AutoConfigureTestDatabase
public class OrderServiceTest {
    <...>
}

Checking inner class configuration:

  1. (optional) Open TwoAnimals project.
  2. Add inner class configuration, e.g.
class OuterClass {
    @Configuration
    static class InnerDolphinConfig {

        @Bean
        public Animal animal() {
            return new Dophin("Flipper");
        }
    }
}
  1. Open test generation window and select inner class configuration, unit test generation, run generation.
  2. See that the test is generated successfully with corresponding content derived from configuration.

@sofurihafe sofurihafe force-pushed the andrey-t/classnotfoundexc branch 3 times, most recently from cca0679 to c325091 Compare July 3, 2023 14:45
@sofurihafe sofurihafe marked this pull request as ready for review July 3, 2023 14:49
@sofurihafe sofurihafe requested a review from EgorkaKulikov July 3, 2023 14:50
@EgorkaKulikov EgorkaKulikov added comp-spring Issue is related to Spring projects support ctg-bug-fix PR is fixing a bug comp-instrumented-process Issue is related to Instrumented process labels Jul 4, 2023

}

enum class SpringConfigurationType(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of enum I suggest to introduce sealed interface SpringConfig with two implementations and use SpringConfig type to denote Spring configs instead of simply using String. We can choose appropriate implementation of SpringConfig in functions responsible for finding xml and Java configs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed in person, it was decided to leave as it is for now.

@sofurihafe sofurihafe force-pushed the andrey-t/classnotfoundexc branch from c325091 to 37d2982 Compare July 5, 2023 17:52
@sofurihafe sofurihafe changed the title Support inner class configurations in Spring Support user-defined configurations and profiles in Spring integration tests Jul 5, 2023
@sofurihafe sofurihafe marked this pull request as draft July 5, 2023 17:57
@IlyaMuravjov IlyaMuravjov changed the title Support user-defined configurations and profiles in Spring integration tests Support user-defined configurations and profiles in Spring integration test code generation Jul 6, 2023
@IlyaMuravjov IlyaMuravjov added comp-codegen Issue is related to code generator and removed comp-instrumented-process Issue is related to Instrumented process labels Jul 6, 2023
@sofurihafe sofurihafe force-pushed the andrey-t/classnotfoundexc branch from 37d2982 to ca044a3 Compare July 6, 2023 12:50
@sofurihafe sofurihafe force-pushed the andrey-t/classnotfoundexc branch from ca044a3 to b91f0d0 Compare July 6, 2023 12:57
@sofurihafe sofurihafe marked this pull request as ready for review July 6, 2023 13:50
Copy link
Collaborator

@IlyaMuravjov IlyaMuravjov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly LGTM

@IlyaMuravjov IlyaMuravjov merged commit e6abd33 into main Jul 6, 2023
@IlyaMuravjov IlyaMuravjov deleted the andrey-t/classnotfoundexc branch July 6, 2023 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-codegen Issue is related to code generator comp-spring Issue is related to Spring projects support ctg-bug-fix PR is fixing a bug

Projects

None yet

4 participants