-
Notifications
You must be signed in to change notification settings - Fork 176
Expand file tree
/
Copy pathHelloControllerTest.java
More file actions
48 lines (39 loc) · 1.93 KB
/
Copy pathHelloControllerTest.java
File metadata and controls
48 lines (39 loc) · 1.93 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
package hello;
import static org.hamcrest.Matchers.containsString;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import io.micrometer.tracing.Span;
import io.micrometer.tracing.TraceContext;
import io.micrometer.tracing.Tracer;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.webmvc.test.autoconfigure.AutoConfigureMockMvc;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.web.servlet.MockMvc;
@SpringBootTest
@AutoConfigureMockMvc
class HelloControllerTest {
@Autowired
private MockMvc mvc;
@MockitoBean
private Tracer tracer;
@Test
void returnsTraceAndSpanDetailsAndParentFromTraceparent() throws Exception {
Span span = org.mockito.Mockito.mock(Span.class);
TraceContext traceContext = org.mockito.Mockito.mock(TraceContext.class);
when(tracer.currentSpan()).thenReturn(span);
when(span.context()).thenReturn(traceContext);
when(traceContext.traceId()).thenReturn("4bf92f3577b34da6a3ce929d0e0e4736");
when(traceContext.spanId()).thenReturn("00f067aa0ba902b7");
when(traceContext.sampled()).thenReturn(Boolean.TRUE);
mvc.perform(get("/")
.header("traceparent", "00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01"))
.andExpect(status().isOk())
.andExpect(content().string(containsString("current span: [Trace:")))
.andExpect(content().string(containsString("Span:")))
.andExpect(content().string(containsString("parents: [00f067aa0ba902b7]")));
}
}