Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

REST Data Panache dev mode #10431

Merged
merged 1 commit into from
Sep 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.quarkus.hibernate.orm.rest.data.panache.deployment;

import static io.restassured.RestAssured.given;
import static io.restassured.RestAssured.when;
import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.Test;

import io.restassured.response.Response;

public abstract class AbstractDevModeTest {

@Test
void testGet() {
when().get("/items/1")
.then().statusCode(200);
}

@Test
void testCreate() {
Response response = given().accept("application/json")
.and().contentType("application/json")
.and().body("{\"name\": \"test-simple\", \"collection\": {\"id\": \"full\"}}")
.when().post("/items")
.thenReturn();
assertThat(response.getStatusCode()).isEqualTo(201);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.quarkus.hibernate.orm.rest.data.panache.deployment.entity;

import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.hibernate.orm.rest.data.panache.deployment.AbstractDevModeTest;
import io.quarkus.test.QuarkusDevModeTest;

public class PanacheEntityResourceDevModeTest extends AbstractDevModeTest {

@RegisterExtension
static final QuarkusDevModeTest TEST = new QuarkusDevModeTest()
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)
.addClasses(Collection.class, AbstractItem.class, Item.class, ItemsController.class)
.addAsResource("application.properties")
.addAsResource("import.sql"));

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.quarkus.hibernate.orm.rest.data.panache.deployment.repository;

import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.hibernate.orm.rest.data.panache.deployment.AbstractDevModeTest;
import io.quarkus.test.QuarkusDevModeTest;

public class PanacheRepositoryResourceDevModeTest extends AbstractDevModeTest {

@RegisterExtension
static final QuarkusDevModeTest TEST = new QuarkusDevModeTest()
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)
.addClasses(Collection.class, AbstractItem.class, Item.class, ItemsController.class, ItemsRepository.class)
.addAsResource("application.properties")
.addAsResource("import.sql"));

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,30 @@
import java.util.HashMap;
import java.util.Map;

import javax.ws.rs.core.UriInfo;

import org.jboss.resteasy.core.ResourceMethodRegistry;
import org.jboss.resteasy.core.ResteasyContext;
import org.jboss.resteasy.links.LinksProvider;
import org.jboss.resteasy.links.RESTServiceDiscovery;
import org.jboss.resteasy.links.impl.ClassLinksProvider;
import org.jboss.resteasy.links.impl.ObjectLinksProvider;
import org.jboss.resteasy.spi.Registry;

public final class ResourceLinksProvider {

private static final String SELF_REF = "self";

public Map<String, String> getClassLinks(Class<?> className) {
return linksToMap(getClassLinksProvider().getLinks(className));
RESTServiceDiscovery links = LinksProvider
.getClassLinksProvider()
.getLinks(className, Thread.currentThread().getContextClassLoader());
return linksToMap(links);
}

public Map<String, String> getInstanceLinks(Object instance) {
return linksToMap(getObjectLinksProvider().getLinks(instance));
RESTServiceDiscovery links = LinksProvider
.getObjectLinksProvider()
.getLinks(instance, Thread.currentThread().getContextClassLoader());
return linksToMap(links);
}

public String getSelfLink(Object instance) {
RESTServiceDiscovery.AtomLink link = getObjectLinksProvider()
.getLinks(instance)
RESTServiceDiscovery.AtomLink link = LinksProvider.getObjectLinksProvider()
.getLinks(instance, Thread.currentThread().getContextClassLoader())
.getLinkForRel(SELF_REF);
return link == null ? null : link.getHref();
}
Expand All @@ -38,16 +38,4 @@ private Map<String, String> linksToMap(RESTServiceDiscovery serviceDiscovery) {
}
return links;
}

private ObjectLinksProvider getObjectLinksProvider() {
UriInfo uriInfo = ResteasyContext.getContextData(UriInfo.class);
ResourceMethodRegistry registry = (ResourceMethodRegistry) ResteasyContext.getContextData(Registry.class);
return new ObjectLinksProvider(uriInfo, registry);
}

private ClassLinksProvider getClassLinksProvider() {
UriInfo uriInfo = ResteasyContext.getContextData(UriInfo.class);
ResourceMethodRegistry registry = (ResourceMethodRegistry) ResteasyContext.getContextData(Registry.class);
return new ClassLinksProvider(uriInfo, registry);
}
}