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

Conversation

IlyaMuravjov
Copy link
Collaborator

Description

Fixes #2591

How to test

Manual tests

Generate integration tests for UserController.getContacts() from Medical-Web-App/develop-new project with MedicalWebApp configuration after removing spring-security-test dependency (comment out code fragment shown below) and removing preexisting tests that rely on it (i.e. UserControllerTest).

<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-test</artifactId>
    <scope>test</scope>
</dependency>

spring-security-test should get reinstalled, test class should be annotated with @WithMockUser and there should be successful tests with HTTP status code 200 like the one below.

@Test
@DisplayName("getContacts: currentUserUsername = 'h0'")
public void testGetContactsWithNonEmptyString() throws Exception {
    UriComponentsBuilder uriComponentsBuilder = fromPath("/api/search/contacts");
    Object[] values = {"h0"};
    UriComponentsBuilder uriComponentsBuilder1 = uriComponentsBuilder.queryParam("currentUserUsername", values);
    String urlTemplate = uriComponentsBuilder1.toUriString();
    Object[] uriVars = {};
    MockHttpServletRequestBuilder mockHttpServletRequestBuilder = get(urlTemplate, uriVars);

    ResultActions actual = mockMvc.perform(mockHttpServletRequestBuilder);

    actual.andDo(print());
    actual.andExpect((status()).is(200));
    actual.andExpect((content()).string("{\"contactWithLastMsg\":[]}"));
}

NOTE: to generate integration tests for Medical-Web-App project you need to setup your environment as described in the Local Development section of the README.

Self-check list

  • I've set the proper labels for my PR (at least, for category and component).
  • PR title and description are clear and intelligible.
  • I've added enough comments to my code, particularly in hard-to-understand areas.
  • The functionality I've repaired, changed or added is covered with automated tests.
  • Manual tests have been provided optionally.
  • The documentation for the functionality I've been working on is up-to-date.

@IlyaMuravjov IlyaMuravjov added ctg-enhancement New feature, improvement or change request comp-ui Improvements of plugin UI appearence and functionality comp-spring Issue is related to Spring projects support labels Sep 29, 2023
@Vassiliy-Kudryashov Vassiliy-Kudryashov merged commit 7ce1752 into main Sep 29, 2023
@Vassiliy-Kudryashov Vassiliy-Kudryashov deleted the ilya_m/spring-security-test branch September 29, 2023 18:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp-spring Issue is related to Spring projects support comp-ui Improvements of plugin UI appearence and functionality ctg-enhancement New feature, improvement or change request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Install spring-security-test if spring-security is present
2 participants