From 04e6b9da3a8fca1a4e112c3d8a07c62d2e1d679b Mon Sep 17 00:00:00 2001 From: Albert Cheng Date: Wed, 28 Nov 2012 10:58:30 -0800 Subject: [PATCH] update locator --- .../content/LocatorRestType.java | 68 ++++++++-- .../services/media/models/Locator.java | 119 +++++++++++++++--- .../services/media/models/LocatorInfo.java | 42 +++++++ .../services/media/models/LocatorType.java | 6 +- .../media/models/LocatorEntityTest.java | 45 ++++++- .../media/models/LocatorInfoTest.java | 29 ++++- 6 files changed, 279 insertions(+), 30 deletions(-) diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/LocatorRestType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/LocatorRestType.java index f498cc765474b..63b0cbee4aa1d 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/LocatorRestType.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/LocatorRestType.java @@ -56,6 +56,14 @@ public class LocatorRestType implements MediaServiceDTO { @XmlElement(name = "StartTime", namespace = Constants.ODATA_DATA_NS) protected Date startTime; + /** The base uri. */ + @XmlElement(name = "BaseUri", namespace = Constants.ODATA_DATA_NS) + private String baseUri; + + /** The content access component. */ + @XmlElement(name = "ContentAccessComponent", namespace = Constants.ODATA_DATA_NS) + private String contentAccessComponent; + /** * Gets the id. * @@ -119,15 +127,6 @@ public LocatorRestType setType(int type) { return this; } - /** - * Gets the path. - * - * @return the path - */ - public String getPath() { - return this.path; - } - /** * Gets the access policy id. * @@ -191,6 +190,15 @@ public LocatorRestType setStartTime(Date startTime) { return this; } + /** + * Gets the path. + * + * @return the path + */ + public String getPath() { + return this.path; + } + /** * Sets the path. * @@ -202,4 +210,46 @@ public LocatorRestType setPath(String path) { this.path = path; return this; } + + /** + * Gets the base uri. + * + * @return the base uri + */ + public String getBaseUri() { + return this.baseUri; + } + + /** + * Sets the base uri. + * + * @param baseUri + * the base uri + * @return the locator rest type + */ + public LocatorRestType setBaseUri(String baseUri) { + this.baseUri = baseUri; + return this; + } + + /** + * Gets the content access component. + * + * @return the content access component + */ + public String getContentAccessComponent() { + return this.contentAccessComponent; + } + + /** + * Sets the content access component. + * + * @param contentAccessComponent + * the content access component + * @return the locator rest type + */ + public LocatorRestType setContentAccessComponent(String contentAccessComponent) { + this.contentAccessComponent = contentAccessComponent; + return this; + } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/Locator.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/Locator.java index 6684aa1f8a56f..c03c6d34b4cf1 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/Locator.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/Locator.java @@ -31,19 +31,23 @@ import com.microsoft.windowsazure.services.media.implementation.entities.EntityUpdateOperation; import com.sun.jersey.api.client.GenericType; +// TODO: Auto-generated Javadoc /** - * Implementation of Locator entity - * + * Implementation of Locator entity. */ public class Locator { + /** The Constant ENTITY_SET. */ private final static String ENTITY_SET = "Locators"; + /** + * Instantiates a new locator. + */ private Locator() { } /** - * Create an operation to create a new locator entity + * Create an operation to create a new locator entity. * * @param accessPolicyId * id of access policy for locator @@ -57,14 +61,46 @@ public static Creator create(String accessPolicyId, String assetId, LocatorType return new Creator(accessPolicyId, assetId, locatorType); } + /** + * The Class Creator. + */ public static class Creator extends EntityOperationSingleResultBase implements EntityCreationOperation { + + /** The access policy id. */ private final String accessPolicyId; + + /** The asset id. */ private final String assetId; + + /** The base uri. */ + private String baseUri; + + /** The content access token. */ + private String contentAccessComponent; + + /** The expiration date time. */ + private Date expirationDateTime; + + /** The locator type. */ private final LocatorType locatorType; + + /** The path. */ + private String path; + + /** The start date time. */ private Date startDateTime; - private Date expirationDateTime; + /** + * Instantiates a new creator. + * + * @param accessPolicyId + * the access policy id + * @param assetId + * the asset id + * @param locatorType + * the locator type + */ protected Creator(String accessPolicyId, String assetId, LocatorType locatorType) { super(ENTITY_SET, LocatorInfo.class); this.accessPolicyId = accessPolicyId; @@ -72,15 +108,43 @@ protected Creator(String accessPolicyId, String assetId, LocatorType locatorType this.locatorType = locatorType; } + /* (non-Javadoc) + * @see com.microsoft.windowsazure.services.media.implementation.entities.EntityCreationOperation#getRequestContents() + */ @Override public Object getRequestContents() { return new LocatorRestType().setAccessPolicyId(accessPolicyId).setAssetId(assetId) .setStartTime(startDateTime).setExpirationDateTime(expirationDateTime) - .setType(locatorType.getCode()); + .setType(locatorType.getCode()).setBaseUri(baseUri) + .setContentAccessComponent(contentAccessComponent).setPath(path); } /** - * Set the date and time for when the locator starts to be available + * Sets the base uri. + * + * @param baseUri + * the base uri + * @return the creator + */ + public Creator setBaseUri(String baseUri) { + this.baseUri = baseUri; + return this; + } + + /** + * Sets the path. + * + * @param path + * the path + * @return the creator + */ + public Creator setPath(String path) { + this.path = path; + return this; + } + + /** + * Set the date and time for when the locator starts to be available. * * @param startDateTime * The date/time @@ -92,7 +156,7 @@ public Creator setStartDateTime(Date startDateTime) { } /** - * Set the date and time at which the locator will expire + * Set the date and time at which the locator will expire. * * @param expirationDateTime * Expiration date and time @@ -102,10 +166,21 @@ public Creator setExpirationDateTime(Date expirationDateTime) { this.expirationDateTime = expirationDateTime; return this; } + + /** + * Sets the content access component. + * + * @param contentAccessComponent + * @return The creator instance + */ + public Creator setContentAccessComponent(String contentAccessComponent) { + this.contentAccessComponent = contentAccessComponent; + return this; + } } /** - * Create an operation to get the given locator + * Create an operation to get the given locator. * * @param locatorId * id of locator to retrieve @@ -116,7 +191,7 @@ public static EntityGetOperation get(String locatorId) { } /** - * Create an operation to list all locators + * Create an operation to list all locators. * * @return the list operation */ @@ -126,7 +201,7 @@ public static EntityListOperation list() { } /** - * Create an operation to list all locators matching the given query parameters + * Create an operation to list all locators matching the given query parameters. * * @param queryParameters * query parameters to send with the request @@ -138,7 +213,7 @@ public static EntityListOperation list(MultivaluedMap creator = Locator.create(exampleAccessPolicyId, exampleAssetId, + LocatorType.SAS).setPath(expectedPath); + + LocatorRestType locatorType = (LocatorRestType) creator.getRequestContents(); + + assertEquals(expectedPath, locatorType.getPath()); + + } + + @Test + public void createLocatorCanSetBaseUri() throws Exception { + + String expectedBaseUri = "testExpectedBaseUri"; + + EntityCreationOperation creator = Locator.create(exampleAccessPolicyId, exampleAssetId, + LocatorType.SAS).setBaseUri(expectedBaseUri); + + LocatorRestType locatorType = (LocatorRestType) creator.getRequestContents(); + + assertEquals(expectedBaseUri, locatorType.getBaseUri()); + + } + + @Test + public void createLocatorCanSetContentAccessComponent() throws Exception { + + String expectedContentAccessComponent = "testExpectedContentAccessComponent"; + + EntityCreationOperation creator = Locator.create(exampleAccessPolicyId, exampleAssetId, + LocatorType.SAS).setContentAccessComponent(expectedContentAccessComponent); + + LocatorRestType locatorType = (LocatorRestType) creator.getRequestContents(); + + assertEquals(expectedContentAccessComponent, locatorType.getContentAccessComponent()); + + } + @Test public void getLocatorGivesExpectedUri() throws Exception { assertEquals(expectedLocatorUri, Locator.get(exampleLocatorId).getUri()); diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/LocatorInfoTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/LocatorInfoTest.java index c749bd1b23cb5..5fbc6ae4abd4e 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/LocatorInfoTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/LocatorInfoTest.java @@ -52,7 +52,7 @@ public void testGetSetExpirationDateTime() { @Test public void testGetSetType() { // Arrange - LocatorType expectedLocatorType = LocatorType.WindowsAzureCDN; + LocatorType expectedLocatorType = LocatorType.Origin; LocatorInfo locatorInfo = new LocatorInfo(); // Act @@ -114,4 +114,31 @@ public void testGetSetStartTime() { assertEquals(expectedStartTime, actualStartTime); } + @Test + public void testGetSetBaseUri() { + // Arrange + String expectedBaseUri = "testBaseUri"; + LocatorInfo locatorInfo = new LocatorInfo(); + + // Act + String actualBaseUri = locatorInfo.setBaseUri(expectedBaseUri).getBaseUri(); + + // Assert + assertEquals(expectedBaseUri, actualBaseUri); + } + + @Test + public void testGetSetContentAccessComponent() { + // Arrange + String expectedContentAccessComponent = "testContentAccessToken"; + LocatorInfo locatorInfo = new LocatorInfo(); + + // Act + String actualContentAccessComponent = locatorInfo.setContentAccessComponent(expectedContentAccessComponent) + .getContentAccessToken(); + + // Assert + assertEquals(expectedContentAccessComponent, actualContentAccessComponent); + + } }