-
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.
Dev UI Test Base for Build Time data and core tests
Signed-off-by: Phillip Kruger <[email protected]>
- Loading branch information
1 parent
7b2179c
commit 1018d93
Showing
7 changed files
with
130 additions
and
25 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
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
38 changes: 38 additions & 0 deletions
38
extensions/vertx-http/deployment/src/test/java/io/quarkus/devui/ExtensionsTest.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,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()); | ||
|
||
} | ||
|
||
} |
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
73 changes: 73 additions & 0 deletions
73
.../vertx-http/dev-ui-tests/src/main/java/io/quarkus/devui/tests/DevUIBuildTimeDataTest.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,73 @@ | ||
package io.quarkus.devui.tests; | ||
|
||
import java.io.IOException; | ||
import java.net.MalformedURLException; | ||
import java.net.URI; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Scanner; | ||
|
||
import org.eclipse.microprofile.config.ConfigProvider; | ||
import org.jboss.logging.Logger; | ||
|
||
import com.fasterxml.jackson.core.JsonFactory; | ||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
public abstract class DevUIBuildTimeDataTest { | ||
|
||
protected static final Logger log = Logger.getLogger(DevUIBuildTimeDataTest.class); | ||
|
||
protected URI uri; | ||
|
||
private final ObjectMapper mapper = new ObjectMapper(); | ||
private final JsonFactory factory = mapper.getFactory(); | ||
|
||
public DevUIBuildTimeDataTest(String namespace) { | ||
String testUrl = ConfigProvider.getConfig().getValue("test.url", String.class); | ||
String nonApplicationRoot = ConfigProvider.getConfig() | ||
.getOptionalValue("quarkus.http.non-application-root-path", String.class).orElse("q"); | ||
if (!nonApplicationRoot.startsWith("/")) { | ||
nonApplicationRoot = "/" + nonApplicationRoot; | ||
} | ||
this.uri = URI.create(testUrl + nonApplicationRoot + "/dev-ui/" + namespace + "-data.js"); | ||
} | ||
|
||
public JsonNode getBuildTimeData(String key) throws Exception { | ||
|
||
String data = readDataFromUrl(); | ||
String[] kvs = data.split(CONST); | ||
|
||
for (String kv : kvs) { | ||
if (kv.startsWith(key + SPACE + EQUALS + SPACE + OPEN_CURLY_BRACKET)) { | ||
String json = kv.substring(kv.indexOf(EQUALS) + 1).trim(); | ||
log.debug("json = " + json); | ||
return toJsonNode(json); | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
protected JsonNode toJsonNode(String json) { | ||
try { | ||
JsonParser parser = factory.createParser(json); | ||
return mapper.readTree(parser); | ||
} catch (IOException ex) { | ||
throw new RuntimeException(ex); | ||
} | ||
} | ||
|
||
private String readDataFromUrl() throws MalformedURLException, IOException { | ||
try (Scanner scanner = new Scanner(uri.toURL().openStream(), | ||
StandardCharsets.UTF_8.toString())) { | ||
scanner.useDelimiter("\\A"); | ||
return scanner.hasNext() ? scanner.next() : null; | ||
} | ||
} | ||
|
||
private static final String CONST = "export const "; | ||
private static final String SPACE = " "; | ||
private static final String EQUALS = "="; | ||
private static final String OPEN_CURLY_BRACKET = "{"; | ||
} |
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