From 35746fe73e442d5e664f806d7977388d51f71a57 Mon Sep 17 00:00:00 2001
From: LiamClark <L.A.Clark@student.tudelft.nl>
Date: Mon, 10 Sep 2018 20:15:53 +0200
Subject: [PATCH] Send two new request to the frontend
however transcation controll will not show them,
when the user clicks on getNext afterwards
---
src/main/resources/templates/layout.html | 2 +-
.../resources/templates/request/list.html | 2 +-
.../controller/RequestControllerWebTest.java | 32 +++++++++++++++----
3 files changed, 27 insertions(+), 9 deletions(-)
diff --git a/src/main/resources/templates/layout.html b/src/main/resources/templates/layout.html
index e68020f67..03ce778ca 100644
--- a/src/main/resources/templates/layout.html
+++ b/src/main/resources/templates/layout.html
@@ -49,7 +49,7 @@
th:href="@{/courses}">Courses</a></li>
<li class="nav-item" th:if="${@permissionService.canViewRequests(#authentication.principal)}"><a
href="#" th:classappend="${page == 'requests' ? 'active text-white' : ''}"
- class="nav-link menu-link" th:href="@{/requests}">Requests</a></li>
+ class="nav-link menu-link" id="requests" th:href="@{/requests}">Requests</a></li>
<li class="nav-item" sec:authorize="hasAnyRole('ADMIN')"><a
href="#" th:classappend="${page == 'admin' ? 'active text-white' : ''}"
class="nav-link menu-link" th:href="@{/admin}">Admin</a></li>
diff --git a/src/main/resources/templates/request/list.html b/src/main/resources/templates/request/list.html
index db6bac23d..d7e3f4dba 100644
--- a/src/main/resources/templates/request/list.html
+++ b/src/main/resources/templates/request/list.html
@@ -10,7 +10,7 @@
<div class="container">
<script type="text/javascript" src="/js/bootstrap-multiselect.js"></script>
<script type="text/javascript" src="/js/request_table.js"></script>
- <script type="text/javascript" src="/webjars/handlebars/4.0.5/handlebars.min.js"></script>
+ <script type="text/javascript" src="/webjars/handlebars/4.0.6/handlebars.min.js"></script>
<link rel="stylesheet" href="/css/bootstrap-multiselect.css" type="text/css"/>
<nav role="navigation" class="breadcrumbs">
diff --git a/src/test/java/nl/tudelft/ewi/queue/controller/RequestControllerWebTest.java b/src/test/java/nl/tudelft/ewi/queue/controller/RequestControllerWebTest.java
index 7cd3fa62a..23c418b03 100644
--- a/src/test/java/nl/tudelft/ewi/queue/controller/RequestControllerWebTest.java
+++ b/src/test/java/nl/tudelft/ewi/queue/controller/RequestControllerWebTest.java
@@ -10,8 +10,6 @@ import nl.tudelft.ewi.queue.repository.RequestRepository;
import nl.tudelft.ewi.queue.repository.UserRepository;
import nl.tudelft.ewi.queue.service.LabService;
import nl.tudelft.ewi.queue.service.RequestService;
-import org.apache.regexp.RE;
-import org.bouncycastle.ocsp.Req;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -22,6 +20,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.time.LocalDate;
+import java.time.LocalDateTime;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = QueueApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
@@ -38,13 +40,16 @@ public class RequestControllerWebTest {
RequestRepository requestRepository;
@Autowired
- LabService requestService;
+ LabService labService;
@Autowired
CourseRepository courseRepository;
@Autowired
UserRepository userRepository;
+
+ @Autowired
+ RequestService requestService;
@Autowired
ObjectMapper objectMapper;
@@ -57,12 +62,12 @@ public class RequestControllerWebTest {
}
@Test
+ @Transactional
public void contextLoads() throws InterruptedException {
chromeDriver.get("localhost:8081/login");
login(chromeDriver);
+ acceptPushNotifcations();
Thread.sleep(2000000);
- final Iterable<Request> requests = requestRepository.findAll(QRequest.request.status.eq(Request.Status.PENDING));
- requestService.createAndSendNotifications(requests.iterator().next());
}
public static void login(ChromeDriver driver) {
@@ -71,8 +76,21 @@ public class RequestControllerWebTest {
driver.findElement(By.id("loginButton")).click();
}
- public static void acceptPushNotifcations(ChromeDriver driver) {
-// driver.executeScript()
+ public void acceptPushNotifcations() {
+ chromeDriver.findElement(By.id("requests")).click();
+ Request newRequest = new Request();
+ Request existing = requestRepository.findAll(QRequest.request.status.eq(Request.Status.PENDING)).iterator().next();
+ requestService.revoke(existing);
+ newRequest.setRequestEntity(existing.getRequestEntity());
+ newRequest.setLab(existing.getLab());
+ newRequest.setCreatedAt(LocalDateTime.now());
+ newRequest.setRoom(existing.getRoom());
+ newRequest.setAssignment(existing.getAssignment());
+ newRequest.setStatus(Request.Status.PENDING);
+ newRequest.setRequestType(existing.getRequestType());
+ requestRepository.delete(existing);
+ requestRepository.save(newRequest);
+ labService.createAndSendNotifications(newRequest);
}
@After
--
GitLab