Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ScarletRedMan committed Mar 25, 2024
1 parent 38cadc8 commit 743c3a9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
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.model.node.PickingMethod;
import ru.dragonestia.picker.api.repository.type.NodeIdentifier;
Expand All @@ -17,6 +18,7 @@ public class NodeServiceTests {
@Autowired
private NodeService nodeService;

@WithMockUser(roles = {"NODE_MANAGEMENT"})
@Test
void test_nodeCreateAndRemove() {
var node = new Node(NodeIdentifier.of("test"), PickingMethod.SEQUENTIAL_FILLING, false);
Expand All @@ -30,6 +32,7 @@ void test_nodeCreateAndRemove() {
Assertions.assertFalse(() -> nodeService.find(node.getIdentifier()).isPresent());
}

@WithMockUser(roles = {"NODE_MANAGEMENT"})
@Test
void test_allNodes() {
nodeService.all().forEach(node -> nodeService.remove(node));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
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.NodeNotFoundException;
import ru.dragonestia.picker.api.exception.NotPersistedNodeException;
Expand Down Expand Up @@ -46,6 +47,7 @@ void init() {
} catch (NodeAlreadyExistException ignore) {}
}

@WithMockUser(roles = {"NODE_MANAGEMENT"})
@Test
void test_createAndRemove() {
var room = roomFactory.create(RoomIdentifier.of("test-room"), node, IRoom.UNLIMITED_SLOTS, "", false);
Expand All @@ -59,6 +61,7 @@ void test_createAndRemove() {
Assertions.assertFalse(roomService.find(node, room.getIdentifier()).isPresent());
}

@WithMockUser(roles = {"NODE_MANAGEMENT"})
@Test
void test_allRooms() {
var rooms = List.of(
Expand All @@ -76,13 +79,15 @@ void test_allRooms() {
Assertions.assertTrue(rooms.containsAll(list));
}

@WithMockUser(roles = {"NODE_MANAGEMENT"})
@Test
void test_exceptNotPersistedNode() {
Assertions.assertThrows(NotPersistedNodeException.class, () -> {
roomService.create(roomFactory.create(RoomIdentifier.of("1"), node, IRoom.UNLIMITED_SLOTS, "", true));
});
}

@WithMockUser(roles = {"NODE_MANAGEMENT"})
@Test
void test_pickRoom() {
var rooms = List.of(
Expand All @@ -107,13 +112,15 @@ void test_pickRoom() {
Assertions.assertEquals("test-room4", roomService.pickAvailable(node, users).roomId());
}

@WithMockUser(roles = {"NODE_MANAGEMENT"})
@Test
void test_removeNode() {
nodeService.remove(node);

Assertions.assertThrows(NodeNotFoundException.class, () -> roomService.all(node));
}

@WithMockUser(roles = {"NODE_MANAGEMENT"})
@Test
void test_nodeDoesNotExists() {
var node = new Node(NodeIdentifier.of("bruh"), PickingMethod.ROUND_ROBIN, false);
Expand Down

0 comments on commit 743c3a9

Please sign in to comment.