Skip to content

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

3 participants