本文整理汇总了Java中io.bootique.BQRuntime类的典型用法代码示例。如果您正苦于以下问题:Java BQRuntime类的具体用法?Java BQRuntime怎么用?Java BQRuntime使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BQRuntime类属于io.bootique包,在下文中一共展示了BQRuntime类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testHeartbeat_Defaults
import io.bootique.BQRuntime; //导入依赖的package包/类
@Test
public void testHeartbeat_Defaults() throws InterruptedException {
BQRuntime runtime = testFactory.app()
.autoLoadModules()
.module(b -> HealthCheckModule.extend(b).addHealthCheck("hc1", success))
.createRuntime();
// defaults have 60 sec delay and 60 sec heartbeat interval.. We are not going to wait that long in the test
// so just check that everything starts ok...
Heartbeat hb = runtime.getInstance(Heartbeat.class);
assertNull("Heartbeat was started prematurely", hb.heartbeatStopper);
hb.start();
assertNotNull("Heartbeat hasn't started with default settings", hb.heartbeatStopper);
}
示例2: testHealthcheckRegistry_Contributions
import io.bootique.BQRuntime; //导入依赖的package包/类
@Test
public void testHealthcheckRegistry_Contributions() {
HealthCheckOutcome hcr = mock(HealthCheckOutcome.class);
HealthCheck hc = mock(HealthCheck.class);
when(hc.safeCheck()).thenReturn(hcr);
BQRuntime runtime = testFactory
.app()
.module(HealthCheckModule.class)
.module(b -> HealthCheckModule.extend(b).addHealthCheck("x", hc))
.createRuntime();
HealthCheckRegistry r = runtime.getInstance(HealthCheckRegistry.class);
assertSame(hcr, r.runHealthCheck("x"));
}
示例3: testNewContext
import io.bootique.BQRuntime; //导入依赖的package包/类
@Test
public void testNewContext() {
BQRuntime runtime = stack.app("--config=classpath:test.yml")
.autoLoadModules()
.createRuntime();
try (DSLContext c = runtime.getInstance(JooqFactory.class).newContext()) {
c.createTable(Tables.TEST_TABLE).columns(Tables.TEST_TABLE.fields()).execute();
c.delete(Tables.TEST_TABLE).execute();
c.insertInto(Tables.TEST_TABLE).set(Tables.TEST_TABLE.ID, 4).set(Tables.TEST_TABLE.NAME, "me").execute();
Record r = c.select().from(Tables.TEST_TABLE).fetchOne();
assertNotNull(r);
assertEquals(Integer.valueOf(4), r.get(Tables.TEST_TABLE.ID));
assertEquals("me", r.get(Tables.TEST_TABLE.NAME));
}
}
示例4: testCreateRealms
import io.bootique.BQRuntime; //导入依赖的package包/类
@Test
public void testCreateRealms() {
BQRuntime bqRuntime = testFactory
.app("-c", "classpath:io/bootique/shiro/realm/RealmFactoryInheritanceIT.yml")
.autoLoadModules()
.createRuntime();
Object[] names = bqRuntime.getInstance(Realms.class).getRealms().stream().map(Realm::getName).toArray();
assertEquals(3, names.length);
assertEquals("Created by RealmFactory2", names[0]);
assertEquals("Created by RealmFactory1", names[1]);
assertEquals("Created by RealmFactory2", names[2]);
}
示例5: testSubject
import io.bootique.BQRuntime; //导入依赖的package包/类
@Test
public void testSubject() {
BQRuntime bqRuntime = testFactory
.app("-c", "classpath:io/bootique/shiro/realm/IniRealmIT.yml")
.autoLoadModules()
.createRuntime();
Subject subject = new Subject.Builder(bqRuntime.getInstance(SecurityManager.class)).buildSubject();
subject.login(new UsernamePasswordToken("u11", "u11p"));
Assert.assertTrue(subject.hasRole("admin"));
assertArrayEquals(new boolean[]{true, true, true}, subject.isPermitted("do1", "do2", "do3"));
subject.logout();
subject.login(new UsernamePasswordToken("u12", "u12p"));
Assert.assertTrue(subject.hasRole("user"));
assertArrayEquals(new boolean[]{false, false, true}, subject.isPermitted("do1", "do2", "do3"));
subject.logout();
subject.login(new UsernamePasswordToken("u21", "u21p"));
Assert.assertFalse(subject.hasRole("user"));
assertArrayEquals(new boolean[]{false, false, false}, subject.isPermitted("do1", "do2", "do3"));
subject.logout();
}
示例6: testFullStack
import io.bootique.BQRuntime; //导入依赖的package包/类
@Test
public void testFullStack() {
Realm mockRealm = mockRealm();
BQRuntime runtime = testFactory.app()
.module(b -> ShiroModule.extend(b).addRealm(mockRealm))
.autoLoadModules()
.createRuntime();
Subject subject = new Subject.Builder(runtime.getInstance(SecurityManager.class)).buildSubject();
assertFalse(subject.isAuthenticated());
// try bad login
try {
subject.login(new UsernamePasswordToken("uname", "badpassword"));
Assert.fail("Should have thrown on bad auth");
} catch (AuthenticationException authEx) {
assertFalse(subject.isAuthenticated());
}
// try good login
subject.login(new UsernamePasswordToken("uname", "password"));
assertTrue(subject.isAuthenticated());
}
示例7: testFullStack_SecurityUtils
import io.bootique.BQRuntime; //导入依赖的package包/类
@Test
public void testFullStack_SecurityUtils() {
Realm mockRealm = mockRealm();
BQRuntime runtime = testFactory.app()
.module(b -> ShiroModule.extend(b).addRealm(mockRealm))
.autoLoadModules()
.createRuntime();
Subject subject = new Subject.Builder(runtime.getInstance(SecurityManager.class)).buildSubject();
assertNull(ThreadContext.getSubject());
// testing Shiro idiom of wrapping lambda in a subject...
subject.execute(() -> {
assertSame("Unexpected subject, thread state is disturbed", subject, SecurityUtils.getSubject());
});
}
示例8: startApp
import io.bootique.BQRuntime; //导入依赖的package包/类
private void startApp(String config) {
Module extensions = (binder) -> {
JerseyModule.extend(binder).addResource(Resource.class);
// TODO: this test is seriously dirty.. we don't start the client from Bootique,
// yet we reuse Bootique Logback configuration for client logging.
// so here we are turning off logging from the server....
BQCoreModule.extend(binder)
.setLogLevel("org.eclipse.jetty.server", Level.OFF)
.setLogLevel("org.eclipse.jetty.util", Level.OFF);
};
Function<BQRuntime, Boolean> startupCheck = r -> r.getInstance(Server.class).isStarted();
serverFactory.app("--server", "--config=src/test/resources/io/bootique/jersey/client/" + config)
.modules(JettyModule.class, JerseyModule.class, LogbackModule.class)
.module(extensions)
.startupCheck(startupCheck)
.start();
}
示例9: testDerbyHealth
import io.bootique.BQRuntime; //导入依赖的package包/类
@Test
public void testDerbyHealth() {
BQRuntime runtime = testFactory.app("--config=classpath:db.yml").autoLoadModules().createRuntime();
HealthCheckRegistry healthChecks = runtime.getInstance(HealthCheckRegistry.class);
Map<String, HealthCheckOutcome> results = healthChecks.runHealthChecks();
assertEquals(3, results.size());
HealthCheckOutcome one = results.get("bq.jdbc.derby1.canConnect");
assertNotNull(one);
assertEquals(HealthCheckStatus.OK, one.getStatus());
HealthCheckOutcome two = results.get("bq.jdbc.derby2.canConnect");
assertNotNull(two);
assertEquals(HealthCheckStatus.OK, two.getStatus());
HealthCheckOutcome three = results.get("bq.jdbc.derby3.canConnect");
assertNotNull(three);
assertEquals(HealthCheckStatus.CRITICAL, three.getStatus());
}
示例10: run
import io.bootique.BQRuntime; //导入依赖的package包/类
public CommandOutcome run(Consumer<BQRuntime> beforeShutdownCallback, String... args) {
BootLogger logger = createBootLogger();
Bootique bootique = Bootique.app(args).bootLogger(logger);
configure(bootique);
BQRuntime runtime = bootique.createRuntime();
try {
return runtime.getInstance(Runner.class).run();
} catch (Exception e) {
logger.stderr("Error", e);
return CommandOutcome.failed(1, getStderr());
} finally {
try {
beforeShutdownCallback.accept(runtime);
}
finally {
runtime.shutdown();
}
}
}
示例11: testRun_Debug
import io.bootique.BQRuntime; //导入依赖的package包/类
@Test
public void testRun_Debug() throws IOException {
File logFile = prepareLogFile("target/logback/testRun_Debug.log");
BQRuntime runtime = app
.app("--config=src/test/resources/io/bootique/bom/logback/test-debug.yml").createRuntime();
CommandOutcome outcome = runtime.run();
// stopping runtime to ensure the logs are flushed before we start making assertions...
runtime.shutdown();
assertEquals(0, outcome.getExitCode());
assertTrue(logFile.isFile());
String logfileContents = Files.lines(logFile.toPath()).collect(joining("\n"));
assertTrue(logfileContents.contains("i.b.b.l.LogbackTestCommand: logback-test-debug"));
assertTrue(logfileContents.contains("i.b.b.l.LogbackTestCommand: logback-test-info"));
assertTrue(logfileContents.contains("i.b.b.l.LogbackTestCommand: logback-test-warn"));
assertTrue(logfileContents.contains("i.b.b.l.LogbackTestCommand: logback-test-error"));
}
示例12: testRun_Warn
import io.bootique.BQRuntime; //导入依赖的package包/类
@Test
public void testRun_Warn() throws IOException {
File logFile = prepareLogFile("target/logback/testRun_Warn.log");
BQRuntime runtime = app.app("--config=src/test/resources/io/bootique/bom/logback/test-warn.yml")
.createRuntime();
CommandOutcome outcome = runtime.run();
// stopping runtime to ensure the logs are flushed before we start making assertions...
runtime.shutdown();
assertEquals(0, outcome.getExitCode());
assertTrue(logFile.isFile());
String logfileContents = Files.lines(logFile.toPath()).collect(joining("\n"));
assertFalse(logfileContents.contains("i.b.b.l.LogbackTestCommand: logback-test-debug"));
assertFalse(logfileContents.contains("i.b.b.l.LogbackTestCommand: logback-test-info"));
assertTrue("Logfile contents: " + logfileContents,
logfileContents.contains("i.b.b.l.LogbackTestCommand: logback-test-warn"));
assertTrue(logfileContents.contains("i.b.b.l.LogbackTestCommand: logback-test-error"));
}
示例13: testRun_Help
import io.bootique.BQRuntime; //导入依赖的package包/类
@Test
public void testRun_Help() {
TestIO io = TestIO.noTrace();
BQRuntime runtime = app.app("--help")
.bootLogger(io.getBootLogger())
.startupAndWaitCheck()
// using longer startup timeout .. sometimes this fails on Travis..
.startupTimeout(8, TimeUnit.SECONDS)
.start();
CommandOutcome outcome = app.getOutcome(runtime).get();
assertEquals(0, outcome.getExitCode());
assertTrue(io.getStdout().contains("--help"));
assertTrue(io.getStdout().contains("--config"));
}
示例14: tablesInInsertOrder
import io.bootique.BQRuntime; //导入依赖的package包/类
static Table[] tablesInInsertOrder(BQRuntime runtime, Collection<DbEntity> dbEntities) {
// note: do not obtain sorter from Cayenne DI. It is not a singleton and will come
// uninitialized
ServerRuntime serverRuntime = runtime.getInstance(ServerRuntime.class);
EntitySorter sorter = serverRuntime.getDataDomain().getEntitySorter();
List<DbEntity> list = new ArrayList<>(dbEntities);
sorter.sortDbEntities(list, false);
DatabaseChannel channel = DatabaseChannel.get(runtime);
Table[] tables = new Table[list.size()];
for (int i = 0; i < tables.length; i++) {
tables[i] = createTableModel(channel, list.get(i));
}
return tables;
}
示例15: testContributeFilters_InitDestroy
import io.bootique.BQRuntime; //导入依赖的package包/类
@Test
public void testContributeFilters_InitDestroy() {
MappedFilter mf1 = new MappedFilter(mockFilter1, Collections.singleton("/a/*"), 10);
MappedFilter mf2 = new MappedFilter(mockFilter2, Collections.singleton("/a/*"), 0);
MappedFilter mf3 = new MappedFilter(mockFilter3, Collections.singleton("/a/*"), 5);
BQRuntime runtime = startApp(b -> JettyModule.extend(b)
.addMappedFilter(mf1)
.addMappedFilter(mf2)
.addMappedFilter(mf3));
Arrays.asList(mockFilter1, mockFilter2, mockFilter3).forEach(f -> {
try {
verify(f).init(any());
} catch (Exception e) {
fail("init failed");
}
});
runtime.shutdown();
Arrays.asList(mockFilter1, mockFilter2, mockFilter3).forEach(f -> verify(f).destroy());
}