-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
162 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
...-orm-panache/deployment/src/test/java/io/quarkus/hibernate/orm/panache/test/MyEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package io.quarkus.hibernate.orm.panache.test; | ||
|
||
import javax.persistence.Entity; | ||
|
||
import io.quarkus.hibernate.orm.panache.PanacheEntity; | ||
|
||
@Entity | ||
public class MyEntity extends PanacheEntity { | ||
public String name; | ||
} |
10 changes: 10 additions & 0 deletions
10
...panache/deployment/src/test/java/io/quarkus/hibernate/orm/panache/test/MyOtherEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package io.quarkus.hibernate.orm.panache.test; | ||
|
||
import javax.persistence.Entity; | ||
|
||
import io.quarkus.hibernate.orm.panache.PanacheEntity; | ||
|
||
@Entity | ||
public class MyOtherEntity extends PanacheEntity { | ||
public String name; | ||
} |
24 changes: 24 additions & 0 deletions
24
...e/deployment/src/test/java/io/quarkus/hibernate/orm/panache/test/MyOtherTestResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package io.quarkus.hibernate.orm.panache.test; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.WebApplicationException; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
|
||
import org.jboss.resteasy.annotations.jaxrs.PathParam; | ||
|
||
@Path("other-entity") | ||
public class MyOtherTestResource { | ||
|
||
@GET | ||
@Path("{id}") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public MyOtherEntity get(@PathParam long id) { | ||
MyOtherEntity ret = MyOtherEntity.findById(id); | ||
if (ret == null) | ||
throw new WebApplicationException(Response.Status.NOT_FOUND); | ||
return ret; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...anache/deployment/src/test/java/io/quarkus/hibernate/orm/panache/test/MyTestResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package io.quarkus.hibernate.orm.panache.test; | ||
|
||
import javax.ws.rs.GET; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.WebApplicationException; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
|
||
import org.jboss.resteasy.annotations.jaxrs.PathParam; | ||
|
||
@Path("entity") | ||
public class MyTestResource { | ||
|
||
@GET | ||
@Path("{id}") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public MyEntity get(@PathParam long id) { | ||
MyEntity ret = MyEntity.findById(id); | ||
if (ret == null) | ||
throw new WebApplicationException(Response.Status.NOT_FOUND); | ||
return ret; | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...loyment/src/test/java/io/quarkus/hibernate/orm/panache/test/PanacheHotReloadTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package io.quarkus.hibernate.orm.panache.test; | ||
|
||
import static org.hamcrest.Matchers.is; | ||
|
||
import java.util.function.Function; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusDevModeTest; | ||
import io.restassured.RestAssured; | ||
|
||
public class PanacheHotReloadTestCase { | ||
@RegisterExtension | ||
final static QuarkusDevModeTest TEST = new QuarkusDevModeTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class) | ||
.addClasses(MyEntity.class, MyTestResource.class) | ||
.addAsResource("application.properties") | ||
.addAsResource("import.sql")); | ||
|
||
@Test | ||
public void testAddNewFieldToEntity() { | ||
String expectedName = "{\"id\":1,\"name\":\"my name\"}"; | ||
assertBodyIs(expectedName); | ||
|
||
TEST.modifySourceFile(MyEntity.class, new Function<String, String>() { | ||
@Override | ||
public String apply(String s) { | ||
return s.replace("public String name;", "public String name;public String tag;"); | ||
} | ||
}); | ||
TEST.modifyResourceFile("import.sql", new Function<String, String>() { | ||
@Override | ||
public String apply(String s) { | ||
return s.replace(";", ";\nUPDATE MyEntity SET tag = 'related' WHERE id = 1;\n"); | ||
} | ||
}); | ||
String hotReloadExpectedName = "{\"id\":1,\"name\":\"my name\",\"tag\":\"related\"}"; | ||
assertBodyIs(hotReloadExpectedName); | ||
} | ||
|
||
@Test | ||
public void testAddEntity() { | ||
RestAssured.when().get("/other-entity/1").then().statusCode(404); | ||
|
||
TEST.addSourceFile(MyOtherEntity.class); | ||
TEST.addSourceFile(MyOtherTestResource.class); | ||
|
||
TEST.modifyResourceFile("import.sql", new Function<String, String>() { | ||
@Override | ||
public String apply(String s) { | ||
return s + s.replaceAll("MyEntity", "MyOtherEntity"); | ||
} | ||
}); | ||
RestAssured.when().get("/other-entity/1").then().statusCode(200).body(is("{\"id\":1,\"name\":\"my name\"}")); | ||
} | ||
|
||
private void assertBodyIs(String expectedBody) { | ||
RestAssured.when().get("/entity/1").then().statusCode(200).body(is(expectedBody)); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...nsions/panache/hibernate-orm-panache/deployment/src/test/resources/application.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
quarkus.datasource.db-kind=h2 | ||
quarkus.datasource.jdbc.url=jdbc:h2:mem:test | ||
|
||
quarkus.hibernate-orm.dialect=org.hibernate.dialect.H2Dialect | ||
quarkus.hibernate-orm.log.sql=true | ||
quarkus.hibernate-orm.database.generation=drop-and-create |
1 change: 1 addition & 0 deletions
1
extensions/panache/hibernate-orm-panache/deployment/src/test/resources/import.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
INSERT INTO MyEntity(id, name) VALUES(1, 'my name'); |