use of com.github.ambry.account.Account in project ambry by linkedin.
the class AccountContainerTest method testAccountAndContainerSerDe.
@Test
public void testAccountAndContainerSerDe() throws IOException {
assumeTrue(Container.getCurrentJsonVersion() == JSON_VERSION_2);
// Make sure the JSONObject string can be deserialized to jackson object
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try (Writer writer = new OutputStreamWriter(outputStream, StandardCharsets.UTF_8)) {
refAccountJson.write(writer);
}
Account deserialized = objectMapper.readValue(outputStream.toByteArray(), Account.class);
Account fromJson = accountFromJson(refAccountJson);
assertTrue(deserialized.equals(fromJson));
// Make sure jackson string can be deserialized to JSONObject object
String serialized = objectMapper.writer(new DefaultPrettyPrinter()).writeValueAsString(deserialized);
JSONObject jsonObject = new JSONObject(serialized);
fromJson = accountFromJson(jsonObject);
assertTrue(deserialized.equals(fromJson));
@JsonIgnoreProperties({ "containers" })
abstract class AccountMixIn {
}
ObjectMapper newObjectMapper = new ObjectMapper();
newObjectMapper.addMixIn(Account.class, AccountMixIn.class);
serialized = newObjectMapper.writeValueAsString(deserialized);
assertFalse(serialized.contains("containers"));
}
use of com.github.ambry.account.Account in project ambry by linkedin.
the class AccountContainerTest method testConstructAccountAndContainerFromArguments.
/**
* Tests constructing {@link Account} and {@link Container} using individual arguments.
*/
@Test
public void testConstructAccountAndContainerFromArguments() throws JSONException {
Account accountFromArguments = new Account(refAccountId, refAccountName, refAccountStatus, refAccountAclInheritedByContainer, refAccountSnapshotVersion, refContainers, refQuotaResourceType);
assertAccountAgainstReference(accountFromArguments, true, true);
}
use of com.github.ambry.account.Account in project ambry by linkedin.
the class AccountContainerTest method testToString.
// Tests for builders
/**
* Tests {@code toString()} methods.
* @throws JSONException
*/
@Test
public void testToString() throws JSONException {
Account account = accountFromJson(refAccountJson);
assertEquals("Account[" + account.getId() + "," + account.getSnapshotVersion() + "]", account.toString());
for (int i = 0; i < CONTAINER_COUNT; i++) {
Container container = containerFromJson(containerJsonList.get(i), refAccountId);
assertEquals("Container[" + account.getId() + ":" + container.getId() + "]", container.toString());
}
}
use of com.github.ambry.account.Account in project ambry by linkedin.
the class AccountContainerTest method testRemoveNonExistContainer.
/**
* Tests removing a non-existent container from accountBuilder.
* @throws JSONException
*/
@Test
public void testRemoveNonExistContainer() throws JSONException {
Account origin = accountFromJson(refAccountJson);
AccountBuilder accountBuilder = new AccountBuilder(origin);
ContainerBuilder containerBuilder = new ContainerBuilder((short) -999, refContainerNames.get(0), refContainerStatuses.get(0), refContainerDescriptions.get(0), refAccountId).setEncrypted(refContainerEncryptionValues.get(0)).setPreviouslyEncrypted(refContainerPreviousEncryptionValues.get(0)).setCacheable(refContainerCachingValues.get(0)).setBackupEnabled(refContainerBackupEnabledValues.get(0)).setMediaScanDisabled(refContainerMediaScanDisabledValues.get(0)).setReplicationPolicy(refContainerReplicationPolicyValues.get(0)).setTtlRequired(refContainerTtlRequiredValues.get(0)).setContentTypeWhitelistForFilenamesOnDownload(refContainerContentTypeAllowListForFilenamesOnDownloadValues.get(0)).setDeleteTriggerTime(refContainerDeleteTriggerTime.get(0)).setAccessControlAllowOrigin(refAccessControlAllowOriginValues.get(0));
Container container = containerBuilder.build();
accountBuilder.removeContainer(container);
accountBuilder.removeContainer(null);
Account account = accountBuilder.build();
assertAccountAgainstReference(account, true, true);
}
use of com.github.ambry.account.Account in project ambry by linkedin.
the class RestUtils method buildBlobProperties.
/**
* Builds {@link BlobProperties} given the arguments associated with a request.
* @param args the arguments associated with the request. Cannot be {@code null}.
* @return the {@link BlobProperties} extracted from the arguments.
* @throws RestServiceException if required arguments aren't present or if they aren't in the format or number
* expected.
*/
public static BlobProperties buildBlobProperties(Map<String, Object> args) throws RestServiceException {
Account account = getAccountFromArgs(args);
Container container = getContainerFromArgs(args);
String serviceId = getHeader(args, Headers.SERVICE_ID, true);
String contentType = getHeader(args, Headers.AMBRY_CONTENT_TYPE, true);
String ownerId = getHeader(args, Headers.OWNER_ID, false);
String externalAssetTag = getHeader(args, Headers.EXTERNAL_ASSET_TAG, false);
String contentEncoding = getHeader(args, Headers.AMBRY_CONTENT_ENCODING, false);
String filename = getHeader(args, Headers.AMBRY_FILENAME, false);
long ttl = getTtlFromRequestHeader(args);
// This field should not matter on newly created blobs, because all privacy/cacheability decisions should be made
// based on the container properties and ACLs. For now, BlobProperties still includes this field, though.
boolean isPrivate = !container.isCacheable();
return new BlobProperties(-1, serviceId, ownerId, contentType, isPrivate, ttl, account.getId(), container.getId(), container.isEncrypted(), externalAssetTag, contentEncoding, filename);
}
Aggregations