@Test
  public void testGetBlobIdFromString() throws IOException, RestServiceException {
    // good path
    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);

      // bad path
      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());
      }
    }
  }
Tests {@link FrontendUtils#getBlobIdFromString(String, ClusterMap)}
@throws IOException
@throws RestServiceException
ambry-frontend/src/test/java/com/github/ambry/frontend/FrontendUtilsTest.java