-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIPManagerApplicationTests.java
More file actions
104 lines (85 loc) · 3.26 KB
/
IPManagerApplicationTests.java
File metadata and controls
104 lines (85 loc) · 3.26 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package com.example.ipmanager;
import com.example.ipmanager.IPAddress.IPAddress;
import com.example.ipmanager.IPAddress.IPAddressController;
import com.example.ipmanager.IPAddress.IPAddressRepository;
import com.example.ipmanager.IPAddress.IPAddressService;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
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.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.util.Assert;
import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
import static org.hamcrest.Matchers.*;
@ContextConfiguration(classes = IPManagerApplication.class)
@WebMvcTest(IPAddressController.class)
class IPManagerApplicationTests {
@Test
void contextLoads() {
}
public IPManagerApplicationTests() {
}
@Autowired
private MockMvc mockMvc;
@MockBean
private IPAddressService ipAddressService;
@MockBean
private IPAddressRepository ipAddressRepository;
IPAddress address1 = new IPAddress("15.0.0.1", "available");
IPAddress address2 = new IPAddress("15.0.0.2", "available");
IPAddress address3 = new IPAddress("15.0.0.3", "acquired");
@Test
public void getAllAddresses_success() throws Exception {
List<IPAddress> addressList = new ArrayList<>(Arrays.asList(address1, address2, address3));
Mockito.when(ipAddressService.getIPAddresses()).thenReturn(addressList);
mockMvc.perform(MockMvcRequestBuilders
.get("/api/v1/GetAllAddresses"))
.andExpect(status().isOk())
.andExpect(jsonPath("$", hasSize(3)));
}
@Test
public void createCIDRBlock_success() throws Exception {
MockHttpServletRequestBuilder mockRequest = MockMvcRequestBuilders
.post("/api/v1/CreateCIDRBlock")
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)
.param("fullAddress", "25.0.0.0/24");
mockMvc.perform(mockRequest)
.andExpect(status().isOk());
}
/*
@Test
public void acquireAddresses_success() throws Exception {
MockHttpServletRequestBuilder mockRequest = MockMvcRequestBuilders
.put("/api/v1/AcquireAddress")
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)
.param("address", "10.0.0.1");
mockMvc.perform(mockRequest)
.andExpect(status().isOk());
}
@Test
public void releaseAddresses_success() throws Exception {
MockHttpServletRequestBuilder mockRequest = MockMvcRequestBuilders
.put("/api/v1/ReleaseAddress")
.contentType(MediaType.APPLICATION_JSON)
.accept(MediaType.APPLICATION_JSON)
.param("address", "10.0.0.3");
mockMvc.perform(mockRequest)
.andExpect(status().isOk());
}
*/
}