@Test public void testGetBlobIdFromString() throws IOException, RestServiceException { byte[] bytes = new byte[2]; ClusterMap referenceClusterMap = new MockClusterMap(); TestUtils.RANDOM.nextBytes(bytes); BlobId.BlobIdType referenceType = TestUtils.RANDOM.nextBoolean() ? BlobId.BlobIdType.NATIVE : BlobId.BlobIdType.CRAFTED; TestUtils.RANDOM.nextBytes(bytes); byte referenceDatacenterId = bytes[0]; short referenceAccountId = getRandomShort(TestUtils.RANDOM); short referenceContainerId = getRandomShort(TestUtils.RANDOM); PartitionId referencePartitionId = referenceClusterMap.getWritablePartitionIds(MockClusterMap.DEFAULT_PARTITION_CLASS).get(0); boolean referenceIsEncrypted = TestUtils.RANDOM.nextBoolean(); List<Short> versions = Arrays.stream(BlobId.getAllValidVersions()) .filter(version -> version >= BlobId.BLOB_ID_V3) .collect(Collectors.toList()); for (short version : versions) { BlobId blobId = new BlobId(version, referenceType, referenceDatacenterId, referenceAccountId, referenceContainerId, referencePartitionId, referenceIsEncrypted, BlobId.BlobDataType.DATACHUNK); BlobId regeneratedBlobId = FrontendUtils.getBlobIdFromString(blobId.getID(), referenceClusterMap); assertEquals("BlobId mismatch", blobId, regeneratedBlobId); assertBlobIdFieldValues(regeneratedBlobId, referenceType, referenceDatacenterId, referenceAccountId, referenceContainerId, referencePartitionId, version >= BlobId.BLOB_ID_V4 && referenceIsEncrypted); try { FrontendUtils.getBlobIdFromString(blobId.getID().substring(1), referenceClusterMap); fail("Should have thrown exception for bad blobId "); } catch (RestServiceException e) { assertEquals("RestServiceErrorCode mismatch", RestServiceErrorCode.BadRequest, e.getErrorCode()); } } }
static BlobId getBlobIdFromString(String blobIdStr, ClusterMap clusterMap) throws RestServiceException { try { return new BlobId(blobIdStr, clusterMap); } catch (Exception e) { throw new RestServiceException("Invalid blob id=" + blobIdStr, RestServiceErrorCode.BadRequest); } }
FrontendUtils { static BlobId getBlobIdFromString(String blobIdStr, ClusterMap clusterMap) throws RestServiceException { try { return new BlobId(blobIdStr, clusterMap); } catch (Exception e) { throw new RestServiceException("Invalid blob id=" + blobIdStr, RestServiceErrorCode.BadRequest); } } }
FrontendUtils { static BlobId getBlobIdFromString(String blobIdStr, ClusterMap clusterMap) throws RestServiceException { try { return new BlobId(blobIdStr, clusterMap); } catch (Exception e) { throw new RestServiceException("Invalid blob id=" + blobIdStr, RestServiceErrorCode.BadRequest); } }  }
FrontendUtils { static BlobId getBlobIdFromString(String blobIdStr, ClusterMap clusterMap) throws RestServiceException { try { return new BlobId(blobIdStr, clusterMap); } catch (Exception e) { throw new RestServiceException("Invalid blob id=" + blobIdStr, RestServiceErrorCode.BadRequest); } }   }
FrontendUtils { static BlobId getBlobIdFromString(String blobIdStr, ClusterMap clusterMap) throws RestServiceException { try { return new BlobId(blobIdStr, clusterMap); } catch (Exception e) { throw new RestServiceException("Invalid blob id=" + blobIdStr, RestServiceErrorCode.BadRequest); } }    }