下面列出了org.junit.jupiter.api.extension.ExtensionContext#Store() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void afterAll(ExtensionContext context) throws Exception {
ExtensionContext.Store store = context.getStore(ExtensionContext.Namespace.create(TempDirectoryExtension.class, app.jweb.test.impl.TempDirectory.class));
app.jweb.test.impl.TempDirectory tempDirectory = (app.jweb.test.impl.TempDirectory) store.get(app.jweb.test.impl.TempDirectory.class);
if (tempDirectory != null) {
tempDirectory.delete();
}
}
@Override
public void beforeEach(final ExtensionContext context) {
final ComponentPackage config = context.getElement().get().getAnnotation(ComponentPackage.class);
final ExtensionContext.Store store = context.getStore(NAMESPACE);
final File pluginDir =
new File(TemporaryFolder.class.cast(store.get(TemporaryFolder.class.getName())).getRoot() + "/"
+ context.getRequiredTestMethod().getName());
final ComponentValidator.Configuration cfg = new ComponentValidator.Configuration();
cfg.setValidateFamily(true);
cfg.setValidateSerializable(true);
cfg.setValidateMetadata(true);
cfg.setValidateInternationalization(true);
cfg.setValidateDataSet(config.validateDataSet());
cfg.setValidateActions(true);
cfg.setValidateComponent(true);
cfg.setValidateModel(true);
cfg.setValidateDataStore(true);
cfg.setValidateLayout(true);
cfg.setValidateOptionNames(true);
cfg.setValidateLocalConfiguration(true);
cfg.setValidateOutputConnection(true);
cfg.setValidatePlaceholder(true);
cfg.setValidateSvg(config.validateSvg());
cfg.setValidateNoFinalOption(true);
cfg.setValidateDocumentation(config.validateDocumentation());
cfg.setValidateWording(config.validateWording());
Optional.of(config.pluginId()).filter(it -> !it.isEmpty()).ifPresent(cfg::setPluginId);
listPackageClasses(pluginDir, config.value().replace('.', '/'));
store.put(ComponentPackage.class.getName(), config);
final TestLog log = new TestLog();
store.put(TestLog.class.getName(), log);
store.put(ComponentValidator.class.getName(), new ComponentValidator(cfg, new File[] { pluginDir }, log));
store.put(ExceptionSpec.class.getName(), new ExceptionSpec());
}
@Override
public void beforeAll(final ExtensionContext extensionContext) throws Exception {
temporaryFolderExtension.beforeAll(extensionContext);
root = TemporaryFolder.class
.cast(temporaryFolderExtension.findInstance(extensionContext, TemporaryFolder.class))
.getRoot();
final ExtensionContext.Store store = extensionContext.getStore(NAMESPACE);
store.put(BaseSpark.class.getName(), this);
AnnotationUtils.findAnnotation(extensionContext.getElement(), WithSpark.class).ifPresent(ws -> {
withSlaves(ws.slaves());
withHadoopBase(ws.hadoopBase());
withHadoopVersion(ws.hadoopVersion());
withInstallWinUtils(ws.installWinUtils());
withScalaVersion(of(ws.scalaVersion())
.filter(it -> !"auto".equals(it))
.orElse(SparkVersions.SPARK_SCALA_VERSION.getValue()));
withSparkVersion(of(ws.sparkVersion())
.filter(it -> !"auto".equals(it))
.orElse(SparkVersions.SPARK_VERSION.getValue()));
});
final Instances instances = start();
if (instances.getException() != null) {
instances.close();
if (Exception.class.isInstance(instances.getException())) {
throw Exception.class.cast(instances.getException());
}
if (Error.class.isInstance(instances.getException())) {
throw Error.class.cast(instances.getException());
}
throw new IllegalStateException(instances.getException());
}
store.put(AutoCloseable.class, instances);
}
@Override
public void beforeAll(final ExtensionContext context) {
final ExtensionContext.Store store = context.getStore(NAMESPACE);
store.put(MonoBase.Instance.class, BASE.startIfNeeded());
if (isPerClass(context)) {
doInject(context);
store.put(LifecyleState.class, onInjection(context, null));
}
}
@Override
public void afterAll(final ExtensionContext context) {
final ExtensionContext.Store store = context.getStore(NAMESPACE);
ofNullable(store.get(LifecyleState.class, LifecyleState.class))
.ifPresent(s -> s.afterLastTest(context));
if (isPerClass(context)) {
store.get(Meecrowave.class, Meecrowave.class).close();
}
}
private ExtensionContext.Store getStore(ExtensionContext context) {
return context.getStore(ExtensionContext.Namespace.create(getClass(), context.getRequiredTestMethod()));
}
protected ExtensionContext.Store getStore(ExtensionContext context) {
return context.getRoot().getStore(NAMESPACE);
}
@Override
protected ExtensionContext.Store getStore(ExtensionContext context) {
return context.getRoot().getStore(NAMESPACE);
}
@Override
protected ExtensionContext.Store getStore(ExtensionContext context) {
return context.getRoot().getStore(NAMESPACE);
}
private ExtensionContext.Store getLocalExtensionStore(final ExtensionContext context) {
// test scoped extension scope (required to differentiate nested classes or parameterized executions)
return context.getStore(ExtensionContext.Namespace
.create(GuiceyExtensionsSupport.class, context.getRequiredTestClass()));
}
protected ExtensionContext.Store getStore(ExtensionContext context) {
return context.getRoot().getStore(NAMESPACE);
}
@Override
protected ExtensionContext.Store getStore(ExtensionContext context) {
return context.getRoot().getStore(NAMESPACE);
}
@Override
public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException {
ExtensionContext.Store store = extensionContext.getStore(ExtensionContext.Namespace.create(TempDirectoryExtension.class, app.jweb.test.impl.TempDirectory.class));
app.jweb.test.impl.TempDirectory tempDirectory = (app.jweb.test.impl.TempDirectory) store.getOrComputeIfAbsent(app.jweb.test.impl.TempDirectory.class, key -> new app.jweb.test.impl.TempDirectory());
return tempDirectory.root();
}
protected ExtensionContext.Store getStore(ExtensionContext context) {
return context.getRoot().getStore(NAMESPACE);
}
private ExtensionContext.Store getStore(ExtensionContext context) {
return context.getStore(ExtensionContext.Namespace.create(getClass(), context.getRequiredTestMethod()));
}
public static void removeHolder(ExtensionContext.Store store) {
store.remove(ParameterHolder.class);
}
private VaultInitializer getInitializer(ExtensionContext extensionContext) {
ExtensionContext.Store store = extensionContext.getStore(VAULT);
return store.getOrComputeIfAbsent(VaultInitializer.class, k -> new VaultInitializer(), VaultInitializer.class);
}
@Override
protected ExtensionContext.Store getStore(ExtensionContext context) {
return context.getRoot().getStore(NAMESPACE);
}
protected abstract ExtensionContext.Store getStore(ExtensionContext context);
protected abstract ExtensionContext.Store getStore(ExtensionContext context);