From f29a551445e1ff96f929badc19aac2d42d5d09e8 Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer <paul-christian.volkmer@mni.thm.de> Date: Mon, 19 May 2014 11:01:32 +0200 Subject: [PATCH] Removed unused tests --- .../de/thm/arsnova/ARSnovaChromeDriver.java | 35 ---- .../java/de/thm/arsnova/HttpRestApiTest.java | 172 ------------------ .../java/de/thm/arsnova/Selenium2Test.java | 150 --------------- .../LecturerQuestionControllerTest.java | 43 +---- 4 files changed, 3 insertions(+), 397 deletions(-) delete mode 100644 src/test/java/de/thm/arsnova/ARSnovaChromeDriver.java delete mode 100644 src/test/java/de/thm/arsnova/HttpRestApiTest.java delete mode 100644 src/test/java/de/thm/arsnova/Selenium2Test.java diff --git a/src/test/java/de/thm/arsnova/ARSnovaChromeDriver.java b/src/test/java/de/thm/arsnova/ARSnovaChromeDriver.java deleted file mode 100644 index 97905e6ac..000000000 --- a/src/test/java/de/thm/arsnova/ARSnovaChromeDriver.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2012 THM webMedia - * - * This file is part of ARSnova. - * - * ARSnova is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ARSnova is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ -package de.thm.arsnova; - -import org.openqa.selenium.chrome.ChromeDriver; -import org.openqa.selenium.html5.*; -import org.openqa.selenium.remote.html5.*; - -public class ARSnovaChromeDriver extends ChromeDriver implements WebStorage { - - public LocalStorage getLocalStorage() { - return new RemoteLocalStorage(this.getExecuteMethod()); - } - - @Override - public SessionStorage getSessionStorage() { - return new RemoteSessionStorage(this.getExecuteMethod()); - } -} diff --git a/src/test/java/de/thm/arsnova/HttpRestApiTest.java b/src/test/java/de/thm/arsnova/HttpRestApiTest.java deleted file mode 100644 index 31c8994a2..000000000 --- a/src/test/java/de/thm/arsnova/HttpRestApiTest.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Copyright (C) 2012 THM webMedia - * - * This file is part of ARSnova. - * - * ARSnova is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ARSnova is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ -package de.thm.arsnova; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.io.BufferedReader; -import java.io.DataOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.net.HttpURLConnection; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.HashMap; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; -import org.junit.Ignore; -import org.junit.Test; - -/** - * Unit test to verify the public RESTlike API. - * - * These tests only check the API communication and structure of responses. They do not verify data. - */ -public class HttpRestApiTest { - public final String host = "localhost"; - public final int port = 8080; - public final String pathPrefix = "/"; - - private HttpURLConnection sendRequest(String path, String method, String accept, HashMap<String, String> parameters, String contentType, String body) throws IOException { - HttpURLConnection conn; - - try { - conn = (HttpURLConnection) (new URL("http", host, port, pathPrefix + path)).openConnection(); - System.out.println(conn.getURL().toExternalForm()); - - conn.setRequestMethod(method); - conn.setRequestProperty("Accept", accept); - conn.setRequestProperty("Host", host + ":" + Integer.valueOf(port)); - - if (null != body) { - conn.setRequestProperty("Content-Type", contentType); - conn.setRequestProperty("Content-Length", Integer.toString(body.getBytes().length)); - conn.setDoOutput(true); - DataOutputStream out = new DataOutputStream(conn.getOutputStream()); - out.writeBytes(body); - out.flush(); - out.close(); - } - } catch (MalformedURLException e) { - conn = null; - e.printStackTrace(); - } - - return conn; - } - - private HttpURLConnection sendRequest(String path, String method, String accept, HashMap<String, String> parameters) throws IOException { - return sendRequest(path, method, accept, parameters, null, null); - } - - private String transformInputToString(InputStream input) throws IOException { - BufferedReader reader = new BufferedReader(new InputStreamReader(input)); - StringBuilder str = new StringBuilder(); - String line; - while (null != (line = reader.readLine())) { - str.append(line); - } - System.out.println(str); - - return str.toString(); - } - - private JSONObject transformInputToJsonObject(InputStream input) throws IOException, JSONException { - return new JSONObject(transformInputToString(input)); - } - - private JSONArray transformInputToJsonArray(InputStream input) throws IOException, JSONException { - return new JSONArray(transformInputToString(input)); - } - - @Ignore("Test not implemented") - @Test - public void testSession() throws Exception { - - } - - @Ignore("Test not implemented") - @Test - public void testQuestionByLecturer() throws Exception { - - } - - @Ignore("Test not implemented") - @Test - public void testQuestionByAudience() throws Exception { - - } - - @Ignore("Test not implemented") - @Test - public void testSocket() throws Exception { - - } - - @Test - public void testCanteen() throws Exception { - HttpURLConnection conn; - JSONArray jsonArr; - String responseBody; - - /* TODO: make test case more specific */ - conn = sendRequest("canteen/menu/vote", "GET", "application/json", null); - assertEquals(200, conn.getResponseCode()); - jsonArr = transformInputToJsonArray(conn.getInputStream()); - assertNotNull(jsonArr); - - conn = sendRequest("canteen/menu/vote/count", "GET", "text/plain", null); - assertEquals(200, conn.getResponseCode()); - responseBody = transformInputToString(conn.getInputStream()); - Integer.valueOf(responseBody); - - /* TODO: implement test for POST /canteen/menu/vote */ - } - - @Test - public void testStatistics() throws Exception { - HttpURLConnection conn; - JSONObject jsonObj; - String responseBody; - - conn = sendRequest("statistics", "GET", "application/json", null); - assertEquals(200, conn.getResponseCode()); - jsonObj = transformInputToJsonObject(conn.getInputStream()); - assertTrue(jsonObj.has("answers")); - assertTrue(jsonObj.has("questions")); - assertTrue(jsonObj.has("openSessions")); - assertTrue(jsonObj.has("closedSessions")); - assertTrue(jsonObj.has("activeUsers")); - - conn = sendRequest("statistics/activeusercount", "GET", "text/plain", null); - assertEquals(200, conn.getResponseCode()); - responseBody = transformInputToString(conn.getInputStream()); - Integer.parseInt(responseBody); - - conn = sendRequest("statistics/sessioncount", "GET", "text/plain", null); - assertEquals(200, conn.getResponseCode()); - responseBody = transformInputToString(conn.getInputStream()); - Integer.parseInt(responseBody); - } -} \ No newline at end of file diff --git a/src/test/java/de/thm/arsnova/Selenium2Test.java b/src/test/java/de/thm/arsnova/Selenium2Test.java deleted file mode 100644 index 98a5211c1..000000000 --- a/src/test/java/de/thm/arsnova/Selenium2Test.java +++ /dev/null @@ -1,150 +0,0 @@ -package de.thm.arsnova; - -import static org.junit.Assert.assertTrue; - -import java.io.IOException; -import java.util.Properties; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.openqa.selenium.By; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.WebElement; -import org.openqa.selenium.html5.LocalStorage; -import org.openqa.selenium.support.ui.ExpectedCondition; -import org.openqa.selenium.support.ui.ExpectedConditions; -import org.openqa.selenium.support.ui.WebDriverWait; -import org.springframework.core.io.FileSystemResource; -import org.springframework.core.io.Resource; -import org.springframework.core.io.support.PropertiesLoaderUtils; - -import de.thm.arsnova.dao.CouchDBDao; -import de.thm.arsnova.entities.Feedback; -import de.thm.arsnova.entities.Session; -import de.thm.arsnova.services.FeedbackService; -import de.thm.arsnova.services.SessionService; -import de.thm.arsnova.services.StubUserService; - -public class Selenium2Test { - - private ARSnovaChromeDriver driver; - private Properties properties; - - private CouchDBDao couchdbDao; - private SessionService sessionService; - private StubUserService userService; - private FeedbackService feedbackService; - - @Before - public final void setUp() throws IOException { - Resource resource = new FileSystemResource("/etc/arsnova/arsnova.properties"); - properties = PropertiesLoaderUtils.loadProperties(resource); - - userService = new StubUserService(); - userService.setUserAuthenticated(true); - - couchdbDao = new CouchDBDao(); - couchdbDao.setDatabaseHost(properties.getProperty("couchdb.host", "localhost")); - couchdbDao.setDatabasePort(properties.getProperty("couchdb.port", "5984")); - couchdbDao.setDatabaseName(properties.getProperty("couchdb.name", "arsnova")); - sessionService = new SessionService(); - couchdbDao.setSessionService(sessionService); - couchdbDao.setUserService(userService); - sessionService.setDatabaseDao(couchdbDao); - feedbackService = new FeedbackService(); - feedbackService.setDatabaseDao(couchdbDao); - - this.driver = new ARSnovaChromeDriver(); - driver.get(properties.getProperty("security.arsnova-url", "http://localhost:8080/arsnova-war/")); - LocalStorage localStorage = this.driver.getLocalStorage(); - localStorage.setItem("html5 info read", ""); - } - - @After - public final void tearDown() { - driver.close(); - driver.quit(); - } - - @Test - public final void studentGuestShouldPostFeedback() { - Session session = couchdbDao.saveSession(createSession()); - Feedback initialFeedback = feedbackService.getFeedback(session.getKeyword()); - - selectStudentRole(); - loginAsGuest(); - joinSession(session); - - WebElement feedbackBadButton = waitForElement(By.className("feedbackBad")); - // Before clicking, ensure that no loading mask is displayed - By loadingSpinner = By.className("x-mask"); - waitWhileVisible(loadingSpinner); - feedbackBadButton.click(); - - // Wait for the feedback to arrive back at the client - By feedbackResultToolbar = By.id("ext-comp-1125"); - waitForElementWithContent(feedbackResultToolbar, "1/"); - - Feedback feedback = feedbackService.getFeedback(session.getKeyword()); - assertEquals(new Feedback(0, 0, 0, 0), initialFeedback); - assertEquals(new Feedback(0, 0, 1, 0), feedback); - } - - private void waitForElementWithContent(final By by, final String content) { - final long timeoutInSecs = 10; - (new WebDriverWait(driver, timeoutInSecs)).until(new ExpectedCondition<Boolean>() { - public Boolean apply(final WebDriver d) { - WebElement element = d.findElement(by); - return element != null && element.getText().contains(content); - } - }); - } - - private void assertEquals(Feedback feedback, Feedback feedback2) { - assertTrue(feedback.equals(feedback2)); - } - - private WebElement waitForElement(final By by) { - final long timeoutInSecs = 10; - (new WebDriverWait(driver, timeoutInSecs)).until(new ExpectedCondition<Boolean>() { - public Boolean apply(final WebDriver d) { - return d.findElement(by) != null; - } - }); - return driver.findElement(by); - } - - private void waitWhileVisible(final By by) { - final long timeoutInSecs = 10; - (new WebDriverWait(driver, timeoutInSecs)).until(ExpectedConditions.invisibilityOfElementLocated(by)); - } - - private Session createSession() { - return createNamedSession(null, null); - } - - private Session createNamedSession(final String name, final String shortName) { - Session session = new Session(); - session.setName(name != null ? name : "selenium test session"); - session.setShortName(shortName != null ? shortName : "selenium"); - return session; - } - - private void joinSession(Session session) { - WebElement sessionKeywordField = waitForElement(By.name("keyword")); - sessionKeywordField.sendKeys(session.getKeyword()); - WebElement joinSessionButton = waitForElement(By.id("ext-gen1138")); - joinSessionButton.click(); - } - - private void loginAsGuest() { - WebElement guestLoginButton = waitForElement(By.id("ext-gen1016")); - guestLoginButton.click(); - } - - private void selectStudentRole() { - WebElement studentRoleButton = waitForElement(By.id("ext-gen1047")); - studentRoleButton.click(); - } -} diff --git a/src/test/java/de/thm/arsnova/controller/LecturerQuestionControllerTest.java b/src/test/java/de/thm/arsnova/controller/LecturerQuestionControllerTest.java index 3ea9fb83d..f985a0720 100644 --- a/src/test/java/de/thm/arsnova/controller/LecturerQuestionControllerTest.java +++ b/src/test/java/de/thm/arsnova/controller/LecturerQuestionControllerTest.java @@ -1,14 +1,9 @@ package de.thm.arsnova.controller; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - import javax.inject.Inject; import org.junit.After; import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; @@ -17,19 +12,16 @@ import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.web.servlet.HandlerAdapter; -import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter; import de.thm.arsnova.dao.StubDatabaseDao; -import de.thm.arsnova.exceptions.NotFoundException; -import de.thm.arsnova.exceptions.UnauthorizedException; import de.thm.arsnova.services.StubUserService; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "file:src/main/webapp/WEB-INF/spring/arsnova-servlet.xml", "file:src/main/webapp/WEB-INF/spring/spring-main.xml", - "file:src/test/resources/test-config.xml" }) +"file:src/test/resources/test-config.xml" }) public class LecturerQuestionControllerTest { @Inject @@ -40,10 +32,10 @@ public class LecturerQuestionControllerTest { @Autowired private LecturerQuestionController lecturerQuestionController; - + @Autowired private StubUserService userService; - + @Autowired private StubDatabaseDao databaseDao; @@ -59,33 +51,4 @@ public class LecturerQuestionControllerTest { handlerAdapter = applicationContext .getBean(AnnotationMethodHandlerAdapter.class); } - - /* TODO: update test case for API changes or remove it if it is not necessary anymore */ - @Ignore - @Test(expected=NotFoundException.class) - public void testShouldNotGetQestionIdsForUnknownSession() throws Exception { - userService.setUserAuthenticated(true); - - request.setMethod("GET"); - request.setRequestURI("/session/00000000/questionids"); - final ModelAndView mav = handlerAdapter.handle(request, response, lecturerQuestionController); - - assertNull(mav); - assertTrue(response.getStatus() == 404); - } - - /* TODO: update test case for API changes or remove it if it is not necessary anymore */ - @Ignore - @Test(expected=UnauthorizedException.class) - public void testShouldNotGetQuestionIdsIfUnauthorized() throws Exception { - userService.setUserAuthenticated(false); - - request.setMethod("GET"); - request.setRequestURI("/session/00000000/questionids"); - final ModelAndView mav = handlerAdapter.handle(request, response, lecturerQuestionController); - - assertNull(mav); - assertTrue(response.getStatus() == 401); - } - } -- GitLab