@Test
  public void testUpdateContainerInAccount() {
    Account account = refAccount;
    AccountBuilder accountBuilder = new AccountBuilder(account);

    // updating with different containers
    for (int i = 0; i < CONTAINER_COUNT; i++) {
      Container container = account.getContainerById(refContainerIds.get(i));
      accountBuilder.removeContainer(container);
      ContainerBuilder containerBuilder = new ContainerBuilder(container);
      short updatedContainerId = (short) (-1 * (container.getId()));
      String updatedContainerName = container.getName() + "-updated";
      Container.ContainerStatus updatedContainerStatus = Container.ContainerStatus.INACTIVE;
      String updatedContainerDescription = container.getDescription() + "--updated";
      boolean updatedEncrypted = !container.isEncrypted();
      boolean updatedPreviouslyEncrypted = updatedEncrypted || container.wasPreviouslyEncrypted();
      boolean updatedCacheable = !container.isCacheable();
      boolean updatedMediaScanDisabled = !container.isMediaScanDisabled();
      boolean updatedParanoidDurabilityEnabled = !container.isParanoidDurabilityEnabled();
      String updatedReplicationPolicy = container.getReplicationPolicy() + "---updated";
      boolean updatedTtlRequired = !container.isTtlRequired();
      boolean updatedWorkflowMigrationEnabled = !container.isWorkflowMigrationEnabled();
      boolean updatedSignedPathRequired = !container.isSecurePathRequired();
      String updatedAccessControlAllowOrigin = container.getAccessControlAllowOrigin() + "---updated";
      Set<String> updatedContentTypeAllowListForFilenamesOnDownloadValues =
          container.getContentTypeWhitelistForFilenamesOnDownload()
              .stream()
              .map(contentType -> contentType + "--updated")
              .collect(Collectors.toSet());
      Long updatedCacheTtlInSecond = System.currentTimeMillis();
      Set<String> updatedUserMetadataKeysToNotPrefixInResponse = container.getUserMetadataKeysToNotPrefixInResponse()
          .stream()
          .map(key -> key + "--updated")
          .collect(Collectors.toSet());

      containerBuilder.setId(updatedContainerId)
          .setName(updatedContainerName)
          .setStatus(updatedContainerStatus)
          .setDescription(updatedContainerDescription)
          .setEncrypted(updatedEncrypted)
          .setCacheable(updatedCacheable)
          .setMediaScanDisabled(updatedMediaScanDisabled)
          .setParanoidDurabilityEnabled(updatedParanoidDurabilityEnabled)
          .setReplicationPolicy(updatedReplicationPolicy)
          .setTtlRequired(updatedTtlRequired)
          .setWorkflowMigrationEnabled(updatedWorkflowMigrationEnabled)
          .setSecurePathRequired(updatedSignedPathRequired)
          .setContentTypeWhitelistForFilenamesOnDownload(updatedContentTypeAllowListForFilenamesOnDownloadValues)
          .setAccessControlAllowOrigin(updatedAccessControlAllowOrigin)
          .setCacheTtlInSecond(updatedCacheTtlInSecond)
          .setUserMetadataKeysToNotPrefixInResponse(updatedUserMetadataKeysToNotPrefixInResponse);
      accountBuilder.addOrUpdateContainer(containerBuilder.build());

      // build account and assert
      Account updatedAccount = accountBuilder.build();
      Container updatedContainer = updatedAccount.getContainerById(updatedContainerId);
      assertEquals("container id is not correctly updated", updatedContainerId, updatedContainer.getId());
      assertEquals("container name is not correctly updated", updatedContainerName, updatedContainer.getName());
      assertEquals("container status is not correctly updated", updatedContainerStatus, updatedContainer.getStatus());
      assertEquals("container description is not correctly updated", updatedContainerDescription,
          updatedContainer.getDescription());
      assertEquals("cacheable is not correctly updated", updatedCacheable, updatedContainer.isCacheable());
      switch (Container.getCurrentJsonVersion()) {
        case Container.JSON_VERSION_1:
          assertEquals("Wrong encryption setting", ENCRYPTED_DEFAULT_VALUE, updatedContainer.isEncrypted());
          assertEquals("Wrong previous encryption setting", PREVIOUSLY_ENCRYPTED_DEFAULT_VALUE,
              updatedContainer.wasPreviouslyEncrypted());
          assertEquals("Wrong media scan disabled setting", MEDIA_SCAN_DISABLED_DEFAULT_VALUE,
              updatedContainer.isMediaScanDisabled());
          assertEquals("Wrong paranoid durability enabled setting", PARANOID_DURABILITY_ENABLED_DEFAULT_VALUE,
              updatedContainer.isParanoidDurabilityEnabled());
          assertNull("Wrong replication policy", updatedContainer.getReplicationPolicy());
          assertEquals("Wrong ttl required setting", TTL_REQUIRED_DEFAULT_VALUE, updatedContainer.isTtlRequired());
          assertEquals("Wrong workflow migration enabled setting", WORKFLOW_MIGRATION_ENABLED_DEFAULT_VALUE, updatedContainer.isWorkflowMigrationEnabled());
          assertEquals("Wrong secure required setting", SECURE_PATH_REQUIRED_DEFAULT_VALUE,
              updatedContainer.isSecurePathRequired());
          assertEquals("Wrong content type allow list for filenames on download value",
              CONTENT_TYPE_WHITELIST_FOR_FILENAMES_ON_DOWNLOAD_DEFAULT_VALUE,
              updatedContainer.getContentTypeWhitelistForFilenamesOnDownload());
          assertEquals("Wrong accessControlAllowOrigin", "", updatedContainer.getAccessControlAllowOrigin());
          break;
        case Container.JSON_VERSION_2:
          assertEquals("Wrong encryption setting", updatedEncrypted, updatedContainer.isEncrypted());
          assertEquals("Wrong previous encryption setting", updatedPreviouslyEncrypted,
              updatedContainer.wasPreviouslyEncrypted());
          assertEquals("Wrong media scan disabled setting", updatedMediaScanDisabled,
              updatedContainer.isMediaScanDisabled());
          assertEquals("Wrong paranoid durability enabled setting", updatedParanoidDurabilityEnabled,
              updatedContainer.isParanoidDurabilityEnabled());
          assertEquals("Wrong replication policy", updatedReplicationPolicy, updatedContainer.getReplicationPolicy());
          assertEquals("Wrong ttl required setting", updatedTtlRequired, updatedContainer.isTtlRequired());
          assertEquals("Wrong workflow migration enabled setting", updatedWorkflowMigrationEnabled, updatedContainer.isWorkflowMigrationEnabled());
          assertEquals("Wrong secure path required setting", updatedSignedPathRequired,
              updatedContainer.isSecurePathRequired());
          assertEquals("Wrong content type allow list for filenames on download value",
              updatedContentTypeAllowListForFilenamesOnDownloadValues,
              updatedContainer.getContentTypeWhitelistForFilenamesOnDownload());
          assertEquals("Wrong accessControlAllowOrigin", updatedAccessControlAllowOrigin,
              updatedContainer.getAccessControlAllowOrigin());
          assertEquals("Wrong cacheTtlInSeconds", updatedCacheTtlInSecond, updatedContainer.getCacheTtlInSecond());
          assertEquals("Wrong user metadata keys to not prefix in response",
              updatedUserMetadataKeysToNotPrefixInResponse,
              updatedContainer.getUserMetadataKeysToNotPrefixInResponse());
          break;
        default:
          throw new IllegalStateException("Unsupported version: " + Container.getCurrentJsonVersion());
      }
    }
  }
Tests updating containers in an account.
ambry-api/src/test/java/com/github/ambry/account/AccountContainerTest.java