Skip to content

Commit

Permalink
Merge pull request #34090 from phillip-kruger/dev-ui-testing
Browse files Browse the repository at this point in the history
Dev UI Testing
  • Loading branch information
phillip-kruger authored Jun 20, 2023
2 parents 2971d53 + 1018d93 commit 582f1f7
Show file tree
Hide file tree
Showing 21 changed files with 639 additions and 65 deletions.
5 changes: 5 additions & 0 deletions bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1863,6 +1863,11 @@
<artifactId>quarkus-vertx-http-dev-ui-spi</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-vertx-http-dev-ui-tests</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-vertx-http-dev-ui-resources</artifactId>
Expand Down
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,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");
}

}
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);
}

}
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");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
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) {
super("io.quarkus.quarkus-hibernate-orm");
this.expectedPersistenceUnitName = expectedPersistenceUnitName;
this.expectedTableName = expectedTableName;
this.expectedClassName = expectedClassName;
}

public DevUIHibernateOrmTest(int expectedNumberOfEntityTypes,
int expectedNumberOfPersistenceUnits) {
super("io.quarkus.quarkus-hibernate-orm");
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());
}
}
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;

}
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;

}
5 changes: 5 additions & 0 deletions extensions/vertx-http/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@
</exclusions>
</dependency>
<!-- 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-security-deployment</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package io.quarkus.devui;

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 BuildMetricsTest extends DevUIJsonRPCTest {

@RegisterExtension
static final QuarkusDevModeTest config = new QuarkusDevModeTest().withEmptyApplication();

public BuildMetricsTest() {
super("devui-build-metrics");
}

@Test
public void testGetBuildStepsMetrics() throws Exception {
JsonNode buildStepsMetricsResponse = super.executeJsonRPCMethod("getBuildStepsMetrics");
Assertions.assertNotNull(buildStepsMetricsResponse);

int duration = buildStepsMetricsResponse.get("duration").asInt();
Assertions.assertTrue(duration > 0);

boolean dependencyGraphsIncluded = buildStepsMetricsResponse.get("dependencyGraphs").isObject();
Assertions.assertTrue(dependencyGraphsIncluded);

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

import java.util.Map;

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 ConfigurationTest extends DevUIJsonRPCTest {

@RegisterExtension
static final QuarkusDevModeTest config = new QuarkusDevModeTest()
.withEmptyApplication();

public ConfigurationTest() {
super("devui-configuration");
}

@Test
public void testLogstreamHistory() throws Exception {

JsonNode updatePropertyResponse = super.executeJsonRPCMethod("updateProperty",
Map.of(
"name", "quarkus.application.name",
"value", "changedByTest"));
Assertions.assertTrue(updatePropertyResponse.asBoolean());

// Get the properties to make sure it is changed
JsonNode allPropertiesResponse = super.executeJsonRPCMethod("getAllValues");
String applicationName = allPropertiesResponse.get("quarkus.application.name").asText();
Assertions.assertEquals("changedByTest", applicationName);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package io.quarkus.devui;

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.DevUIBuildTimeDataTest;
import io.quarkus.test.QuarkusDevModeTest;

public class ExtensionsTest extends DevUIBuildTimeDataTest {

@RegisterExtension
static final QuarkusDevModeTest config = new QuarkusDevModeTest().withEmptyApplication();

public ExtensionsTest() {
super("devui");
}

@Test
public void testGetExtensions() throws Exception {
JsonNode extensionsResponse = super.getBuildTimeData("extensions");
Assertions.assertNotNull(extensionsResponse);

JsonNode activeExtensions = extensionsResponse.get("active");
Assertions.assertNotNull(activeExtensions);
Assertions.assertTrue(activeExtensions.isArray());

JsonNode inactiveExtensions = extensionsResponse.get("inactive");
Assertions.assertNotNull(inactiveExtensions);
Assertions.assertTrue(inactiveExtensions.isArray());

log.info(extensionsResponse.toPrettyString());

}

}
Loading

0 comments on commit 582f1f7

Please sign in to comment.