content: package com.konsol.beatstream.web.rest;
  
  import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
  import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
  
  import com.konsol.beatstream.IntegrationTest;
  import com.konsol.beatstream.domain.User;
  import com.konsol.beatstream.repository.UserRepository;
  import com.konsol.beatstream.security.AuthoritiesConstants;
  import java.util.Objects;
  import java.util.Set;
  import org.junit.jupiter.api.AfterEach;
  import org.junit.jupiter.api.BeforeEach;
  import org.junit.jupiter.api.Test;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
  import org.springframework.cache.Cache;
  import org.springframework.cache.CacheManager;
  import org.springframework.http.MediaType;
  import org.springframework.security.test.context.support.WithMockUser;
  import org.springframework.test.web.servlet.MockMvc;
  
  /**
   * Integration tests for the {@link PublicUserResource} REST controller.
   */
  @AutoConfigureMockMvc
  @WithMockUser(authorities = AuthoritiesConstants.ADMIN)
  @IntegrationTest
  class PublicUserResourceIT {
  
      @Autowired
      private UserRepository userRepository;
  
      @Autowired
      private CacheManager cacheManager;
  
      @Autowired
      private MockMvc restUserMockMvc;
  
      private User user;
  
      @BeforeEach
      public void initTest() {
          user = UserResourceIT.initTestUser();
      }
  
      @AfterEach
      public void cleanupAndCheck() {
          cacheManager
              .getCacheNames()
              .stream()
              .map(cacheName -> this.cacheManager.getCache(cacheName))
              .filter(Objects::nonNull)
              .forEach(Cache::clear);
          userRepository.deleteAll();
      }
  
      @Test
      void getAllPublicUsers() throws Exception {
          // Initialize the database
          userRepository.save(user);
  
          // Get all the users
          restUserMockMvc
              .perform(get("/api/users").accept(MediaType.APPLICATION_JSON))
              .andExpect(status().isOk())
              .andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE))
              .andExpect(jsonPath("$.[?(@.id == '%s')].login", user.getId()).value(user.getLogin()))
              .andExpect(jsonPath("$.[?(@.id == '%s')].keys()", user.getId()).value(Set.of("id", "login")))
              .andExpect(jsonPath("$.[*].email").doesNotHaveJsonPath())
              .andExpect(jsonPath("$.[*].imageUrl").doesNotHaveJsonPath())
              .andExpect(jsonPath("$.[*].langKey").doesNotHaveJsonPath());
      }
  }
  