下面列出了怎么用org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable的API类实例代码及写法,或者点击链接到github查看源代码。
@Test
@DisabledIfEnvironmentVariable(named = "JENKINS_ASF_CI", matches = "true")
public void testSftpComponent() throws InterruptedException {
// Create a new file on the SFTP server
RestAssured.given()
.contentType(ContentType.TEXT)
.body("Hello Camel Quarkus SFTP")
.post("/sftp/create/hello.txt")
.then()
.statusCode(201);
// Read file back from the SFTP server
RestAssured.get("/sftp/get/hello.txt")
.then()
.statusCode(200)
.body(is("Hello Camel Quarkus SFTP"));
}
@Test
// This test is slow since it runs yarn, just run locally for now.
@DisabledIfEnvironmentVariable(named = "CI", matches = "true")
void updatesResolutions() {
assertThat(
GradleRunner.create()
.withProjectDir(projectDir.toFile())
.withArguments(":checkNodeResolutions")
.withPluginClasspath())
.fails()
.tasksDidRun(":checkNodeResolutions");
assertThat(
GradleRunner.create()
.withProjectDir(projectDir.toFile())
.withArguments(":updateNodeResolutions")
.withPluginClasspath())
.builds()
.tasksDidSucceed(":updateNodeResolutions");
}
@Test
@DisabledIfEnvironmentVariable(named = "CI", matches = ".*")
void ex5() throws IOException {
//## config
Graphviz.useEngine(new GraphvizCmdLineEngine()); // Rasterizer.builtIn() works only with CmdLineEngine
Graph g = graph("example5").directed().with(node("abc").link(node("xyz")));
Graphviz viz = Graphviz.fromGraph(g);
viz.width(200).render(Format.SVG).toFile(new File("example/ex5.svg"));
viz.width(200).rasterize(Rasterizer.BATIK).toFile(new File("example/ex5b.png"));
viz.width(200).rasterize(Rasterizer.SALAMANDER).toFile(new File("example/ex5s.png"));
viz.width(200).rasterize(Rasterizer.builtIn("pdf")).toFile(new File("example/ex5p"));
String dot = viz.render(Format.DOT).toString();
String json = viz.engine(Engine.NEATO).render(Format.JSON).toString();
BufferedImage image = viz.render(Format.PNG).toImage();
//## end
end();
init();
}
@Test
// This test is slow since it downloads a file, just run locally for now.
@DisabledIfEnvironmentVariable(named = "CI", matches = "true")
void terraformInstallsKubectl() {
assertThat(
GradleRunner.create()
.withProjectDir(projectDir.toFile())
.withArguments(":terraform:terraformInit", "--stacktrace")
.withPluginClasspath())
.builds()
.tasksDidSucceed(":gcloudInstallComponents", ":terraform:terraformInit");
}
@Test
// This test is slow since it runs yarn, just run locally for now.
@DisabledIfEnvironmentVariable(named = "CI", matches = "true")
void checksResolutions() {
assertThat(
GradleRunner.create()
.withProjectDir(projectDir.toFile())
.withArguments(":checkNodeResolutions")
.withPluginClasspath())
.builds()
.tasksDidSucceed(":checkNodeResolutions");
}
@DisabledIfEnvironmentVariable(named = "BRIDGE_EXTERNAL_ENV", matches = "((?i)FALSE(?-i))")
@Test
void createConsumerEmptyBody(VertxTestContext context) throws InterruptedException, TimeoutException, ExecutionException {
AtomicReference<String> name = new AtomicReference<>();
// create consumer
CompletableFuture<Boolean> create = new CompletableFuture<>();
consumerService().createConsumerRequest(groupId, null)
.send(ar -> {
context.verify(() -> {
assertThat(ar.succeeded(), is(true));
HttpResponse<JsonObject> response = ar.result();
assertThat(response.statusCode(), is(HttpResponseStatus.OK.code()));
JsonObject bridgeResponse = response.body();
String consumerInstanceId = bridgeResponse.getString("instance_id");
name.set(consumerInstanceId);
String consumerBaseUri = bridgeResponse.getString("base_uri");
assertThat(consumerInstanceId.startsWith(config.get(BridgeConfig.BRIDGE_ID).toString()), is(true));
assertThat(consumerBaseUri, is(Urls.consumerInstance(groupId, consumerInstanceId)));
});
create.complete(true);
});
create.get(TEST_TIMEOUT, TimeUnit.SECONDS);
consumerService()
.deleteConsumer(context, groupId, name.get());
context.completeNow();
assertThat(context.awaitCompletion(TEST_TIMEOUT, TimeUnit.SECONDS), is(true));
}
@Test
@EnabledOnOs(OS.WINDOWS)
@DisabledIfEnvironmentVariable(named = "CI", matches = "true")
void canInstantiateInternetExplorerDriverWithInternetExplorerOptions() {
driver = provider.createDriver(new InternetExplorerOptions());
assertTrue(driver instanceof InternetExplorerDriver);
}
@Test
@EnabledOnOs(OS.WINDOWS)
@DisabledIfEnvironmentVariable(named = "CI", matches = "true")
void canInstantiateEdgeDriverWithEdgeOptions() {
driver = provider.createDriver(new EdgeOptions());
assertTrue(driver instanceof EdgeDriver);
}
@Test
@EnabledOnOs(OS.MAC)
@DisabledIfEnvironmentVariable(named = "CI", matches = "true")
void canInstantiateSafariDriverWithSafariOptions() {
driver = provider.createDriver(new SafariOptions());
assertTrue(driver instanceof SafariDriver);
}
@Test
@DisabledIfEnvironmentVariable(named = "CI", matches = ".*")
void builtInRasterizer() throws IOException {
final File out = new File("target/builtIn.pdf");
out.delete();
Graphviz.useEngine(new GraphvizCmdLineEngine());
final Graphviz g = Graphviz.fromGraph(graph().with(node("a").link("b")));
g.basedir(new File("example")).rasterize(Rasterizer.builtIn("pdf")).toFile(new File("target/builtIn"));
assertTrue(out.exists());
end();
init();
}
@Test
@DisabledIfEnvironmentVariable(named = "CI", matches = ".*")
void ex7() throws IOException {
//## img
Graphviz.useEngine(new GraphvizCmdLineEngine());
Graphviz g = Graphviz.fromGraph(graph()
.with(node(Label.html("<table border='0'><tr><td><img src='graphviz.png' /></td></tr></table>"))));
g.basedir(new File("example")).render(Format.PNG).toFile(new File("example/ex7.png"));
//## img
}
@Test
@DisabledIfEnvironmentVariable(named = "USER", matches = "pankaj")
void test6() {
assertFalse(3 < 0);
}
@Disabled("Will be check in the next PR, this is just external tests for Bridge")
@DisabledIfEnvironmentVariable(named = "BRIDGE_EXTERNAL_ENV", matches = "((?i)FALSE(?-i))")
@Test
void sendBinaryMessageWithKey(VertxTestContext context) {
String topic = "sendBinaryMessageWithKey";
kafkaCluster.createTopic(topic, 2, 1);
String value = "message-value";
String key = "my-key-bin";
JsonArray records = new JsonArray();
JsonObject json = new JsonObject();
json.put("value", DatatypeConverter.printBase64Binary(value.getBytes()));
json.put("key", DatatypeConverter.printBase64Binary(key.getBytes()));
records.add(json);
JsonObject root = new JsonObject();
root.put("records", records);
producerService()
.sendRecordsRequest(topic, root, BridgeContentType.KAFKA_JSON_BINARY)
.sendJsonObject(root, verifyOK(context));
Properties config = kafkaCluster.getConsumerProperties();
KafkaConsumer<byte[], byte[]> consumer = KafkaConsumer.create(vertx, config,
new ByteArrayDeserializer(), new ByteArrayDeserializer());
consumer.handler(record -> {
context.verify(() -> {
assertThat(new String(record.value()), is(value));
assertThat(record.topic(), is(topic));
assertThat(record.partition(), notNullValue());
assertThat(record.offset(), is(0L));
assertThat(new String(record.key()), is(key));
});
LOGGER.info("Message consumed topic={} partition={} offset={}, key={}, value={}",
record.topic(), record.partition(), record.offset(), record.key(), record.value());
consumer.close();
context.completeNow();
});
consumer.subscribe(topic, done -> {
if (!done.succeeded()) {
context.failNow(done.cause());
}
});
}
@Test
@DisabledIfEnvironmentVariable(named = "CI", matches = "true")
void canInstantiateFirefoxDriverWithFirefoxOptions() {
driver = provider.createDriver(new FirefoxOptions());
assertTrue(driver instanceof FirefoxDriver);
}
@Test
@DisabledIfEnvironmentVariable(named = "CI", matches = "true")
void canInstantiateChromeDriverWithChromeOptions() {
driver = provider.createDriver(new ChromeOptions());
assertTrue(driver instanceof ChromeDriver);
}