MORE UNIT TESTS

This commit is contained in:
Индекс Зиро 2025-02-19 18:31:47 +03:00
parent 0e5ab92a4a
commit 0b02367cc3
2 changed files with 142 additions and 0 deletions

View File

@ -118,6 +118,24 @@ class EmployeeControllerTests {
.andExpect(status().isForbidden());
}
@Test
void getByLogin() throws Exception {
this.mockMvc.perform(
get("/api/employee/pivanov")
.with(httpBasic("pivanov", "HelloWorld1234")))
.andDo(print())
.andExpect(status().isOk());
}
@Test
void getByLoginForbidden() throws Exception {
this.mockMvc.perform(
get("/api/employee/pivanov")
.with(httpBasic("afedorov", "HelloWorld1234")))
.andDo(print())
.andExpect(status().isForbidden());
}
}

View File

@ -0,0 +1,124 @@
package com.indexzero.finals;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.web.servlet.MockMvc;
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.httpBasic;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@SpringBootTest
@AutoConfigureMockMvc
class EntranceControllerTests {
@Autowired
private MockMvc mockMvc;
@Test
void getUserEntries() throws Exception {
this.mockMvc.perform(
get("/api/entrance")
.with(httpBasic("pivanov", "HelloWorld1234"))
)
.andDo(print())
.andExpect(status().isOk()
);
}
@Test
void getUserEntriesUnathorized() throws Exception {
this.mockMvc.perform(
get("/api/entrance")
.with(httpBasic("pivanov", "HelloWorld12345"))
)
.andDo(print())
.andExpect(status().isUnauthorized());
}
@Test
void getUserLastEntry() throws Exception {
this.mockMvc.perform(
get("/api/entrance/last")
.with(httpBasic("pivanov", "HelloWorld1234"))
)
.andDo(print())
.andExpect(status().isOk()
);
}
@Test
void getUserLastEntryUnathorized() throws Exception {
this.mockMvc.perform(
get("/api/entrance/last")
.with(httpBasic("pivanov", "HelloWorld12345"))
)
.andDo(print())
.andExpect(status().isUnauthorized());
}
@Test
void getUserAllEntries() throws Exception {
this.mockMvc.perform(
get("/api/entrance/all")
.with(httpBasic("pivanov", "HelloWorld1234"))
)
.andDo(print())
.andExpect(status().isOk()
);
}
@Test
void getUserAllEntriesForbidden() throws Exception {
this.mockMvc.perform(
get("/api/entrance/all")
.with(httpBasic("afedorov", "HelloWorld1234"))
)
.andDo(print())
.andExpect(status().isForbidden());
}
@Test
void getUserAllEntriesUnauthorized() throws Exception {
this.mockMvc.perform(
get("/api/entrance/all")
.with(httpBasic("pivanov", "HelloWorld12345"))
)
.andDo(print())
.andExpect(status().isUnauthorized());
}
@Test
void getUserEntriesByLogin() throws Exception {
this.mockMvc.perform(
get("/api/entrance/pivanov")
.with(httpBasic("pivanov", "HelloWorld1234"))
)
.andDo(print())
.andExpect(status().isOk());
}
@Test
void getUserEntriesByLoginNotFound() throws Exception {
this.mockMvc.perform(
get("/api/entrance/pivanova")
.with(httpBasic("pivanov", "HelloWorld1234"))
)
.andDo(print())
.andExpect(status().isNotFound());
}
@Test
void getUserEntriesByLoginForbidden() throws Exception {
this.mockMvc.perform(
get("/api/entrance/pivanov")
.with(httpBasic("afedorov", "HelloWorld1234"))
)
.andDo(print())
.andExpect(status().isForbidden());
}
}