类org.junit.platform.commons.util.StringUtils源码实例Demo

下面列出了怎么用org.junit.platform.commons.util.StringUtils的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: quarkus   文件: DisabledOnNativeImageCondition.java
/**
 * 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;
}
 
@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");
}
 
@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();
}
 
@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);
}
 
@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();
}
 
@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();
}
 
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());
}
 
源代码8 项目: database-rider   文件: DBUnitExtension.java
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);
}
 
源代码9 项目: syncope   文件: SAML2IdPMetadataITCase.java
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()));
}
 
源代码10 项目: cloudbreak   文件: UmsRightProviderTest.java
@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))));
}
 
源代码11 项目: syncope   文件: SAML2SPKeystoreITCase.java
private static void testIsValid(final SAML2SPKeystoreTO keystoreTO) {
    assertFalse(StringUtils.isBlank(keystoreTO.getOwner()));
    assertFalse(StringUtils.isBlank(keystoreTO.getKeystore()));
}
 
源代码12 项目: syncope   文件: SAML2SPMetadataITCase.java
private static void testIsValid(final SAML2SPMetadataTO metadataTO) {
    assertFalse(StringUtils.isBlank(metadataTO.getOwner()));
    assertFalse(StringUtils.isBlank(metadataTO.getMetadata()));
}
 
 类所在包
 类方法
 同包方法