下面列出了怎么用org.junit.jupiter.params.provider.EnumSource.Mode的API类实例代码及写法,或者点击链接到github查看源代码。
@ParameterizedTest
@EnumSource(value = HttpMethod.class, mode = Mode.EXCLUDE, names = "UNKNOWN")
void emptyRequest(HttpMethod method) throws Exception {
try (ServerSocket ss = new ServerSocket(0)) {
final int port = ss.getLocalPort();
final WebClient client = WebClient.of("h1c://127.0.0.1:" + port);
client.execute(HttpRequest.of(method, "/")).aggregate();
try (Socket s = ss.accept()) {
final BufferedReader in = new BufferedReader(
new InputStreamReader(s.getInputStream(), StandardCharsets.US_ASCII));
assertThat(in.readLine()).isEqualTo(method.name() + " / HTTP/1.1");
assertThat(in.readLine()).startsWith("host: 127.0.0.1:");
assertThat(in.readLine()).startsWith("user-agent: armeria/");
if (hasContent(method)) {
assertThat(in.readLine()).isEqualTo("content-length: 0");
}
assertThat(in.readLine()).isEmpty();
}
}
}
@ParameterizedTest
@EnumSource(value = SessionProtocol.class, mode = Mode.EXCLUDE, names = { "HTTP", "HTTPS", "PROXY"})
void default_withRetryClient(SessionProtocol protocol) {
final HttpRequest request = HttpRequest.of(HttpMethod.GET, server2.uri(protocol) + "/retry");
final WebClient client = WebClient.builder()
.decorator(RetryingClient.newDecorator(RetryRule.failsafe()))
.factory(ClientFactory.insecure())
.build();
try (ClientRequestContextCaptor captor = Clients.newContextCaptor()) {
client.execute(request).aggregate().join();
final ClientRequestContext ctx = captor.get();
assertThat(ctx.sessionProtocol()).isEqualTo(protocol);
for (RequestLogAccess child : ctx.log().partial().children()) {
assertThat(child.partial().sessionProtocol()).isEqualTo(protocol);
}
}
}
@ParameterizedTest
@EnumSource(value = SftpCommand.class, mode = Mode.EXCLUDE, names = {"PUT", "PUT_FROM_FILE"})
void shouldNotSupportTwoParameters(SftpCommand command)
{
shouldNotSupportUnexpectedParameters(command, "Command %s doesn't support two parameters",
PARAM_1, PARAM_2);
}
@ParameterizedTest
@EnumSource(names = "SCENARIO", mode = Mode.EXCLUDE)
void shouldNotClearCookieStoreAfterScenario(CookieStoreLevel cookieStoreLevel)
{
CookieStoreProvider cookieStoreProvider = createProviderWithCookie(cookieStoreLevel);
cookieStoreProvider.resetScenarioCookies();
assertEquals(List.of(COOKIE), cookieStoreProvider.getCookieStore().getCookies());
}
@ParameterizedTest
@EnumSource(names = "STORY", mode = Mode.EXCLUDE)
void shouldNotClearCookieStoreAfterStory(CookieStoreLevel cookieStoreLevel)
{
CookieStoreProvider cookieStoreProvider = createProviderWithCookie(cookieStoreLevel);
cookieStoreProvider.resetStoryCookies();
assertEquals(List.of(COOKIE), cookieStoreProvider.getCookieStore().getCookies());
}
@ParameterizedTest
@EnumSource(value = VariableScope.class, mode = Mode.EXCLUDE, names = {"NEXT_BATCHES", "GLOBAL"})
void testPutVariable(VariableScope variableScope)
{
bddVariableContext.setTestContext(new SimpleTestContext());
Variables variables = new Variables();
when(variablesFactory.createVariables()).thenReturn(variables);
bddVariableContext.putVariable(variableScope, VARIABLE_KEY, VALUE);
verifyScopedVariable(variableScope, variables);
assertThat(logger.getLoggingEvents(), equalTo(List.of(
info(SAVE_MESSAGE_TEMPLATE, VALUE, variableScope, VARIABLE_KEY))));
}
@ParameterizedTest
@EnumSource(value = AriCommandType.class, mode = Mode.EXCLUDE, names = {"COMMAND_NOT_CREATING_A_NEW_RESOURCE"})
void ensureInvalidUriAndBodyResultInAFailure(AriCommandType type) {
assertAll(
String.format("Extractors for type=%s", type),
() -> assertThat(type.extractResourceIdFromUri(INVALID_COMMAND_URI).get(), instanceOf(Failure.class)),
() -> assertThat(type.extractResourceIdFromBody(INVALID_COMMAND_BODY).get(), instanceOf(Failure.class))
);
}
@ParameterizedTest
@EnumSource(value = AriMessageType.class, mode = Mode.EXCLUDE, names = {"STASIS_START", "STASIS_END"})
void verifyNoMetricsAreGatheredForTheSpecifiedEventTypes(AriMessageType type) {
final Seq<MetricsGatherer> decision = AriEventProcessing
.determineMetricsGatherer(type);
assertThat(
((IncreaseCounter) decision.get(0).withCallContextSupplier(() -> "CALL_CONTEXT")).getName(),
is(type.name())
);
}
@ParameterizedTest
@EnumSource(value = HttpMethod.class, mode = Mode.EXCLUDE, names = "UNKNOWN")
void default_withAbsolutePath(HttpMethod method) {
final HttpRequest request = HttpRequest.of(method, server2.httpUri() + "/simple-client");
final HttpResponse response = WebClient.of().execute(request);
assertThat(response.aggregate().join().status()).isEqualTo(OK);
}
@ParameterizedTest
@EnumSource(value = SessionProtocol.class, mode = Mode.EXCLUDE, names = "PROXY")
void default_withScheme(SessionProtocol protocol) {
final HttpRequest request = HttpRequest.of(HttpMethod.GET, server2.uri(protocol) + "/simple-client");
try (ClientRequestContextCaptor captor = Clients.newContextCaptor()) {
final WebClient client = WebClient.builder().factory(ClientFactory.insecure()).build();
final HttpResponse response = client.execute(request);
final ClientRequestContext ctx = captor.get();
assertThat(ctx.sessionProtocol()).isEqualTo(protocol);
assertThat(response.aggregate().join().status()).isEqualTo(OK);
}
}
@ParameterizedTest
@EnumSource(value = HttpMethod.class, mode = Mode.EXCLUDE, names = {"CONNECT", "UNKNOWN"})
void implemented(HttpMethod method) {
final AggregatedHttpResponse response = client.execute(HttpRequest.of(method, "/implemented"))
.aggregate().join();
assertThat(response.status()).isEqualTo(HttpStatus.OK);
// HEAD responses content stripped out by framework.
if (method != HttpMethod.HEAD) {
assertThat(response.contentUtf8()).isEqualTo(method.name().toLowerCase());
}
}
@ParameterizedTest
@EnumSource(value = PollingResult.class, names = "SUCCESS", mode = Mode.EXCLUDE)
public void testIfFreeIpaPollingServiceReturnsWithUnsuccessfulResultThenCreationFailedEventShouldBeSent(PollingResult pollingResult) {
EnvironmentDto environmentDto = someEnvironmentWithFreeIpaCreation();
Environment environment = mock(Environment.class);
when(environment.getCloudPlatform()).thenReturn(environmentDto.getCloudPlatform());
when(environment.isCreateFreeIpa()).thenReturn(environmentDto.getFreeIpaCreation().getCreate());
Pair<PollingResult, Exception> result = mock(Pair.class);
when(result.getKey()).thenReturn(pollingResult);
when(environmentService.findEnvironmentById(environmentDto.getId())).thenReturn(Optional.of(environment));
when(supportedPlatforms.supportedPlatformForFreeIpa(environmentDto.getCloudPlatform())).thenReturn(true);
when(connectors.getDefault(any())).thenReturn(mock(CloudConnector.class));
when(freeIpaPollingService.pollWithTimeout(
any(FreeIpaCreationRetrievalTask.class),
any(FreeIpaPollerObject.class),
anyLong(),
anyInt(),
anyInt()))
.thenReturn(result);
victim.accept(new Event<>(environmentDto));
verify(eventBus).notify(anyString(), any(Event.class));
verify(environmentService, times(1)).findEnvironmentById(anyLong());
verify(environmentService, times(1)).findEnvironmentById(environmentDto.getId());
verify(supportedPlatforms, times(1)).supportedPlatformForFreeIpa(anyString());
verify(supportedPlatforms, times(1)).supportedPlatformForFreeIpa(environmentDto.getCloudPlatform());
verify(freeIpaPollingService, times(1)).pollWithTimeout(
any(FreeIpaCreationRetrievalTask.class),
any(FreeIpaPollerObject.class),
anyLong(),
anyInt(),
anyInt());
}
@ParameterizedTest
@EnumSource(names = {"SEVERITY", "EPIC", "FEATURE"}, mode = Mode.INCLUDE)
void shouldNotCreateLink(VividusLabel vividusLabel)
{
assertEquals(Optional.empty(), vividusLabel.createLink("any"));
}
@ParameterizedTest
@EnumSource(value = SftpCommand.class, mode = Mode.EXCLUDE, names = "PWD")
void shouldNotSupportZeroParameters(SftpCommand command)
{
shouldNotSupportUnexpectedParameters(command, "Command %s requires parameter(s)");
}
@ParameterizedTest
@EnumSource(value = SftpCommand.class, mode = Mode.INCLUDE, names = { "PWD", "PUT" })
void shouldNotSupportSingleParameter(SftpCommand command)
{
shouldNotSupportUnexpectedParameters(command, "Command %s doesn't support single parameter", PARAM_1);
}
@ParameterizedTest
@EnumSource(value = AriMessageType.class, mode = Mode.INCLUDE, names = { "APPLICATION_REPLACED" })
void ensureMessageTypesWithoutAnExtractorResultInANone(AriMessageType type) {
assertThat(type.extractResourceIdFromBody(mock(JsonNode.class)), is(None()));
}
@ParameterizedTest(name = " 0 {0} is not compatible with unit") // #163
@EnumSource(value = Metric.class, names = "UNIT", mode = Mode.EXCLUDE)
void zeroMetricIsNotCompatibleWithAnyOther(Metric metric) {
assertThat(Quantity.of(0, metric).isCompatibleWith(Metric.UNIT)).isFalse();
}