Skip to content

Commit

Permalink
don't delete all Users in AccountResourceIT
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed May 23, 2024
1 parent 9372b6d commit 625ba10
Showing 1 changed file with 61 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,14 @@
See the License for the specific language governing permissions and
limitations under the License.
-%>
<%_
const callBlock = reactive ? '.block()' : '';
const callBlockOptional = reactive ? '.blockOptional()' : '';
_%>
package <%= packageName %>.web.rest;
import static org.assertj.core.api.Assertions.assertThat;
import <%= packageName %>.IntegrationTest;
import <%= packageName %>.config.Constants;
<%_ if (authenticationTypeSession && !reactive) { _%>
Expand All @@ -44,9 +50,8 @@ import <%= packageName %>.web.rest.vm.ManagedUserVM;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang3.RandomStringUtils;
<%_ if (reactive && authenticationUsesCsrf || databaseTypeMongodb || databaseTypeNeo4j) { _%>
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
<%_ } _%>
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
Expand Down Expand Up @@ -137,27 +142,33 @@ class AccountResourceIT {
@Autowired
private PasswordEncoder passwordEncoder;
private Long numberOfUsers;
@Autowired
<%_ if (reactive) { _%>
private WebTestClient accountWebTestClient;
<%_ } else { _%>
private MockMvc restAccountMockMvc;
<%_ } _%>
<%_ if (databaseTypeMongodb || databaseTypeNeo4j) { _%>
@BeforeEach
public void setup() {
userRepository.deleteAll()<% if (reactive) { %>.block()<% } %>;
public void countUsers() {
numberOfUsers = userRepository.count()<%- callBlock %>;
}
<%_ } _%>
<%_ if (reactive && authenticationUsesCsrf) { _%>
@BeforeEach
public void setupCsrf() {
accountWebTestClient = accountWebTestClient.mutateWith(csrf());
}
<%_ } _%>
@AfterEach
public void checkUsersCount() {
assertThat(numberOfUsers).isEqualTo(userRepository.count()<%- callBlock %>);
numberOfUsers = null;
}
@Test
@WithUnauthenticatedMockUser
<%_ if (reactive) { _%>
Expand Down Expand Up @@ -246,6 +257,8 @@ class AccountResourceIT {
.andExpect(jsonPath("$.authorities").value(AuthoritiesConstants.ADMIN));

<%_ } _%>

userService.deleteUser(TEST_USER_LOGIN)<%- callBlock %>;
}

@Test
Expand Down Expand Up @@ -301,6 +314,8 @@ class AccountResourceIT {
<%_ } _%>

assertThat(userRepository.findOneByLogin("test-register-valid")<% if (reactive) { %>.blockOptional()<% } %>).isPresent();

userService.deleteUser("test-register-valid")<%- callBlock %>;
}

@Test
Expand Down Expand Up @@ -484,6 +499,8 @@ class AccountResourceIT {
.with(csrf())<% } %>)
.andExpect(status().is4xxClientError());
<%_ } _%>

userService.deleteUser("alice")<%- callBlock %>;
}

@Test
Expand Down Expand Up @@ -610,6 +627,8 @@ class AccountResourceIT {
.with(csrf())<% } %>)
.andExpect(status().is4xxClientError());
<%_ } _%>

userService.deleteUser("test-register-duplicate-email")<%- callBlock %>;
}

@Test
Expand Down Expand Up @@ -649,6 +668,8 @@ class AccountResourceIT {
assertThat(userDup).isPresent();
assertThat(userDup.orElseThrow().getAuthorities()).hasSize(1)
.containsExactly(<% if (databaseTypeSql || databaseTypeMongodb || databaseTypeNeo4j) { %>authorityRepository.findById(AuthoritiesConstants.USER).<% if (reactive) { %>block<% } else { %>orElseThrow<% } %>()<% } %><% if (databaseTypeCassandra || databaseTypeCouchbase) { %>AuthoritiesConstants.USER<% } %>);

userService.deleteUser("badguy")<%- callBlock %>;
}

@Test
Expand Down Expand Up @@ -683,6 +704,8 @@ class AccountResourceIT {

user = userRepository.findOneByLogin(user.getLogin())<%_ if (reactive) { _%>.block()<% } else { %>.orElse(null)<% } %>;
assertThat(user.isActivated()).isTrue();

userService.deleteUser("activate-account")<%- callBlock %>;
}

@Test
Expand Down Expand Up @@ -757,6 +780,8 @@ class AccountResourceIT {
<%_ } _%>
assertThat(updatedUser.isActivated()).isTrue();
assertThat(updatedUser.getAuthorities()).isEmpty();

userService.deleteUser("save-account")<%- callBlock %>;
}

@Test
Expand Down Expand Up @@ -810,6 +835,8 @@ class AccountResourceIT {
<%_ } _%>

assertThat(userRepository.findOneByEmailIgnoreCase("invalid email")<% if (reactive) { %>.blockOptional()<% } %>).isNotPresent();

userService.deleteUser("save-invalid-email")<%- callBlock %>;
}

@Test
Expand Down Expand Up @@ -874,6 +901,8 @@ class AccountResourceIT {

<%= user.persistClass %> updatedUser = userRepository.findOneByLogin("save-existing-email")<%_ if (reactive) { _%>.block()<% } else { %>.orElse(null)<% } %>;
assertThat(updatedUser.getEmail()).isEqualTo("save-existing-email@example.com");

userService.deleteUser("save-existing-email")<%- callBlock %>;
}

@Test
Expand Down Expand Up @@ -924,6 +953,8 @@ class AccountResourceIT {

<%= user.persistClass %> updatedUser = userRepository.findOneByLogin("save-existing-email-and-login")<%_ if (reactive) { _%>.block()<% } else { %>.orElse(null)<% } %>;
assertThat(updatedUser.getEmail()).isEqualTo("save-existing-email-and-login@example.com");

userService.deleteUser("save-existing-email-and-login")<%- callBlock %>;
}

@Test
Expand Down Expand Up @@ -963,6 +994,8 @@ class AccountResourceIT {
<%= user.persistClass %> updatedUser = userRepository.findOneByLogin("change-password-wrong-existing-password")<%_ if (!reactive) { _%>.orElse(null)<% } else { %>.block()<% } %>;
assertThat(passwordEncoder.matches("new password", updatedUser.getPassword())).isFalse();
assertThat(passwordEncoder.matches(currentPassword, updatedUser.getPassword())).isTrue();

userService.deleteUser("change-password-wrong-existing-password")<%- callBlock %>;
}

@Test
Expand Down Expand Up @@ -1001,6 +1034,8 @@ class AccountResourceIT {

<%= user.persistClass %> updatedUser = userRepository.findOneByLogin("change-password")<%_ if (reactive) { _%>.block()<% } else { %>.orElse(null)<% } %>;
assertThat(passwordEncoder.matches("new password", updatedUser.getPassword())).isTrue();

userService.deleteUser("change-password")<%- callBlock %>;
}

@Test
Expand Down Expand Up @@ -1041,6 +1076,8 @@ class AccountResourceIT {

<%= user.persistClass %> updatedUser = userRepository.findOneByLogin("change-password-too-small")<%_ if (reactive) { _%>.block()<% } else { %>.orElse(null)<% } %>;
assertThat(updatedUser.getPassword()).isEqualTo(user.getPassword());

userService.deleteUser("change-password-too-small")<%- callBlock %>;
}

@Test
Expand Down Expand Up @@ -1081,6 +1118,8 @@ class AccountResourceIT {

<%= user.persistClass %> updatedUser = userRepository.findOneByLogin("change-password-too-long")<%_ if (!reactive) { _%>.orElse(null)<% } else { %>.block()<% } %>;
assertThat(updatedUser.getPassword()).isEqualTo(user.getPassword());

userService.deleteUser("change-password-too-long")<%- callBlock %>;
}

@Test
Expand Down Expand Up @@ -1119,6 +1158,8 @@ class AccountResourceIT {

<%= user.persistClass %> updatedUser = userRepository.findOneByLogin("change-password-empty")<%_ if (reactive) { _%>.block()<% } else { %>.orElse(null)<% } %>;
assertThat(updatedUser.getPassword()).isEqualTo(user.getPassword());

userService.deleteUser("change-password-empty")<%- callBlock %>;
}
<%_ if (authenticationTypeSession && !reactive) { _%>

Expand Down Expand Up @@ -1165,6 +1206,9 @@ class AccountResourceIT {
.andExpect(jsonPath("$.[*].ipAddress").value(hasItem(token.getIpAddress())))
.andExpect(jsonPath("$.[*].userAgent").value(hasItem(token.getUserAgent())))
.andExpect(jsonPath("$.[*].tokenDate").value(hasItem(containsString(<% if (databaseTypeCassandra) { %>"2017-03-28T15:25:57.123Z"<% } else { %>token.getTokenDate().toString()<% } %>))));

persistentTokenRepository.delete(token);
userService.deleteUser("current-sessions")<%- callBlock %>;
}

@Test
Expand Down Expand Up @@ -1210,6 +1254,9 @@ class AccountResourceIT {
.andExpect(status().isOk());

assertThat(persistentTokenRepository.findByUser(user)).isEmpty();

persistentTokenRepository.delete(token);
userService.deleteUser("invalidate-session")<%- callBlock %>;
}
<%_ } _%>

Expand Down Expand Up @@ -1244,6 +1291,8 @@ class AccountResourceIT {
.with(csrf())<%_ } _%>)
.andExpect(status().isOk());
<%_ } _%>

userService.deleteUser("password-reset")<%- callBlock %>;
}

@Test
Expand Down Expand Up @@ -1277,6 +1326,8 @@ class AccountResourceIT {
.with(csrf())<%_ } _%>)
.andExpect(status().isOk());
<%_ } _%>

userService.deleteUser("password-reset-upper-case")<%- callBlock %>;
}

@Test
Expand Down Expand Up @@ -1336,6 +1387,8 @@ class AccountResourceIT {

<%= user.persistClass %> updatedUser = userRepository.findOneByLogin(user.getLogin())<%_ if (reactive) { _%>.block()<% } else { %>.orElse(null)<% } %>;
assertThat(passwordEncoder.matches(keyAndPassword.getNewPassword(), updatedUser.getPassword())).isTrue();

userService.deleteUser("finish-password-reset")<%- callBlock %>;
}

@Test
Expand Down Expand Up @@ -1378,6 +1431,8 @@ class AccountResourceIT {

<%= user.persistClass %> updatedUser = userRepository.findOneByLogin(user.getLogin())<%_ if (!reactive) { _%>.orElse(null)<% } else { %>.block()<% } %>;
assertThat(passwordEncoder.matches(keyAndPassword.getNewPassword(), updatedUser.getPassword())).isFalse();

userService.deleteUser("finish-password-reset-too-small")<%- callBlock %>;
}

@Test
Expand Down

0 comments on commit 625ba10

Please sign in to comment.