Test implemented!
This commit is contained in:
parent
62e287e1b0
commit
8ce68d5833
|
@ -1,4 +1,4 @@
|
|||
curl -w "\n" http://localhost:8080/mocktail/barkeeper/getrecipesall
|
||||
curl --header "Content-Type: application/json" --request POST --data "{\"id\":\"0\",\"name\":\"Peter\",\"ingredients\":\"guelle\",\"recipe\":\"ruehren\"}" http://localhost:8080/mocktail/barkeeper/create
|
||||
curl --header "Content-Type: application/json" --request PUT --data "{\"id\":\"4\",\"name\":\"Peter\",\"ingredients\":\"guelle\",\"recipe\":\"ruehren\"}" http://localhost:8080/mocktail/barkeeper/update
|
||||
curl --header "Content-Type: application/json" --request DELETE --data "{\"id\":\"4\"}" http://localhost:8080/mocktail/barkeeper/delete
|
||||
curl -w "\n" http://localhost:8080/mocktail/search/getrecipesall
|
||||
curl --header "Content-Type: application/json" --request POST --data "{\"id\":\"0\",\"name\":\"Peter\",\"ingredients\":\"guelle\",\"recipe\":\"ruehren\"}" http://localhost:8080/mocktail/create/single
|
||||
curl --header "Content-Type: application/json" --request PUT --data "{\"id\":\"4\",\"name\":\"Peter\",\"ingredients\":\"guelle\",\"recipe\":\"ruehren\"}" http://localhost:8080/mocktail/update/single
|
||||
curl --header "Content-Type: application/json" --request DELETE --data "{\"id\":\"4\"}" http://localhost:8080/mocktail/delete/single
|
||||
|
|
|
@ -3,62 +3,60 @@ package de.hsos.swa.ma.api.al;
|
|||
import java.util.ArrayList;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.ws.rs.GET;
|
||||
/* import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.DELETE; */
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
/* import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
import javax.ws.rs.core.MediaType; */
|
||||
|
||||
import org.jboss.resteasy.annotations.jaxrs.PathParam;
|
||||
|
||||
@Path("/mocktail/barkeeper")
|
||||
public class Barkeeper implements ISearch, ICreate, IDelete{
|
||||
@Path("/mocktail")
|
||||
public class Barkeeper implements ISearch, ICreate, IUpdate, IDelete{
|
||||
|
||||
@Inject
|
||||
StorageTransport st;
|
||||
|
||||
@GET
|
||||
@Produces (MediaType.APPLICATION_JSON)
|
||||
@Path("/getrecipesall")
|
||||
//@GET
|
||||
//@Produces (MediaType.APPLICATION_JSON)
|
||||
//@Path("/getrecipesall")
|
||||
public ArrayList<Mocktail> getRecipesAll() {
|
||||
ArrayList<Mocktail> mts = st.getRecipesAll();
|
||||
return mts;
|
||||
}
|
||||
|
||||
@POST
|
||||
/* @POST
|
||||
@Produces (MediaType.TEXT_PLAIN)
|
||||
@Consumes (MediaType.APPLICATION_JSON)
|
||||
@Path("/create")
|
||||
@Path("/create") */
|
||||
public String createMocktail(Mocktail m) {
|
||||
//Mocktail newMock = new Mocktail(m.name, m.ingredients, m.recipe);
|
||||
System.out.println("action-create -> index: "+ m.id);
|
||||
if(this.st.addMocktail(m)) {
|
||||
return "Mocktail wurde erstellt.";
|
||||
}
|
||||
return "Mocktail konnte nicht erstellt werden.";
|
||||
|
||||
}
|
||||
|
||||
@PUT
|
||||
/* @PUT
|
||||
@Produces (MediaType.TEXT_PLAIN)
|
||||
@Consumes (MediaType.APPLICATION_JSON)
|
||||
@Path("/update")
|
||||
@Path("/update") */
|
||||
public String updateMocktail(Mocktail m) {
|
||||
System.out.println("action-update -> index: "+ m.id);
|
||||
if(this.st.updateMocktail(m)) {
|
||||
return "Mocktail wurde geupdatet.";
|
||||
}
|
||||
return "Mocktail konnte nicht geupdatet werden...";
|
||||
}
|
||||
|
||||
@DELETE
|
||||
/* @DELETE
|
||||
@Consumes (MediaType.APPLICATION_JSON)
|
||||
@Path("/delete")
|
||||
public String deleteMocktail(Mocktail mocktail) {
|
||||
System.out.println("index: "+ mocktail.id);
|
||||
if(this.st.deleteMocktail(mocktail.id)){
|
||||
return "objekt wurde entfernt";
|
||||
@Path("/delete") */
|
||||
public String deleteMocktail(Mocktail m) {
|
||||
System.out.println("action-delete -> index: "+ m.id);
|
||||
if(this.st.deleteMocktail(m.id)){
|
||||
return "Mocktail wurde entfernt.";
|
||||
}
|
||||
return "Objekt konnte nicht entfernt werden...";
|
||||
}
|
||||
|
|
|
@ -1,16 +1,18 @@
|
|||
package de.hsos.swa.ma.api.al;
|
||||
|
||||
/*import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jboss.resteasy.annotations.jaxrs.PathParam;*/
|
||||
|
||||
//@Path("/create")
|
||||
public interface ICreate {
|
||||
|
||||
/*@GET
|
||||
@Produces (MediaType.TEXT_PLAIN)*/
|
||||
@POST
|
||||
@Produces (MediaType.TEXT_PLAIN)
|
||||
@Consumes (MediaType.APPLICATION_JSON)
|
||||
@Path("/create/single")
|
||||
public String createMocktail(Mocktail m);
|
||||
//public Mocktail[] showRecipesByName(/*@PathParam */String name);
|
||||
//public Mocktail[] showRecipesById(int id);
|
||||
|
|
|
@ -1,9 +1,19 @@
|
|||
package de.hsos.swa.ma.api.al;
|
||||
|
||||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
/**
|
||||
* IDelete
|
||||
*/
|
||||
//@Path("/delete")
|
||||
public interface IDelete {
|
||||
|
||||
public String deleteMocktail(Mocktail mocktail);
|
||||
@DELETE
|
||||
@Consumes (MediaType.APPLICATION_JSON)
|
||||
@Produces (MediaType.TEXT_PLAIN)
|
||||
@Path("/delete/single")
|
||||
public String deleteMocktail(Mocktail m);
|
||||
}
|
|
@ -2,17 +2,16 @@ package de.hsos.swa.ma.api.al;
|
|||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/*import javax.ws.rs.GET;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jboss.resteasy.annotations.jaxrs.PathParam;*/
|
||||
|
||||
public interface ISearch {
|
||||
|
||||
/*@GET
|
||||
@Produces (MediaType.TEXT_PLAIN)*/
|
||||
@GET
|
||||
@Produces (MediaType.APPLICATION_JSON)
|
||||
@Path("search/getrecipesall")
|
||||
public ArrayList<Mocktail> getRecipesAll();
|
||||
//public Mocktail[] showRecipesByName(/*@PathParam */String name);
|
||||
//public Mocktail[] showRecipesById(int id);
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
package de.hsos.swa.ma.api.al;
|
||||
|
||||
import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
//@Path("/mocktail/update")
|
||||
public interface IUpdate {
|
||||
|
||||
@PUT
|
||||
@Produces (MediaType.TEXT_PLAIN)
|
||||
@Consumes (MediaType.APPLICATION_JSON)
|
||||
@Path("/update/single")
|
||||
public String updateMocktail(Mocktail m);
|
||||
|
||||
}
|
|
@ -3,7 +3,7 @@ package de.hsos.swa.ma.api.al;
|
|||
import io.quarkus.jsonb.JsonbConfigCustomizer;
|
||||
import javax.inject.Singleton;
|
||||
import javax.json.bind.JsonbConfig;
|
||||
import javax.json.bind.serializer.JsonbSerializer;
|
||||
//import javax.json.bind.serializer.JsonbSerializer;
|
||||
|
||||
@Singleton
|
||||
public class JsonBSerializer implements JsonbConfigCustomizer{
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
package de.hsos.swa.ma.api.al;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
//import java.util.UUID;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
|
||||
@QuarkusTest
|
||||
public class MocktailTest {
|
||||
|
||||
@Test
|
||||
public void testCreateSingleEndpoint() {
|
||||
//String uuid = UUID.randomUUID().toString();
|
||||
String json = "{\"id\":\"0\",\"name\":\"Peter\",\"ingredients\":\"guelle\",\"recipe\":\"ruehren\"}";
|
||||
|
||||
|
||||
given()
|
||||
//.pathParam("name", uuid)
|
||||
.when().header("Content-Type", "application/json")
|
||||
.body(json)
|
||||
.post("/mocktail/create/single")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(is("Mocktail wurde erstellt." /* + uuid */));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateSingleEndpoint() {
|
||||
//String uuid = UUID.randomUUID().toString();
|
||||
String json = "{\"id\":\"4\",\"name\":\"Peter\",\"ingredients\":\"guelle\",\"recipe\":\"ruehren\"}";
|
||||
|
||||
|
||||
given()
|
||||
//.pathParam("name", uuid)
|
||||
.when().header("Content-Type", "application/json")
|
||||
.body(json)
|
||||
.put("/mocktail/update/single")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(is("Mocktail wurde geupdatet." /* + uuid */));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDeleteSingleEndpoint() {
|
||||
//String uuid = UUID.randomUUID().toString();
|
||||
String json = "{\"id\":\"3\"}";
|
||||
|
||||
|
||||
given()
|
||||
//.pathParam("name", uuid)
|
||||
.when().header("Content-Type", "application/json")
|
||||
.body(json)
|
||||
.delete("/mocktail/delete/single")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(is("Mocktail wurde entfernt." /* + uuid */));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
package org.acme.resteasy;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import jdk.internal.jline.internal.TestAccessible;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import de.hsos.swa.ma.api.al.Mocktail;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
|
||||
@QuarkusTest
|
||||
@Path("/mocktail/barkeeper")
|
||||
public class ExampleResourceTest {
|
||||
|
||||
@Test
|
||||
public void testHelloEndpoint() {
|
||||
given()
|
||||
.when().get("/resteasy/hello")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body(is("hello"));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
package org.acme.resteasy;
|
||||
|
||||
import io.quarkus.test.junit.NativeImageTest;
|
||||
|
||||
@NativeImageTest
|
||||
public class NativeExampleResourceIT extends ExampleResourceTest {
|
||||
|
||||
// Execute the same tests but in native mode.
|
||||
}
|
Loading…
Reference in New Issue