Skip to content

Commit

Permalink
add 1 test
Browse files Browse the repository at this point in the history
Signed-off-by: David BRAQUART <[email protected]>
  • Loading branch information
dbraquart committed Mar 28, 2024
1 parent f9078b8 commit c636359
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions src/test/java/org/gridsuite/useradmin/server/UserAdminTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import org.gridsuite.useradmin.server.dto.UserInfos;
import org.gridsuite.useradmin.server.entity.ConnectionEntity;
import org.gridsuite.useradmin.server.repository.ConnectionRepository;
import org.gridsuite.useradmin.server.repository.UserAdminRepository;
Expand Down Expand Up @@ -61,6 +63,9 @@ class UserAdminTest {
@Autowired
private OutputDestination output;

@Autowired
private ObjectMapper mapper;

private final String maintenanceMessageDestination = "config.message";

private static final long TIMEOUT = 1000;
Expand All @@ -76,6 +81,7 @@ public void cleanDB() {
private static final String USER_UNKNOWN = "UNKNOWN";
private static final String ADMIN_USER = "admin1";
private static final String NOT_ADMIN = "notAdmin";
private static final String PROFILE_1 = "profile_1";

@Test
void testUserAdmin() throws Exception {
Expand Down Expand Up @@ -187,6 +193,57 @@ void testUserAdmin() throws Exception {
.andReturn();
}

@Test
void testUpdateUser() throws Exception {
ObjectWriter objectWriter = mapper.writer().withDefaultPrettyPrinter();
// add a user
mockMvc.perform(post("/" + UserAdminApi.API_VERSION + "/users/{sub}", USER_SUB)
.header("userId", ADMIN_USER)
)
.andExpect(status().isCreated())
.andReturn();
UserInfos userInfos = objectMapper.readValue(
mockMvc.perform(get("/" + UserAdminApi.API_VERSION + "/users/{sub}", USER_SUB)
.header("userId", ADMIN_USER)
.contentType(APPLICATION_JSON))
.andExpect(status().isOk())
.andReturn().getResponse().getContentAsString(),
new TypeReference<>() {
});
// the new user has no profile by default
assertNotNull(userInfos);
assertNull(userInfos.profileName());
assertEquals(USER_SUB, userInfos.sub());

// Create a profile
mockMvc.perform(post("/" + UserAdminApi.API_VERSION + "/profiles/{profileName}", PROFILE_1)
.header("userId", ADMIN_USER)
)
.andExpect(status().isCreated())
.andReturn();

// udpate the user: change its name and link it to the profile
UserInfos userInfo = new UserInfos(USER_SUB2, false, PROFILE_1);
mockMvc.perform(put("/" + UserAdminApi.API_VERSION + "/users/{sub}", USER_SUB)
.content(objectWriter.writeValueAsString(userInfo))
.contentType(MediaType.APPLICATION_JSON)
.header("userId", ADMIN_USER))
.andExpect(status().isOk());

userInfos = objectMapper.readValue(
mockMvc.perform(get("/" + UserAdminApi.API_VERSION + "/users/{sub}", USER_SUB2)
.header("userId", ADMIN_USER)
.contentType(APPLICATION_JSON))
.andExpect(status().isOk())
.andReturn().getResponse().getContentAsString(),
new TypeReference<>() {
});
// the new user has the new name and profile
assertNotNull(userInfos);
assertEquals(USER_SUB2, userInfos.sub());
assertEquals(PROFILE_1, userInfos.profileName());
}

@Test
void testGetConnections() throws Exception {
mockMvc.perform(post("/" + UserAdminApi.API_VERSION + "/users/{sub}", USER_SUB)
Expand Down

0 comments on commit c636359

Please sign in to comment.