org.junit.jupiter.api.extension.ParameterContext Java Examples
The following examples show how to use
org.junit.jupiter.api.extension.ParameterContext.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MemoryQuotaSearchTestSystemExtension.java From james-project with Apache License 2.0 | 6 votes |
@Override public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { try { InMemoryIntegrationResources resources = InMemoryIntegrationResources.defaultResources(); DNSService dnsService = mock(DNSService.class); MemoryDomainList domainList = new MemoryDomainList(dnsService); MemoryUsersRepository usersRepository = MemoryUsersRepository.withVirtualHosting(domainList); QuotaComponents quotaComponents = resources.getMailboxManager().getQuotaComponents(); return new QuotaSearchTestSystem( quotaComponents.getMaxQuotaManager(), resources.getMailboxManager(), quotaComponents.getQuotaManager(), resources.getDefaultUserQuotaRootResolver(), new ScanningQuotaSearcher(usersRepository, new ClauseConverter(resources.getDefaultUserQuotaRootResolver(), quotaComponents.getQuotaManager())), usersRepository, domainList, resources.getCurrentQuotaManager(), NO_AWAIT); } catch (Exception e) { throw new ParameterResolutionException("Error while resolving parameter", e); } }
Example #2
Source File: JsonSchemaValidatorExtension.java From vertx-web with Apache License 2.0 | 6 votes |
@Override public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { Class<?> type = parameterContext.getParameter().getType(); ExtensionContext.Store store = extensionContext.getStore(ExtensionContext.Namespace.create(JsonSchemaValidatorExtension.class, extensionContext)); if (SchemaRouter.class.equals(type)) return getRouter(extensionContext, store); if (Draft7SchemaParser.class.equals(type) || SchemaParser.class.equals(type)) return store.getOrComputeIfAbsent( DRAFT7_PARSER, s -> Draft7SchemaParser.create(getRouter(extensionContext, store)), Draft7SchemaParser.class ); if (OpenAPI3SchemaParser.class.equals(type)) return store.getOrComputeIfAbsent( OPENAPI3_PARSER, s -> OpenAPI3SchemaParser.create(getRouter(extensionContext, store)), OpenAPI3SchemaParser.class ); throw new IllegalStateException("Looks like the ParameterResolver needs a fix..."); }
Example #3
Source File: FlowableDmnExtension.java From flowable-engine with Apache License 2.0 | 6 votes |
@Override public Object resolveParameter(ParameterContext parameterContext, ExtensionContext context) { FlowableDmnTestHelper flowableTestHelper = getTestHelper(context); if (parameterContext.isAnnotated(DmnDeploymentId.class)) { return flowableTestHelper.getDeploymentIdFromDeploymentAnnotation(); } Class<?> parameterType = parameterContext.getParameter().getType(); DmnEngine dmnEngine = flowableTestHelper.getDmnEngine(); if (parameterType.isInstance(dmnEngine)) { return dmnEngine; } else if (FlowableDmnTestHelper.class.equals(parameterType)) { return flowableTestHelper; } try { return DmnEngine.class.getDeclaredMethod("get" + parameterType.getSimpleName()).invoke(dmnEngine); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) { throw new ParameterResolutionException("Could not find service " + parameterType, ex); } }
Example #4
Source File: RemoteActionCodeTest.java From triplea with GNU General Public License v3.0 | 6 votes |
@Override public Method aggregateArguments( final ArgumentsAccessor arguments, final ParameterContext context) throws ArgumentsAggregationException { // Ignore CSV columns that are already used by different parameters final int offset = context.getIndex(); final Class<?> remoteInterface = arguments.get(offset, Class.class); final String methodName = arguments.getString(offset + 1); final Class<?>[] argumentTypes = IntStream.range(offset + 2, arguments.size()) .mapToObj(i -> arguments.get(i, Class.class)) .toArray(Class<?>[]::new); try { return remoteInterface.getMethod(methodName, argumentTypes); } catch (final NoSuchMethodException e) { throw new ArgumentsAggregationException("Invalid method specified", e); } }
Example #5
Source File: FlowableCmmnExtension.java From flowable-engine with Apache License 2.0 | 6 votes |
@Override public Object resolveParameter(ParameterContext parameterContext, ExtensionContext context) { FlowableCmmnTestHelper flowableTestHelper = getTestHelper(context); if (parameterContext.isAnnotated(CmmnDeploymentId.class)) { return flowableTestHelper.getDeploymentIdFromDeploymentAnnotation(); } Class<?> parameterType = parameterContext.getParameter().getType(); CmmnEngine cmmnEngine = flowableTestHelper.getCmmnEngine(); if (parameterType.isInstance(cmmnEngine)) { return cmmnEngine; } else if (FlowableCmmnTestHelper.class.equals(parameterType)) { return flowableTestHelper; } try { return CmmnEngine.class.getDeclaredMethod("get" + parameterType.getSimpleName()).invoke(cmmnEngine); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) { throw new ParameterResolutionException("Could not find service " + parameterType, ex); } }
Example #6
Source File: FlowableEventExtension.java From flowable-engine with Apache License 2.0 | 6 votes |
@Override public Object resolveParameter(ParameterContext parameterContext, ExtensionContext context) { FlowableEventTestHelper flowableTestHelper = getTestHelper(context); if (parameterContext.isAnnotated(EventDeploymentId.class)) { return flowableTestHelper.getDeploymentIdFromDeploymentAnnotation(); } Class<?> parameterType = parameterContext.getParameter().getType(); EventRegistryEngine eventRegistryEngine = flowableTestHelper.getEventRegistryEngine(); if (parameterType.isInstance(eventRegistryEngine)) { return eventRegistryEngine; } else if (FlowableEventTestHelper.class.equals(parameterType)) { return flowableTestHelper; } try { return EventRegistryEngine.class.getDeclaredMethod("get" + parameterType.getSimpleName()).invoke(eventRegistryEngine); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException ex) { throw new ParameterResolutionException("Could not find service " + parameterType, ex); } }
Example #7
Source File: WeldJunit5Extension.java From weld-junit with Apache License 2.0 | 5 votes |
private List<Annotation> resolveQualifiers(ParameterContext pc, BeanManager bm) { List<Annotation> qualifiers = new ArrayList<>(); if (pc.getParameter().getAnnotations().length == 0) { return Collections.emptyList(); } else { for (Annotation annotation : pc.getParameter().getAnnotations()) { // use BeanManager.isQualifier to be able to detect custom qualifiers which don't need to have @Qualifier if (bm.isQualifier(annotation.annotationType())) { qualifiers.add(annotation); } } } return qualifiers; }
Example #8
Source File: TempDirectoryExtension.java From incubator-tuweni with Apache License 2.0 | 5 votes |
@Override public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { if (tempDirectory == null) { try { tempDirectory = createTempDirectory(extensionContext.getRequiredTestClass().getSimpleName()); } catch (IOException e) { throw new UncheckedIOException(e); } } return tempDirectory; }
Example #9
Source File: VertxExtension.java From incubator-tuweni with Apache License 2.0 | 5 votes |
@Override public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { if (vertx == null) { System.setProperty("vertx.disableFileCPResolving", "true"); vertx = Vertx.vertx(); } return vertx; }
Example #10
Source File: TemporaryFolderExtension.java From p4ic4idea with Apache License 2.0 | 5 votes |
@Override public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { try { return createFolder(extensionContext); } catch (IOException e) { throw new ParameterResolutionException("could not make tmp folder", e); } }
Example #11
Source File: CassandraEventSourcingDLPConfigurationStoreExtension.java From james-project with Apache License 2.0 | 5 votes |
@Override public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { JsonEventSerializer jsonEventSerializer = JsonEventSerializer .forModules(DLPConfigurationModules.DLP_CONFIGURATION_STORE, DLPConfigurationModules.DLP_CONFIGURATION_CLEAR) .withoutNestedType(); EventStoreDao eventStoreDao = new EventStoreDao( cassandraExtension.getCassandraCluster().getConf(), jsonEventSerializer, cassandraExtension.getCassandraConsistenciesConfiguration()); return new EventSourcingDLPConfigurationStore(new CassandraEventStore(eventStoreDao)); }
Example #12
Source File: SpringExtension.java From spring-analysis-note with MIT License | 5 votes |
/** * Resolve a value for the {@link Parameter} in the supplied {@link ParameterContext} by * retrieving the corresponding dependency from the test's {@link ApplicationContext}. * <p>Delegates to {@link ParameterResolutionDelegate#resolveDependency}. * @see #supportsParameter * @see ParameterResolutionDelegate#resolveDependency */ @Override @Nullable public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) { Parameter parameter = parameterContext.getParameter(); int index = parameterContext.getIndex(); Class<?> testClass = extensionContext.getRequiredTestClass(); ApplicationContext applicationContext = getApplicationContext(extensionContext); return ParameterResolutionDelegate.resolveDependency(parameter, index, testClass, applicationContext.getAutowireCapableBeanFactory()); }
Example #13
Source File: CriteriaGeneratedClassNameParameterResolver.java From doma with Apache License 2.0 | 5 votes |
@Override public Object resolveParameter( ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { if (clazz.isAnnotationPresent(Entity.class)) { return ClassNames.newEntityMetamodelClassNameBuilder(clazz.getName(), prefix, suffix) .toString(); } throw new AssertionFailedError("annotation not found."); }
Example #14
Source File: ParameterHolder.java From GitToolBox with Apache License 2.0 | 5 votes |
Optional<Object> get(ParameterContext parameterContext) { return storage.entrySet().stream() .filter(entry -> entry.getKey().matches(parameterContext)) .findAny() .map(Map.Entry::getValue) .map(provider -> provider.apply(parameterContext)); }
Example #15
Source File: ClassName_ParameterResolver.java From JUnit-5-Quick-Start-Guide-and-Framework-Support with MIT License | 5 votes |
/** * Simple example that simply resolves the Parameter by returning the Class-Name based on the Parameter-Context. */ @Override public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { Class<?> contextClass = extensionContext.getTestClass().orElse(null); return contextClass == null ? null : contextClass.getSimpleName(); }
Example #16
Source File: CassandraClusterExtension.java From james-project with Apache License 2.0 | 5 votes |
@Override public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { Class<?> paramType = parameterContext.getParameter().getType(); if (paramType.isAssignableFrom(CassandraCluster.class)) { return cassandraCluster; } else if (paramType.isAssignableFrom(DockerCassandra.class)) { return DockerCassandraSingleton.singleton; } throw new IllegalArgumentException("Unsupported parameter type " + paramType.getName()); }
Example #17
Source File: SeleniumExtension.java From selenium-jupiter with Apache License 2.0 | 5 votes |
private DriverHandler getDriverHandler(ParameterContext parameterContext, ExtensionContext extensionContext, Parameter parameter, Class<?> type, Browser browser, Class<?> constructorClass, boolean isRemote) { DriverHandler driverHandler = null; try { driverHandler = getDriverHandler(extensionContext, parameter, type, constructorClass, browser, isRemote); Optional<DockerBrowser> dockerBrowser = annotationsReader .getDocker(parameter); String contextId = extensionContext.getUniqueId(); if (type.equals(RemoteWebDriver.class) || type.equals(WebDriver.class) || type.equals(List.class) || (dockerBrowser.isPresent() && type.equals(SelenideDriver.class))) { initHandlerForDocker(contextId, driverHandler); } boolean isTemplate = isTestTemplate(extensionContext); if (!isTemplate && isGeneric(type) && isRemote) { ((RemoteDriverHandler) driverHandler).setParent(this); ((RemoteDriverHandler) driverHandler) .setParameterContext(parameterContext); } putDriverHandlerInMap(extensionContext.getUniqueId(), driverHandler); } catch (Exception e) { handleException(parameter, driverHandler, constructorClass, e); } return driverHandler; }
Example #18
Source File: SeleniumExtension.java From selenium-jupiter with Apache License 2.0 | 5 votes |
@Override public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) { Class<?> type = parameterContext.getParameter().getType(); return (WebDriver.class.isAssignableFrom(type) || type.equals(List.class) || type.equals(SelenideDriver.class)) && !isTestTemplate(extensionContext); }
Example #19
Source File: WeldJunit5Extension.java From weld-junit with Apache License 2.0 | 5 votes |
@Override public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { // we did our checks in supportsParameter() method, now we can do simple resolution if (getContainerFromStore(extensionContext) != null) { List<Annotation> qualifiers = resolveQualifiers(parameterContext, getContainerFromStore(extensionContext).getBeanManager()); return getContainerFromStore(extensionContext) .select(parameterContext.getParameter().getType(), qualifiers.toArray(new Annotation[qualifiers.size()])).get(); } return null; }
Example #20
Source File: BrokerPropertiesParameterResolver.java From spring-cloud-app-broker with Apache License 2.0 | 5 votes |
@SuppressWarnings("PMD.AvoidUncheckedExceptionsInSignatures") @Override public BrokerProperties resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { String[] properties = getValueHolderProperties(extensionContext); return new BrokerProperties(properties); }
Example #21
Source File: JunitServerExtensionTest.java From junit-servers with MIT License | 5 votes |
@Test void it_should_resolve_http_client_parameter_with_auto_strategy() throws Exception { final FixtureClass testInstance = new FixtureClass(); final FakeExtensionContext context = new FakeExtensionContext(testInstance); final JunitServerExtension extension = initializeExtension(context); final ParameterContext parameterContext = createParameterContext("method_http_client", HttpClient.class); final Object result = extension.resolveParameter(parameterContext, context); assertThat(result).isNotNull().isInstanceOf(HttpClient.class); }
Example #22
Source File: GuiceExtension.java From junit5-extensions with MIT License | 5 votes |
@Override public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { Parameter parameter = parameterContext.getParameter(); Key<?> key = getKey(extensionContext.getTestClass(), parameter); Injector injector = getInjectorForParameterResolution(extensionContext) .orElseThrow(() -> new ParameterResolutionException( String.format( "Could not create injector for: %s It has no annotated element.", extensionContext.getDisplayName()))); return injector.getInstance(key); }
Example #23
Source File: CommandRuleExtension.java From resp-server with MIT License | 5 votes |
@Override public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { CommandRule commandRule = new CommandRule( parameterContext.getTarget().orElseThrow(() -> new ParameterResolutionException("no target"))); commandRule.init(); return commandRule; }
Example #24
Source File: ClassArgumentConverter.java From junit5-extensions with MIT License | 5 votes |
@SuppressWarnings("unchecked") @Override public Object convert(Object input, ParameterContext context) throws ArgumentConversionException { TypeToken<?> parameterType = TypeToken.of(context.getParameter().getParameterizedType()); if (parameterType.getRawType() != Class.class) { throw new ArgumentConversionException( String.format("Could not convert: %s. Invalid parameter type.", input)); } return convert(input.toString(), (TypeToken<? extends Class<?>>) parameterType); }
Example #25
Source File: ValidPersonParameterResolver.java From tutorials with MIT License | 5 votes |
@Override public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { Object ret = null; // // Return a random, valid Person object if Person.class is the type of Parameter /// to be resolved. Otherwise return null. if (parameterContext.getParameter() .getType() == Person.class) { ret = VALID_PERSONS[new Random().nextInt(VALID_PERSONS.length)]; } return ret; }
Example #26
Source File: VaultExtension.java From spring-vault with Apache License 2.0 | 4 votes |
@Override public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { return getInitializer(extensionContext); }
Example #27
Source File: GuiceExtensionTest.java From junit5-extensions with MIT License | 4 votes |
@Override public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { return parameterContext.getParameter().getType() == String[].class; }
Example #28
Source File: MyParameterResolver.java From Mastering-Software-Testing-with-JUnit-5 with MIT License | 4 votes |
@Override public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { return true; }
Example #29
Source File: RabbitMQExtension.java From james-project with Apache License 2.0 | 4 votes |
@Override public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { return rabbitMQ; }
Example #30
Source File: IdeaMocksExtension.java From GitToolBox with Apache License 2.0 | 4 votes |
@Override public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { return RESOLVER.resolveParameter(parameterContext, extensionContext); }