|
| 1 | +package org.gridsuite.explore.server; |
| 2 | + |
| 3 | +import org.gridsuite.explore.server.services.DirectoryService; |
| 4 | +import org.junit.jupiter.api.Test; |
| 5 | +import org.mockito.ArgumentCaptor; |
| 6 | +import org.mockito.Mock; |
| 7 | +import org.springframework.beans.factory.annotation.Autowired; |
| 8 | +import org.springframework.boot.test.context.SpringBootTest; |
| 9 | +import org.springframework.boot.test.mock.mockito.MockBean; |
| 10 | +import org.springframework.http.HttpEntity; |
| 11 | +import org.springframework.http.HttpMethod; |
| 12 | +import org.springframework.http.ResponseEntity; |
| 13 | +import org.springframework.web.client.RestTemplate; |
| 14 | + |
| 15 | +import java.net.URI; |
| 16 | +import java.util.UUID; |
| 17 | + |
| 18 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 19 | +import static org.mockito.ArgumentMatchers.*; |
| 20 | +import static org.mockito.Mockito.verify; |
| 21 | +import static org.mockito.Mockito.when; |
| 22 | + |
| 23 | +@SpringBootTest |
| 24 | +class DirectoryServiceTest { |
| 25 | + |
| 26 | + @MockBean |
| 27 | + private RestTemplate restTemplate; |
| 28 | + |
| 29 | + @Mock |
| 30 | + private ResponseEntity<String> responseEntity; |
| 31 | + |
| 32 | + @Autowired |
| 33 | + private DirectoryService directoryService; |
| 34 | + |
| 35 | + @Test |
| 36 | + void testSearchElementsWithSpecialCharacters() { |
| 37 | + String userInput = "a+éè{}\\`b"; |
| 38 | + String directoryUuid = UUID.randomUUID().toString(); |
| 39 | + String userId = "testUser"; |
| 40 | + when(restTemplate.exchange(any(URI.class), eq(HttpMethod.GET), any(HttpEntity.class), eq(String.class))) |
| 41 | + .thenReturn(responseEntity); |
| 42 | + |
| 43 | + directoryService.searchElements(userInput, directoryUuid, userId); |
| 44 | + |
| 45 | + ArgumentCaptor<URI> uriCaptor = ArgumentCaptor.forClass(URI.class); |
| 46 | + verify(restTemplate).exchange(uriCaptor.capture(), any(), any(), any(Class.class)); |
| 47 | + String uriString = uriCaptor.getValue().toString(); |
| 48 | + assertTrue(uriString.contains("userInput=a%2B%C3%A9%C3%A8%7B%7D%5C%60b")); |
| 49 | + } |
| 50 | +} |
0 commit comments