Fixed tests

This commit is contained in:
Andrey Terentev 2024-03-26 00:53:16 +07:00 committed by Andrey Terentev
parent 38cadc804f
commit 743c3a9d21
2 changed files with 10 additions and 0 deletions

View File

@ -4,6 +4,7 @@ import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.security.test.context.support.WithMockUser;
import ru.dragonestia.picker.api.exception.NodeAlreadyExistException; import ru.dragonestia.picker.api.exception.NodeAlreadyExistException;
import ru.dragonestia.picker.api.model.node.PickingMethod; import ru.dragonestia.picker.api.model.node.PickingMethod;
import ru.dragonestia.picker.api.repository.type.NodeIdentifier; import ru.dragonestia.picker.api.repository.type.NodeIdentifier;
@ -17,6 +18,7 @@ public class NodeServiceTests {
@Autowired @Autowired
private NodeService nodeService; private NodeService nodeService;
@WithMockUser(roles = {"NODE_MANAGEMENT"})
@Test @Test
void test_nodeCreateAndRemove() { void test_nodeCreateAndRemove() {
var node = new Node(NodeIdentifier.of("test"), PickingMethod.SEQUENTIAL_FILLING, false); var node = new Node(NodeIdentifier.of("test"), PickingMethod.SEQUENTIAL_FILLING, false);
@ -30,6 +32,7 @@ public class NodeServiceTests {
Assertions.assertFalse(() -> nodeService.find(node.getIdentifier()).isPresent()); Assertions.assertFalse(() -> nodeService.find(node.getIdentifier()).isPresent());
} }
@WithMockUser(roles = {"NODE_MANAGEMENT"})
@Test @Test
void test_allNodes() { void test_allNodes() {
nodeService.all().forEach(node -> nodeService.remove(node)); nodeService.all().forEach(node -> nodeService.remove(node));

View File

@ -5,6 +5,7 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.security.test.context.support.WithMockUser;
import ru.dragonestia.picker.api.exception.NodeAlreadyExistException; import ru.dragonestia.picker.api.exception.NodeAlreadyExistException;
import ru.dragonestia.picker.api.exception.NodeNotFoundException; import ru.dragonestia.picker.api.exception.NodeNotFoundException;
import ru.dragonestia.picker.api.exception.NotPersistedNodeException; import ru.dragonestia.picker.api.exception.NotPersistedNodeException;
@ -46,6 +47,7 @@ public class RoomServiceTests {
} catch (NodeAlreadyExistException ignore) {} } catch (NodeAlreadyExistException ignore) {}
} }
@WithMockUser(roles = {"NODE_MANAGEMENT"})
@Test @Test
void test_createAndRemove() { void test_createAndRemove() {
var room = roomFactory.create(RoomIdentifier.of("test-room"), node, IRoom.UNLIMITED_SLOTS, "", false); var room = roomFactory.create(RoomIdentifier.of("test-room"), node, IRoom.UNLIMITED_SLOTS, "", false);
@ -59,6 +61,7 @@ public class RoomServiceTests {
Assertions.assertFalse(roomService.find(node, room.getIdentifier()).isPresent()); Assertions.assertFalse(roomService.find(node, room.getIdentifier()).isPresent());
} }
@WithMockUser(roles = {"NODE_MANAGEMENT"})
@Test @Test
void test_allRooms() { void test_allRooms() {
var rooms = List.of( var rooms = List.of(
@ -76,6 +79,7 @@ public class RoomServiceTests {
Assertions.assertTrue(rooms.containsAll(list)); Assertions.assertTrue(rooms.containsAll(list));
} }
@WithMockUser(roles = {"NODE_MANAGEMENT"})
@Test @Test
void test_exceptNotPersistedNode() { void test_exceptNotPersistedNode() {
Assertions.assertThrows(NotPersistedNodeException.class, () -> { Assertions.assertThrows(NotPersistedNodeException.class, () -> {
@ -83,6 +87,7 @@ public class RoomServiceTests {
}); });
} }
@WithMockUser(roles = {"NODE_MANAGEMENT"})
@Test @Test
void test_pickRoom() { void test_pickRoom() {
var rooms = List.of( var rooms = List.of(
@ -107,6 +112,7 @@ public class RoomServiceTests {
Assertions.assertEquals("test-room4", roomService.pickAvailable(node, users).roomId()); Assertions.assertEquals("test-room4", roomService.pickAvailable(node, users).roomId());
} }
@WithMockUser(roles = {"NODE_MANAGEMENT"})
@Test @Test
void test_removeNode() { void test_removeNode() {
nodeService.remove(node); nodeService.remove(node);
@ -114,6 +120,7 @@ public class RoomServiceTests {
Assertions.assertThrows(NodeNotFoundException.class, () -> roomService.all(node)); Assertions.assertThrows(NodeNotFoundException.class, () -> roomService.all(node));
} }
@WithMockUser(roles = {"NODE_MANAGEMENT"})
@Test @Test
void test_nodeDoesNotExists() { void test_nodeDoesNotExists() {
var node = new Node(NodeIdentifier.of("bruh"), PickingMethod.ROUND_ROBIN, false); var node = new Node(NodeIdentifier.of("bruh"), PickingMethod.ROUND_ROBIN, false);