Skip to content
Snippets Groups Projects
Commit 9b84b008 authored by Yvan Peter's avatar Yvan Peter
Browse files

récupération dernières modifications

parent 03251600
No related branches found
No related tags found
No related merge requests found
...@@ -48,12 +48,36 @@ ...@@ -48,12 +48,36 @@
<groupId>org.glassfish.jersey.inject</groupId> <groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId> <artifactId>jersey-hk2</artifactId>
</dependency> </dependency>
<!-- Ajout pour utiliser le serveur HTTP Grizzly2 -->
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-grizzly2-http</artifactId>
<version>2.27</version>
</dependency>
<!-- Ajout pour pouvoir tester dans un container Jetty -->
<!-- <dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.4.12.v20180830</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.test-framework.providers</groupId>
<artifactId>jersey-test-framework-provider-jetty</artifactId>
<version>2.27</version>
</dependency> -->
<!-- uncomment this to get JSON support --> <!-- uncomment this to get JSON support -->
<dependency> <dependency>
<groupId>org.glassfish.jersey.media</groupId> <groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-binding</artifactId> <artifactId>jersey-media-json-binding</artifactId>
</dependency> </dependency>
<!-- --> <!-- -->
<!-- Ajout de la dépendance à JUnit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<!-- Ajout de la dépendance à jjwt, API java de Json Web Token --> <!-- Ajout de la dépendance à jjwt, API java de Json Web Token -->
<dependency> <dependency>
<groupId>io.jsonwebtoken</groupId> <groupId>io.jsonwebtoken</groupId>
...@@ -89,7 +113,7 @@ ...@@ -89,7 +113,7 @@
</dependencies> </dependencies>
<properties> <properties>
<jersey.version>2.26</jersey.version> <jersey.version>2.27</jersey.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>
</project> </project>
package fr.ulille.iut;
import java.io.IOException;
import java.net.URI;
import javax.ws.rs.core.UriBuilder;
import org.glassfish.grizzly.http.server.HttpServer;
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
public class Main {
public static final String BASE_URI = "http://localhost:8080/app/";
static HttpServer startServer() throws IOException {
URI baseUri = UriBuilder.fromUri("http://localhost/app").port(8080).build();
HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, new EntryPoint());
// start the server
server.start();
return server;
}
}
package fr.ulille.iut;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Form;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class AuthRessourceTest {
private HttpServer server;
private WebTarget target;
private final String authURL = "/api/v1/authenticate";
@Before
public void setUp() throws Exception {
// start the server
server = Main.startServer();
// create the client
target = ClientBuilder.newClient().target(Main.BASE_URI);
}
@After
public void tearDown() throws Exception {
server.stop();
}
@Test
public void testAuthenticateGoodUser() {
Form form = new Form();
form.param("login", "Yvan");
form.param("passwd", "GoodPass");
Entity<Form> formEntity = Entity.entity(form, MediaType.APPLICATION_FORM_URLENCODED_TYPE);
Response response = target.path(authURL).request().post(formEntity);
assertEquals(response.getStatus(), 200);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment