@Test public void testRequestPathParsing() { String baseId = "expectedOpOrId"; String queryString = "?queryParam1=queryValue1&queryParam2=queryParam2=queryValue2"; String securePath = "secure-path"; List<String> prefixesToRemove = Arrays.asList("media", "toRemove/multipart", securePath); String blobId = TestUtils.getRandomString(10); String blobIdQuery = RestUtils.Headers.BLOB_ID + "=" + blobId; Map<String, String> prefixesToTest = new HashMap<>(); prefixesToTest.put("", ""); prefixesToRemove.forEach(prefix -> prefixesToTest.put("/" + prefix, prefix)); Map<String, String> clusterNameSegmentsToTest = new HashMap<>(); clusterNameSegmentsToTest.put("", ""); clusterNameSegmentsToTest.put("/" + CLUSTER_NAME.toLowerCase(), CLUSTER_NAME); clusterNameSegmentsToTest.put("/" + CLUSTER_NAME.toUpperCase(), CLUSTER_NAME); List<String> opsOrIdsToTest = Arrays.asList("/", "/" + baseId, "/" + baseId + "/random/extra", "/" + RestUtils.SIGNED_ID_PREFIX + "/" + baseId, "/media" + baseId, "/" + CLUSTER_NAME + baseId, "/" + RestUtils.SubResource.BlobInfo); prefixesToTest.forEach((prefixToUse, expectedPrefix) -> { clusterNameSegmentsToTest.forEach((clusterNameToUse, expectedClusterName) -> { opsOrIdsToTest.forEach(opOrId -> { String path = prefixToUse + clusterNameToUse + opOrId; parseRequestPathAndVerify(path, prefixesToRemove, CLUSTER_NAME, new RequestPath(expectedPrefix, expectedClusterName, opOrId, opOrId, null, NO_BLOB_SEGMENT_IDX_SPECIFIED), null); parseRequestPathAndVerify(path + queryString, prefixesToRemove, CLUSTER_NAME, new RequestPath(expectedPrefix, expectedClusterName, opOrId, opOrId, null, NO_BLOB_SEGMENT_IDX_SPECIFIED), null); if (opOrId.length() > 1) { for (RestUtils.SubResource subResource : RestUtils.SubResource.values()) { String subResourceStr = "/" + subResource.name(); int segment = NO_BLOB_SEGMENT_IDX_SPECIFIED; if (subResource.name().equals("Segment")) { segment = new Random().nextInt(Integer.MAX_VALUE); subResourceStr = subResourceStr + "/" + segment; } parseRequestPathAndVerify(path + subResourceStr, prefixesToRemove, CLUSTER_NAME, new RequestPath(expectedPrefix, expectedClusterName, opOrId + subResourceStr, opOrId, subResource, segment), null); parseRequestPathAndVerify(path + subResourceStr + queryString, prefixesToRemove, CLUSTER_NAME, new RequestPath(expectedPrefix, expectedClusterName, opOrId + subResourceStr, opOrId, subResource, segment), null); } } else { parseRequestPathAndVerify(path + "?" + blobIdQuery, prefixesToRemove, CLUSTER_NAME, new RequestPath(expectedPrefix, expectedClusterName, opOrId, blobId, null, NO_BLOB_SEGMENT_IDX_SPECIFIED), null); parseRequestPathAndVerify(path + queryString + "&" + blobIdQuery, prefixesToRemove, CLUSTER_NAME, new RequestPath(expectedPrefix, expectedClusterName, opOrId, blobId, null, NO_BLOB_SEGMENT_IDX_SPECIFIED), null); } }); }); }); }
@Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } RequestPath that = (RequestPath) o; return prefix.equals(that.prefix) && clusterName.equals(that.clusterName) && operationOrBlobId.equals( that.operationOrBlobId) && subResource == that.subResource && blobSegmentIdx == that.blobSegmentIdx; }
RequestPath { @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } RequestPath that = (RequestPath) o; return prefix.equals(that.prefix) && clusterName.equals(that.clusterName) && operationOrBlobId.equals( that.operationOrBlobId) && subResource == that.subResource && blobSegmentIdx == that.blobSegmentIdx; } }
RequestPath { @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } RequestPath that = (RequestPath) o; return prefix.equals(that.prefix) && clusterName.equals(that.clusterName) && operationOrBlobId.equals( that.operationOrBlobId) && subResource == that.subResource && blobSegmentIdx == that.blobSegmentIdx; } RequestPath(String prefix, String clusterName, String pathAfterPrefixes, String operationOrBlobId,
      SubResource subResource, int blobSegmentIdx); }
RequestPath { @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } RequestPath that = (RequestPath) o; return prefix.equals(that.prefix) && clusterName.equals(that.clusterName) && operationOrBlobId.equals( that.operationOrBlobId) && subResource == that.subResource && blobSegmentIdx == that.blobSegmentIdx; } RequestPath(String prefix, String clusterName, String pathAfterPrefixes, String operationOrBlobId,
      SubResource subResource, int blobSegmentIdx); static RequestPath parse(RestRequest restRequest, List<String> prefixesToRemove, String clusterName); static RequestPath parse(String path, Map<String, Object> args, List<String> prefixesToRemove,
      String clusterName); String getPrefix(); String getClusterName(); String getPathAfterPrefixes(); String getOperationOrBlobId(boolean stripLeadingSlash); SubResource getSubResource(); int getBlobSegmentIdx(); boolean matchesOperation(String operation); @Override boolean equals(Object o); @Override String toString(); }
RequestPath { @Override public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } RequestPath that = (RequestPath) o; return prefix.equals(that.prefix) && clusterName.equals(that.clusterName) && operationOrBlobId.equals( that.operationOrBlobId) && subResource == that.subResource && blobSegmentIdx == that.blobSegmentIdx; } RequestPath(String prefix, String clusterName, String pathAfterPrefixes, String operationOrBlobId,
      SubResource subResource, int blobSegmentIdx); static RequestPath parse(RestRequest restRequest, List<String> prefixesToRemove, String clusterName); static RequestPath parse(String path, Map<String, Object> args, List<String> prefixesToRemove,
      String clusterName); String getPrefix(); String getClusterName(); String getPathAfterPrefixes(); String getOperationOrBlobId(boolean stripLeadingSlash); SubResource getSubResource(); int getBlobSegmentIdx(); boolean matchesOperation(String operation); @Override boolean equals(Object o); @Override String toString();  }