org.junit.jupiter.params.provider.EnumSource.Mode Java Examples

The following examples show how to use org.junit.jupiter.params.provider.EnumSource.Mode. 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: Http1EmptyRequestTest.java    From armeria with Apache License 2.0 6 votes vote down vote up
@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();
        }
    }
}
 
Example #2
Source File: HttpClientRequestPathTest.java    From armeria with Apache License 2.0 6 votes vote down vote up
@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);
        }
    }
}
 
Example #3
Source File: FreeIpaCreationHandlerTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #4
Source File: SftpCommandTests.java    From vividus with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #5
Source File: CookieStoreProviderTests.java    From vividus with Apache License 2.0 5 votes vote down vote up
@ParameterizedTest
@EnumSource(names = "SCENARIO", mode = Mode.EXCLUDE)
void shouldNotClearCookieStoreAfterScenario(CookieStoreLevel cookieStoreLevel)
{
    CookieStoreProvider cookieStoreProvider = createProviderWithCookie(cookieStoreLevel);
    cookieStoreProvider.resetScenarioCookies();
    assertEquals(List.of(COOKIE), cookieStoreProvider.getCookieStore().getCookies());
}
 
Example #6
Source File: CookieStoreProviderTests.java    From vividus with Apache License 2.0 5 votes vote down vote up
@ParameterizedTest
@EnumSource(names = "STORY", mode = Mode.EXCLUDE)
void shouldNotClearCookieStoreAfterStory(CookieStoreLevel cookieStoreLevel)
{
    CookieStoreProvider cookieStoreProvider = createProviderWithCookie(cookieStoreLevel);
    cookieStoreProvider.resetStoryCookies();
    assertEquals(List.of(COOKIE), cookieStoreProvider.getCookieStore().getCookies());
}
 
Example #7
Source File: BddVariableContextTests.java    From vividus with Apache License 2.0 5 votes vote down vote up
@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))));
}
 
Example #8
Source File: AriCommandTypeTest.java    From ari-proxy with GNU Affero General Public License v3.0 5 votes vote down vote up
@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))
	);
}
 
Example #9
Source File: AbstractPooledHttpServiceTest.java    From armeria with Apache License 2.0 5 votes vote down vote up
@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());
    }
}
 
Example #10
Source File: AriEventProcessingTest.java    From ari-proxy with GNU Affero General Public License v3.0 5 votes vote down vote up
@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())
	);
}
 
Example #11
Source File: HttpClientRequestPathTest.java    From armeria with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #12
Source File: HttpClientRequestPathTest.java    From armeria with Apache License 2.0 5 votes vote down vote up
@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);
    }
}
 
Example #13
Source File: AriMessageTypeTest.java    From ari-proxy with GNU Affero General Public License v3.0 4 votes vote down vote up
@ParameterizedTest
@EnumSource(value = AriMessageType.class, mode = Mode.INCLUDE, names = { "APPLICATION_REPLACED" })
void ensureMessageTypesWithoutAnExtractorResultInANone(AriMessageType type) {
	assertThat(type.extractResourceIdFromBody(mock(JsonNode.class)), is(None()));
}
 
Example #14
Source File: QuantityUnitTests.java    From salespoint with Apache License 2.0 4 votes vote down vote up
@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();
}
 
Example #15
Source File: VividusLabelTests.java    From vividus with Apache License 2.0 4 votes vote down vote up
@ParameterizedTest
@EnumSource(names = {"SEVERITY", "EPIC", "FEATURE"}, mode = Mode.INCLUDE)
void shouldNotCreateLink(VividusLabel vividusLabel)
{
    assertEquals(Optional.empty(), vividusLabel.createLink("any"));
}
 
Example #16
Source File: SftpCommandTests.java    From vividus with Apache License 2.0 4 votes vote down vote up
@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);
}
 
Example #17
Source File: SftpCommandTests.java    From vividus with Apache License 2.0 4 votes vote down vote up
@ParameterizedTest
@EnumSource(value = SftpCommand.class, mode = Mode.EXCLUDE, names = "PWD")
void shouldNotSupportZeroParameters(SftpCommand command)
{
    shouldNotSupportUnexpectedParameters(command, "Command %s requires parameter(s)");
}