Example usage for org.apache.commons.lang3 StringUtils length

List of usage examples for org.apache.commons.lang3 StringUtils length

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringUtils length.

Prototype

public static int length(final CharSequence cs) 

Source Link

Document

Gets a CharSequence length or 0 if the CharSequence is null .

Usage

From source file:org.finra.herd.service.helper.notification.BusinessObjectDefinitionDescriptionSuggestionChangeMessageBuilderTest.java

@Test
public void testBuildBusinessObjectDefinitionDescriptionSuggestionChangeMessagesOnlyOneUserIdInNotificationList()
        throws Exception {
    // Create a namespace entity.
    NamespaceEntity namespaceEntity = namespaceDaoTestHelper.createNamespaceEntity(BDEF_NAMESPACE);

    // Create a business object definition description suggestion key.
    BusinessObjectDefinitionDescriptionSuggestionKey businessObjectDefinitionDescriptionSuggestionKey = new BusinessObjectDefinitionDescriptionSuggestionKey(
            BDEF_NAMESPACE, BDEF_NAME, USER_ID);

    // Create a business object definition description suggestion.
    BusinessObjectDefinitionDescriptionSuggestion businessObjectDefinitionDescriptionSuggestion = new BusinessObjectDefinitionDescriptionSuggestion(
            ID, businessObjectDefinitionDescriptionSuggestionKey, DESCRIPTION_SUGGESTION,
            BusinessObjectDefinitionDescriptionSuggestionStatusEntity.BusinessObjectDefinitionDescriptionSuggestionStatuses.PENDING
                    .name(),/*from ww w. ja va2s  .  c o  m*/
            CREATED_BY, CREATED_ON);

    // Override configuration.
    ConfigurationEntity configurationEntity = new ConfigurationEntity();
    configurationEntity.setKey(
            ConfigurationValue.HERD_NOTIFICATION_BUSINESS_OBJECT_DEFINITION_DESCRIPTION_SUGGESTION_CHANGE_MESSAGE_DEFINITIONS
                    .getKey());
    configurationEntity.setValueClob(xmlHelper.objectToXml(new NotificationMessageDefinitions(
            Collections.singletonList(new NotificationMessageDefinition(MESSAGE_TYPE_SNS, MESSAGE_DESTINATION,
                    BUSINESS_OBJECT_DEFINITION_DESCRIPTION_SUGGESTION_CHANGE_NOTIFICATION_MESSAGE_VELOCITY_TEMPLATE,
                    getMessageHeaderDefinitions())))));
    configurationDao.saveAndRefresh(configurationEntity);

    // Build a notification message.
    List<NotificationMessage> result = businessObjectDefinitionDescriptionSuggestionChangeMessageBuilder
            .buildNotificationMessages(new BusinessObjectDefinitionDescriptionSuggestionChangeNotificationEvent(
                    businessObjectDefinitionDescriptionSuggestion, UPDATED_BY, UPDATED_ON,
                    namespaceEntity.getCode()));

    // Validate the results.
    assertEquals(1, CollectionUtils.size(result));
    assertEquals(7, CollectionUtils.size(result.get(0).getMessageHeaders()));
    String uuid = result.get(0).getMessageHeaders().get(4).getValue();
    assertEquals(UUID.randomUUID().toString().length(), StringUtils.length(uuid));
    validateBusinessObjectDefinitionDescriptionSuggestionChangeMessage(MESSAGE_TYPE_SNS, MESSAGE_DESTINATION,
            businessObjectDefinitionDescriptionSuggestion, UPDATED_BY, UPDATED_ON.toString(),
            Lists.newArrayList(CREATED_BY),
            String.format("https://udc.dev.finra.org/data-entities/%s/%s", BDEF_NAMESPACE, BDEF_NAME),
            getExpectedMessageHeaders(uuid), result.get(0));
}

From source file:org.finra.herd.service.helper.notification.BusinessObjectDefinitionDescriptionSuggestionChangeMessageBuilderTest.java

/**
 * Validates a business object definition description suggestion change notification message.
 *
 * @param expectedMessageType the expected message type
 * @param expectedMessageDestination the expected message destination
 * @param expectedBusinessObjectDefinitionDescriptionSuggestion the expected business object definition description suggestion
 * @param expectedLastUpdatedByUserId the expected User ID of the user who last updated this business object definition description suggestion
 * @param expectedLastUpdatedOn the expected timestamp when this business object definition description suggestion was last updated on
 * @param expectedNotificationList the expected notification list
 * @param expectedBusinessObjectDefinitionUri the expected UDC URI for the business object definition
 * @param expectedMessageHeaders the list of expected message headers
 * @param notificationMessage the notification message to be validated
 *//*ww w.j av  a  2 s.  c om*/
private void validateBusinessObjectDefinitionDescriptionSuggestionChangeMessage(String expectedMessageType,
        String expectedMessageDestination,
        BusinessObjectDefinitionDescriptionSuggestion expectedBusinessObjectDefinitionDescriptionSuggestion,
        String expectedLastUpdatedByUserId, String expectedLastUpdatedOn, List<String> expectedNotificationList,
        String expectedBusinessObjectDefinitionUri, List<MessageHeader> expectedMessageHeaders,
        NotificationMessage notificationMessage) throws IOException {
    assertNotNull(notificationMessage);

    assertEquals(expectedMessageType, notificationMessage.getMessageType());
    assertEquals(expectedMessageDestination, notificationMessage.getMessageDestination());

    BusinessObjectDefinitionDescriptionSuggestionChangeJsonMessagePayload businessObjectDefinitionDescriptionSuggestionChangeJsonMessagePayload = jsonHelper
            .unmarshallJsonToObject(BusinessObjectDefinitionDescriptionSuggestionChangeJsonMessagePayload.class,
                    notificationMessage.getMessageText());

    assertEquals(
            StringUtils.length(businessObjectDefinitionDescriptionSuggestionChangeJsonMessagePayload.eventDate),
            StringUtils.length(HerdDateUtils.now().toString()));
    assertEquals(
            expectedBusinessObjectDefinitionDescriptionSuggestion
                    .getBusinessObjectDefinitionDescriptionSuggestionKey(),
            businessObjectDefinitionDescriptionSuggestionChangeJsonMessagePayload.businessObjectDefinitionDescriptionSuggestionKey);
    assertEquals(expectedBusinessObjectDefinitionDescriptionSuggestion.getStatus(),
            businessObjectDefinitionDescriptionSuggestionChangeJsonMessagePayload.status);
    assertEquals(expectedBusinessObjectDefinitionDescriptionSuggestion.getCreatedByUserId(),
            businessObjectDefinitionDescriptionSuggestionChangeJsonMessagePayload.createdByUserId);
    assertEquals(expectedBusinessObjectDefinitionDescriptionSuggestion.getCreatedOn().toString(),
            businessObjectDefinitionDescriptionSuggestionChangeJsonMessagePayload.createdOn);
    assertEquals(expectedLastUpdatedByUserId,
            businessObjectDefinitionDescriptionSuggestionChangeJsonMessagePayload.lastUpdatedByUserId);
    assertEquals(expectedLastUpdatedOn,
            businessObjectDefinitionDescriptionSuggestionChangeJsonMessagePayload.lastUpdatedOn);
    assertEquals(expectedNotificationList,
            businessObjectDefinitionDescriptionSuggestionChangeJsonMessagePayload.notificationList);
    assertEquals(expectedBusinessObjectDefinitionUri,
            businessObjectDefinitionDescriptionSuggestionChangeJsonMessagePayload.businessObjectDefinitionUri);

    assertEquals(expectedMessageHeaders, notificationMessage.getMessageHeaders());
}

From source file:org.finra.herd.service.helper.notification.BusinessObjectFormatVersionChangeMessageBuilderTest.java

@Test
public void testBuildBusinessObjectFormatVersionChangeMessagesJsonPayload() throws Exception {
    // Create a business object format key.
    BusinessObjectFormatKey businessObjectFormatKey = new BusinessObjectFormatKey(BDEF_NAMESPACE, BDEF_NAME,
            FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION);

    // Override configuration.
    ConfigurationEntity configurationEntity = new ConfigurationEntity();
    configurationEntity.setKey(//from ww w  . j a v a 2  s .co  m
            ConfigurationValue.HERD_NOTIFICATION_BUSINESS_OBJECT_FORMAT_VERSION_CHANGE_MESSAGE_DEFINITIONS
                    .getKey());
    configurationEntity.setValueClob(xmlHelper.objectToXml(new NotificationMessageDefinitions(
            Collections.singletonList(new NotificationMessageDefinition(MESSAGE_TYPE_SNS, MESSAGE_DESTINATION,
                    BUSINESS_OBJECT_FORMAT_VERSION_CHANGE_NOTIFICATION_MESSAGE_VELOCITY_TEMPLATE_JSON,
                    getMessageHeaderDefinitions())))));
    configurationDao.saveAndRefresh(configurationEntity);

    // Build a notification message.
    List<NotificationMessage> result = businessObjectFormatVersionChangeMessageBuilder
            .buildNotificationMessages(new BusinessObjectFormatVersionChangeNotificationEvent(
                    businessObjectFormatKey, FORMAT_VERSION_2.toString()));

    // Validate the results.
    assertEquals(1, CollectionUtils.size(result));
    assertEquals(7, CollectionUtils.size(result.get(0).getMessageHeaders()));
    String uuid = result.get(0).getMessageHeaders().get(4).getValue();
    assertEquals(UUID.randomUUID().toString().length(), StringUtils.length(uuid));
    validateBusinessObjectFormatVersionChangeMessageWithJsonPayload(MESSAGE_TYPE_SNS, MESSAGE_DESTINATION,
            businessObjectFormatKey, businessObjectFormatKey.getBusinessObjectFormatVersion().toString(),
            FORMAT_VERSION_2.toString(), getExpectedMessageHeaders(uuid), result.get(0));
}

From source file:org.finra.herd.service.helper.notification.BusinessObjectFormatVersionChangeMessageBuilderTest.java

/**
 * Validates a business object data status change notification message with JSON payload.
 *
 * @param expectedMessageType the expected message type
 * @param expectedMessageDestination the expected message destination
 * @param expectedBusinessObjectFormatKey the expected business object format key
 * @param expectedNewBusinessObjectFormatVersion the expected new business object format version
 * @param expectedOldBusinessObjectFormatVersion the expected old business object format version
 * @param expectedMessageHeaders the list of expected message headers
 * @param notificationMessage the notification message to be validated
 *//*from   w  w  w.  j  a  v  a2 s.c  o m*/
private void validateBusinessObjectFormatVersionChangeMessageWithJsonPayload(String expectedMessageType,
        String expectedMessageDestination, BusinessObjectFormatKey expectedBusinessObjectFormatKey,
        String expectedNewBusinessObjectFormatVersion, String expectedOldBusinessObjectFormatVersion,
        List<MessageHeader> expectedMessageHeaders, NotificationMessage notificationMessage)
        throws IOException {
    assertNotNull(notificationMessage);

    assertEquals(expectedMessageType, notificationMessage.getMessageType());
    assertEquals(expectedMessageDestination, notificationMessage.getMessageDestination());

    BusinessObjectFormatVersionChangeJsonMessagePayload businessObjectFormatVersionChangeJsonMessagePayload = jsonHelper
            .unmarshallJsonToObject(BusinessObjectFormatVersionChangeJsonMessagePayload.class,
                    notificationMessage.getMessageText());

    assertEquals(StringUtils.length(businessObjectFormatVersionChangeJsonMessagePayload.eventDate),
            StringUtils.length(HerdDateUtils.now().toString()));
    assertEquals(expectedBusinessObjectFormatKey,
            businessObjectFormatVersionChangeJsonMessagePayload.businessObjectFormatKey);
    assertEquals(expectedNewBusinessObjectFormatVersion,
            businessObjectFormatVersionChangeJsonMessagePayload.newBusinessObjectFormatVersion);
    assertEquals(expectedOldBusinessObjectFormatVersion,
            businessObjectFormatVersionChangeJsonMessagePayload.oldBusinessObjectFormatVersion);
    assertEquals(expectedMessageHeaders, notificationMessage.getMessageHeaders());
}

From source file:org.finra.herd.service.helper.notification.StorageUnitStatusChangeMessageBuilderTest.java

@Test
public void testBuildStorageUnitStatusChangeMessagesJsonPayload() throws Exception {
    // Create a business object data key.
    BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME,
            FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES,
            DATA_VERSION);//w w  w. j a va  2s.  c o m

    // Override configuration.
    ConfigurationEntity configurationEntity = new ConfigurationEntity();
    configurationEntity.setKey(
            ConfigurationValue.HERD_NOTIFICATION_STORAGE_UNIT_STATUS_CHANGE_MESSAGE_DEFINITIONS.getKey());
    configurationEntity.setValueClob(xmlHelper.objectToXml(new NotificationMessageDefinitions(
            Collections.singletonList(new NotificationMessageDefinition(MESSAGE_TYPE_SNS, MESSAGE_DESTINATION,
                    STORAGE_UNIT_STATUS_CHANGE_NOTIFICATION_MESSAGE_VELOCITY_TEMPLATE_JSON,
                    getMessageHeaderDefinitions())))));
    configurationDao.saveAndRefresh(configurationEntity);

    // Build a notification message.
    List<NotificationMessage> result = storageUnitStatusChangeMessageBuilder
            .buildNotificationMessages(new StorageUnitStatusChangeNotificationEvent(businessObjectDataKey,
                    STORAGE_NAME, STORAGE_UNIT_STATUS, STORAGE_UNIT_STATUS_2));

    // Validate the results.
    assertEquals(1, CollectionUtils.size(result));
    assertEquals(7, CollectionUtils.size(result.get(0).getMessageHeaders()));
    String uuid = result.get(0).getMessageHeaders().get(4).getValue();
    assertEquals(UUID.randomUUID().toString().length(), StringUtils.length(uuid));
    validateStorageUnitStatusChangeMessageWithJsonPayload(MESSAGE_TYPE_SNS, MESSAGE_DESTINATION,
            businessObjectDataKey, STORAGE_NAME, STORAGE_UNIT_STATUS, STORAGE_UNIT_STATUS_2,
            getExpectedMessageHeaders(uuid), result.get(0));
}

From source file:org.finra.herd.service.helper.notification.StorageUnitStatusChangeMessageBuilderTest.java

/**
 * Validates a storage unit status change notification message with JSON payload.
 *
 * @param expectedMessageType the expected message type
 * @param expectedMessageDestination the expected message destination
 * @param expectedBusinessObjectDataKey the expected business object data key
 * @param expectedStorageName the expected storage name
 * @param expectedNewStorageUnitStatus the expected new business object data status
 * @param expectedOldStorageUnitStatus the expected old business object data status
 * @param expectedMessageHeaders the list of expected message headers
 * @param notificationMessage the notification message to be validated
 *//*from   www  .j  a va 2 s.  c  o m*/
private void validateStorageUnitStatusChangeMessageWithJsonPayload(String expectedMessageType,
        String expectedMessageDestination, BusinessObjectDataKey expectedBusinessObjectDataKey,
        String expectedStorageName, String expectedNewStorageUnitStatus, String expectedOldStorageUnitStatus,
        List<MessageHeader> expectedMessageHeaders, NotificationMessage notificationMessage)
        throws IOException {
    assertNotNull(notificationMessage);

    assertEquals(expectedMessageType, notificationMessage.getMessageType());
    assertEquals(expectedMessageDestination, notificationMessage.getMessageDestination());

    StorageUnitStatusChangeJsonMessagePayload storageUnitStatusChangeJsonMessagePayload = jsonHelper
            .unmarshallJsonToObject(StorageUnitStatusChangeJsonMessagePayload.class,
                    notificationMessage.getMessageText());

    assertEquals(StringUtils.length(storageUnitStatusChangeJsonMessagePayload.eventDate),
            StringUtils.length(HerdDateUtils.now().toString()));
    assertEquals(expectedBusinessObjectDataKey,
            storageUnitStatusChangeJsonMessagePayload.businessObjectDataKey);
    assertEquals(expectedStorageName, storageUnitStatusChangeJsonMessagePayload.storageName);
    assertEquals(expectedNewStorageUnitStatus, storageUnitStatusChangeJsonMessagePayload.newStorageUnitStatus);
    assertEquals(expectedOldStorageUnitStatus, storageUnitStatusChangeJsonMessagePayload.oldStorageUnitStatus);
    assertEquals(expectedMessageHeaders, notificationMessage.getMessageHeaders());
}

From source file:org.finra.herd.service.helper.notification.UserNamespaceAuthorizationChangeMessageBuilderTest.java

@Test
public void testBuildUserNamespaceAuthorizationChangeMessagesJsonPayload() throws Exception {
    // Create a user namespace authorization key.
    UserNamespaceAuthorizationKey userNamespaceAuthorizationKey = new UserNamespaceAuthorizationKey(USER_ID,
            BDEF_NAMESPACE);//from  w  ww. j ava 2 s  .c o  m

    // Override configuration.
    ConfigurationEntity configurationEntity = new ConfigurationEntity();
    configurationEntity
            .setKey(ConfigurationValue.HERD_NOTIFICATION_USER_NAMESPACE_AUTHORIZATION_CHANGE_MESSAGE_DEFINITIONS
                    .getKey());
    configurationEntity.setValueClob(xmlHelper.objectToXml(new NotificationMessageDefinitions(
            Collections.singletonList(new NotificationMessageDefinition(MESSAGE_TYPE_SNS, MESSAGE_DESTINATION,
                    USER_NAMESPACE_AUTHORIZATION_CHANGE_NOTIFICATION_MESSAGE_VELOCITY_TEMPLATE_JSON,
                    getMessageHeaderDefinitions())))));
    configurationDao.saveAndRefresh(configurationEntity);

    // Build a notification message.
    List<NotificationMessage> result = userNamespaceAuthorizationChangeMessageBuilder.buildNotificationMessages(
            new UserNamespaceAuthorizationChangeNotificationEvent(userNamespaceAuthorizationKey));

    // Validate the results.
    assertEquals(1, CollectionUtils.size(result));
    assertEquals(7, CollectionUtils.size(result.get(0).getMessageHeaders()));
    String uuid = result.get(0).getMessageHeaders().get(4).getValue();
    assertEquals(UUID.randomUUID().toString().length(), StringUtils.length(uuid));
    validateUserNamespaceAuthorizationChangeMessageWithJsonPayload(MESSAGE_TYPE_SNS, MESSAGE_DESTINATION,
            userNamespaceAuthorizationKey, getExpectedMessageHeaders(uuid), result.get(0));
}

From source file:org.goko.controller.grbl.v08.GrblExecutor.java

/** (inheritDoc)
 * @see org.goko.core.execution.monitor.executor.AbstractStreamingExecutor#isReadyForNextLine()
 *//*from   w w  w.  j a  v a2  s . c  o m*/
@Override
protected boolean isReadyForNextLine() throws GkException {
    if (getToken().hasMoreLine()) {
        GCodeLine nextLine = getToken().getNextLine();
        String lineStr = gcodeService.render(nextLine);
        return grblService.getUsedGrblBuffer() + StringUtils.length(lineStr) < Grbl.GRBL_BUFFER_SIZE;
    }
    return true;
}

From source file:org.goko.core.gcode.rs274ngcv3.parser.GCodeLexer.java

/**
 * Recursive method used to split the stringCommand into a list of tokens
 * @param stringCommand the string command
 * @param tokens the list of token//ww  w  .j a v  a  2 s  .co  m
 * @throws GkException GkException
 */
protected List<GCodeToken> createTokens(String pStringCommand, List<GCodeToken> tokens,
        IValidationTarget validationTarget, int lineNumber, int columnNumber) throws GkException {
    String stringCommand = pStringCommand;
    int totalColumn = columnNumber + StringUtils.length(stringCommand);
    if (StringUtils.isBlank(stringCommand)) {
        return tokens;
    }
    Matcher spaceMatcher = spacePattern.matcher(stringCommand);
    if (spaceMatcher.find()) {
        String remainingString = spaceMatcher.replaceFirst(StringUtils.EMPTY);
        return createTokens(remainingString, tokens, validationTarget, lineNumber,
                totalColumn - StringUtils.length(remainingString));
    }
    Matcher multilineCommentMatcher = multilineCommentPattern.matcher(stringCommand);
    if (multilineCommentMatcher.find()) {
        String remainingString = extractToken(multilineCommentMatcher, tokens,
                GCodeTokenType.MULTILINE_COMMENT);
        return createTokens(remainingString, tokens, validationTarget, lineNumber,
                totalColumn - StringUtils.length(remainingString));
    }
    Matcher simpleCommentMatcher = simpleCommentPattern.matcher(stringCommand);
    if (simpleCommentMatcher.find()) {
        String remainingString = extractToken(simpleCommentMatcher, tokens, GCodeTokenType.SIMPLE_COMMENT);
        return createTokens(remainingString, tokens, validationTarget, lineNumber,
                totalColumn - StringUtils.length(remainingString));
    }
    // Remove all white spaces ( comments already removed )
    while (StringUtils.startsWith(stringCommand, " ")) {
        stringCommand = stringCommand.replaceFirst("\\s", StringUtils.EMPTY);
        columnNumber += 1;
    }
    Matcher lineNumberMatcher = lineNumberPattern.matcher(stringCommand);
    if (lineNumberMatcher.find()) {
        String remainingString = extractToken(lineNumberMatcher, tokens, GCodeTokenType.LINE_NUMBER);
        return createTokens(remainingString, tokens, validationTarget, lineNumber,
                totalColumn - StringUtils.length(remainingString));
    }

    Matcher wordMatcher = wordPattern.matcher(stringCommand);
    if (wordMatcher.find()) {
        String remainingString = extractToken(wordMatcher, tokens, GCodeTokenType.WORD);
        return createTokens(remainingString, tokens, validationTarget, lineNumber,
                totalColumn - StringUtils.length(remainingString));
    }

    Matcher percentMatcher = percentPattern.matcher(stringCommand);
    if (percentMatcher.find()) {
        String remainingString = extractToken(percentMatcher, tokens, GCodeTokenType.PERCENT);
        return createTokens(remainingString, tokens, validationTarget, lineNumber,
                totalColumn - StringUtils.length(remainingString));
    }
    if (validationTarget != null) {
        ValidationElement vElement = new ValidationElement(ValidationSeverity.ERROR,
                new Location(lineNumber, columnNumber), StringUtils.length(stringCommand),
                MessageFormat.format(MessageResource.getMessage("GCO-101"), stringCommand));
        validationTarget.addValidationElement(vElement);
        return tokens;
    } else {
        throw new GkFunctionalException("GCO-101", stringCommand);
    }
}

From source file:org.goko.grbl.controller.GrblControllerService.java

protected void handleOkResponse() throws GkException {
    GrblGCodeExecutionToken currentToken = executionQueue.getCurrentToken();
    if (currentToken != null) {
        GCodeCommand command = currentToken.markNextCommandAsConfirmed();
        if (command != null) {
            String strCommand = new String(getGCodeService().convert(command));
            setUsedGrblBuffer(usedGrblBuffer - StringUtils.length(strCommand));
        }/* ww w. jav  a  2  s.  c  o m*/
        grblStreamingRunnable.releaseBufferSpaceMutex();
    }
}