-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Phillip Kruger <[email protected]>
- Loading branch information
1 parent
bd8a4ff
commit 8cb021f
Showing
11 changed files
with
227 additions
and
65 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
33 changes: 33 additions & 0 deletions
33
.../io/quarkus/hibernate/orm/devui/DevUIHibernateOrmActiveFalseAndNamedPuActiveTrueTest.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,33 @@ | ||
package io.quarkus.hibernate.orm.devui; | ||
|
||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.hibernate.orm.devui.namedpu.MyNamedPuEntity; | ||
import io.quarkus.test.QuarkusDevModeTest; | ||
|
||
public class DevUIHibernateOrmActiveFalseAndNamedPuActiveTrueTest extends DevUIHibernateOrmTest { | ||
|
||
@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" | ||
+ "quarkus.datasource.\"nameddatasource\".db-kind=h2\n" | ||
+ "quarkus.datasource.\"nameddatasource\".jdbc.url=jdbc:h2:mem:test2\n" | ||
// Hibernate ORM is inactive for the default PU | ||
+ "quarkus.hibernate-orm.active=false\n" | ||
+ "quarkus.hibernate-orm.datasource=<default>\n" | ||
+ "quarkus.hibernate-orm.packages=io.quarkus.test.devconsole\n" | ||
// ... but it's (implicitly) active for a named PU | ||
+ "quarkus.hibernate-orm.\"namedpu\".datasource=nameddatasource\n" | ||
+ "quarkus.hibernate-orm.\"namedpu\".packages=io.quarkus.hibernate.orm.devui.namedpu\n"), | ||
"application.properties") | ||
.addClasses(MyEntity.class) | ||
.addClasses(MyNamedPuEntity.class)); | ||
|
||
public DevUIHibernateOrmActiveFalseAndNamedPuActiveTrueTest() { | ||
super("namedpu", "MyNamedPuEntity", "io.quarkus.hibernate.orm.devui.namedpu.MyNamedPuEntity"); | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
...oyment/src/test/java/io/quarkus/hibernate/orm/devui/DevUIHibernateOrmActiveFalseTest.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.devui; | ||
|
||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusDevModeTest; | ||
|
||
public class DevUIHibernateOrmActiveFalseTest extends DevUIHibernateOrmTest { | ||
|
||
@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" | ||
// Hibernate ORM is inactive: the dev console should be empty. | ||
+ "quarkus.hibernate-orm.active=false\n"), | ||
"application.properties") | ||
.addClasses(MyEntity.class)); | ||
|
||
public DevUIHibernateOrmActiveFalseTest() { | ||
super(0, 0); | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
...m/deployment/src/test/java/io/quarkus/hibernate/orm/devui/DevUIHibernateOrmSmokeTest.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,21 @@ | ||
package io.quarkus.hibernate.orm.devui; | ||
|
||
import org.jboss.shrinkwrap.api.asset.StringAsset; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusDevModeTest; | ||
|
||
public class DevUIHibernateOrmSmokeTest extends DevUIHibernateOrmTest { | ||
|
||
@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)); | ||
|
||
public DevUIHibernateOrmSmokeTest() { | ||
super("<default>", "MyEntity", "io.quarkus.hibernate.orm.devui.MyEntity"); | ||
} | ||
} |
109 changes: 109 additions & 0 deletions
109
...te-orm/deployment/src/test/java/io/quarkus/hibernate/orm/devui/DevUIHibernateOrmTest.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,109 @@ | ||
package io.quarkus.hibernate.orm.devui; | ||
|
||
import java.util.Iterator; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
|
||
import io.quarkus.devui.tests.DevUIJsonRPCTest; | ||
|
||
/** | ||
* All tests test the same api call, with different configuration and different expected results | ||
* This abstract class reduce the code in each test | ||
*/ | ||
public abstract class DevUIHibernateOrmTest extends DevUIJsonRPCTest { | ||
|
||
private String expectedPersistenceUnitName = null; | ||
private String expectedTableName = null; | ||
private String expectedClassName = null; | ||
private int expectedNumberOfEntityTypes = 1; | ||
private int expectedNumberOfPersistenceUnits = 1; | ||
|
||
public DevUIHibernateOrmTest(String expectedPersistenceUnitName, String expectedTableName, String expectedClassName) { | ||
this.expectedPersistenceUnitName = expectedPersistenceUnitName; | ||
this.expectedTableName = expectedTableName; | ||
this.expectedClassName = expectedClassName; | ||
} | ||
|
||
public DevUIHibernateOrmTest(int expectedNumberOfEntityTypes, | ||
int expectedNumberOfPersistenceUnits) { | ||
this.expectedNumberOfEntityTypes = expectedNumberOfEntityTypes; | ||
this.expectedNumberOfPersistenceUnits = expectedNumberOfPersistenceUnits; | ||
} | ||
|
||
@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()); | ||
|
||
if (expectedPersistenceUnitName == null) { | ||
Assertions.assertEquals(0, persistenceUnits.size()); | ||
} else { | ||
Assertions.assertEquals(1, persistenceUnits.size()); | ||
Iterator<JsonNode> persistenceUnitsIterator = persistenceUnits.elements(); | ||
while (persistenceUnitsIterator.hasNext()) { | ||
JsonNode defaultPersistenceUnit = persistenceUnitsIterator.next(); | ||
JsonNode name = defaultPersistenceUnit.get("name"); | ||
Assertions.assertEquals(expectedPersistenceUnitName, 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(); | ||
Assertions.assertEquals(expectedNumberOfPersistenceUnits, persistenceUnits.size()); | ||
|
||
String tableName = myEntity.get("tableName").asText(); | ||
Assertions.assertEquals(expectedTableName, tableName); | ||
|
||
String className = myEntity.get("className").asText(); | ||
Assertions.assertEquals(expectedClassName, className); | ||
|
||
} | ||
|
||
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(expectedNumberOfPersistenceUnits, getNumberOfPersistenceUnitsResponse.asInt()); | ||
} | ||
|
||
@Test | ||
public void testGetNumberOfEntityTypes() throws Exception { | ||
JsonNode getNumberOfEntityTypesResponse = super.executeJsonRPCMethod("getNumberOfEntityTypes"); | ||
Assertions.assertNotNull(getNumberOfEntityTypesResponse); | ||
Assertions.assertTrue(getNumberOfEntityTypesResponse.isInt()); | ||
Assertions.assertEquals(expectedNumberOfEntityTypes, 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"; | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
...sions/hibernate-orm/deployment/src/test/java/io/quarkus/hibernate/orm/devui/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,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; | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
...-orm/deployment/src/test/java/io/quarkus/hibernate/orm/devui/namedpu/MyNamedPuEntity.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,14 @@ | ||
package io.quarkus.hibernate.orm.devui.namedpu; | ||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.Id; | ||
|
||
@Entity | ||
public class MyNamedPuEntity { | ||
|
||
@Id | ||
Long id; | ||
|
||
String field; | ||
|
||
} |
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
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
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
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