Skip to content
Snippets Groups Projects
Commit 01a61484 authored by Martin Stähr's avatar Martin Stähr
Browse files

test: adding tests for rest api view

parent 1202ffc9
No related branches found
No related tags found
No related merge requests found
...@@ -146,6 +146,17 @@ ...@@ -146,6 +146,17 @@
<version>3.0.1</version> <version>3.0.1</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </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> </dependencies>
......
package unipotsdam.gf.core.management.user; package unipotsdam.gf.core.management.user;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
/** /**
* Created by dehne on 31.05.2018. * Created by dehne on 31.05.2018.
*/ */
@JsonIgnoreProperties(ignoreUnknown = true)
public class User { public class User {
// the email is the id!
public String getId() {
return this.email;
}
private String name; private String name;
private String password; private String password;
private String email; private String email;
...@@ -35,6 +34,11 @@ public class User { ...@@ -35,6 +34,11 @@ public class User {
this.isStudent = isStudent; this.isStudent = isStudent;
} }
// the email is the id!
public String getId() {
return this.email;
}
public String getName() { public String getName() {
return name; return name;
} }
...@@ -68,7 +72,6 @@ public class User { ...@@ -68,7 +72,6 @@ public class User {
} }
public Boolean getStudent() { public Boolean getStudent() {
return isStudent; return isStudent;
} }
......
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()));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment