Skip to content

Commit

Permalink
Dev UI: Add Hibernate JsonRPC Tests
Browse files Browse the repository at this point in the history
Signed-off-by: Phillip Kruger <[email protected]>
  • Loading branch information
phillip-kruger committed Jun 16, 2023
1 parent bd8a4ff commit 9aab9fb
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 21 deletions.
5 changes: 5 additions & 0 deletions extensions/hibernate-orm/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-vertx-http-dev-ui-spi</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-vertx-http-dev-ui-tests</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-internal</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package io.quarkus.hibernate.orm.devui;

import java.util.Iterator;

import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import com.fasterxml.jackson.databind.JsonNode;

import io.quarkus.devui.tests.DevUIJsonRPCTest;
import io.quarkus.test.QuarkusDevModeTest;

public class HibernateOrmDevUITest extends DevUIJsonRPCTest {

@RegisterExtension
static final QuarkusDevModeTest test = new QuarkusDevModeTest()
.withApplicationRoot((jar) -> jar.addAsResource(
new StringAsset("quarkus.datasource.db-kind=h2\n"
+ "quarkus.datasource.jdbc.url=jdbc:h2:mem:test\n"),
"application.properties")
.addClasses(MyEntity.class));

@Test
public void testGetInfo() throws Exception {
JsonNode getInfoResponse = super.executeJsonRPCMethod("getInfo");
Assertions.assertNotNull(getInfoResponse);

JsonNode persistenceUnits = getInfoResponse.get("persistenceUnits");
Assertions.assertNotNull(persistenceUnits);
Assertions.assertTrue(persistenceUnits.isArray());

Iterator<JsonNode> persistenceUnitsIterator = persistenceUnits.elements();
while (persistenceUnitsIterator.hasNext()) {
JsonNode defaultPersistenceUnit = persistenceUnitsIterator.next();
JsonNode name = defaultPersistenceUnit.get("name");
Assertions.assertEquals("<default>", name.asText());

JsonNode managedEntities = defaultPersistenceUnit.get("managedEntities");
Assertions.assertNotNull(managedEntities);
Assertions.assertTrue(managedEntities.isArray());

Iterator<JsonNode> managedEntitiesIterator = managedEntities.elements();
while (managedEntitiesIterator.hasNext()) {
JsonNode myEntity = managedEntitiesIterator.next();

String className = myEntity.get("className").asText();
Assertions.assertEquals("io.quarkus.hibernate.orm.devui.MyEntity", className);

String tableName = myEntity.get("tableName").asText();
Assertions.assertEquals("MyEntity", tableName);
}

JsonNode namedQueries = defaultPersistenceUnit.get("namedQueries");
Assertions.assertNotNull(namedQueries);
Assertions.assertTrue(namedQueries.isArray());

}
}

@Test
public void testGetNumberOfPersistenceUnits() throws Exception {
JsonNode getNumberOfPersistenceUnitsResponse = super.executeJsonRPCMethod("getNumberOfPersistenceUnits");
Assertions.assertNotNull(getNumberOfPersistenceUnitsResponse);
Assertions.assertTrue(getNumberOfPersistenceUnitsResponse.isInt());
Assertions.assertEquals(1, getNumberOfPersistenceUnitsResponse.asInt());
}

@Test
public void testGetNumberOfEntityTypes() throws Exception {
JsonNode getNumberOfEntityTypesResponse = super.executeJsonRPCMethod("getNumberOfEntityTypes");
Assertions.assertNotNull(getNumberOfEntityTypesResponse);
Assertions.assertTrue(getNumberOfEntityTypesResponse.isInt());
Assertions.assertEquals(1, getNumberOfEntityTypesResponse.asInt());
}

@Test
public void testGetNumberOfNamedQueries() throws Exception {
JsonNode getNumberOfNamedQueriesResponse = super.executeJsonRPCMethod("getNumberOfNamedQueries");
Assertions.assertNotNull(getNumberOfNamedQueriesResponse);
Assertions.assertTrue(getNumberOfNamedQueriesResponse.isInt());
Assertions.assertEquals(0, getNumberOfNamedQueriesResponse.asInt());
}

@Override
protected String getNamespace() {
return "io.quarkus.quarkus-hibernate-orm";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.quarkus.hibernate.orm.devui;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;

@Entity
public class MyEntity {

@Id
Long id;

@Column
String field;

}
5 changes: 5 additions & 0 deletions integration-tests/devmode/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@

<dependencies>
<!-- test dependencies -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-vertx-http-dev-ui-tests</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive-deployment</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,4 @@ public void testLegacyPages() {
.statusCode(200)
.body(Matchers.containsString("No named queries were found."));
}

@Test
public void testPages() {
// TODO #31970 restore tests of the page's content as we used to do for the old Dev UI

RestAssured.get("q/dev-ui/hibernate-orm/persistence-units")
.then()
.statusCode(200);
// .body(Matchers.containsString("&lt;default&gt;"));

RestAssured.get("q/dev-ui/hibernate-orm/entity-types")
.then()
.statusCode(200);
// .body(Matchers.containsString("io.quarkus.test.devconsole.MyEntity"));

RestAssured.get("q/dev-ui/hibernate-orm/named-queries")
.then()
.statusCode(200);
// .body(Matchers.containsString("No named queries were found."));
}

}

0 comments on commit 9aab9fb

Please sign in to comment.