-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Decode path for createElementInDirectoryPath endpoint (#156)
- Loading branch information
1 parent
c9f13dc
commit 4d88e0d
Showing
2 changed files
with
66 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/test/java/org/gridsuite/directory/server/DirectoryControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/** | ||
* Copyright (c) 2024, RTE (http://www.rte-france.com) | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
package org.gridsuite.directory.server; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import org.gridsuite.directory.server.dto.ElementAttributes; | ||
import org.gridsuite.directory.server.services.DirectoryRepositoryService; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.eq; | ||
import static org.mockito.Mockito.verify; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
/** | ||
* @author Antoine Bouhours <antoine.bouhours at rte-france.com> | ||
*/ | ||
@RunWith(SpringRunner.class) | ||
@WebMvcTest(DirectoryController.class) | ||
public class DirectoryControllerTest { | ||
|
||
@Autowired | ||
ObjectMapper objectMapper; | ||
|
||
@Autowired | ||
private MockMvc mockMvc; | ||
|
||
@MockBean | ||
private DirectoryService directoryService; | ||
|
||
@MockBean | ||
private DirectoryRepositoryService directoryRepositoryService; | ||
|
||
@Test | ||
public void testCreateElementWithEncodedPath() throws Exception { | ||
String encodedPath = "%26~%23%7B%5B%5Eimport%C3%A9%22"; | ||
String decodedPath = "&~#{[^importé\""; | ||
String userId = "testUser"; | ||
String requestBody = new ObjectMapper().writeValueAsString(ElementAttributes.builder().build()); | ||
mockMvc.perform(post("/v1/directories/paths/elements") | ||
.param("directoryPath", encodedPath) | ||
.content(requestBody) | ||
.header("userId", userId) | ||
.contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(status().isOk()) | ||
.andExpect(content().contentType(MediaType.APPLICATION_JSON_VALUE)); | ||
verify(directoryService).createElementInDirectoryPath(eq(decodedPath), any(), eq(userId)); | ||
} | ||
} |