Java Code Examples for com.nike.internal.util.StringUtils#join()

The following examples show how to use com.nike.internal.util.StringUtils#join() . 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: ApiException.java    From backstopper with Apache License 2.0 6 votes vote down vote up
/**
 * Extracts and joins all messages from the input List<{@link ApiError}> if the desired message is null.
 *
 * Will return null if the input error List is null
 */
protected static String extractMessage(List<ApiError> apiErrors, String desiredMessage) {
    if (desiredMessage != null) {
        return desiredMessage;
    }

    if (apiErrors == null || apiErrors.isEmpty()) {
        return null;
    }

    if (apiErrors.size() == 1) {
        return extractMessage(apiErrors.get(0));
    }

    List<String> apiErrorMessages = new ArrayList<>(apiErrors.size());
    for (ApiError error : apiErrors) {
        apiErrorMessages.add(error.getMessage());
    }

    return StringUtils.join(apiErrorMessages, ", ", "[", "]");
}
 
Example 2
Source File: VerifyMultipartRequestsWorkComponentTest.java    From riposte with Apache License 2.0 5 votes vote down vote up
@Test
public void verify_multipart_with_mixed_types_works_properly() throws IOException, InterruptedException {
    String imageName = "someImageFile";
    String imageFilename = "helloWorld.png";
    InputStream imageFileInputStream = VerifyMultipartRequestsWorkComponentTest.class.getClassLoader().getResourceAsStream(imageFilename);
    byte[] imageFileBytes = IOUtils.toByteArray(imageFileInputStream);

    String textName = "someTextFile";
    String textFilename = "testMultipartFile.txt";
    InputStream textFileInputStream = VerifyMultipartRequestsWorkComponentTest.class.getClassLoader().getResourceAsStream(textFilename);
    byte[] textFileBytes = IOUtils.toByteArray(textFileInputStream);

    String attributeName = "someAttribute";
    String attributeString = UUID.randomUUID().toString();

    String responseString =
                given()
                    .baseUri("http://127.0.0.1")
                    .port(serverConfig.endpointsPort())
                    .basePath(MultipartTestEndpoint.MATCHING_PATH)
                    .log().all()
                .when()
                    .multiPart(imageName, imageFilename, imageFileBytes, "image/png")
                    .multiPart(attributeName, attributeString)
                    .multiPart(textName, textFilename, textFileBytes)
                    .post()
                .then()
                    .log().all()
                    .statusCode(200)
                    .extract().asString();

    String expectedImageFileHash = getHashForMultipartPayload(imageName, imageFilename, imageFileBytes);
    String expectedAttributeHash = getHashForMultipartPayload(attributeName, null, attributeString.getBytes(CharsetUtil.UTF_8));
    String expectedTextFileHash = getHashForMultipartPayload(textName, textFilename, textFileBytes);
    String expectedResponse = StringUtils.join(Arrays.asList(expectedImageFileHash, expectedAttributeHash, expectedTextFileHash), ",");
    assertThat(responseString).isEqualTo(expectedResponse);
}
 
Example 3
Source File: HttpServletRequestWrapperForRequestInfo.java    From riposte with Apache License 2.0 5 votes vote down vote up
@Override
public String getQueryString() {
    List<String> queryParams = requestInfo.getQueryParams().parameters().entrySet().stream()
                                          .map(entry -> entry.getKey() + "="
                                                        + StringUtils.join(entry.getValue(), ","))
                                          .collect(Collectors.toList());

    if (queryParams.isEmpty())
        return null;

    return StringUtils.join(queryParams, "&");
}
 
Example 4
Source File: CodahaleMetricsListener.java    From riposte with Apache License 2.0 4 votes vote down vote up
protected String getMatchingHttpMethodsAsCombinedString(Endpoint<?> endpoint) {
    if (endpoint.requestMatcher().isMatchAllMethods())
        return "ALL";

    return StringUtils.join(endpoint.requestMatcher().matchingMethods(), ",");
}
 
Example 5
Source File: EndpointMetricsHandlerDefaultImpl.java    From riposte with Apache License 2.0 4 votes vote down vote up
protected String getMatchingHttpMethodsAsCombinedString(Endpoint<?> endpoint) {
    if (endpoint.requestMatcher().isMatchAllMethods())
        return "ALL";

    return StringUtils.join(endpoint.requestMatcher().matchingMethods(), ",");
}