-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTinyURLControllerTest.java
More file actions
51 lines (43 loc) · 1.9 KB
/
TinyURLControllerTest.java
File metadata and controls
51 lines (43 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.victuxbb.systemdesigns.tinyurlapi.infrastructure.controller;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.victuxbb.systemdesigns.tinyurlapi.domain.kgs.KGSRepository;
import com.victuxbb.systemdesigns.tinyurlapi.domain.kgs.URLKey;
import com.victuxbb.systemdesigns.tinyurlapi.infrastructure.bootstrap.TinyURLAPIApplication;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.http.MediaType;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.reactive.server.WebTestClient;
import reactor.core.publisher.Mono;
import static org.mockito.Mockito.when;
@RunWith(SpringRunner.class)
@ActiveProfiles("test")
@SpringBootTest(classes = TinyURLAPIApplication.class)
@AutoConfigureWebTestClient
public class TinyURLControllerTest {
@Autowired
private WebTestClient webTestClient;
@Autowired
private ObjectMapper objectMapper;
@SpyBean
private KGSRepository kgsRepository;
@Test
public void createTinyURL() throws JsonProcessingException {
when(kgsRepository.getUniqueKey()).thenReturn(Mono.just(new URLKey("/miau")));
webTestClient
.post()
.uri("/tinyURL")
.contentType(MediaType.APPLICATION_JSON)
.syncBody(objectMapper.writeValueAsString(new CreateTinyURLRequest("/yupiiiii")))
.exchange()
.expectStatus().is2xxSuccessful()
.expectBody()
.jsonPath("$.hash", "/miau");
}
}