下面列出了怎么用org.junit.rules.ExternalResource的API类实例代码及写法,或者点击链接到github查看源代码。
public TestRule createTestRule() {
final TemporaryFolder tempFolder = new TemporaryFolder();
return RuleChain
.outerRule(tempFolder)
.around(new ExternalResource() {
TomcatServerBootstrap bootstrap = new JerseyTomcatServerBootstrap(webXmlResource);
protected void before() throws Throwable {
bootstrap.setWorkingDir(tempFolder.getRoot().getAbsolutePath());
bootstrap.start();
}
protected void after() {
bootstrap.stop();
}
});
}
public TestRule createTestRule() {
final TemporaryFolder tempFolder = new TemporaryFolder();
return RuleChain
.outerRule(tempFolder)
.around(new ExternalResource() {
WinkTomcatServerBootstrap bootstrap = new WinkTomcatServerBootstrap(webXmlResource);
protected void before() throws Throwable {
bootstrap.setWorkingDir(tempFolder.getRoot().getAbsolutePath());
bootstrap.start();
}
protected void after() {
bootstrap.stop();
}
});
}
public TestRule createTestRule() {
final TemporaryFolder tempFolder = new TemporaryFolder();
return RuleChain
.outerRule(tempFolder)
.around(new ExternalResource() {
TomcatServerBootstrap bootstrap = new JerseyTomcatServerBootstrap(webXmlResource);
protected void before() throws Throwable {
bootstrap.setWorkingDir(tempFolder.getRoot().getAbsolutePath());
bootstrap.start();
}
protected void after() {
bootstrap.stop();
}
});
}
public TestRule createTestRule() {
final TemporaryFolder tempFolder = new TemporaryFolder();
return RuleChain
.outerRule(tempFolder)
.around(new ExternalResource() {
TomcatServerBootstrap bootstrap = new CXFTomcatServerBootstrap(webXmlResource);
protected void before() throws Throwable {
bootstrap.setWorkingDir(tempFolder.getRoot().getAbsolutePath());
bootstrap.start();
}
protected void after() {
bootstrap.stop();
}
});
}
public TestRule createTestRule() {
final TemporaryFolder tempFolder = new TemporaryFolder();
return RuleChain
.outerRule(tempFolder)
.around(new ExternalResource() {
ResteasyTomcatServerBootstrap bootstrap = new ResteasyTomcatServerBootstrap(webXmlResource);
protected void before() throws Throwable {
bootstrap.setWorkingDir(tempFolder.getRoot().getAbsolutePath());
bootstrap.start();
}
protected void after() {
bootstrap.stop();
}
});
}
@Override
protected List<TestRule> classRules() {
final TemporaryFolder temporaryFolder = new TemporaryFolder();
try {
hmsPort = HiveTestUtils.getFreePort();
} catch (IOException e) {
throw new RuntimeException(e);
}
HiveServerContext context = new FlinkStandaloneHiveServerContext(temporaryFolder, config, hmsPort);
List<TestRule> rules = super.classRules();
ExternalResource hms = new ExternalResource() {
@Override
protected void before() throws Throwable {
LOGGER.info("Setting up {} in {}", getName(), temporaryFolder.getRoot().getAbsolutePath());
hmsWatcher = startHMS(context, hmsPort);
}
@Override
protected void after() {
if (hmsWatcher != null) {
hmsWatcher.cancel(true);
}
}
};
ExternalResource hiveShell = new ExternalResource() {
@Override
protected void before() throws Throwable {
container = createHiveServerContainer(getTestClass().getJavaClass(), context);
}
@Override
protected void after() {
tearDown();
}
};
rules.add(hiveShell);
rules.add(hms);
rules.add(temporaryFolder);
return rules;
}
/**
* A JUnit {@link TestRule} that stops tests from interfering with one
* another. JUnit will automatically set up/clean up the catalog when this
* rule is used. <br/>
* Usage:<br/>
* {@code @Rule public final TestRule catalogMaintainer = TestCatalogModel.maintainer()}
* @return the TestRule
*/
public static TestRule maintainer() {
return new ExternalResource() {
@Override
protected void after() {
getDefault().clearDocumentPool();
}
};
}
@Override
protected List<TestRule> classRules() {
final TemporaryFolder temporaryFolder = new TemporaryFolder();
try {
hmsPort = HiveTestUtils.getFreePort();
} catch (IOException e) {
throw new RuntimeException(e);
}
HiveServerContext context = new FlinkStandaloneHiveServerContext(temporaryFolder, config, hmsPort);
List<TestRule> rules = super.classRules();
ExternalResource hms = new ExternalResource() {
@Override
protected void before() throws Throwable {
LOGGER.info("Setting up {} in {}", getName(), temporaryFolder.getRoot().getAbsolutePath());
hmsWatcher = startHMS(context, hmsPort);
}
@Override
protected void after() {
if (hmsWatcher != null) {
hmsWatcher.cancel(true);
}
}
};
ExternalResource hiveShell = new ExternalResource() {
@Override
protected void before() throws Throwable {
container = createHiveServerContainer(getTestClass().getJavaClass(), context);
}
@Override
protected void after() {
tearDown();
}
};
rules.add(hiveShell);
rules.add(hms);
rules.add(temporaryFolder);
return rules;
}
public TestRule createTestRule() {
return new ExternalResource() {
JerseyServerBootstrap bootstrap = new JerseyServerBootstrap(jaxRsApplication);
protected void before() throws Throwable {
bootstrap.start();
}
protected void after() {
bootstrap.stop();
}
};
}
public TestRule createTestRule() {
return new ExternalResource() {
ResteasyServerBootstrap bootstrap = new ResteasyServerBootstrap(jaxRsApplication);
protected void before() throws Throwable {
bootstrap.start();
}
protected void after() {
bootstrap.stop();
}
};
}
public TestRule createTestRule() {
return new ExternalResource() {
JerseyServerBootstrap bootstrap = new JerseyServerBootstrap(jaxRsApplication);
protected void before() throws Throwable {
bootstrap.start();
}
protected void after() {
bootstrap.stop();
}
};
}
public TestRule createTestRule() {
return new ExternalResource() {
JerseyServerBootstrap bootstrap = new JerseyServerBootstrap(jaxRsApplication);
protected void before() throws Throwable {
bootstrap.start();
}
protected void after() {
bootstrap.stop();
}
};
}
public TestRule createTestRule() {
return new ExternalResource() {
CXFServerBootstrap bootstrap = new CXFServerBootstrap(jaxRsApplication);
protected void before() throws Throwable {
bootstrap.start();
}
protected void after() {
bootstrap.stop();
}
};
}
public TestRule createTestRule() {
return new ExternalResource() {
ResteasyServerBootstrap bootstrap = new ResteasyServerBootstrap(jaxRsApplication);
protected void before() throws Throwable {
bootstrap.start();
}
protected void after() {
bootstrap.stop();
}
};
}
@Override
public TestRule createRule() {
return new ExternalResource() {
};
}
@ClassRule
public static TestRule rule() {
return new ExternalResource() {
};
}