Assignments Controller test + authj test fix
This commit is contained in:
parent
fe5d2d20c3
commit
73104850fe
@ -30,7 +30,7 @@ public class CommisionService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Optional<Commision> getNewestCommision(User user) {
|
public Optional<Commision> getNewestCommision(User user) {
|
||||||
return Optional.of(this.repo.getNewestCommision(user.getId()).get(0));
|
return this.repo.getNewestCommision(user.getId()).stream().findFirst();
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getCommisionsAmmount() {
|
public long getCommisionsAmmount() {
|
||||||
|
@ -1,27 +1,51 @@
|
|||||||
package com.plannaplan.controllers;
|
package com.plannaplan.controllers;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import com.plannaplan.entities.User;
|
||||||
|
import com.plannaplan.services.UserService;
|
||||||
|
import com.plannaplan.types.UserRoles;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||||
|
import org.springframework.web.context.WebApplicationContext;
|
||||||
|
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||||
|
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.*;
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
@ContextConfiguration
|
@ContextConfiguration
|
||||||
public class AssignmentsControllerTest {
|
public class AssignmentsControllerTest {
|
||||||
|
|
||||||
|
private static final String ASSIGFNMENTS_ENDPOINT = "/api/v1/assignments/getCurrentAssignments";
|
||||||
|
private static final String TEST_MAIL = "notexistingassignmentuser@mail.domain";
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private WebApplicationContext webApplicationContext;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserService service;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldReturn4xx() {
|
public void shouldReturn4xx() throws Exception {
|
||||||
assertTrue(false);
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||||
|
mockMvc.perform(get(ASSIGFNMENTS_ENDPOINT)).andExpect(status().is4xxClientError());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldReturnOk() {
|
public void shouldReturnOk() throws Exception {
|
||||||
assertTrue(false);
|
this.service.save(new User(null, null, TEST_MAIL, UserRoles.TEST_USER));
|
||||||
|
final String token = this.service.login(TEST_MAIL);
|
||||||
|
|
||||||
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||||
|
mockMvc.perform(get(ASSIGFNMENTS_ENDPOINT).header("Authorization", "Bearer " + token))
|
||||||
|
.andExpect(status().isOk());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -67,8 +67,8 @@ public class ConfigControllerTest {
|
|||||||
final String token = this.service.login(TEST_MAIL);
|
final String token = this.service.login(TEST_MAIL);
|
||||||
|
|
||||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||||
mockMvc.perform(multipart(CONFIG_ENDPOINT).file(file).header("Bearer ", token))
|
mockMvc.perform(multipart(CONFIG_ENDPOINT).file(file).header("Authorization", "Bearer " + token))
|
||||||
.andExpect(status().is4xxClientError());
|
.andExpect(status().isOk());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user