diff --git a/gemeinsamforschen/pom.xml b/gemeinsamforschen/pom.xml index 5a64238d7df507d87d4847ae40e923fbecbacd3a..f10c541c1e44bb43155bdb3c9d9730032ae6ab4b 100644 --- a/gemeinsamforschen/pom.xml +++ b/gemeinsamforschen/pom.xml @@ -146,6 +146,17 @@ <version>3.0.1</version> <scope>provided</scope> </dependency> + <dependency> + <groupId>org.glassfish.jersey.test-framework.providers</groupId> + <artifactId>jersey-test-framework-provider-inmemory</artifactId> + <version>${jersey.version}</version> + </dependency> + <dependency> + <groupId>org.glassfish.jersey.test-framework</groupId> + <artifactId>jersey-test-framework-util</artifactId> + <version>2.27</version> + <scope>test</scope> + </dependency> </dependencies> diff --git a/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/user/User.java b/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/user/User.java index 2bc14ae52197262a69a27da74c5874daf1475daf..18376324134d68a1520717640b2fa0ea90c574a4 100644 --- a/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/user/User.java +++ b/gemeinsamforschen/src/main/java/unipotsdam/gf/core/management/user/User.java @@ -1,14 +1,13 @@ package unipotsdam.gf.core.management.user; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; + /** * Created by dehne on 31.05.2018. */ +@JsonIgnoreProperties(ignoreUnknown = true) public class User { - // the email is the id! - public String getId() { - return this.email; - } private String name; private String password; private String email; @@ -35,6 +34,11 @@ public class User { this.isStudent = isStudent; } + // the email is the id! + public String getId() { + return this.email; + } + public String getName() { return name; } @@ -68,7 +72,6 @@ public class User { } - public Boolean getStudent() { return isStudent; } diff --git a/gemeinsamforschen/src/test/java/unipotsdam/gf/modules/communication/view/CommunicationViewTest.java b/gemeinsamforschen/src/test/java/unipotsdam/gf/modules/communication/view/CommunicationViewTest.java new file mode 100644 index 0000000000000000000000000000000000000000..27f5517d1cd2aece4096cab23af9d4b745a1f7d7 --- /dev/null +++ b/gemeinsamforschen/src/test/java/unipotsdam/gf/modules/communication/view/CommunicationViewTest.java @@ -0,0 +1,76 @@ +package unipotsdam.gf.modules.communication.view; + +import org.glassfish.jersey.server.ResourceConfig; +import org.glassfish.jersey.test.JerseyTest; +import org.glassfish.jersey.test.util.runner.ConcurrentRunner; +import org.junit.Test; +import org.junit.runner.RunWith; +import unipotsdam.gf.core.management.user.User; +import unipotsdam.gf.modules.communication.model.chat.ChatRoom; + +import javax.ws.rs.client.Entity; +import javax.ws.rs.core.Application; +import javax.ws.rs.core.Response; +import java.util.ArrayList; +import java.util.List; + +import static javax.ws.rs.core.Response.Status.BAD_REQUEST; +import static javax.ws.rs.core.Response.Status.NOT_FOUND; +import static javax.ws.rs.core.Response.Status.OK; +import static org.hamcrest.Matchers.is; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; + +@RunWith(ConcurrentRunner.class) +public class CommunicationViewTest extends JerseyTest { + + + private final static String CHAT_ENDPOINT = "chat"; + + @Override + protected Application configure() { + CommunicationView communicationView = new CommunicationView(); + ResourceConfig resourceConfig = new ResourceConfig(); + resourceConfig.register(communicationView); + return resourceConfig; + } + + @Test + public void getChatRoomInformation() { + Response responseOk = target().path("chat/info/1").request().get(); + assertThat(responseOk.getStatus(), is(OK.getStatusCode())); + assertNotNull(responseOk.readEntity(ChatRoom.class)); + + Response responseNotFound = target().path("/chat/info/").request().get(); + assertThat(responseNotFound.getStatus(), is(NOT_FOUND.getStatusCode())); + } + + @Test + public void getChatHistory() { + String path = "chat/history/"; + Response responseOk = target().path(path + "1").request().get(); + assertThat(responseOk.getStatus(), is(OK.getStatusCode())); + assertNotNull(responseOk.readEntity(List.class)); + + Response responseNotFound = target().path(path).request().get(); + assertThat(responseNotFound.getStatus(), is(NOT_FOUND.getStatusCode())); + } + + @Test + public void createChatRoom() { + String path = "chat/create"; + Response responseOk = target().path("chat/create").queryParam("name", "test").request().post(null); + assertThat(responseOk.getStatus(), is(OK.getStatusCode())); + assertNotNull(responseOk.readEntity(String.class)); + + ArrayList<User> users = new ArrayList<>(); + users.add(new User("test", "test", "test", true)); + responseOk = target().path("chat/create").queryParam("name", "test").request().post(Entity.json(users)); + assertThat(responseOk.getStatus(), is(OK.getStatusCode())); + assertNotNull(responseOk.readEntity(String.class)); + + Response responseBadRequest = target().path("chat/create").request().post(Entity.json(users)); + assertThat(responseBadRequest.getStatus(), is(BAD_REQUEST.getStatusCode())); + } + +}