Open Kilda Java Documentation
SwitchControllerTest.java
Go to the documentation of this file.
1 package org.openkilda.controller;
2 
3 import static org.junit.jupiter.api.Assertions.assertTrue;
4 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
5 import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
6 
7 import org.springframework.http.MediaType;
8 import org.springframework.test.web.servlet.MockMvc;
9 import org.springframework.test.web.servlet.setup.MockMvcBuilders;
10 
11 import java.util.ArrayList;
12 import java.util.List;
13 
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.junit.jupiter.api.extension.ExtendWith;
17 import org.junit.runner.RunWith;
18 import org.mockito.InjectMocks;
19 import org.mockito.Mock;
20 import org.mockito.Mockito;
21 import org.mockito.MockitoAnnotations;
22 import org.mockito.runners.MockitoJUnitRunner;
27 
28 @ExtendWith(MockitoExtension.class)
29 @RunWith(MockitoJUnitRunner.class)
30 public class SwitchControllerTest {
31 
32  private MockMvc mockMvc;
33 
34  @Mock
35  private SwitchService serviceSwitch;
36 
37  @InjectMocks
38  private SwitchController switchController;
39 
40  private static final String switchUuid = "de:ad:be:ef:00:00:00:03";
41 
42  @Before
43  public void init() {
44  MockitoAnnotations.initMocks(this);
45  mockMvc = MockMvcBuilders.standaloneSetup(switchController).build();
46  }
47 
48  @Test
49  public void testGetAllSwitchesDetails() {
50  List<SwitchInfo> switchesInfo = new ArrayList<>();
51  try {
52  Mockito.when(serviceSwitch.getSwitches()).thenReturn(switchesInfo);
53  mockMvc.perform(get("/switch").contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk());
54  assertTrue(true);
55  } catch (Exception exception) {
56  assertTrue(false);
57  }
58  }
59 
60  @Test
61  public void testGetSwichLinkDetails() {
62  List<SwitchInfo> switchesInfo = new ArrayList<>();
63  try {
64  Mockito.when(serviceSwitch.getSwitches()).thenReturn(switchesInfo);
65  mockMvc.perform(get("/switch/links").contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk());
66  assertTrue(true);
67  } catch (Exception e) {
68  assertTrue(false);
69  }
70  }
71 }
def status()
Definition: rest.py:593