org.junit.platform.commons.util.StringUtils Java Examples

The following examples show how to use org.junit.platform.commons.util.StringUtils. 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: DisabledOnNativeImageCondition.java    From quarkus with Apache License 2.0 6 votes vote down vote up
/**
 * Containers/tests are disabled if {@code @DisabledOnNativeImage} is present on the test
 * class or method and we're running on a native image.
 */
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
    Optional<AnnotatedElement> element = context.getElement();
    Optional<DisabledOnNativeImage> disabled = findAnnotation(element, DisabledOnNativeImage.class);
    if (disabled.isPresent()) {
        // Cannot use ExtensionState here because this condition needs to be evaluated before QuarkusTestExtension
        boolean nativeImage = findAnnotation(context.getTestClass(), NativeImageTest.class).isPresent();
        if (nativeImage) {
            String reason = disabled.map(DisabledOnNativeImage::value)
                    .filter(StringUtils::isNotBlank)
                    .orElseGet(() -> element.get() + " is @DisabledOnNativeImage");
            return ConditionEvaluationResult.disabled(reason);
        }
    }
    return ENABLED;
}
 
Example #2
Source File: ExposedEndpointsControllerTest.java    From blackduck-alert with Apache License 2.0 6 votes vote down vote up
@Test
public void getTest() {
    RequestMappingHandlerMapping handlerMapping = Mockito.mock(RequestMappingHandlerMapping.class);
    ExposedEndpointsController controller = new ExposedEndpointsController(new Gson(), handlerMapping);

    String endpoint1 = "/api/test";
    String endpoint2 = "/api/other/test";

    Map<RequestMappingInfo, HandlerMethod> handlerMethods = new HashMap<>();
    RequestMappingInfo info = new RequestMappingInfo(new PatternsRequestCondition(endpoint1, endpoint2), new RequestMethodsRequestCondition(RequestMethod.GET, RequestMethod.POST), null, null, null, null, null);
    handlerMethods.put(info, null);

    Mockito.when(handlerMapping.getHandlerMethods()).thenReturn(handlerMethods);

    ResponseEntity<String> responseEntity = controller.get();
    Assertions.assertTrue(StringUtils.isNotBlank(responseEntity.getBody()), "Expected the response body to contain json");
}
 
Example #3
Source File: AMatrixHttpClientLoginTest.java    From matrix-java-sdk with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void loginWithDeviceIdAndLogout() throws URISyntaxException {
    MatrixHomeserver hs = new MatrixHomeserver(domain, baseUrl);
    MatrixClientContext context = new MatrixClientContext(hs);
    MatrixHttpClient client = new MatrixHttpClient(context);

    MatrixPasswordCredentials credentials = new MatrixPasswordCredentials(user.getLocalPart(), password);
    client.login(credentials);

    String deviceId = client.getDeviceId().get();

    client.logout();

    context = new MatrixClientContext(hs).setDeviceId(deviceId);
    client = new MatrixHttpClient(context);
    client.login(credentials);

    assertTrue(StringUtils.isNotBlank(client.getAccessToken().get()));
    assertTrue(StringUtils.isNotBlank(client.getDeviceId().get()));
    assertTrue(StringUtils.isNotBlank(client.getUser().get().getId()));
    assertEquals(deviceId, client.getDeviceId().get());

    client.logout();
}
 
Example #4
Source File: PasswordResetServiceTest.java    From blackduck-alert with Apache License 2.0 5 votes vote down vote up
@Test
@Tag(TestTags.CUSTOM_EXTERNAL_CONNECTION)
public void resetPasswordValidTestIT() throws AlertException {
    TestProperties testProperties = new TestProperties();
    Map<String, ConfigurationFieldModel> keyToFieldMap = new HashMap<>();

    String mailSmtpHost = testProperties.getProperty(TestPropertyKey.TEST_EMAIL_SMTP_HOST);
    String mailSmtpFrom = testProperties.getProperty(TestPropertyKey.TEST_EMAIL_SMTP_FROM);
    assumeTrue(StringUtils.isNotBlank(mailSmtpHost) && StringUtils.isNotBlank(mailSmtpFrom), "Minimum email properties not configured");
    addConfigurationFieldToMap(keyToFieldMap, EmailPropertyKeys.JAVAMAIL_HOST_KEY.getPropertyKey(), mailSmtpHost);
    addConfigurationFieldToMap(keyToFieldMap, EmailPropertyKeys.JAVAMAIL_FROM_KEY.getPropertyKey(), mailSmtpFrom);

    addConfigurationFieldToMap(keyToFieldMap, EmailPropertyKeys.JAVAMAIL_USER_KEY.getPropertyKey(), testProperties.getProperty(TestPropertyKey.TEST_EMAIL_SMTP_USER));
    addConfigurationFieldToMap(keyToFieldMap, EmailPropertyKeys.JAVAMAIL_PASSWORD_KEY.getPropertyKey(), testProperties.getProperty(TestPropertyKey.TEST_EMAIL_SMTP_PASSWORD));
    addConfigurationFieldToMap(keyToFieldMap, EmailPropertyKeys.JAVAMAIL_EHLO_KEY.getPropertyKey(), testProperties.getProperty(TestPropertyKey.TEST_EMAIL_SMTP_EHLO));
    addConfigurationFieldToMap(keyToFieldMap, EmailPropertyKeys.JAVAMAIL_AUTH_KEY.getPropertyKey(), testProperties.getProperty(TestPropertyKey.TEST_EMAIL_SMTP_AUTH));
    addConfigurationFieldToMap(keyToFieldMap, EmailPropertyKeys.JAVAMAIL_PORT_KEY.getPropertyKey(), testProperties.getProperty(TestPropertyKey.TEST_EMAIL_SMTP_PORT));

    String username = "username";
    UserModel userModel = UserModel.newUser(username, "", "[email protected]", AuthenticationType.DATABASE, Set.of(), true);
    DefaultUserAccessor userAccessor = Mockito.mock(DefaultUserAccessor.class);
    Mockito.when(userAccessor.getUser(Mockito.eq(username))).thenReturn(Optional.of(userModel));
    Mockito.when(userAccessor.changeUserPassword(Mockito.eq(username), Mockito.anyString())).thenReturn(true);

    ConfigurationModel emailConfig = Mockito.mock(ConfigurationModel.class);
    Mockito.when(emailConfig.getCopyOfKeyToFieldMap()).thenReturn(keyToFieldMap);

    ConfigurationAccessor baseConfigurationAccessor = Mockito.mock(ConfigurationAccessor.class);
    Mockito.when(baseConfigurationAccessor.getConfigurationsByDescriptorKeyAndContext(Mockito.eq(EMAIL_CHANNEL_KEY), Mockito.eq(ConfigContextEnum.GLOBAL))).thenReturn(List.of(emailConfig));

    TestAlertProperties alertProperties = new TestAlertProperties();
    FreemarkerTemplatingService freemarkerTemplatingService = new FreemarkerTemplatingService();
    PasswordResetService passwordResetService = new PasswordResetService(alertProperties, userAccessor, baseConfigurationAccessor, freemarkerTemplatingService, EMAIL_CHANNEL_KEY);
    passwordResetService.resetPassword(username);
}
 
Example #5
Source File: AMatrixHttpClientLoginTest.java    From matrix-java-sdk with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void loginAndLogout() throws URISyntaxException {
    MatrixHomeserver hs = new MatrixHomeserver(domain, baseUrl);
    MatrixClientContext context = new MatrixClientContext(hs);
    MatrixHttpClient client = new MatrixHttpClient(context);

    MatrixPasswordCredentials credentials = new MatrixPasswordCredentials(user.getLocalPart(), password);
    client.login(credentials);

    assertTrue(StringUtils.isNotBlank(client.getAccessToken().get()));
    assertTrue(StringUtils.isNotBlank(client.getDeviceId().get()));
    assertTrue(StringUtils.isNotBlank(client.getUser().get().getId()));

    client.logout();
}
 
Example #6
Source File: AMatrixHttpClientLoginTest.java    From matrix-java-sdk with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void loginWithDeviceNameAndLogout() {
    MatrixHomeserver hs = new MatrixHomeserver(domain, baseUrl);
    MatrixClientContext context = new MatrixClientContext(hs).setInitialDeviceName("initialDeviceName");
    MatrixHttpClient client = new MatrixHttpClient(context);

    MatrixPasswordCredentials credentials = new MatrixPasswordCredentials(user.getLocalPart(), password);
    client.login(credentials);

    assertTrue(StringUtils.isNotBlank(client.getAccessToken().get()));
    assertTrue(StringUtils.isNotBlank(client.getDeviceId().get()));
    assertTrue(StringUtils.isNotBlank(client.getUser().get().getId()));

    client.logout();
}
 
Example #7
Source File: AMatrixHttpClientSyncTest.java    From matrix-java-sdk with GNU Affero General Public License v3.0 5 votes vote down vote up
private void validateSyncData(_SyncData data) {
    assertNotNull(data);
    assertTrue(StringUtils.isNotBlank(data.nextBatchToken()));
    assertNotNull(data.getAccountData());
    assertNotNull(data.getRooms());
    assertNotNull(data.getRooms().getInvited());
    assertNotNull(data.getRooms().getJoined());
    assertNotNull(data.getRooms().getLeft());
}
 
Example #8
Source File: DBUnitExtension.java    From database-rider with Apache License 2.0 5 votes vote down vote up
private String getExecutorId(final ExtensionContext extensionContext, DataSet dataSet) {
    Optional<DataSet> annDataSet;
    if (dataSet != null) {
        annDataSet = Optional.of(dataSet);
    } else {
        annDataSet = findDataSetAnnotation(extensionContext);
    }
    String dataSourceBeanName = getConfiguredDataSourceBeanName(extensionContext);
    String executionIdSuffix = dataSourceBeanName.isEmpty() ? EMPTY_STRING : "-" + dataSourceBeanName;
    return annDataSet
            .map(DataSet::executorId)
            .filter(StringUtils::isNotBlank)
            .map(id -> id + executionIdSuffix)
            .orElseGet(() -> JUNIT5_EXECUTOR + executionIdSuffix);
}
 
Example #9
Source File: SAML2IdPMetadataITCase.java    From syncope with Apache License 2.0 5 votes vote down vote up
private void testIsValid(final SAML2IdPMetadataTO saml2IdPMetadataTO) {
    assertFalse(StringUtils.isBlank(saml2IdPMetadataTO.getAppliesTo()));
    assertFalse(StringUtils.isBlank(saml2IdPMetadataTO.getMetadata()));
    assertFalse(StringUtils.isBlank(saml2IdPMetadataTO.getEncryptionKey()));
    assertFalse(StringUtils.isBlank(saml2IdPMetadataTO.getEncryptionCertificate()));
    assertFalse(StringUtils.isBlank(saml2IdPMetadataTO.getSigningCertificate()));
    assertFalse(StringUtils.isBlank(saml2IdPMetadataTO.getSigningKey()));
}
 
Example #10
Source File: UmsRightProviderTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Test
public void testIfEveryActionIsInMap() {
    underTest.init();
    ThreadBasedUserCrnProvider.setUserCrn(USER_CRN);
    when(grpcUmsClient.isAuthorizationEntitlementRegistered(any(), any())).thenReturn(Boolean.TRUE);
    assertTrue(Arrays.stream(AuthorizationResourceAction.values())
            .allMatch(action -> StringUtils.isNotBlank(underTest.getRight(action))));
}
 
Example #11
Source File: SAML2SPKeystoreITCase.java    From syncope with Apache License 2.0 4 votes vote down vote up
private static void testIsValid(final SAML2SPKeystoreTO keystoreTO) {
    assertFalse(StringUtils.isBlank(keystoreTO.getOwner()));
    assertFalse(StringUtils.isBlank(keystoreTO.getKeystore()));
}
 
Example #12
Source File: SAML2SPMetadataITCase.java    From syncope with Apache License 2.0 4 votes vote down vote up
private static void testIsValid(final SAML2SPMetadataTO metadataTO) {
    assertFalse(StringUtils.isBlank(metadataTO.getOwner()));
    assertFalse(StringUtils.isBlank(metadataTO.getMetadata()));
}