diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/Configuration.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/Configuration.java index e5afff9047a29..4eb524c6e10b2 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/Configuration.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/Configuration.java @@ -35,6 +35,12 @@ public class Configuration { */ public static final String PROPERTY_READ_TIMEOUT = "com.microsoft.windowsazure.services.core.Configuration.readTimeout"; + /** + * Property name to control if HTTP logging to console is on or off. If property is set, logging is on, regardless + * of value. + */ + public static final String PROPERTY_LOG_HTTP_REQUESTS = "com.microsoft.windowsazure.services.core.Configuration.logHttpRequests"; + private static Configuration instance; Map properties; Builder builder; diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/pipeline/ClientConfigSettings.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/pipeline/ClientConfigSettings.java new file mode 100644 index 0000000000000..75cfa5ef47828 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/pipeline/ClientConfigSettings.java @@ -0,0 +1,99 @@ +/** + * Copyright 2012 Microsoft Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.microsoft.windowsazure.services.core.utils.pipeline; + +import com.sun.jersey.api.client.Client; +import com.sun.jersey.api.client.config.ClientConfig; +import com.sun.jersey.api.client.filter.LoggingFilter; + +/** + * Class used for injecting timeout settings into the various places that need it. + * + */ +public class ClientConfigSettings { + private static final int DEFAULT_TIMEOUT_MS = 90 * 1000; + + private final Integer connectTimeout; + private final Integer readTimeout; + private final boolean shouldLog; + + /** + * Construct a {@link ClientConfigSettings} object with the default + * settings. + */ + public ClientConfigSettings() { + connectTimeout = Integer.valueOf(null); + readTimeout = Integer.valueOf(null); + shouldLog = false; + } + + /** + * Construct a {@link ClientConfigSettings} object wit the given + * settings. + * + * @param connectTimeout + * Connection timeout in milliseconds + * @param readTimeout + * read timeout in milliseconds + * @param shouldLog + * if true, add logging filter to clients. + */ + public ClientConfigSettings(Object connectTimeout, Object readTimeout, boolean shouldLog) { + this.connectTimeout = getTimeout(connectTimeout); + this.readTimeout = getTimeout(readTimeout); + this.shouldLog = shouldLog; + } + + /** + * Update the given {@link ClientConfig} object with the appropriate + * settings from configuration. + * + * @param clientConfig + * object to update. + */ + public void applyConfig(ClientConfig clientConfig) { + clientConfig.getProperties().put(ClientConfig.PROPERTY_CONNECT_TIMEOUT, connectTimeout); + clientConfig.getProperties().put(ClientConfig.PROPERTY_READ_TIMEOUT, readTimeout); + } + + /** + * Update the given {@link client} object with the appropriate settings + * from configuration. + * + * @param client + */ + public void applyConfig(Client client) { + if (shouldLog) { + client.addFilter(new LoggingFilter()); + } + } + + private Integer getTimeout(Object timeoutValue) { + if (timeoutValue == null) { + return new Integer(DEFAULT_TIMEOUT_MS); + } + + if (timeoutValue instanceof Integer) { + return (Integer) timeoutValue; + } + + if (timeoutValue instanceof String) { + return Integer.valueOf((String) timeoutValue); + } + + throw new IllegalArgumentException("timeoutValue"); + } +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/pipeline/Exports.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/pipeline/Exports.java index e6a97e159afbc..fc565c3dde132 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/pipeline/Exports.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/core/utils/pipeline/Exports.java @@ -15,7 +15,6 @@ package com.microsoft.windowsazure.services.core.utils.pipeline; import java.util.Map; -import java.util.Map.Entry; import com.microsoft.windowsazure.services.core.Builder; import com.microsoft.windowsazure.services.core.Builder.Registry; @@ -32,39 +31,21 @@ public void register(Registry registry) { @Override public ClientConfig create(String profile, Builder builder, Map properties) { ClientConfig clientConfig = new DefaultClientConfig(); - profile = normalizeProfile(profile); - - // Lower levels of the stack assume timeouts are set. - // Set default timeout on clientConfig in case user - // hasn't set it yet in their configuration - - clientConfig.getProperties().put(ClientConfig.PROPERTY_CONNECT_TIMEOUT, new Integer(90 * 1000)); - clientConfig.getProperties().put(ClientConfig.PROPERTY_READ_TIMEOUT, new Integer(90 * 1000)); + ClientConfigSettings settings = builder.build(profile, ClientConfigSettings.class, properties); + settings.applyConfig(clientConfig); + return clientConfig; + } + }); - for (Entry entry : properties.entrySet()) { - Object propertyValue = entry.getValue(); - String propertyKey = entry.getKey(); + registry.add(new Builder.Factory() { - if (propertyKey.equals(profile + Configuration.PROPERTY_CONNECT_TIMEOUT)) { - propertyKey = ClientConfig.PROPERTY_CONNECT_TIMEOUT; - } - if (propertyKey.equals(profile + Configuration.PROPERTY_READ_TIMEOUT)) { - propertyKey = ClientConfig.PROPERTY_READ_TIMEOUT; - } + @Override + public ClientConfigSettings create(String profile, Builder builder, Map properties) { + Object connectTimeout = getPropertyIfExists(profile, properties, Configuration.PROPERTY_CONNECT_TIMEOUT); + Object readTimeout = getPropertyIfExists(profile, properties, Configuration.PROPERTY_READ_TIMEOUT); - // ClientConfig requires instance of Integer to properly set - // timeouts, but config file will deliver strings. Special - // case these timeout properties and convert them to Integer - // if necessary. - if (propertyKey.equals(ClientConfig.PROPERTY_CONNECT_TIMEOUT) - || propertyKey.equals(ClientConfig.PROPERTY_READ_TIMEOUT)) { - if (propertyValue instanceof String) { - propertyValue = Integer.valueOf((String) propertyValue); - } - } - clientConfig.getProperties().put(propertyKey, propertyValue); - } - return clientConfig; + return new ClientConfigSettings(connectTimeout, readTimeout, getPropertyIfExists(profile, properties, + Configuration.PROPERTY_LOG_HTTP_REQUESTS) != null); } }); @@ -72,8 +53,9 @@ public ClientConfig create(String profile, Builder builder, Map @Override public Client create(String profile, Builder builder, Map properties) { ClientConfig clientConfig = builder.build(profile, ClientConfig.class, properties); + ClientConfigSettings settings = builder.build(profile, ClientConfigSettings.class, properties); Client client = Client.create(clientConfig); - // client.addFilter(new LoggingFilter()); + settings.applyConfig(client); return client; } }); @@ -82,15 +64,16 @@ public Client create(String profile, Builder builder, Map proper @Override public HttpURLConnectionClient create(String profile, Builder builder, Map properties) { ClientConfig clientConfig = builder.build(profile, ClientConfig.class, properties); + ClientConfigSettings settings = builder.build(profile, ClientConfigSettings.class, properties); HttpURLConnectionClient client = HttpURLConnectionClient.create(clientConfig); - // client.addFilter(new LoggingFilter()); + settings.applyConfig(client); return client; } }); } private static String normalizeProfile(String profile) { - if (profile == null) { + if (profile == null || profile.equals("")) { return ""; } @@ -100,4 +83,13 @@ private static String normalizeProfile(String profile) { return profile + "."; } + + private static Object getPropertyIfExists(String profile, Map properties, String propertyName) { + String fullPropertyName = normalizeProfile(profile) + propertyName; + + if (properties.containsKey(fullPropertyName)) { + return properties.get(fullPropertyName); + } + return null; + } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaConfiguration.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaConfiguration.java index b9b9d0e74aff8..e3d207f848ed9 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaConfiguration.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaConfiguration.java @@ -32,24 +32,24 @@ public class MediaConfiguration { * Defines the OAUTH configuration URI constant. * */ - public static final String OAUTH_URI = "oauth.uri"; + public static final String OAUTH_URI = "media.oauth.uri"; /** * Defines the OAUTH configuration client ID constant. * */ - public static final String OAUTH_CLIENT_ID = "oauth.client.id"; + public static final String OAUTH_CLIENT_ID = "media.oauth.client.id"; /** * Defines the OAUTH configuration client secret constant. * */ - public static final String OAUTH_CLIENT_SECRET = "oauth.client.secret"; + public static final String OAUTH_CLIENT_SECRET = "media.oauth.client.secret"; /** * Defines the SCOPE of the media service sent to OAUTH. */ - public static final String OAUTH_SCOPE = "oauth.scope"; + public static final String OAUTH_SCOPE = "media.oauth.scope"; /** * Creates a media service configuration using the specified media service base URI, OAUTH URI, diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaContract.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaContract.java index 47ddbbac61b5f..f6a80ea5ffc80 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaContract.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaContract.java @@ -19,6 +19,7 @@ import com.microsoft.windowsazure.services.core.FilterableService; import com.microsoft.windowsazure.services.media.implementation.entities.EntityContract; +import com.microsoft.windowsazure.services.media.models.LocatorInfo; /** * Contract for interacting with the back end of Media Services @@ -28,4 +29,13 @@ public interface MediaContract extends FilterableService, EntityC URI getRestServiceUri(); + /** + * Creates an instance of the WritableBlobContainerContract API that will + * write to the blob container given by the provided locator. + * + * @param locator + * locator specifying where to upload to + * @return the implementation of WritableBlobContainerContract + */ + WritableBlobContainerContract createBlobWriter(LocatorInfo locator); } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaService.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaService.java index bc2d5d54e2a19..9cf13258bab88 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaService.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/MediaService.java @@ -14,13 +14,7 @@ */ package com.microsoft.windowsazure.services.media; -import java.net.URI; - import com.microsoft.windowsazure.services.core.Configuration; -import com.microsoft.windowsazure.services.media.implementation.MediaBlobContainerWriter; -import com.microsoft.windowsazure.services.media.models.LocatorInfo; -import com.microsoft.windowsazure.services.media.models.LocatorType; -import com.sun.jersey.api.client.Client; /** * @@ -70,55 +64,4 @@ public static MediaContract create(String profile) { public static MediaContract create(String profile, Configuration config) { return config.create(profile, MediaContract.class); } - - /** - * Creates an instance of the WritableBlobContainerContract API that will - * write to the blob container given by the provided locator. - * - * @param locator - * locator specifying where to upload to - * @return the implementation of WritableBlobContainerContract - */ - public static WritableBlobContainerContract createBlobWriter(LocatorInfo locator) { - if (locator.getLocatorType() != LocatorType.SAS) { - throw new IllegalArgumentException("Can only write to SAS locators"); - } - - LocatorParser p = new LocatorParser(locator); - - return new MediaBlobContainerWriter(createUploaderClient(), p.getAccountName(), p.getStorageUri(), - p.getContainer(), p.getSASToken()); - } - - /** - * Helper class to encapsulate pulling information out of the locator. - */ - private static class LocatorParser { - URI locatorPath; - - LocatorParser(LocatorInfo locator) { - locatorPath = URI.create(locator.getPath()); - } - - String getAccountName() { - return locatorPath.getHost().split("\\.")[0]; - } - - String getStorageUri() { - return locatorPath.getScheme() + "://" + locatorPath.getAuthority(); - } - - String getContainer() { - return locatorPath.getPath().substring(1); - } - - String getSASToken() { - return locatorPath.getRawQuery(); - } - } - - private static Client createUploaderClient() { - Client client = Client.create(); - return client; - } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaExceptionProcessor.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaExceptionProcessor.java index cc8ad049d972f..5301f415a80a0 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaExceptionProcessor.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaExceptionProcessor.java @@ -26,6 +26,7 @@ import com.microsoft.windowsazure.services.core.ServiceFilter; import com.microsoft.windowsazure.services.core.utils.ServiceExceptionFactory; import com.microsoft.windowsazure.services.media.MediaContract; +import com.microsoft.windowsazure.services.media.WritableBlobContainerContract; import com.microsoft.windowsazure.services.media.implementation.entities.EntityActionOperation; import com.microsoft.windowsazure.services.media.implementation.entities.EntityCreationOperation; import com.microsoft.windowsazure.services.media.implementation.entities.EntityDeleteOperation; @@ -33,6 +34,7 @@ import com.microsoft.windowsazure.services.media.implementation.entities.EntityListOperation; import com.microsoft.windowsazure.services.media.implementation.entities.EntityUpdateOperation; import com.microsoft.windowsazure.services.media.models.ListResult; +import com.microsoft.windowsazure.services.media.models.LocatorInfo; import com.sun.jersey.api.client.ClientHandlerException; import com.sun.jersey.api.client.UniformInterfaceException; @@ -196,4 +198,12 @@ public URI getRestServiceUri() { return service.getRestServiceUri(); } + /* (non-Javadoc) + * @see com.microsoft.windowsazure.services.media.MediaContract#createBlobWriter(com.microsoft.windowsazure.services.media.models.LocatorInfo) + */ + @Override + public WritableBlobContainerContract createBlobWriter(LocatorInfo locator) { + return service.createBlobWriter(locator); + } + } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaRestProxy.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaRestProxy.java index 3952c822c88f0..68240cdcc2578 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaRestProxy.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/MediaRestProxy.java @@ -24,9 +24,15 @@ import org.apache.commons.logging.LogFactory; import com.microsoft.windowsazure.services.core.ServiceFilter; +import com.microsoft.windowsazure.services.core.utils.pipeline.ClientConfigSettings; import com.microsoft.windowsazure.services.media.MediaContract; +import com.microsoft.windowsazure.services.media.WritableBlobContainerContract; import com.microsoft.windowsazure.services.media.implementation.entities.EntityRestProxy; +import com.microsoft.windowsazure.services.media.models.LocatorInfo; +import com.microsoft.windowsazure.services.media.models.LocatorType; import com.sun.jersey.api.client.Client; +import com.sun.jersey.api.client.config.ClientConfig; +import com.sun.jersey.api.client.config.DefaultClientConfig; /** * The Class MediaRestProxy. @@ -38,6 +44,8 @@ public class MediaRestProxy extends EntityRestProxy implements MediaContract { /** The redirect filter. */ private RedirectFilter redirectFilter; + private final ClientConfigSettings clientConfigSettings; + /** * Instantiates a new media rest proxy. * @@ -49,12 +57,16 @@ public class MediaRestProxy extends EntityRestProxy implements MediaContract { * the redirect filter * @param versionHeadersFilter * the version headers filter + * @param clientConfigSettings + * Currently configured HTTP client settings + * */ @Inject public MediaRestProxy(Client channel, OAuthFilter authFilter, RedirectFilter redirectFilter, - VersionHeadersFilter versionHeadersFilter) { + VersionHeadersFilter versionHeadersFilter, ClientConfigSettings clientConfigSettings) { super(channel, new ServiceFilter[0]); + this.clientConfigSettings = clientConfigSettings; this.redirectFilter = redirectFilter; channel.addFilter(redirectFilter); channel.addFilter(authFilter); @@ -68,9 +80,12 @@ public MediaRestProxy(Client channel, OAuthFilter authFilter, RedirectFilter red * the channel * @param filters * the filters + * @param clientConfigSettings + * currently configured HTTP client settings */ - private MediaRestProxy(Client channel, ServiceFilter[] filters) { + private MediaRestProxy(Client channel, ServiceFilter[] filters, ClientConfigSettings clientConfigSettings) { super(channel, filters); + this.clientConfigSettings = clientConfigSettings; } /* (non-Javadoc) @@ -81,7 +96,7 @@ public MediaContract withFilter(ServiceFilter filter) { ServiceFilter[] filters = getFilters(); ServiceFilter[] newFilters = Arrays.copyOf(filters, filters.length + 1); newFilters[filters.length] = filter; - return new MediaRestProxy(getChannel(), newFilters); + return new MediaRestProxy(getChannel(), newFilters, clientConfigSettings); } /* (non-Javadoc) @@ -91,4 +106,54 @@ public MediaContract withFilter(ServiceFilter filter) { public URI getRestServiceUri() { return this.redirectFilter.getBaseURI(); } -} + + /* (non-Javadoc) + * @see com.microsoft.windowsazure.services.media.MediaContract#createBlobWriter(com.microsoft.windowsazure.services.media.models.LocatorInfo) + */ + @Override + public WritableBlobContainerContract createBlobWriter(LocatorInfo locator) { + if (locator.getLocatorType() != LocatorType.SAS) { + throw new IllegalArgumentException("Can only write to SAS locators"); + } + + LocatorParser p = new LocatorParser(locator); + + return new MediaBlobContainerWriter(createUploaderClient(), p.getAccountName(), p.getStorageUri(), + p.getContainer(), p.getSASToken()); + } + + /** + * Helper class to encapsulate pulling information out of the locator. + */ + private static class LocatorParser { + URI locatorPath; + + LocatorParser(LocatorInfo locator) { + locatorPath = URI.create(locator.getPath()); + } + + String getAccountName() { + return locatorPath.getHost().split("\\.")[0]; + } + + String getStorageUri() { + return locatorPath.getScheme() + "://" + locatorPath.getAuthority(); + } + + String getContainer() { + return locatorPath.getPath().substring(1); + } + + String getSASToken() { + return locatorPath.getRawQuery(); + } + } + + private Client createUploaderClient() { + ClientConfig clientConfig = new DefaultClientConfig(); + clientConfigSettings.applyConfig(clientConfig); + Client client = Client.create(clientConfig); + clientConfigSettings.applyConfig(client); + return client; + } +} \ No newline at end of file diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/OAuthTokenManager.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/OAuthTokenManager.java index 7e5df57b529ca..58afef9d1ad1b 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/OAuthTokenManager.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/OAuthTokenManager.java @@ -89,22 +89,16 @@ public OAuthTokenManager(OAuthContract contract, DateFactory dateFactory, */ public String getAccessToken() throws ServiceException, URISyntaxException { Date now = dateFactory.getDate(); - OAuthTokenResponse oAuth2TokenResponse = null; + if (this.activeToken == null || now.after(this.activeToken.getExpiresUtc())) { + OAuthTokenResponse oAuth2TokenResponse = contract.getAccessToken(acsBaseUri, clientId, clientSecret, scope); + Date expiresUtc = new Date(now.getTime() + oAuth2TokenResponse.getExpiresIn() * Timer.ONE_SECOND / 2); - if (this.activeToken == null) { - this.activeToken = new ActiveToken(); - } - else if (now.before(this.activeToken.getExpiresUtc())) { - return this.activeToken.getAccessToken(); - } - - oAuth2TokenResponse = contract.getAccessToken(acsBaseUri, clientId, clientSecret, scope); - Date expiresUtc = new Date(now.getTime() + oAuth2TokenResponse.getExpiresIn() * Timer.ONE_SECOND / 2); + ActiveToken newToken = new ActiveToken(); + newToken.setAccessToken(oAuth2TokenResponse.getAccessToken()); + newToken.setExpiresUtc(expiresUtc); - this.activeToken.setAccessToken(oAuth2TokenResponse.getAccessToken()); - this.activeToken.setExpiresUtc(expiresUtc); - - return oAuth2TokenResponse.getAccessToken(); + this.activeToken = newToken; + } + return this.activeToken.getAccessToken(); } - } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntity.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntity.java index 4d3ce09d1dc96..fa1a382f72117 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntity.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/ODataEntity.java @@ -17,12 +17,16 @@ import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.List; import javax.xml.bind.JAXBElement; import com.microsoft.windowsazure.services.media.implementation.atom.ContentType; import com.microsoft.windowsazure.services.media.implementation.atom.EntryType; +import com.microsoft.windowsazure.services.media.implementation.atom.LinkType; import com.microsoft.windowsazure.services.media.implementation.content.Constants; +import com.microsoft.windowsazure.services.media.models.LinkInfo; import com.microsoft.windowsazure.services.media.models.ListResult; /** @@ -40,6 +44,7 @@ protected ODataEntity(EntryType entry, T content) { this.content = content; } + @SuppressWarnings({ "unchecked", "rawtypes" }) protected ODataEntity(T content) { this.content = content; @@ -65,6 +70,66 @@ protected T getContent() { return content; } + /** + * Test if the entity contains a link with the given rel attribute. + * + * @param rel + * Rel of link to check for + * @return True if link is found, false if not. + */ + public boolean hasLink(String rel) { + return getLink(rel) != null; + } + + /** + * Get the link with the given rel attribute + * + * @param rel + * rel of link to retrieve + * @return The link if found, null if not. + */ + public LinkInfo getLink(String rel) { + for (Object child : entry.getEntryChildren()) { + + LinkType link = LinkFromChild(child); + if (link != null && link.getRel().equals(rel)) { + return new LinkInfo(link); + } + } + return null; + } + + /** + * Return the links from this entry + * + * @return List of the links. + */ + public List getLinks() { + ArrayList links = new ArrayList(); + for (Object child : entry.getEntryChildren()) { + LinkType link = LinkFromChild(child); + if (link != null) { + links.add(new LinkInfo(link)); + } + } + return links; + } + + @SuppressWarnings("rawtypes") + private static LinkType LinkFromChild(Object child) { + if (child instanceof JAXBElement) { + return LinkFromElement((JAXBElement) child); + } + return null; + } + + private static LinkType LinkFromElement(@SuppressWarnings("rawtypes") JAXBElement element) { + if (element.getDeclaredType() == LinkType.class) { + return (LinkType) element.getValue(); + } + return null; + } + /** * Is the given type inherited from ODataEntity * diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/AccessPolicyType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/AccessPolicyType.java index 219a65b668f16..6fe22bad67aac 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/AccessPolicyType.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/AccessPolicyType.java @@ -41,10 +41,10 @@ public class AccessPolicyType implements MediaServiceDTO { protected String name; @XmlElement(name = "DurationInMinutes", namespace = Constants.ODATA_DATA_NS) - protected double durationInMinutes; + protected Double durationInMinutes; @XmlElement(name = "Permissions", namespace = Constants.ODATA_DATA_NS) - protected int permissions; + protected Integer permissions; /** * @return the id @@ -113,7 +113,7 @@ public AccessPolicyType setName(String name) { /** * @return the durationInMinutes */ - public double getDurationInMinutes() { + public Double getDurationInMinutes() { return durationInMinutes; } @@ -129,7 +129,7 @@ public AccessPolicyType setDurationInMinutes(double durationInMinutes) { /** * @return the permissions */ - public int getPermissions() { + public Integer getPermissions() { return permissions; } @@ -137,7 +137,7 @@ public int getPermissions() { * @param permissions * the permissions to set */ - public AccessPolicyType setPermissions(int permissions) { + public AccessPolicyType setPermissions(Integer permissions) { this.permissions = permissions; return this; } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/AssetType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/AssetType.java index 7cc7b9bd3cf22..6563c1e08ffd8 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/AssetType.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/AssetType.java @@ -33,7 +33,7 @@ public class AssetType implements MediaServiceDTO { protected String id; @XmlElement(name = "State", namespace = Constants.ODATA_DATA_NS) - protected int state; + protected Integer state; @XmlElement(name = "Created", namespace = Constants.ODATA_DATA_NS) protected Date created; @@ -61,14 +61,15 @@ public String getId() { * @param id * the id to set */ - public void setId(String id) { + public AssetType setId(String id) { this.id = id; + return this; } /** * @return the state */ - public int getState() { + public Integer getState() { return state; } @@ -76,8 +77,9 @@ public int getState() { * @param state * the state to set */ - public void setState(int state) { + public AssetType setState(Integer state) { this.state = state; + return this; } /** @@ -91,8 +93,9 @@ public Date getCreated() { * @param created * the created to set */ - public void setCreated(Date created) { + public AssetType setCreated(Date created) { this.created = created; + return this; } /** @@ -106,8 +109,9 @@ public Date getLastModified() { * @param lastModified * the lastModified to set */ - public void setLastModified(Date lastModified) { + public AssetType setLastModified(Date lastModified) { this.lastModified = lastModified; + return this; } /** @@ -121,8 +125,9 @@ public String getAlternateId() { * @param alternateId * the alternateId to set */ - public void setAlternateId(String alternateId) { + public AssetType setAlternateId(String alternateId) { this.alternateId = alternateId; + return this; } /** @@ -136,8 +141,9 @@ public String getName() { * @param name * the name to set */ - public void setName(String name) { + public AssetType setName(String name) { this.name = name; + return this; } /** @@ -151,7 +157,8 @@ public Integer getOptions() { * @param options * the options to set */ - public void setOptions(Integer options) { + public AssetType setOptions(Integer options) { this.options = options; + return this; } } 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 63b0cbee4aa1d..5dc08a2776268 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 @@ -38,7 +38,7 @@ public class LocatorRestType implements MediaServiceDTO { /** The type. */ @XmlElement(name = "Type", namespace = Constants.ODATA_DATA_NS) - protected int type; + protected Integer type; /** The path. */ @XmlElement(name = "Path", namespace = Constants.ODATA_DATA_NS) @@ -111,7 +111,7 @@ public LocatorRestType setExpirationDateTime(Date expirationDateTime) { * * @return the type */ - public int getType() { + public Integer getType() { return this.type; } @@ -122,7 +122,7 @@ public int getType() { * the type * @return the locator rest type */ - public LocatorRestType setType(int type) { + public LocatorRestType setType(Integer type) { this.type = type; return this; } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/MediaProcessorType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/MediaProcessorType.java index de8338173a9b8..ec1966c204117 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/MediaProcessorType.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/MediaProcessorType.java @@ -56,8 +56,9 @@ public String getId() { * @param id * the id to set */ - public void setId(String id) { + public MediaProcessorType setId(String id) { this.id = id; + return this; } /** @@ -71,39 +72,44 @@ public String getName() { * @param name * the name to set */ - public void setName(String name) { + public MediaProcessorType setName(String name) { this.name = name; + return this; } public String getDescription() { return this.description; } - public void setDescription(String description) { + public MediaProcessorType setDescription(String description) { this.description = description; + return this; } public String getSku() { return this.sku; } - public void setSku(String sku) { + public MediaProcessorType setSku(String sku) { this.sku = sku; + return this; } public String getVendor() { return vendor; } - public void setVendor(String vendor) { + public MediaProcessorType setVendor(String vendor) { this.vendor = vendor; + return this; } public String getVersion() { return this.version; } - public void setVersion(String version) { + public MediaProcessorType setVersion(String version) { this.version = version; + return this; } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/TaskType.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/TaskType.java index 67d92f8620b72..743316ae27528 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/TaskType.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/implementation/content/TaskType.java @@ -70,7 +70,7 @@ public class TaskType implements MediaServiceDTO { protected String taskBody; @XmlElement(name = "Options", namespace = Constants.ODATA_DATA_NS) - protected int options; + protected Integer options; @XmlElement(name = "EncryptionKeyId", namespace = Constants.ODATA_DATA_NS) protected String encryptionKeyId; diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AccessPolicyInfo.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AccessPolicyInfo.java index f4d608dd712a5..09647b8a9711d 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AccessPolicyInfo.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AccessPolicyInfo.java @@ -22,67 +22,76 @@ import com.microsoft.windowsazure.services.media.implementation.atom.EntryType; import com.microsoft.windowsazure.services.media.implementation.content.AccessPolicyType; +/** + * Type containing data about access policies. + * + */ public class AccessPolicyInfo extends ODataEntity { + /** + * Creates a new {@link AccessPolicyInfo} wrapping the given ATOM + * entry and content objects. + * + * @param entry + * Entry containing this AccessPolicy data + * @param content + * Content with the AccessPolicy data + */ public AccessPolicyInfo(EntryType entry, AccessPolicyType content) { super(entry, content); } - public AccessPolicyInfo() { - super(new AccessPolicyType()); - } - + /** + * Get the access policy id. + * + * @return the id. + */ public String getId() { return getContent().getId(); } - public AccessPolicyInfo setId(String id) { - getContent().setId(id); - return this; - } - + /** + * Get the creation date. + * + * @return the date. + */ public Date getCreated() { return getContent().getCreated(); } - public AccessPolicyInfo setCreated(Date created) { - getContent().setCreated(created); - return this; - } - + /** + * Get the last modified date. + * + * @return the date. + */ public Date getLastModified() { return getContent().getLastModified(); } - public AccessPolicyInfo setLastModified(Date lastModified) { - getContent().setLastModified(lastModified); - return this; - } - + /** + * Get the name. + * + * @return the name. + */ public String getName() { return getContent().getName(); } - public AccessPolicyInfo setName(String name) { - getContent().setName(name); - return this; - } - + /** + * Get the duration. + * + * @return the duration. + */ public double getDurationInMinutes() { return getContent().getDurationInMinutes(); } - public AccessPolicyInfo setDurationInMinutes(double durationInMinutes) { - getContent().setDurationInMinutes(durationInMinutes); - return this; - } - + /** + * Get the permissions. + * + * @return the permissions. + */ public EnumSet getPermissions() { return AccessPolicyPermission.permissionsFromBits(getContent().getPermissions()); } - - public AccessPolicyInfo setPermissions(EnumSet permissions) { - getContent().setPermissions(AccessPolicyPermission.bitsFromPermissions(permissions)); - return this; - } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/Asset.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/Asset.java index aea5c606241d0..e736b536d9e0e 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/Asset.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/Asset.java @@ -71,7 +71,7 @@ public static class Creator extends EntityOperationSingleResultBase i private String alternateId; /** The options. */ - private EncryptionOption options; + private AssetOption options; /** The state. */ private AssetState state; @@ -132,7 +132,7 @@ public Creator setAlternateId(String alternateId) { * the options * @return the creator */ - public Creator setOptions(EncryptionOption options) { + public Creator setOptions(AssetOption options) { this.options = options; return this; } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AssetInfo.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AssetInfo.java index e187f252f9b29..7572827f3c411 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AssetInfo.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AssetInfo.java @@ -39,13 +39,6 @@ public AssetInfo(EntryType entry, AssetType content) { super(entry, content); } - /** - * Instantiates a new asset info. - */ - public AssetInfo() { - super(new AssetType()); - } - /** * Get the asset id. * @@ -55,18 +48,6 @@ public String getId() { return getContent().getId(); } - /** - * Set the id. - * - * @param id - * the id - * @return the asset info - */ - public AssetInfo setId(String id) { - getContent().setId(id); - return this; - } - /** * Get the asset name. * @@ -76,18 +57,6 @@ public String getName() { return this.getContent().getName(); } - /** - * set the name. - * - * @param name - * the name - * @return the asset info - */ - public AssetInfo setName(String name) { - this.getContent().setName(name); - return this; - } - /** * Get the asset state. * @@ -97,18 +66,6 @@ public AssetState getState() { return AssetState.fromCode(getContent().getState()); } - /** - * Set the state. - * - * @param state - * the state - * @return the asset info - */ - public AssetInfo setState(AssetState state) { - getContent().setState(state.getCode()); - return this; - } - /** * Get the creation date. * @@ -118,18 +75,6 @@ public Date getCreated() { return this.getContent().getCreated(); } - /** - * Set creation date. - * - * @param created - * the date - * @return the asset info - */ - public AssetInfo setCreated(Date created) { - getContent().setCreated(created); - return this; - } - /** * Get last modified date. * @@ -139,18 +84,6 @@ public Date getLastModified() { return getContent().getLastModified(); } - /** - * Set last modified date. - * - * @param lastModified - * the date - * @return the asset info - */ - public AssetInfo setLastModified(Date lastModified) { - getContent().setLastModified(lastModified); - return this; - } - /** * Get the alternate id. * @@ -160,37 +93,12 @@ public String getAlternateId() { return getContent().getAlternateId(); } - /** - * Set the alternate id. - * - * @param alternateId - * the id - * @return the asset info - */ - public AssetInfo setAlternateId(String alternateId) { - getContent().setAlternateId(alternateId); - return this; - } - /** * Get the options. * * @return the options */ - public EncryptionOption getOptions() { - return EncryptionOption.fromCode(getContent().getOptions()); - } - - /** - * Set the options. - * - * @param encryptionOption - * the encryption option - * @return the asset info - */ - public AssetInfo setOptions(EncryptionOption encryptionOption) { - getContent().setOptions(encryptionOption.getCode()); - return this; + public AssetOption getOptions() { + return AssetOption.fromCode(getContent().getOptions()); } - } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/EncryptionOption.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AssetOption.java similarity index 80% rename from microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/EncryptionOption.java rename to microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AssetOption.java index 6b989e3aa279d..6acd1f144c41f 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/EncryptionOption.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/AssetOption.java @@ -20,7 +20,7 @@ /** * Specifies the options for encryption. */ -public enum EncryptionOption { +public enum AssetOption { /** The None. */ None(0), @@ -38,7 +38,7 @@ public enum EncryptionOption { * @param encryptionOptionCode * the encryption option code */ - private EncryptionOption(int encryptionOptionCode) { + private AssetOption(int encryptionOptionCode) { this.encryptionOptionCode = encryptionOptionCode; } @@ -52,21 +52,21 @@ public int getCode() { } /** - * Create an EncryptionOption instance based on the + * Create an AssetOption instance based on the * given integer. * * @param option * the integer value of option - * @return The EncryptionOption + * @return The AssetOption */ - public static EncryptionOption fromCode(int option) { + public static AssetOption fromCode(int option) { switch (option) { case 0: - return EncryptionOption.None; + return AssetOption.None; case 1: - return EncryptionOption.StorageEncrypted; + return AssetOption.StorageEncrypted; case 2: - return EncryptionOption.CommonEncryptionProtected; + return AssetOption.CommonEncryptionProtected; default: throw new InvalidParameterException("option"); } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/ContentKeyInfo.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/ContentKeyInfo.java index 85b4eca7176f3..b03dd95a53c1d 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/ContentKeyInfo.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/ContentKeyInfo.java @@ -39,13 +39,6 @@ public ContentKeyInfo(EntryType entry, ContentKeyRestType content) { super(entry, content); } - /** - * Instantiates a new content key info. - */ - public ContentKeyInfo() { - super(new ContentKeyRestType()); - } - /** * Gets the id. * @@ -55,30 +48,6 @@ public String getId() { return getContent().getId(); } - /** - * Sets the id. - * - * @param id - * the id - * @return the content key info - */ - public ContentKeyInfo setId(String id) { - getContent().setId(id); - return this; - } - - /** - * Sets the create. - * - * @param created - * the created - * @return the content key info - */ - public ContentKeyInfo setCreated(Date created) { - getContent().setCreated(created); - return this; - } - /** * Gets the created. * @@ -97,18 +66,6 @@ public Date getLastModified() { return getContent().getLastModified(); } - /** - * Sets the last modified. - * - * @param lastModified - * the last modified - * @return the content key info - */ - public ContentKeyInfo setLastModified(Date lastModified) { - getContent().setLastModified(lastModified); - return this; - } - /** * Gets the name. * @@ -118,30 +75,6 @@ public String getName() { return getContent().getName(); } - /** - * Sets the name. - * - * @param name - * the name - * @return the content key info - */ - public ContentKeyInfo setName(String name) { - getContent().setName(name); - return this; - } - - /** - * Sets the check sum. - * - * @param checksum - * the check sum - * @return the content key info - */ - public ContentKeyInfo setChecksum(String checksum) { - getContent().setChecksum(checksum); - return this; - } - /** * Gets the check sum. * @@ -151,18 +84,6 @@ public String getChecksum() { return getContent().getChecksum(); } - /** - * Sets the protection key type. - * - * @param protectionKeyType - * the protection key type - * @return the content key info - */ - public ContentKeyInfo setProtectionKeyType(ProtectionKeyType protectionKeyType) { - getContent().setProtectionKeyType(protectionKeyType.getCode()); - return this; - } - /** * Gets the protection key type. * @@ -172,18 +93,6 @@ public ProtectionKeyType getProtectionKeyType() { return ProtectionKeyType.fromCode(getContent().getProtectionKeyType()); } - /** - * Sets the protection key id. - * - * @param protectionKeyId - * the protection key id - * @return the content key info - */ - public ContentKeyInfo setProtectionKeyId(String protectionKeyId) { - getContent().setProtectionKeyId(protectionKeyId); - return this; - } - /** * Gets the protection key id. * @@ -193,18 +102,6 @@ public String getProtectionKeyId() { return getContent().getProtectionKeyId(); } - /** - * Sets the encrypted content key. - * - * @param encryptedContentKey - * the encrypted content key - * @return the content key info - */ - public ContentKeyInfo setEncryptedContentKey(String encryptedContentKey) { - getContent().setEncryptedContentKey(encryptedContentKey); - return this; - } - /** * Gets the encrypted content key. * @@ -214,23 +111,6 @@ public String getEncryptedContentKey() { return getContent().getEncryptedContentKey(); } - /** - * Sets the content key type. - * - * @param contentKeyType - * the content key type - * @return the content key info - */ - public ContentKeyInfo setContentKeyType(ContentKeyType contentKeyType) { - if (contentKeyType == null) { - getContent().setContentKeyType(null); - } - else { - getContent().setContentKeyType(contentKeyType.getCode()); - } - return this; - } - /** * Gets the content key type. * diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/JobInfo.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/JobInfo.java index 627081d001de7..23f9c36de43e0 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/JobInfo.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/JobInfo.java @@ -39,13 +39,6 @@ public JobInfo(EntryType entry, JobType content) { super(entry, content); } - /** - * Instantiates a new job info. - */ - public JobInfo() { - super(new EntryType(), new JobType()); - } - /** * Gets the id. * @@ -55,18 +48,6 @@ public String getId() { return getContent().getId(); } - /** - * Sets the id. - * - * @param id - * the id - * @return the job info - */ - public JobInfo setId(String id) { - getContent().setId(id); - return this; - } - /** * Gets the name. * @@ -76,18 +57,6 @@ public String getName() { return getContent().getName(); } - /** - * Sets the name. - * - * @param name - * the name - * @return the job info - */ - public JobInfo setName(String name) { - getContent().setName(name); - return this; - } - /** * Gets the created. * @@ -97,18 +66,6 @@ public Date getCreated() { return getContent().getCreated(); } - /** - * Sets the created. - * - * @param created - * the created - * @return the job info - */ - public JobInfo setCreated(Date created) { - getContent().setCreated(created); - return this; - } - /** * Gets the last modified. * @@ -118,18 +75,6 @@ public Date getLastModified() { return getContent().getLastModified(); } - /** - * Sets the last modified. - * - * @param lastModified - * the last modified - * @return the job info - */ - public JobInfo setLastModified(Date lastModified) { - getContent().setLastModified(lastModified); - return this; - } - /** * Gets the end time. * @@ -139,18 +84,6 @@ public Date getEndTime() { return getContent().getEndTime(); } - /** - * Sets the end time. - * - * @param endTime - * the end time - * @return the job info - */ - public JobInfo setEndTime(Date endTime) { - getContent().setEndTime(endTime); - return this; - } - /** * Gets the priority. * @@ -160,18 +93,6 @@ public Integer getPriority() { return getContent().getPriority(); } - /** - * Sets the priority. - * - * @param priority - * the priority - * @return the job info - */ - public JobInfo setPriority(Integer priority) { - getContent().setPriority(priority); - return this; - } - /** * Gets the running duration. * @@ -181,18 +102,6 @@ public Double getRunningDuration() { return getContent().getRunningDuration(); } - /** - * Sets the running duration. - * - * @param runningDuration - * the running duration - * @return the job info - */ - public JobInfo setRunningDuration(Double runningDuration) { - getContent().setRunningDuration(runningDuration); - return this; - } - /** * Gets the start time. * @@ -202,18 +111,6 @@ public Date getStartTime() { return getContent().getStartTime(); } - /** - * Sets the start time. - * - * @param startTime - * the start time - * @return the job info - */ - public JobInfo setStartTime(Date startTime) { - getContent().setStartTime(startTime); - return this; - } - /** * Gets the state. * @@ -223,18 +120,6 @@ public JobState getState() { return JobState.fromCode(getContent().getState()); } - /** - * Sets the state. - * - * @param state - * the state - * @return the job info - */ - public JobInfo setState(JobState state) { - getContent().setState(state.getCode()); - return this; - } - /** * Gets the template id. * @@ -244,18 +129,6 @@ public String getTemplateId() { return getContent().getTemplateId(); } - /** - * Sets the template id. - * - * @param templateId - * the template id - * @return the job info - */ - public JobInfo setTemplateId(String templateId) { - getContent().setTemplateId(templateId); - return this; - } - /** * Gets the input media assets. * @@ -265,18 +138,6 @@ public List getInputMediaAssets() { return getContent().getInputMediaAssets(); } - /** - * Sets the input media assets. - * - * @param inputMediaAssets - * the input media assets - * @return the job info - */ - public JobInfo setInputMediaAssets(List inputMediaAssets) { - getContent().setInputMediaAssets(inputMediaAssets); - return this; - } - /** * Gets the output media assets. * @@ -286,18 +147,6 @@ public List getOutputMediaAssets() { return getContent().getOutputMediaAssets(); } - /** - * Sets the output media assets. - * - * @param outputMediaAssets - * the output media assets - * @return the job info - */ - public JobInfo setOutputMediaAssets(List outputMediaAssets) { - getContent().setOutputMediaAssets(outputMediaAssets); - return this; - } - /** * Gets the task body. * @@ -306,16 +155,4 @@ public JobInfo setOutputMediaAssets(List outputMediaAssets) { public String getTaskBody() { return getContent().getTaskBody(); } - - /** - * Sets the tasks. - * - * @param tasks - * the tasks - * @return the job info - */ - public JobInfo setTaskBody(String taskBody) { - getContent().setTaskBody(taskBody); - return this; - } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/LinkInfo.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/LinkInfo.java new file mode 100644 index 0000000000000..0acf7e6b2e431 --- /dev/null +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/LinkInfo.java @@ -0,0 +1,69 @@ +/** + * Copyright 2012 Microsoft Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.microsoft.windowsazure.services.media.models; + +import com.microsoft.windowsazure.services.media.implementation.atom.LinkType; + +/** + * Provides access to OData links + * + */ +public class LinkInfo { + private final LinkType rawLink; + + /** + * Construct a new {@link LinkInfo} instance + */ + public LinkInfo(LinkType rawLink) { + this.rawLink = rawLink; + } + + /** + * Get link rel + * + * @return the rel + */ + public String getRel() { + return rawLink.getRel(); + } + + /** + * Get link type + * + * @return the type + */ + public String getType() { + return rawLink.getType(); + } + + /** + * Get link href + * + * @return the href + */ + public String getHref() { + return rawLink.getHref(); + } + + /** + * Get link title + * + * @return the title + */ + public String getTitle() { + return rawLink.getTitle(); + } +} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/ListTasksResult.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/ListTasksResult.java deleted file mode 100644 index 55f4360a27910..0000000000000 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/ListTasksResult.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * Copyright 2011 Microsoft Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.microsoft.windowsazure.services.media.models; - -import java.util.List; - -/** - * The Class ListTasksResult. - */ -public class ListTasksResult { - - /** The task infos. */ - private List taskInfos; - - /** - * Gets the task infos. - * - * @return the task infos - */ - public List getTaskInfos() { - return taskInfos; - } - - /** - * Sets the task infos. - * - * @param taskInfos - * the task infos - * @return the list tasks result - */ - public ListTasksResult setTaskInfos(List taskInfos) { - this.taskInfos = taskInfos; - return this; - } - -} diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/LocatorInfo.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/LocatorInfo.java index 7c164b6385e61..b5ed565f80334 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/LocatorInfo.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/LocatorInfo.java @@ -38,13 +38,6 @@ public LocatorInfo(EntryType entry, LocatorRestType content) { super(entry, content); } - /** - * Instantiates a new locator info. - */ - public LocatorInfo() { - super(new LocatorRestType()); - } - /** * Gets the id. * @@ -54,18 +47,6 @@ public String getId() { return getContent().getId(); } - /** - * Sets the id. - * - * @param id - * the id - * @return the locator info - */ - public LocatorInfo setId(String id) { - getContent().setId(id); - return this; - } - /** * Gets the expiration date time. * @@ -75,30 +56,6 @@ public Date getExpirationDateTime() { return getContent().getExpirationDateTime(); } - /** - * Sets the expiration date time. - * - * @param expirationDateTime - * the expiration date time - * @return the locator info - */ - public LocatorInfo setExpirationDateTime(Date expirationDateTime) { - getContent().setExpirationDateTime(expirationDateTime); - return this; - } - - /** - * Sets the locator type. - * - * @param locatorType - * the locator type - * @return the locator info - */ - public LocatorInfo setLocatorType(LocatorType locatorType) { - getContent().setType(locatorType.getCode()); - return this; - } - /** * Gets the locator type. * @@ -108,18 +65,6 @@ public LocatorType getLocatorType() { return LocatorType.fromCode(getContent().getType()); } - /** - * Sets the path. - * - * @param path - * the path - * @return the locator info - */ - public LocatorInfo setPath(String path) { - getContent().setPath(path); - return this; - } - /** * Gets the path. * @@ -129,18 +74,6 @@ public String getPath() { return getContent().getPath(); } - /** - * Sets the access policy id. - * - * @param accessPolicyId - * the access policy id - * @return the locator info - */ - public LocatorInfo setAccessPolicyId(String accessPolicyId) { - getContent().setAccessPolicyId(accessPolicyId); - return this; - } - /** * Gets the access policy id. * @@ -150,18 +83,6 @@ public String getAccessPolicyId() { return getContent().getAccessPolicyId(); } - /** - * Sets the asset id. - * - * @param assetId - * the asset id - * @return the locator info - */ - public LocatorInfo setAssetId(String assetId) { - getContent().setAssetId(assetId); - return this; - } - /** * Gets the asset id. * @@ -171,18 +92,6 @@ public String getAssetId() { return getContent().getAssetId(); } - /** - * Sets the start time. - * - * @param startTime - * the start time - * @return the locator info - */ - public LocatorInfo setStartTime(Date startTime) { - getContent().setStartTime(startTime); - return this; - } - /** * Gets the start time. * @@ -201,30 +110,6 @@ public String getBaseUri() { return getContent().getBaseUri(); } - /** - * Sets the base uri. - * - * @param baseUri - * the base uri - * @return the locator info - */ - public LocatorInfo setBaseUri(String baseUri) { - this.getContent().setBaseUri(baseUri); - return this; - } - - /** - * Sets the content access component. - * - * @param contentAccessComponent - * the content access component - * @return the locator info - */ - public LocatorInfo setContentAccessComponent(String contentAccessComponent) { - this.getContent().setContentAccessComponent(contentAccessComponent); - return this; - } - /** * Gets the content access token. * @@ -233,5 +118,4 @@ public LocatorInfo setContentAccessComponent(String contentAccessComponent) { public String getContentAccessToken() { return this.getContent().getContentAccessComponent(); } - } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/MediaProcessorInfo.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/MediaProcessorInfo.java index 3fedc21bca39c..8d6ec26235a9c 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/MediaProcessorInfo.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/MediaProcessorInfo.java @@ -38,13 +38,6 @@ public MediaProcessorInfo(EntryType entry, MediaProcessorType content) { super(entry, content); } - /** - * Instantiates a new media processor info. - */ - public MediaProcessorInfo() { - super(new MediaProcessorType()); - } - /** * Get the asset id. * @@ -54,18 +47,6 @@ public String getId() { return getContent().getId(); } - /** - * Set the id. - * - * @param id - * the id - * @return the asset info - */ - public MediaProcessorInfo setId(String id) { - getContent().setId(id); - return this; - } - /** * Get the asset name. * @@ -75,18 +56,6 @@ public String getName() { return this.getContent().getName(); } - /** - * set the name. - * - * @param name - * the name - * @return the asset info - */ - public MediaProcessorInfo setName(String name) { - this.getContent().setName(name); - return this; - } - /** * Gets the description. * @@ -96,18 +65,6 @@ public String getDescription() { return this.getContent().getDescription(); } - /** - * Sets the description. - * - * @param description - * the description - * @return the media processor info - */ - public MediaProcessorInfo setDescription(String description) { - this.getContent().setDescription(description); - return this; - } - /** * Gets the sku. * @@ -117,18 +74,6 @@ public String getSku() { return this.getContent().getSku(); } - /** - * Sets the sku. - * - * @param sku - * the sku - * @return the media processor info - */ - public MediaProcessorInfo setSku(String sku) { - this.getContent().setSku(sku); - return this; - } - /** * Gets the vendor. * @@ -138,18 +83,6 @@ public String getVendor() { return this.getContent().getVendor(); } - /** - * Sets the vendor. - * - * @param vendor - * the vendor - * @return the media processor info - */ - public MediaProcessorInfo setVendor(String vendor) { - this.getContent().setVendor(vendor); - return this; - } - /** * Gets the version. * @@ -158,16 +91,4 @@ public MediaProcessorInfo setVendor(String vendor) { public String getVersion() { return this.getContent().getVersion(); } - - /** - * Sets the version. - * - * @param version - * the version - * @return the media processor info - */ - public MediaProcessorInfo setVersion(String version) { - this.getContent().setVersion(version); - return this; - } } diff --git a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/TaskInfo.java b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/TaskInfo.java index dda71ca5e6ea2..3ed2fc51d31d1 100644 --- a/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/TaskInfo.java +++ b/microsoft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/TaskInfo.java @@ -38,13 +38,6 @@ public TaskInfo(EntryType entry, TaskType content) { super(entry, content); } - /** - * Instantiates a new task info. - */ - public TaskInfo() { - super(new TaskType()); - } - /** * Gets the id. * @@ -54,18 +47,6 @@ public String getId() { return getContent().getId(); } - /** - * Sets the id. - * - * @param id - * the id - * @return the task info - */ - public TaskInfo setId(String id) { - getContent().setId(id); - return this; - } - /** * Gets the configuration. * @@ -75,18 +56,6 @@ public String getConfiguration() { return getContent().getConfiguration(); } - /** - * Sets the configuration. - * - * @param configuration - * the configuration - * @return the task info - */ - public TaskInfo setConfiguration(String configuration) { - getContent().setConfiguration(configuration); - return this; - } - /** * Gets the end time. * @@ -96,18 +65,6 @@ public Date getEndTime() { return getContent().getEndTime(); } - /** - * Sets the end time. - * - * @param endTime - * the end time - * @return the task info - */ - public TaskInfo setEndTime(Date endTime) { - getContent().setEndTime(endTime); - return this; - } - /** * Gets the error details. * @@ -117,18 +74,6 @@ public String getErrorDetails() { return getContent().getErrorDetails(); } - /** - * Sets the error details. - * - * @param errorDetails - * the error details - * @return the task info - */ - public TaskInfo setErrorDetails(String errorDetails) { - getContent().setErrorDetails(errorDetails); - return this; - } - /** * Gets the media processor id. * @@ -138,18 +83,6 @@ public String getMediaProcessorId() { return getContent().getMediaProcessorId(); } - /** - * Sets the media processor id. - * - * @param mediaProcessorId - * the media processor id - * @return the task info - */ - public TaskInfo setMediaProcessorId(String mediaProcessorId) { - getContent().setMediaProcessorId(mediaProcessorId); - return this; - } - /** * Gets the name. * @@ -159,18 +92,6 @@ public String getName() { return getContent().getName(); } - /** - * Sets the name. - * - * @param name - * the name - * @return the task info - */ - public TaskInfo setName(String name) { - getContent().setName(name); - return this; - } - /** * Gets the perf message. * @@ -180,18 +101,6 @@ public String getPerfMessage() { return getContent().getPerfMessage(); } - /** - * Sets the perf message. - * - * @param perfMessage - * the perf message - * @return the task info - */ - public TaskInfo setPerfMessage(String perfMessage) { - getContent().setPerfMessage(perfMessage); - return this; - } - /** * Gets the priority. * @@ -201,18 +110,6 @@ public Integer getPriority() { return getContent().getPriority(); } - /** - * Sets the priority. - * - * @param priority - * the priority - * @return the task info - */ - public TaskInfo setPriority(Integer priority) { - getContent().setPriority(priority); - return this; - } - /** * Gets the progress. * @@ -222,17 +119,6 @@ public Double getProgress() { return getContent().getProgress(); } - /** - * - * @param progress - * the progress - * @return the task info - */ - public TaskInfo setProgress(Double progress) { - getContent().setProgress(progress); - return this; - } - /** * Gets the running duration. * @@ -242,18 +128,6 @@ public double getRunningDuration() { return getContent().getRunningDuration(); } - /** - * Sets the running duration. - * - * @param runningDuration - * the running duration - * @return the task info - */ - public TaskInfo setRunningDuration(double runningDuration) { - getContent().setRunningDuration(runningDuration); - return this; - } - /** * Gets the start time. * @@ -263,18 +137,6 @@ public Date getStartTime() { return getContent().getStartTime(); } - /** - * Sets the start time. - * - * @param startTime - * the start time - * @return the task info - */ - public TaskInfo setStartTime(Date startTime) { - getContent().setStartTime(startTime); - return this; - } - /** * Gets the state. * @@ -284,18 +146,6 @@ public Integer getState() { return getContent().getState(); } - /** - * Sets the state. - * - * @param state - * the state - * @return the task info - */ - public TaskInfo setState(Integer state) { - getContent().setState(state); - return this; - } - /** * Gets the task body. * @@ -305,18 +155,6 @@ public String getTaskBody() { return getContent().getTaskBody(); } - /** - * Sets the task body. - * - * @param taskBody - * the task body - * @return the task info - */ - public TaskInfo setTaskBody(String taskBody) { - getContent().setTaskBody(taskBody); - return this; - } - /** * Gets the options. * @@ -326,18 +164,6 @@ public Integer getOptions() { return getContent().getOptions(); } - /** - * Sets the options. - * - * @param options - * the options - * @return the task info - */ - public TaskInfo setOptions(Integer options) { - getContent().setOptions(options); - return this; - } - /** * Gets the encryption key id. * @@ -347,18 +173,6 @@ public String getEncryptionKeyId() { return getContent().getEncryptionKeyId(); } - /** - * Sets the encryption key id. - * - * @param encryptionKeyId - * the encryption key id - * @return the task info - */ - public TaskInfo setEncryptionKeyId(String encryptionKeyId) { - getContent().setEncryptionKeyId(encryptionKeyId); - return this; - } - /** * Gets the encryption scheme. * @@ -368,18 +182,6 @@ public String getEncryptionScheme() { return getContent().getEncryptionScheme(); } - /** - * Sets the encryption scheme. - * - * @param encryptionScheme - * the encryption scheme - * @return the task info - */ - public TaskInfo setEncryptionScheme(String encryptionScheme) { - getContent().setEncryptionScheme(encryptionScheme); - return this; - } - /** * Gets the encryption version. * @@ -389,18 +191,6 @@ public String getEncryptionVersion() { return getContent().getEncryptionVersion(); } - /** - * Sets the encryption version. - * - * @param encryptionVersion - * the encryption version - * @return the task info - */ - public TaskInfo setEncryptionVersion(String encryptionVersion) { - getContent().setEncryptionVersion(encryptionVersion); - return this; - } - /** * Gets the initialization vector. * @@ -409,17 +199,4 @@ public TaskInfo setEncryptionVersion(String encryptionVersion) { public String getInitializationVector() { return getContent().getInitializationVector(); } - - /** - * Sets the initialization vector. - * - * @param initializationVector - * the initialization vector - * @return the task info - */ - public TaskInfo setInitializationVector(String initializationVector) { - getContent().setInitializationVector(initializationVector); - return this; - } - } diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/AssetFileIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/AssetFileIntegrationTest.java index 093dbcf246295..458b8a5da8588 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/AssetFileIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/AssetFileIntegrationTest.java @@ -37,9 +37,7 @@ import com.microsoft.windowsazure.services.media.models.AssetFileInfo; import com.microsoft.windowsazure.services.media.models.AssetInfo; import com.microsoft.windowsazure.services.media.models.ListResult; -import com.microsoft.windowsazure.services.media.models.Locator; import com.microsoft.windowsazure.services.media.models.LocatorInfo; -import com.microsoft.windowsazure.services.media.models.LocatorType; public class AssetFileIntegrationTest extends IntegrationTestBase { @@ -64,13 +62,13 @@ public static void setup() throws Exception { public void canCreateFileForUploadedBlob() throws Exception { AssetInfo asset = createTestAsset("createFileForUploadedBlob"); LocatorInfo locator = createLocator(writePolicy, asset, 5, 10); - WritableBlobContainerContract blobWriter = MediaService.createBlobWriter(locator); + WritableBlobContainerContract blobWriter = service.createBlobWriter(locator); createAndUploadBlob(blobWriter, BLOB_NAME, firstPrimes); service.action(AssetFile.createFileInfos(asset.getId())); - ListResult files = service.list(AssetFile.list()); + ListResult files = service.list(AssetFile.list(asset.getId())); assertEquals(1, files.size()); AssetFileInfo file = files.get(0); @@ -81,7 +79,7 @@ public void canCreateFileForUploadedBlob() throws Exception { public void canCreateFileEntityDirectly() throws Exception { AssetInfo asset = createTestAsset("createFileEntityDirectly"); LocatorInfo locator = createLocator(writePolicy, asset, 5, 10); - WritableBlobContainerContract blobWriter = MediaService.createBlobWriter(locator); + WritableBlobContainerContract blobWriter = service.createBlobWriter(locator); createAndUploadBlob(blobWriter, BLOB_NAME_2, firstPrimes); @@ -106,7 +104,7 @@ public void canCreateAssetWithMultipleFiles() throws Exception { AccessPolicyInfo policy = createWritePolicy("createWithMultipleFiles", 10); LocatorInfo locator = createLocator(policy, asset, 5, 10); - WritableBlobContainerContract blobWriter = MediaService.createBlobWriter(locator); + WritableBlobContainerContract blobWriter = service.createBlobWriter(locator); createAndUploadBlob(blobWriter, "blob1.bin", firstPrimes); createAndUploadBlob(blobWriter, "blob2.bin", onesAndZeros); @@ -119,7 +117,7 @@ public void canCreateAssetWithMultipleFiles() throws Exception { .setIsEncrypted(false).setContentFileSize(new Long(onesAndZeros.length))); AssetFileInfo file3 = service.create(AssetFile.create(asset.getId(), "blob3.bin").setIsPrimary(false) - .setIsEncrypted(false).setContentFileSize(new Long(countingUp.length))); + .setIsEncrypted(false).setContentFileSize(new Long(countingUp.length)).setContentChecksum("1234")); ListResult files = service.list(AssetFile.list(asset.getId())); @@ -133,9 +131,9 @@ public int compare(AssetFileInfo o1, AssetFileInfo o2) { } }); - assertAssetFileInfoEquals(file1, results.get(0)); - assertAssetFileInfoEquals(file2, results.get(1)); - assertAssetFileInfoEquals(file3, results.get(2)); + assertAssetFileInfoEquals("results.get(0)", file1, results.get(0)); + assertAssetFileInfoEquals("results.get(1)", file2, results.get(1)); + assertAssetFileInfoEquals("results.get(2)", file3, results.get(2)); } @Test @@ -143,7 +141,7 @@ public void canCreateFileAndThenUpdateIt() throws Exception { AssetInfo asset = createTestAsset("createAndUpdate"); AccessPolicyInfo policy = createWritePolicy("createAndUpdate", 10); LocatorInfo locator = createLocator(policy, asset, 5, 10); - WritableBlobContainerContract blobWriter = MediaService.createBlobWriter(locator); + WritableBlobContainerContract blobWriter = service.createBlobWriter(locator); createAndUploadBlob(blobWriter, "toUpdate.bin", firstPrimes); @@ -161,7 +159,7 @@ public void canDeleteFileFromAsset() throws Exception { AssetInfo asset = createTestAsset("deleteFile"); AccessPolicyInfo policy = createWritePolicy("deleteFile", 10); LocatorInfo locator = createLocator(policy, asset, 5, 10); - WritableBlobContainerContract blobWriter = MediaService.createBlobWriter(locator); + WritableBlobContainerContract blobWriter = service.createBlobWriter(locator); createAndUploadBlob(blobWriter, "todelete.bin", firstPrimes); createAndUploadBlob(blobWriter, "tokeep.bin", onesAndZeros); @@ -195,17 +193,6 @@ private static AccessPolicyInfo createWritePolicy(String name, int durationInMin EnumSet.of(AccessPolicyPermission.WRITE))); } - private static LocatorInfo createLocator(AccessPolicyInfo accessPolicy, AssetInfo asset, int startDeltaMinutes, - int expirationDeltaMinutes) throws ServiceException { - - Date now = new Date(); - Date start = new Date(now.getTime() - (startDeltaMinutes * 60 * 1000)); - Date expire = new Date(now.getTime() + (expirationDeltaMinutes * 60 * 1000)); - - return service.create(Locator.create(accessPolicy.getId(), asset.getId(), LocatorType.SAS) - .setStartDateTime(start).setExpirationDateTime(expire)); - } - private static void createAndUploadBlob(WritableBlobContainerContract blobWriter, String blobName, byte[] data) throws ServiceException { InputStream blobContent = new ByteArrayInputStream(data); @@ -216,19 +203,36 @@ private static void createAndUploadBlob(WritableBlobContainerContract blobWriter // Assertion helpers // - private void assertAssetFileInfoEquals(AssetFileInfo expected, AssetFileInfo actual) { - assertEquals(expected.getId(), actual.getId()); - assertEquals(expected.getName(), actual.getName()); - assertEquals(expected.getParentAssetId(), actual.getParentAssetId()); - assertEquals(expected.getIsPrimary(), actual.getIsPrimary()); - assertEquals(expected.getIsEncrypted(), actual.getIsEncrypted()); - assertEquals(expected.getEncryptionKeyId(), actual.getEncryptionKeyId()); - assertEquals(expected.getEncryptionScheme(), actual.getEncryptionScheme()); - assertEquals(expected.getEncryptionVersion(), actual.getEncryptionVersion()); - assertEquals(expected.getInitializationVector(), actual.getInitializationVector()); - assertDateApproxEquals(expected.getCreated(), actual.getCreated()); - assertDateApproxEquals(expected.getLastModified(), actual.getLastModified()); - assertEquals(expected.getMimeType(), actual.getMimeType()); + private void assertAssetFileInfoEquals(String message, AssetFileInfo expected, AssetFileInfo actual) { + verifyAssetInfoProperties(message, expected.getId(), expected.getName(), expected.getParentAssetId(), + expected.getIsPrimary(), expected.getIsEncrypted(), expected.getEncryptionKeyId(), + expected.getEncryptionScheme(), expected.getEncryptionVersion(), expected.getInitializationVector(), + expected.getCreated(), expected.getLastModified(), expected.getContentChecksum(), + expected.getMimeType(), actual); + } + + private void verifyAssetInfoProperties(String message, String id, String name, String parentAssetId, + boolean isPrimary, boolean isEncrypted, String encryptionKeyId, String encryptionScheme, + String encryptionVersion, String initializationVector, Date created, Date lastModified, + String contentChecksum, String mimeType, AssetFileInfo assetFile) { + assertNotNull(message, assetFile); + + assertEquals(message + ".getId", id, assetFile.getId()); + assertEquals(message + ".getName", name, assetFile.getName()); + assertEquals(message + ".getParentAssetId", parentAssetId, assetFile.getParentAssetId()); + assertEquals(message + ".getIsPrimary", isPrimary, assetFile.getIsPrimary()); + + assertEquals(message + ".getIsEncrypted", isEncrypted, assetFile.getIsEncrypted()); + assertEquals(message + ".getEncryptionKeyId", encryptionKeyId, assetFile.getEncryptionKeyId()); + assertEquals(message + ".getEncryptionScheme", encryptionScheme, assetFile.getEncryptionScheme()); + assertEquals(message + ".getEncryptionVersion", encryptionVersion, assetFile.getEncryptionVersion()); + assertEquals(message + ".getInitializationVector", initializationVector, assetFile.getInitializationVector()); + + assertDateApproxEquals(message + ".getCreated", created, assetFile.getCreated()); + assertDateApproxEquals(message + ".getLastModified", lastModified, assetFile.getLastModified()); + assertEquals(message + ".getContentChecksum", contentChecksum, assetFile.getContentChecksum()); + assertEquals(message + ".getMimeType", mimeType, assetFile.getMimeType()); + } } diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/AssetIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/AssetIntegrationTest.java index 8696fb1819bdb..acfbfa7868271 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/AssetIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/AssetIntegrationTest.java @@ -38,7 +38,7 @@ import com.microsoft.windowsazure.services.media.models.ContentKey; import com.microsoft.windowsazure.services.media.models.ContentKeyInfo; import com.microsoft.windowsazure.services.media.models.ContentKeyType; -import com.microsoft.windowsazure.services.media.models.EncryptionOption; +import com.microsoft.windowsazure.services.media.models.AssetOption; import com.sun.jersey.core.util.MultivaluedMapImpl; public class AssetIntegrationTest extends IntegrationTestBase { @@ -49,12 +49,12 @@ private void verifyInfosEqual(String message, AssetInfo expected, AssetInfo actu } private void verifyAssetProperties(String message, String testName, String altId, - EncryptionOption encryptionOption, AssetState assetState, AssetInfo actualAsset) { + AssetOption encryptionOption, AssetState assetState, AssetInfo actualAsset) { verifyAssetProperties(message, testName, altId, encryptionOption, assetState, null, null, null, actualAsset); } private void verifyAssetProperties(String message, String testName, String altId, - EncryptionOption encryptionOption, AssetState assetState, String id, Date created, Date lastModified, + AssetOption encryptionOption, AssetState assetState, String id, Date created, Date lastModified, AssetInfo actualAsset) { assertNotNull(message, actualAsset); assertEquals(message + " Name", testName, actualAsset.getName()); @@ -77,7 +77,7 @@ public void createAssetOptionsSuccess() throws Exception { // Arrange String testName = testAssetPrefix + "createAssetOptionsSuccess"; String altId = "altId"; - EncryptionOption encryptionOption = EncryptionOption.StorageEncrypted; + AssetOption encryptionOption = AssetOption.StorageEncrypted; AssetState assetState = AssetState.Published; // Act @@ -113,7 +113,7 @@ public void createAssetNullNameSuccess() throws Exception { try { actualAsset = service.create(Asset.create()); // Assert - verifyAssetProperties("actualAsset", "", "", EncryptionOption.None, AssetState.Initialized, actualAsset); + verifyAssetProperties("actualAsset", "", "", AssetOption.None, AssetState.Initialized, actualAsset); } finally { // Clean up the anonymous asset now while we have the id, because we @@ -134,7 +134,7 @@ public void getAssetSuccess() throws Exception { // Arrange String testName = testAssetPrefix + "GetAssetSuccess"; String altId = "altId"; - EncryptionOption encryptionOption = EncryptionOption.StorageEncrypted; + AssetOption encryptionOption = AssetOption.StorageEncrypted; AssetState assetState = AssetState.Published; AssetInfo assetInfo = service.create(Asset.create().setName(testName).setAlternateId(altId) @@ -165,7 +165,7 @@ public void getAssetNonexistId() throws ServiceException { public void listAssetSuccess() throws ServiceException { // Arrange String altId = "altId"; - EncryptionOption encryptionOption = EncryptionOption.StorageEncrypted; + AssetOption encryptionOption = AssetOption.StorageEncrypted; AssetState assetState = AssetState.Published; String[] assetNames = new String[] { testAssetPrefix + "assetA", testAssetPrefix + "assetB" }; @@ -213,7 +213,7 @@ public void canListAssetsWithOptions() throws ServiceException { public void updateAssetSuccess() throws Exception { // Arrange String originalTestName = testAssetPrefix + "updateAssetSuccessOriginal"; - EncryptionOption originalEncryptionOption = EncryptionOption.StorageEncrypted; + AssetOption originalEncryptionOption = AssetOption.StorageEncrypted; AssetState originalAssetState = AssetState.Initialized; AssetInfo originalAsset = service.create(Asset.create().setName(originalTestName).setAlternateId("altId") .setOptions(originalEncryptionOption)); @@ -285,7 +285,7 @@ public void linkAssetContentKeySuccess() throws ServiceException, URISyntaxExcep // Arrange String originalTestName = testAssetPrefix + "linkAssetContentKeyInvalidIdFailed"; AssetInfo assetInfo = service.create(Asset.create().setName(originalTestName) - .setOptions(EncryptionOption.StorageEncrypted)); + .setOptions(AssetOption.StorageEncrypted)); String contentKeyId = String.format("nb:kid:UUID:%s", UUID.randomUUID()); String encryptedContentKey = "dummyEncryptedContentKey"; ContentKeyInfo contentKeyInfo = service.create(ContentKey.create(contentKeyId, diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/IntegrationTestBase.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/IntegrationTestBase.java index d7a2a9c13e846..df6918a26e466 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/IntegrationTestBase.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/IntegrationTestBase.java @@ -14,15 +14,19 @@ import org.junit.rules.ExpectedException; import com.microsoft.windowsazure.services.core.Configuration; +import com.microsoft.windowsazure.services.core.ServiceException; import com.microsoft.windowsazure.services.media.models.AccessPolicy; import com.microsoft.windowsazure.services.media.models.AccessPolicyInfo; import com.microsoft.windowsazure.services.media.models.Asset; import com.microsoft.windowsazure.services.media.models.AssetInfo; import com.microsoft.windowsazure.services.media.models.ContentKey; import com.microsoft.windowsazure.services.media.models.ContentKeyInfo; +import com.microsoft.windowsazure.services.media.models.Job; +import com.microsoft.windowsazure.services.media.models.JobInfo; import com.microsoft.windowsazure.services.media.models.ListResult; import com.microsoft.windowsazure.services.media.models.Locator; import com.microsoft.windowsazure.services.media.models.LocatorInfo; +import com.microsoft.windowsazure.services.media.models.LocatorType; public abstract class IntegrationTestBase { protected static MediaContract service; @@ -31,6 +35,7 @@ public abstract class IntegrationTestBase { protected static final String testAssetPrefix = "testAsset"; protected static final String testPolicyPrefix = "testPolicy"; protected static final String testContentKeyPrefix = "testContentKey"; + protected static final String testJobPrefix = "testJobPrefix"; protected static final String validButNonexistAssetId = "nb:cid:UUID:0239f11f-2d36-4e5f-aa35-44d58ccc0973"; protected static final String validButNonexistAccessPolicyId = "nb:pid:UUID:38dcb3a0-ef64-4ad0-bbb5-67a14c6df2f7"; @@ -50,7 +55,6 @@ public static void setup() throws Exception { overrideWithEnv(config, MediaConfiguration.OAUTH_CLIENT_SECRET); overrideWithEnv(config, MediaConfiguration.OAUTH_SCOPE); - // TODO: Replace with call to MediaService.create once that's updated service = MediaService.create(config); cleanupEnvironment(); @@ -77,6 +81,7 @@ private static void cleanupEnvironment() { removeAllTestAssets(); removeAllTestAccessPolicies(); removeAllTestContentKeys(); + removeAllTestJobs(); } private static void removeAllTestContentKeys() { @@ -136,10 +141,35 @@ private static void removeAllTestLocators() { } } + private static void removeAllTestJobs() { + try { + ListResult jobs = service.list(Job.list()); + for (JobInfo job : jobs) { + if (job.getName().startsWith(testAssetPrefix)) { + service.delete(Job.delete(job.getId())); + } + } + } + catch (Exception e) { + e.printStackTrace(); + } + } + interface ComponentDelegate { void verifyEquals(String message, Object expected, Object actual); } + protected static LocatorInfo createLocator(AccessPolicyInfo accessPolicy, AssetInfo asset, int startDeltaMinutes, + int expirationDeltaMinutes) throws ServiceException { + + Date now = new Date(); + Date start = new Date(now.getTime() - (startDeltaMinutes * 60 * 1000)); + Date expire = new Date(now.getTime() + (expirationDeltaMinutes * 60 * 1000)); + + return service.create(Locator.create(accessPolicy.getId(), asset.getId(), LocatorType.SAS) + .setStartDateTime(start).setExpirationDateTime(expire)); + } + protected void verifyListResultContains(List expectedInfos, Collection actualInfos, ComponentDelegate delegate) { verifyListResultContains("", expectedInfos, actualInfos, delegate); diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/JobIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/JobIntegrationTest.java index e21f95db164a3..bfa003d0cc98d 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/JobIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/JobIntegrationTest.java @@ -24,9 +24,11 @@ import java.util.Date; import java.util.EnumSet; import java.util.List; +import java.util.UUID; import javax.ws.rs.core.MultivaluedMap; +import org.junit.BeforeClass; import org.junit.Test; import com.microsoft.windowsazure.services.core.ServiceException; @@ -40,144 +42,168 @@ import com.microsoft.windowsazure.services.media.models.JobInfo; import com.microsoft.windowsazure.services.media.models.JobState; import com.microsoft.windowsazure.services.media.models.ListResult; -import com.microsoft.windowsazure.services.media.models.Locator; import com.microsoft.windowsazure.services.media.models.LocatorInfo; -import com.microsoft.windowsazure.services.media.models.LocatorType; import com.microsoft.windowsazure.services.media.models.Task; +import com.microsoft.windowsazure.services.media.models.Task.CreateBatchOperation; import com.sun.jersey.core.util.MultivaluedMapImpl; public class JobIntegrationTest extends IntegrationTestBase { - private final String testJobPrefix = "testJobPrefix"; - private final byte[] testBlobData = new byte[] { 0, 1, 2 }; - private final String taskBody = "" - + "JobInputAsset(0)JobOutputAsset(0)" + ""; + private static AssetInfo assetInfo; + private static final byte[] testBlobData = new byte[] { 4, 8, 15, 16, 23, 42 }; private void verifyJobInfoEqual(String message, JobInfo expected, JobInfo actual) { verifyJobProperties(message, expected.getName(), expected.getPriority(), expected.getRunningDuration(), - expected.getState(), expected.getTemplateId(), expected.getInputMediaAssets(), + expected.getState(), expected.getTemplateId(), expected.getCreated(), expected.getLastModified(), + expected.getStartTime(), expected.getEndTime(), expected.getInputMediaAssets(), expected.getOutputMediaAssets(), actual); } - private AccessPolicyInfo createWritableAccessPolicy(String name, int durationInMinutes) throws ServiceException { - return service.create(AccessPolicy.create(testPolicyPrefix + name, durationInMinutes, - EnumSet.of(AccessPolicyPermission.WRITE))); - } - - private void createAndUploadBlob(WritableBlobContainerContract blobWriter, String blobName, byte[] blobData) - throws ServiceException { - InputStream blobContent = new ByteArrayInputStream(blobData); - blobWriter.createBlockBlob(blobName, blobContent); - } - - private String createFileAsset(String name) throws ServiceException { - String testBlobName = "test" + name + ".bin"; - AssetInfo assetInfo = service.create(Asset.create().setName(name)); - AccessPolicyInfo accessPolicyInfo = createWritableAccessPolicy(name, 10); - LocatorInfo locator = createLocator(accessPolicyInfo, assetInfo, 5, 10); - WritableBlobContainerContract blobWriter = MediaService.createBlobWriter(locator); - createAndUploadBlob(blobWriter, testBlobName, testBlobData); - - service.create(AssetFile.create(assetInfo.getId(), testBlobName).setIsPrimary(true).setIsEncrypted(false) - .setContentFileSize(new Long(testBlobData.length))); - - service.action(AssetFile.createFileInfos(assetInfo.getId())); - return assetInfo.getId(); - } - - private LocatorInfo createLocator(AccessPolicyInfo accessPolicy, AssetInfo asset, int startDeltaMinutes, - int expirationDeltaMinutes) throws ServiceException { - - Date now = new Date(); - Date start = new Date(now.getTime() - (startDeltaMinutes * 60 * 1000)); - Date expire = new Date(now.getTime() + (expirationDeltaMinutes * 60 * 1000)); - - return service.create(Locator.create(accessPolicy.getId(), asset.getId(), LocatorType.SAS) - .setStartDateTime(start).setExpirationDateTime(expire)); - } - private void verifyJobProperties(String message, String testName, Integer priority, Double runningDuration, - JobState state, String templateId, List inputMediaAssets, List outputMediaAssets, - JobInfo actualJob) { + JobState state, String templateId, Date created, Date lastModified, Date startTime, Date endTime, + List inputMediaAssets, List outputMediaAssets, JobInfo actualJob) { assertNotNull(message, actualJob); + + assertNotNull(message + "Id", actualJob.getId()); + assertEquals(message + " Name", testName, actualJob.getName()); // comment out due to issue 464 // assertEquals(message + " Priority", priority, actualJob.getPriority()); assertEquals(message + " RunningDuration", runningDuration, actualJob.getRunningDuration()); assertEquals(message + " State", state, actualJob.getState()); - // commented out due to issue 463 - // assertEquals(message + " TemplateId", templateId, actualJob.getTemplateId()); + assertEqualsNullEmpty(message + " TemplateId", templateId, actualJob.getTemplateId()); + + assertDateApproxEquals(message + " Created", created, actualJob.getCreated()); + assertDateApproxEquals(message + " LastModified", lastModified, actualJob.getLastModified()); + assertDateApproxEquals(message + " StartTime", startTime, actualJob.getStartTime()); + assertDateApproxEquals(message + " EndTime", endTime, actualJob.getEndTime()); + + // TODO: Add test for accessing the input and output media assets when fixed: + // https://github.com/WindowsAzure/azure-sdk-for-java-pr/issues/508 assertEquals(message + " InputMediaAssets", inputMediaAssets, actualJob.getInputMediaAssets()); assertEquals(message + " OutputMediaAssets", outputMediaAssets, actualJob.getOutputMediaAssets()); + + // TODO: Add test for accessing the tasks when fixed: + // https://github.com/WindowsAzure/azure-sdk-for-java-pr/issues/531 + } + + private void assertEqualsNullEmpty(String message, String expected, String actual) { + if ((expected == null || expected.length() == 0) && (actual == null || actual.length() == 0)) { + // both nullOrEmpty, so match. + } + else { + assertEquals(message, expected, actual); + } } private JobInfo createJob(String name) throws ServiceException { - String assetId = createFileAsset(name); URI serviceUri = service.getRestServiceUri(); - return service.create(Job - .create(serviceUri) - .setName("My Encoding Job") - .setPriority(3) - .addInputMediaAsset(assetId) - .addTaskCreator( - Task.create().setConfiguration("H.264 256k DSL CBR") - .setMediaProcessorId("nb:mpid:UUID:2f381738-c504-4e4a-a38e-d199e207fcd5") - .setName("My encoding Task").setTaskBody(taskBody))); + return service.create(Job.create(serviceUri).setName(name).setPriority(3).addInputMediaAsset(assetInfo.getId()) + .addTaskCreator(getTaskCreator(0))); } - @Test - public void createJobSuccess() throws Exception { - // Arrange - AssetInfo assetInfo = service.create(Asset.create()); + private CreateBatchOperation getTaskCreator(int outputAssetPosition) { + return Task + .create() + .setConfiguration("H.264 256k DSL CBR") + .setMediaProcessorId("nb:mpid:UUID:2f381738-c504-4e4a-a38e-d199e207fcd5") + .setName("My encoding Task") + .setTaskBody( + "" + "JobInputAsset(0)" + "JobOutputAsset(" + + outputAssetPosition + ")" + ""); + } - JobInfo expectedJob = new JobInfo(); - expectedJob.setName("My Encoding Job"); - expectedJob.setPriority(3); - expectedJob.setRunningDuration(0.0); - expectedJob.setState(JobState.Queued); + @BeforeClass + public static void setup() throws Exception { + IntegrationTestBase.setup(); - AccessPolicyInfo accessPolicyInfo = createWritableAccessPolicy("createJobSuccess", 10); - LocatorInfo locator = createLocator(accessPolicyInfo, assetInfo, 5, 10); - WritableBlobContainerContract blobWriter = MediaService.createBlobWriter(locator); - createAndUploadBlob(blobWriter, "blob1.bin", testBlobData); + String name = UUID.randomUUID().toString(); + String testBlobName = "test" + name + ".bin"; + assetInfo = service.create(Asset.create().setName(testAssetPrefix + name)); - service.create(AssetFile.create(assetInfo.getId(), "blob1.bin").setIsPrimary(true).setIsEncrypted(false) - .setContentFileSize(new Long(testBlobData.length))); + AccessPolicyInfo accessPolicyInfo = service.create(AccessPolicy.create(testPolicyPrefix + name, 10, + EnumSet.of(AccessPolicyPermission.WRITE))); + LocatorInfo locator = createLocator(accessPolicyInfo, assetInfo, 5, 10); + WritableBlobContainerContract blobWriter = service.createBlobWriter(locator); + InputStream blobContent = new ByteArrayInputStream(testBlobData); + blobWriter.createBlockBlob(testBlobName, blobContent); service.action(AssetFile.createFileInfos(assetInfo.getId())); + } - URI serviceURI = service.getRestServiceUri(); + @Test + public void createJobSuccess() throws Exception { + // Arrange + String name = testJobPrefix + "createJobSuccess"; + int priority = 3; + double duration = 0.0; + JobState state = JobState.Queued; + String templateId = null; + List inputMediaAssets = null; + List outputMediaAssets = null; + Date created = new Date(); + Date lastModified = new Date(); + Date stateTime = null; + Date endTime = null; + + // Act + JobInfo actualJob = service.create(Job.create(service.getRestServiceUri()).setName(name).setPriority(priority) + .addInputMediaAsset(assetInfo.getId()).addTaskCreator(getTaskCreator(0))); + + // Assert + verifyJobProperties("actualJob", name, priority, duration, state, templateId, created, lastModified, stateTime, + endTime, inputMediaAssets, outputMediaAssets, actualJob); + } + + @Test + public void createJobTwoTasksSuccess() throws Exception { + // Arrange + String name = testJobPrefix + "createJobSuccess"; + int priority = 3; + double duration = 0.0; + JobState state = JobState.Queued; + String templateId = null; + List inputMediaAssets = null; + List outputMediaAssets = null; + Date created = new Date(); + Date lastModified = new Date(); + Date stateTime = null; + Date endTime = null; + List tasks = new ArrayList(); + tasks.add(getTaskCreator(0)); + tasks.add(getTaskCreator(1)); // Act - JobInfo actualJob = service.create(Job - .create(serviceURI) - .setName("My Encoding Job") - .setPriority(3) - .addInputMediaAsset(assetInfo.getId()) - .addTaskCreator( - Task.create().setConfiguration("H.264 256k DSL CBR") - .setMediaProcessorId("nb:mpid:UUID:2f381738-c504-4e4a-a38e-d199e207fcd5") - .setName("My encoding Task").setTaskBody(taskBody))); + JobInfo actualJob = service.create(Job.create(service.getRestServiceUri()).setName(name).setPriority(priority) + .addInputMediaAsset(assetInfo.getId()).addTaskCreator(tasks.get(0)).addTaskCreator(tasks.get(1))); // Assert - verifyJobInfoEqual("actualJob", expectedJob, actualJob); + verifyJobProperties("actualJob", name, priority, duration, state, templateId, created, lastModified, stateTime, + endTime, inputMediaAssets, outputMediaAssets, actualJob); } @Test public void getJobSuccess() throws Exception { // Arrange - JobInfo expectedJob = new JobInfo(); - expectedJob.setName("My Encoding Job"); - expectedJob.setPriority(3); - expectedJob.setRunningDuration(0.0); - expectedJob.setState(JobState.Queued); - String jobId = createJob("getJobSuccess").getId(); + String name = testJobPrefix + "getJobSuccess"; + int priority = 3; + double duration = 0.0; + JobState state = JobState.Queued; + String templateId = null; + List inputMediaAssets = null; + List outputMediaAssets = null; + String jobId = createJob(name).getId(); + Date created = new Date(); + Date lastModified = new Date(); + Date stateTime = null; + Date endTime = null; // Act JobInfo actualJob = service.get(Job.get(jobId)); // Assert - verifyJobInfoEqual("actualJob", expectedJob, actualJob); + verifyJobProperties("actualJob", name, priority, duration, state, templateId, created, lastModified, stateTime, + endTime, inputMediaAssets, outputMediaAssets, actualJob); } @Test @@ -190,7 +216,7 @@ public void getJobInvalidIdFailed() throws ServiceException { @Test public void listJobSuccess() throws ServiceException { // Arrange - JobInfo jobInfo = createJob("listJobSuccess"); + JobInfo jobInfo = createJob(testJobPrefix + "listJobSuccess"); List jobInfos = new ArrayList(); jobInfos.add(jobInfo); ListResult expectedListJobsResult = new ListResult(jobInfos); @@ -209,12 +235,10 @@ public void verifyEquals(String message, Object expected, Object actual) { @Test public void canListJobsWithOptions() throws ServiceException { - String[] assetNames = new String[] { testJobPrefix + "assetListOptionsA", testJobPrefix + "assetListOptionsB", - testJobPrefix + "assetListOptionsC", testJobPrefix + "assetListOptionsD" }; + String[] assetNameSuffixes = new String[] { "A", "B", "C", "D" }; List expectedJobs = new ArrayList(); - for (int i = 0; i < assetNames.length; i++) { - String name = assetNames[i]; - JobInfo jobInfo = createJob(name); + for (String suffix : assetNameSuffixes) { + JobInfo jobInfo = createJob(testJobPrefix + "assetListOptions" + suffix); expectedJobs.add(jobInfo); } @@ -229,14 +253,14 @@ public void canListJobsWithOptions() throws ServiceException { @Test public void cancelJobSuccess() throws Exception { // Arrange - JobInfo jobInfo = createJob("cancelJobSuccess"); + JobInfo jobInfo = createJob(testJobPrefix + "cancelJobSuccess"); // Act service.action(Job.cancel(jobInfo.getId())); // Assert JobInfo canceledJob = service.get(Job.get(jobInfo.getId())); - assertEquals(6, canceledJob.getState()); + assertEquals(JobState.Canceling, canceledJob.getState()); } @@ -255,7 +279,7 @@ public void cancelJobFailedWithInvalidId() throws ServiceException { @Test public void deleteJobSuccess() throws ServiceException { // Arrange - JobInfo jobInfo = createJob("deleteJobSuccess"); + JobInfo jobInfo = createJob(testJobPrefix + "deleteJobSuccess"); service.action(Job.cancel(jobInfo.getId())); JobInfo cancellingJobInfo = service.get(Job.get(jobInfo.getId())); while (cancellingJobInfo.getState() == JobState.Canceling) { diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/LocatorIntegrationTests.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/LocatorIntegrationTests.java index 3b2f8b23c2b92..5a1237b462ccb 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/LocatorIntegrationTests.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/LocatorIntegrationTests.java @@ -25,7 +25,6 @@ import org.junit.Before; import org.junit.BeforeClass; -import org.junit.Ignore; import org.junit.Test; import com.microsoft.windowsazure.services.core.ServiceException; @@ -134,7 +133,6 @@ public void createLocatorWithSpecifiedIdSuccess() throws ServiceException { expectedExpirationDateTime, locatorInfo); } - @Ignore("due to media service bug 596240") @Test public void createLocatorOptionsSetExpirationDateTimeSuccess() throws ServiceException { // Arrange @@ -150,7 +148,6 @@ public void createLocatorOptionsSetExpirationDateTimeSuccess() throws ServiceExc expectedExpirationDateTime, locatorInfo); } - @Ignore("due to media service bug 596240") @Test public void createLocatorOptionsSetStartTimeSuccess() throws ServiceException { // Arrange diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/MediaConfigurationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/MediaConfigurationTest.java index ccc8c5ca54016..4842f9e3a1434 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/MediaConfigurationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/MediaConfigurationTest.java @@ -33,10 +33,10 @@ public void createMediaConfigurationTestSuccess() { // Assert assertEquals("https://testMediaServiceBaseUri", configuration.getProperty("media.uri")); - assertEquals("testOAuthUri", configuration.getProperty("oauth.uri")); - assertEquals("testClientId", configuration.getProperty("oauth.client.id")); - assertEquals("testClientSecret", configuration.getProperty("oauth.client.secret")); - assertEquals("testScope", configuration.getProperty("oauth.scope")); + assertEquals("testOAuthUri", configuration.getProperty("media.oauth.uri")); + assertEquals("testClientId", configuration.getProperty("media.oauth.client.id")); + assertEquals("testClientSecret", configuration.getProperty("media.oauth.client.secret")); + assertEquals("testScope", configuration.getProperty("media.oauth.scope")); } @Test @@ -52,9 +52,9 @@ public void createMediaConfigurationPassingExistingConfigurationSuccess() { // Assert assertEquals("preexistingValue", configuration.getProperty("preexistingName")); assertEquals("https://testMediaServiceBaseUri", configuration.getProperty("media.uri")); - assertEquals("testOAuthUri", configuration.getProperty("oauth.uri")); - assertEquals("testClientId", configuration.getProperty("oauth.client.id")); - assertEquals("testClientSecret", configuration.getProperty("oauth.client.secret")); + assertEquals("testOAuthUri", configuration.getProperty("media.oauth.uri")); + assertEquals("testClientId", configuration.getProperty("media.oauth.client.id")); + assertEquals("testClientSecret", configuration.getProperty("media.oauth.client.secret")); } @@ -72,9 +72,9 @@ public void createMediaConfigurationWithProfileConfigurationSuccess() { // Assert assertEquals("preexistingValue", configuration.getProperty("preexistingName")); assertEquals("https://testMediaServiceBaseUri", configuration.getProperty("testProfile.media.uri")); - assertEquals("testOAuthUri", configuration.getProperty("testProfile.oauth.uri")); - assertEquals("testClientId", configuration.getProperty("testProfile.oauth.client.id")); - assertEquals("testClientSecret", configuration.getProperty("testProfile.oauth.client.secret")); + assertEquals("testOAuthUri", configuration.getProperty("testProfile.media.oauth.uri")); + assertEquals("testClientId", configuration.getProperty("testProfile.media.oauth.client.id")); + assertEquals("testClientSecret", configuration.getProperty("testProfile.media.oauth.client.secret")); } } diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/UploadingIntegrationTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/UploadingIntegrationTest.java index 55e3aa790b12b..652901696fc95 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/UploadingIntegrationTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/UploadingIntegrationTest.java @@ -17,7 +17,6 @@ import java.io.ByteArrayInputStream; import java.io.InputStream; -import java.util.Date; import java.util.EnumSet; import org.junit.BeforeClass; @@ -34,9 +33,7 @@ import com.microsoft.windowsazure.services.media.models.AccessPolicyPermission; import com.microsoft.windowsazure.services.media.models.Asset; import com.microsoft.windowsazure.services.media.models.AssetInfo; -import com.microsoft.windowsazure.services.media.models.Locator; import com.microsoft.windowsazure.services.media.models.LocatorInfo; -import com.microsoft.windowsazure.services.media.models.LocatorType; /** * Testing uploading in various permutations. @@ -55,14 +52,9 @@ public static void setup() throws Exception { AccessPolicyInfo policy = service.create(AccessPolicy.create(testPolicyPrefix + "uploadWritePolicy", 10, EnumSet.of(AccessPolicyPermission.WRITE))); - Date now = new Date(); - Date fiveMinutesAgo = new Date(now.getTime() - (5 * 60 * 1000)); - Date tenMinutesFromNow = new Date(now.getTime() + (10 * 60 * 1000)); + LocatorInfo locator = createLocator(policy, asset, 5, 10); - LocatorInfo locator = service.create(Locator.create(policy.getId(), asset.getId(), LocatorType.SAS) - .setStartDateTime(fiveMinutesAgo).setExpirationDateTime(tenMinutesFromNow)); - - blobWriter = MediaService.createBlobWriter(locator); + blobWriter = service.createBlobWriter(locator); ExponentialRetryPolicy retryPolicy = new ExponentialRetryPolicy(5000, 5, new int[] { 400, 404 }); blobWriter = blobWriter.withFilter(new RetryPolicyFilter(retryPolicy)); diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/LinkRetrievalTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/LinkRetrievalTest.java new file mode 100644 index 0000000000000..56ff698b68c32 --- /dev/null +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/implementation/LinkRetrievalTest.java @@ -0,0 +1,114 @@ +/** + * Copyright 2012 Microsoft Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.microsoft.windowsazure.services.media.implementation; + +import static org.junit.Assert.*; + +import java.util.List; + +import javax.xml.bind.JAXBElement; +import javax.xml.namespace.QName; + +import org.junit.Before; +import org.junit.Test; + +import com.microsoft.windowsazure.services.media.implementation.atom.ContentType; +import com.microsoft.windowsazure.services.media.implementation.atom.EntryType; +import com.microsoft.windowsazure.services.media.implementation.atom.LinkType; +import com.microsoft.windowsazure.services.media.implementation.content.Constants; +import com.microsoft.windowsazure.services.media.implementation.content.MediaProcessorType; +import com.microsoft.windowsazure.services.media.models.LinkInfo; +import com.microsoft.windowsazure.services.media.models.MediaProcessorInfo; + +/** + * Testing retrieval of links from ATOM entities + * + */ +public class LinkRetrievalTest { + private static QName linkName = new QName("link", Constants.ATOM_NS); + private MediaProcessorInfo info; + private LinkType link1; + private LinkType link2; + + @Before + public void setup() { + EntryType entry = new EntryType(); + + link1 = new LinkType(); + link1.setTitle("someLink"); + link1.setRel("Related/something"); + link1.setHref("some/uri/somewhere"); + + link2 = new LinkType(); + link2.setTitle("someOtherLink"); + link2.setRel("Related/else"); + link2.setHref("some/other/href/somewhere"); + + entry.getEntryChildren().add(new JAXBElement(linkName, LinkType.class, link1)); + entry.getEntryChildren().add(new JAXBElement(linkName, LinkType.class, link2)); + + MediaProcessorType payload = new MediaProcessorType().setId("DummyId").setName("Dummy Name") + .setVersion("0.0.0").setVendor("Contoso").setSku("sku skiddo").setDescription("For testing links only"); + + ContentType contentElement = new ContentType(); + contentElement.getContent().add( + new JAXBElement(Constants.ODATA_PROPERTIES_ELEMENT_NAME, MediaProcessorType.class, + payload)); + + entry.getEntryChildren().add( + new JAXBElement(Constants.ATOM_CONTENT_ELEMENT_NAME, ContentType.class, contentElement)); + + info = new MediaProcessorInfo(entry, payload); + } + + @Test + public void canRetrieveSingleLinkFromEntity() { + assertTrue(info.hasLink(link1.getRel())); + } + + @Test + public void getFalseWhenLinkIsntThere() { + assertFalse(info.hasLink("noSuchLink")); + } + + @Test + public void canRetrieveEntireLinkByRel() { + LinkInfo link = info.getLink(link2.getRel()); + + assertLinksEqual(link2, link); + } + + @Test + public void getNullWhenLinkIsntThere() { + assertNull(info.getLink("noSuchLink")); + } + + @Test + public void getLinksReturnsTwoExpectedLinksInOrder() { + List links = info.getLinks(); + + assertEquals(2, links.size()); + assertLinksEqual(link1, links.get(0)); + assertLinksEqual(link2, links.get(1)); + } + + private static void assertLinksEqual(LinkType expected, LinkInfo actual) { + assertEquals(expected.getTitle(), actual.getTitle()); + assertEquals(expected.getRel(), actual.getRel()); + assertEquals(expected.getHref(), actual.getHref()); + assertEquals(expected.getType(), actual.getType()); + } +} diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/AccessPolicyEntityTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/AccessPolicyEntityTest.java index b3ba31d391914..c3533b379c4cc 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/AccessPolicyEntityTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/AccessPolicyEntityTest.java @@ -28,9 +28,6 @@ import com.microsoft.windowsazure.services.media.implementation.entities.EntityCreationOperation; import com.microsoft.windowsazure.services.media.implementation.entities.EntityGetOperation; import com.microsoft.windowsazure.services.media.implementation.entities.EntityListOperation; -import com.microsoft.windowsazure.services.media.models.AccessPolicy; -import com.microsoft.windowsazure.services.media.models.AccessPolicyInfo; -import com.microsoft.windowsazure.services.media.models.AccessPolicyPermission; import com.sun.jersey.core.util.MultivaluedMapImpl; /** @@ -58,7 +55,7 @@ public void createAccessPolicyProvidesExpectedPayload() throws Exception { assertEquals(name, payload.getName()); assertEquals(duration, payload.getDurationInMinutes(), 0.0); - assertEquals(AccessPolicyPermission.bitsFromPermissions(permissions), payload.getPermissions()); + assertEquals(AccessPolicyPermission.bitsFromPermissions(permissions), payload.getPermissions().intValue()); } @Test diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/AccessPolicyInfoTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/AccessPolicyInfoTest.java index c18e9a5297c56..6a1764eee282d 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/AccessPolicyInfoTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/AccessPolicyInfoTest.java @@ -21,65 +21,69 @@ import org.junit.Assert; import org.junit.Test; +import com.microsoft.windowsazure.services.media.implementation.content.AccessPolicyType; + public class AccessPolicyInfoTest { @Test public void getSetId() { - AccessPolicyInfo policy = new AccessPolicyInfo(); String expected = "expectedId"; - String actual = policy.setId(expected).getId(); + AccessPolicyInfo policy = new AccessPolicyInfo(null, new AccessPolicyType().setId(expected)); + + String actual = policy.getId(); Assert.assertEquals(expected, actual); } @Test public void getSetCreated() { - AccessPolicyInfo policy = new AccessPolicyInfo(); Date expected = new Date(); + AccessPolicyInfo policy = new AccessPolicyInfo(null, new AccessPolicyType().setCreated(expected)); - Date actual = policy.setCreated(expected).getCreated(); + Date actual = policy.getCreated(); Assert.assertEquals(expected, actual); } @Test public void getSetLastModified() { - AccessPolicyInfo policy = new AccessPolicyInfo(); Date expected = new Date(); + AccessPolicyInfo policy = new AccessPolicyInfo(null, new AccessPolicyType().setLastModified(expected)); - Date actual = policy.setLastModified(expected).getLastModified(); + Date actual = policy.getLastModified(); Assert.assertEquals(expected, actual); } @Test public void getSetName() { - AccessPolicyInfo policy = new AccessPolicyInfo(); String expected = "policy name goes here"; + AccessPolicyInfo policy = new AccessPolicyInfo(null, new AccessPolicyType().setName(expected)); - String actual = policy.setName(expected).getName(); + String actual = policy.getName(); Assert.assertEquals(expected, actual); } @Test public void getSetDurationInMinutes() { - AccessPolicyInfo policy = new AccessPolicyInfo(); double expected = 60; // arbitrary value + AccessPolicyInfo policy = new AccessPolicyInfo(null, new AccessPolicyType().setDurationInMinutes(expected)); - double actual = policy.setDurationInMinutes(expected).getDurationInMinutes(); + double actual = policy.getDurationInMinutes(); Assert.assertEquals(expected, actual, 0.0); } @Test public void getSetPermissions() { - AccessPolicyInfo policy = new AccessPolicyInfo(); EnumSet expected = EnumSet .of(AccessPolicyPermission.LIST, AccessPolicyPermission.WRITE); + AccessPolicyInfo policy = new AccessPolicyInfo(null, + new AccessPolicyType().setPermissions(AccessPolicyPermission.bitsFromPermissions(expected))); - EnumSet actual = policy.setPermissions(expected).getPermissions(); + EnumSet actual = policy.getPermissions(); Assert.assertEquals(expected, actual); } diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/AssetEntityTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/AssetEntityTest.java index 57ffe163e3c7c..5ec15ac69f1ac 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/AssetEntityTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/AssetEntityTest.java @@ -46,7 +46,7 @@ public void assetCreateReturnsDefaultCreatePayload() { assertNotNull(payload); assertNull(payload.getId()); - assertEquals(0, payload.getState()); + assertNull(payload.getState()); assertNull(payload.getCreated()); assertNull(payload.getLastModified()); assertNull(payload.getAlternateId()); @@ -64,7 +64,7 @@ public void assetCreateCanSetAssetName() { assertNotNull(payload); assertNull(payload.getId()); - assertEquals(0, payload.getState()); + assertNull(payload.getState()); assertNull(payload.getCreated()); assertNull(payload.getLastModified()); assertNull(payload.getAlternateId()); diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/AssetInfoTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/AssetInfoTest.java index 2e974c81773c9..21eba4a11ded9 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/AssetInfoTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/AssetInfoTest.java @@ -20,16 +20,18 @@ import org.junit.Test; +import com.microsoft.windowsazure.services.media.implementation.content.AssetType; + public class AssetInfoTest { @Test public void testGetSetId() { // Arrange String expectedId = "expectedId"; - AssetInfo assetInfo = new AssetInfo(); + AssetInfo assetInfo = new AssetInfo(null, new AssetType().setId(expectedId)); // Act - String actualId = assetInfo.setId(expectedId).getId(); + String actualId = assetInfo.getId(); // Assert assertEquals(expectedId, actualId); @@ -40,10 +42,10 @@ public void testGetSetId() { public void testGetSetState() { // Arrange AssetState expectedState = AssetState.Published; - AssetInfo assetInfo = new AssetInfo(); + AssetInfo assetInfo = new AssetInfo(null, new AssetType().setState(expectedState.getCode())); // Act - AssetState actualState = assetInfo.setState(expectedState).getState(); + AssetState actualState = assetInfo.getState(); // Assert assertEquals(expectedState, actualState); @@ -54,10 +56,10 @@ public void testGetSetCreated() throws Exception { // Arrange Date expectedCreated = new Date(); - AssetInfo assetInfo = new AssetInfo(); + AssetInfo assetInfo = new AssetInfo(null, new AssetType().setCreated(expectedCreated)); // Act - Date actualCreated = assetInfo.setCreated(expectedCreated).getCreated(); + Date actualCreated = assetInfo.getCreated(); // Assert assertEquals(expectedCreated, actualCreated); @@ -68,10 +70,10 @@ public void testGetSetCreated() throws Exception { public void testGetSetLastModified() throws Exception { // Arrange Date expectedLastModified = new Date(); - AssetInfo assetInfo = new AssetInfo(); + AssetInfo assetInfo = new AssetInfo(null, new AssetType().setLastModified(expectedLastModified)); // Act - Date actualLastModified = assetInfo.setLastModified(expectedLastModified).getLastModified(); + Date actualLastModified = assetInfo.getLastModified(); // Assert assertEquals(expectedLastModified, actualLastModified); @@ -81,10 +83,10 @@ public void testGetSetLastModified() throws Exception { public void testGetSetAlternateId() { // Arrange String expectedAlternateId = "testAlternateId"; - AssetInfo assetInfo = new AssetInfo(); + AssetInfo assetInfo = new AssetInfo(null, new AssetType().setAlternateId(expectedAlternateId)); // Act - String actualAlternateId = assetInfo.setAlternateId(expectedAlternateId).getAlternateId(); + String actualAlternateId = assetInfo.getAlternateId(); // Assert assertEquals(expectedAlternateId, actualAlternateId); @@ -94,10 +96,10 @@ public void testGetSetAlternateId() { public void testGetSetName() { // Arrange String expectedName = "testName"; - AssetInfo assetInfo = new AssetInfo(); + AssetInfo assetInfo = new AssetInfo(null, new AssetType().setName(expectedName)); // Act - String actualName = assetInfo.setName(expectedName).getName(); + String actualName = assetInfo.getName(); // Assert assertEquals(expectedName, actualName); @@ -106,11 +108,12 @@ public void testGetSetName() { @Test public void testGetSetOptions() { // Arrange - EncryptionOption expectedOptions = EncryptionOption.None; - AssetInfo assetInfo = new AssetInfo(); + + AssetOption expectedOptions = AssetOption.None; + AssetInfo assetInfo = new AssetInfo(null, new AssetType().setOptions(expectedOptions.getCode())); // Act - EncryptionOption actualOptions = assetInfo.setOptions(expectedOptions).getOptions(); + AssetOption actualOptions = assetInfo.getOptions(); // Assert assertEquals(expectedOptions, actualOptions); diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/ContentKeyInfoTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/ContentKeyInfoTest.java index 0e9a21e3cdc83..675b3dc090b02 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/ContentKeyInfoTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/ContentKeyInfoTest.java @@ -20,16 +20,18 @@ import org.junit.Test; +import com.microsoft.windowsazure.services.media.implementation.content.ContentKeyRestType; + public class ContentKeyInfoTest { @Test public void testGetSetId() { // Arrange String expectedId = "expectedId"; - ContentKeyInfo contentKeyInfo = new ContentKeyInfo(); + ContentKeyInfo contentKeyInfo = new ContentKeyInfo(null, new ContentKeyRestType().setId(expectedId)); // Act - String actualId = contentKeyInfo.setId(expectedId).getId(); + String actualId = contentKeyInfo.getId(); // Assert assertEquals(expectedId, actualId); @@ -39,10 +41,10 @@ public void testGetSetId() { public void testGetSetCreated() { // Arrange Date expectedCreated = new Date(); - ContentKeyInfo contentKeyInfo = new ContentKeyInfo(); + ContentKeyInfo contentKeyInfo = new ContentKeyInfo(null, new ContentKeyRestType().setCreated(expectedCreated)); // Act - Date actualCreated = contentKeyInfo.setCreated(expectedCreated).getCreated(); + Date actualCreated = contentKeyInfo.getCreated(); // Assert assertEquals(expectedCreated, actualCreated); @@ -52,10 +54,11 @@ public void testGetSetCreated() { public void testGetSetLastModified() { // Arrange Date expectedLastModified = new Date(); - ContentKeyInfo contentKeyInfo = new ContentKeyInfo(); + ContentKeyInfo contentKeyInfo = new ContentKeyInfo(null, + new ContentKeyRestType().setLastModified(expectedLastModified)); // Act - Date actualLastModified = contentKeyInfo.setLastModified(expectedLastModified).getLastModified(); + Date actualLastModified = contentKeyInfo.getLastModified(); // Assert assertEquals(expectedLastModified, actualLastModified); @@ -65,11 +68,11 @@ public void testGetSetLastModified() { public void testGetSetContentKeyType() { // Arrange ContentKeyType expectedContentKeyType = ContentKeyType.ConfigurationEncryption; - ContentKeyInfo contentKeyInfo = new ContentKeyInfo(); + ContentKeyInfo contentKeyInfo = new ContentKeyInfo(null, + new ContentKeyRestType().setContentKeyType(expectedContentKeyType.getCode())); // Act - ContentKeyType actualContentKeyType = contentKeyInfo.setContentKeyType(expectedContentKeyType) - .getContentKeyType(); + ContentKeyType actualContentKeyType = contentKeyInfo.getContentKeyType(); // Assert assertEquals(expectedContentKeyType, actualContentKeyType); @@ -80,11 +83,11 @@ public void testGetSetContentKeyType() { public void testGetSetEncryptedContentKey() { // Arrange String expectedEncryptedContentKey = "testX509Certificate"; - ContentKeyInfo contentKeyInfo = new ContentKeyInfo(); + ContentKeyInfo contentKeyInfo = new ContentKeyInfo(null, + new ContentKeyRestType().setEncryptedContentKey(expectedEncryptedContentKey)); // Act - String actualEncryptedContentKey = contentKeyInfo.setEncryptedContentKey(expectedEncryptedContentKey) - .getEncryptedContentKey(); + String actualEncryptedContentKey = contentKeyInfo.getEncryptedContentKey(); // Assert assertEquals(expectedEncryptedContentKey, actualEncryptedContentKey); @@ -94,10 +97,10 @@ public void testGetSetEncryptedContentKey() { public void testGetSetName() { // Arrange String expectedName = "expectedName"; - ContentKeyInfo contentKeyInfo = new ContentKeyInfo(); + ContentKeyInfo contentKeyInfo = new ContentKeyInfo(null, new ContentKeyRestType().setName(expectedName)); // Act - String actualName = contentKeyInfo.setName(expectedName).getName(); + String actualName = contentKeyInfo.getName(); // Assert assertEquals(expectedName, actualName); @@ -107,10 +110,11 @@ public void testGetSetName() { public void testGetSetProtectionKeyId() { // Arrange String expectedProtectionKeyId = "expectedProtectionKeyId"; - ContentKeyInfo contentKeyInfo = new ContentKeyInfo(); + ContentKeyInfo contentKeyInfo = new ContentKeyInfo(null, + new ContentKeyRestType().setProtectionKeyId(expectedProtectionKeyId)); // Act - String actualProtectionKeyId = contentKeyInfo.setProtectionKeyId(expectedProtectionKeyId).getProtectionKeyId(); + String actualProtectionKeyId = contentKeyInfo.getProtectionKeyId(); // Assert assertEquals(expectedProtectionKeyId, actualProtectionKeyId); @@ -121,11 +125,11 @@ public void testGetSetProtectionKeyId() { public void testGetSetProtectionKeyType() { // Arrange ProtectionKeyType expectedProtectionKeyType = ProtectionKeyType.X509CertificateThumbprint; - ContentKeyInfo contentKeyInfo = new ContentKeyInfo(); + ContentKeyInfo contentKeyInfo = new ContentKeyInfo(null, + new ContentKeyRestType().setProtectionKeyType(expectedProtectionKeyType.getCode())); // Act - ProtectionKeyType actualProtectionKeyType = contentKeyInfo.setProtectionKeyType(expectedProtectionKeyType) - .getProtectionKeyType(); + ProtectionKeyType actualProtectionKeyType = contentKeyInfo.getProtectionKeyType(); // Assert assertEquals(expectedProtectionKeyType, actualProtectionKeyType); @@ -135,10 +139,10 @@ public void testGetSetProtectionKeyType() { public void testGetSetCheckSum() { // Arrange String expectedCheckSum = "testCheckSum"; - ContentKeyInfo contentKeyInfo = new ContentKeyInfo(); + ContentKeyInfo contentKeyInfo = new ContentKeyInfo(null, new ContentKeyRestType().setChecksum(expectedCheckSum)); // Act - String actualCheckSum = contentKeyInfo.setChecksum(expectedCheckSum).getChecksum(); + String actualCheckSum = contentKeyInfo.getChecksum(); // Assert assertEquals(expectedCheckSum, actualCheckSum); diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/LocatorEntityTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/LocatorEntityTest.java index 82fa8faed1fc5..41734de3972a4 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/LocatorEntityTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/LocatorEntityTest.java @@ -61,7 +61,7 @@ public void createLocatorHasCorrectPayload() throws Exception { assertEquals(exampleAssetId, locatorType.getAssetId()); assertEquals(exampleAccessPolicyId, locatorType.getAccessPolicyId()); - assertEquals(LocatorType.SAS.getCode(), locatorType.getType()); + assertEquals(LocatorType.SAS.getCode(), locatorType.getType().intValue()); assertNull(locatorType.getStartTime()); assertNull(locatorType.getExpirationDateTime()); } @@ -79,7 +79,7 @@ public void createLocatorCanSetTimes() throws Exception { assertEquals(exampleAssetId, locatorType.getAssetId()); assertEquals(exampleAccessPolicyId, locatorType.getAccessPolicyId()); - assertEquals(LocatorType.SAS.getCode(), locatorType.getType()); + assertEquals(LocatorType.SAS.getCode(), locatorType.getType().intValue()); assertEquals(now, locatorType.getStartTime()); assertEquals(tomorrow, locatorType.getExpirationDateTime()); } 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 5b5c4ab547698..ab5ef0cf27206 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 @@ -20,16 +20,18 @@ import org.junit.Test; +import com.microsoft.windowsazure.services.media.implementation.content.LocatorRestType; + public class LocatorInfoTest { @Test public void testGetSetId() { // Arrange String expectedId = "testId"; - LocatorInfo locator = new LocatorInfo(); + LocatorInfo locator = new LocatorInfo(null, new LocatorRestType().setId(expectedId)); // Act - String actualId = locator.setId(expectedId).getId(); + String actualId = locator.getId(); // Assert assertEquals(expectedId, actualId); @@ -39,11 +41,11 @@ public void testGetSetId() { public void testGetSetExpirationDateTime() { // Arrange Date expectedExpirationDateTime = new Date(); - LocatorInfo locatorInfo = new LocatorInfo(); + LocatorInfo locatorInfo = new LocatorInfo(null, + new LocatorRestType().setExpirationDateTime(expectedExpirationDateTime)); // Act - Date actualExpirationDateTime = locatorInfo.setExpirationDateTime(expectedExpirationDateTime) - .getExpirationDateTime(); + Date actualExpirationDateTime = locatorInfo.getExpirationDateTime(); // Assert assertEquals(expectedExpirationDateTime, actualExpirationDateTime); @@ -53,10 +55,10 @@ public void testGetSetExpirationDateTime() { public void testGetSetType() { // Arrange LocatorType expectedLocatorType = LocatorType.SAS; - LocatorInfo locatorInfo = new LocatorInfo(); + LocatorInfo locatorInfo = new LocatorInfo(null, new LocatorRestType().setType(expectedLocatorType.getCode())); // Act - LocatorType actualLocatorType = locatorInfo.setLocatorType(expectedLocatorType).getLocatorType(); + LocatorType actualLocatorType = locatorInfo.getLocatorType(); // Assert assertEquals(expectedLocatorType, actualLocatorType); @@ -66,10 +68,10 @@ public void testGetSetType() { public void testGetSetPath() { // Arrange String expectedPath = "testPath"; - LocatorInfo locatorInfo = new LocatorInfo(); + LocatorInfo locatorInfo = new LocatorInfo(null, new LocatorRestType().setPath(expectedPath)); // Act - String actualPath = locatorInfo.setPath(expectedPath).getPath(); + String actualPath = locatorInfo.getPath(); // Assert assertEquals(expectedPath, actualPath); @@ -79,10 +81,10 @@ public void testGetSetPath() { public void testGetSetAccessPolicyId() { // Arrange String expectedAccessPolicyId = "testAccessPolicyId"; - LocatorInfo locatorInfo = new LocatorInfo(); + LocatorInfo locatorInfo = new LocatorInfo(null, new LocatorRestType().setAccessPolicyId(expectedAccessPolicyId)); // Act - String actualAccessPolicyId = locatorInfo.setAccessPolicyId(expectedAccessPolicyId).getAccessPolicyId(); + String actualAccessPolicyId = locatorInfo.getAccessPolicyId(); // Assert assertEquals(expectedAccessPolicyId, actualAccessPolicyId); @@ -92,10 +94,10 @@ public void testGetSetAccessPolicyId() { public void testGetSetAssetId() { // Arrange String expectedAssetId = "testAssetId"; - LocatorInfo locatorInfo = new LocatorInfo(); + LocatorInfo locatorInfo = new LocatorInfo(null, new LocatorRestType().setAssetId(expectedAssetId)); // Act - String actualAssetId = locatorInfo.setAssetId(expectedAssetId).getAssetId(); + String actualAssetId = locatorInfo.getAssetId(); // Assert assertEquals(expectedAssetId, actualAssetId); @@ -105,10 +107,10 @@ public void testGetSetAssetId() { public void testGetSetStartTime() { // Arrange Date expectedStartTime = new Date(); - LocatorInfo locatorInfo = new LocatorInfo(); + LocatorInfo locatorInfo = new LocatorInfo(null, new LocatorRestType().setStartTime(expectedStartTime)); // Act - Date actualStartTime = locatorInfo.setStartTime(expectedStartTime).getStartTime(); + Date actualStartTime = locatorInfo.getStartTime(); // Assert assertEquals(expectedStartTime, actualStartTime); @@ -118,10 +120,10 @@ public void testGetSetStartTime() { public void testGetSetBaseUri() { // Arrange String expectedBaseUri = "testBaseUri"; - LocatorInfo locatorInfo = new LocatorInfo(); + LocatorInfo locatorInfo = new LocatorInfo(null, new LocatorRestType().setBaseUri(expectedBaseUri)); // Act - String actualBaseUri = locatorInfo.setBaseUri(expectedBaseUri).getBaseUri(); + String actualBaseUri = locatorInfo.getBaseUri(); // Assert assertEquals(expectedBaseUri, actualBaseUri); @@ -131,14 +133,13 @@ public void testGetSetBaseUri() { public void testGetSetContentAccessComponent() { // Arrange String expectedContentAccessComponent = "testContentAccessToken"; - LocatorInfo locatorInfo = new LocatorInfo(); + LocatorInfo locatorInfo = new LocatorInfo(null, + new LocatorRestType().setContentAccessComponent(expectedContentAccessComponent)); // Act - String actualContentAccessComponent = locatorInfo.setContentAccessComponent(expectedContentAccessComponent) - .getContentAccessToken(); + String actualContentAccessComponent = locatorInfo.getContentAccessToken(); // Assert assertEquals(expectedContentAccessComponent, actualContentAccessComponent); - } } diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/MediaProcessorInfoTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/MediaProcessorInfoTest.java index c247486b1c482..4e05b0f5e4538 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/MediaProcessorInfoTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/media/models/MediaProcessorInfoTest.java @@ -18,16 +18,18 @@ import org.junit.Test; +import com.microsoft.windowsazure.services.media.implementation.content.MediaProcessorType; + public class MediaProcessorInfoTest { @Test public void testGetSetId() { // Arrange String expectedId = "expectedId"; - MediaProcessorInfo mediaProcessorInfo = new MediaProcessorInfo(); + MediaProcessorInfo mediaProcessorInfo = new MediaProcessorInfo(null, new MediaProcessorType().setId(expectedId)); // Act - String actualId = mediaProcessorInfo.setId(expectedId).getId(); + String actualId = mediaProcessorInfo.getId(); // Assert assertEquals(expectedId, actualId); @@ -38,10 +40,11 @@ public void testGetSetId() { public void testGetSetName() { // Arrange String expectedName = "testName"; - MediaProcessorInfo mediaProcessorInfo = new MediaProcessorInfo(); + MediaProcessorInfo mediaProcessorInfo = new MediaProcessorInfo(null, + new MediaProcessorType().setName(expectedName)); // Act - String actualName = mediaProcessorInfo.setName(expectedName).getName(); + String actualName = mediaProcessorInfo.getName(); // Assert assertEquals(expectedName, actualName); @@ -52,10 +55,11 @@ public void testGetSetDescription() throws Exception { // Arrange String expectedDescription = "testDescription"; - MediaProcessorInfo mediaProcessorInfo = new MediaProcessorInfo(); + MediaProcessorInfo mediaProcessorInfo = new MediaProcessorInfo(null, + new MediaProcessorType().setDescription(expectedDescription)); // Act - String actualDescription = mediaProcessorInfo.setDescription(expectedDescription).getDescription(); + String actualDescription = mediaProcessorInfo.getDescription(); // Assert assertEquals(expectedDescription, actualDescription); @@ -66,10 +70,11 @@ public void testGetSetDescription() throws Exception { public void testGetSetSku() throws Exception { // Arrange String expectedSku = "testSku"; - MediaProcessorInfo mediaProcessorInfo = new MediaProcessorInfo(); + MediaProcessorInfo mediaProcessorInfo = new MediaProcessorInfo(null, + new MediaProcessorType().setSku(expectedSku)); // Act - String actualSku = mediaProcessorInfo.setSku(expectedSku).getSku(); + String actualSku = mediaProcessorInfo.getSku(); // Assert assertEquals(expectedSku, actualSku); @@ -79,10 +84,11 @@ public void testGetSetSku() throws Exception { public void testGetSetVendor() { // Arrange String expectedVendor = "testVendor"; - MediaProcessorInfo mediaProcessorInfo = new MediaProcessorInfo(); + MediaProcessorInfo mediaProcessorInfo = new MediaProcessorInfo(null, + new MediaProcessorType().setVendor(expectedVendor)); // Act - String actualVendor = mediaProcessorInfo.setVendor(expectedVendor).getVendor(); + String actualVendor = mediaProcessorInfo.getVendor(); // Assert assertEquals(expectedVendor, actualVendor); @@ -92,10 +98,11 @@ public void testGetSetVendor() { public void testGetSetVersion() { // Arrange String expectedVersion = "testVersion"; - MediaProcessorInfo mediaProcessorInfo = new MediaProcessorInfo(); + MediaProcessorInfo mediaProcessorInfo = new MediaProcessorInfo(null, + new MediaProcessorType().setVersion(expectedVersion)); // Act - String actualVersion = mediaProcessorInfo.setVersion(expectedVersion).getVersion(); + String actualVersion = mediaProcessorInfo.getVersion(); // Assert assertEquals(expectedVersion, actualVersion); diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/scenarios/MediaServiceMocks.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/scenarios/MediaServiceMocks.java deleted file mode 100644 index cfedb89502d4c..0000000000000 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/scenarios/MediaServiceMocks.java +++ /dev/null @@ -1,113 +0,0 @@ -/** - * Copyright 2012 Microsoft Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.microsoft.windowsazure.services.scenarios; - -import java.util.ArrayList; -import java.util.List; - -import com.microsoft.windowsazure.services.media.models.AssetInfo; -import com.microsoft.windowsazure.services.media.models.AssetFileInfo; - -// TODO: Remove when no longer needed. -// Tracked by https://github.com/WindowsAzure/azure-sdk-for-java-pr/issues/457 -class MediaServiceMocks { - - static class MockMediaContract { - public List getAssetFiles(String id) { - return new ArrayList(); - } - - public JobInfo createJob(CreateJobOptions jobOptions) { - return new JobInfo(); - } - - public JobInfo getJob(String id) { - return new JobInfo(); - } - - public List getJobOutputMediaAssets(String id) { - return new ArrayList(); - } - - public void cancelJob(String id) { - } - - public List getFiles() { - return new ArrayList(); - } - - public AssetFileInfo createFileInfo(AssetFileInfo fi) { - return null; - } - } - - static enum JobState { - Finished, Canceled, Error - } - - static class JobInfo { - - public String getId() { - return null; - } - - public JobState getState() { - return JobState.Finished; - } - } - - static class CreateTaskOptions { - - public CreateTaskOptions setName(String string) { - return this; - } - - public CreateTaskOptions setProcessorId(String id) { - return this; - } - - public CreateTaskOptions setConfiguration(String string) { - return this; - } - - public CreateTaskOptions setTaskBody(String string) { - return this; - } - - public CreateTaskOptions setTaskCreationOptions(TaskCreationOptions options) { - return this; - } - } - - static class CreateJobOptions { - - public CreateJobOptions setName(String jobName) { - return this; - } - - public CreateJobOptions addInputMediaAsset(String id) { - return this; - } - - public CreateJobOptions addTask(CreateTaskOptions task) { - return this; - } - } - - static enum TaskCreationOptions { - ProtectedConfiguration - } -} diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/scenarios/MediaServiceScenarioTest.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/scenarios/MediaServiceScenarioTest.java index 1ff39bcc28c73..55dca19d3a94c 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/scenarios/MediaServiceScenarioTest.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/scenarios/MediaServiceScenarioTest.java @@ -26,15 +26,16 @@ import org.junit.AfterClass; import org.junit.BeforeClass; -import org.junit.Ignore; import org.junit.Test; import com.microsoft.windowsazure.services.core.ServiceException; import com.microsoft.windowsazure.services.media.MediaContract; import com.microsoft.windowsazure.services.media.MediaService; import com.microsoft.windowsazure.services.media.models.AssetInfo; -import com.microsoft.windowsazure.services.media.models.EncryptionOption; +import com.microsoft.windowsazure.services.media.models.AssetOption; +import com.microsoft.windowsazure.services.media.models.JobInfo; import com.microsoft.windowsazure.services.media.models.ListResult; +import com.microsoft.windowsazure.services.media.models.Task; public class MediaServiceScenarioTest extends ScenarioTestBase { private static final String rootTestAssetPrefix = "testAssetPrefix-"; @@ -59,8 +60,8 @@ public static void cleanup() throws ServiceException { @Test public void newAsset() throws Exception { - AssetInfo asset = wrapper.createAsset(testAssetPrefix + "newAsset", EncryptionOption.None); - validator.validateAsset(asset, testAssetPrefix + "newAsset", EncryptionOption.None); + AssetInfo asset = wrapper.createAsset(testAssetPrefix + "newAsset", AssetOption.None); + validator.validateAsset(asset, testAssetPrefix + "newAsset", AssetOption.None); } @Test @@ -69,7 +70,7 @@ public void pageOverAssets() throws ServiceException { String rootName = testAssetPrefix + "pageOverAssets"; List assetNames = createListOfAssetNames(rootName, 4); for (String assetName : assetNames) { - wrapper.createAsset(assetName, EncryptionOption.None); + wrapper.createAsset(assetName, AssetOption.None); } signalSetupFinished(); @@ -77,22 +78,20 @@ public void pageOverAssets() throws ServiceException { validator.validateAssetSortedPages(pages, assetNames, 3); } - @Ignore("Needs https://github.com/WindowsAzure/azure-sdk-for-java-pr/issues/277") @Test public void uploadFiles() throws Exception { signalSetupStarting(); - AssetInfo asset = wrapper.createAsset(testAssetPrefix + "uploadFiles", EncryptionOption.None); + AssetInfo asset = wrapper.createAsset(testAssetPrefix + "uploadFiles", AssetOption.None); signalSetupFinished(); wrapper.uploadFilesToAsset(asset, 10, getTestAssetFiles()); validator.validateAssetFiles(asset, getTestAssetFiles()); } - @Ignore("Needs https://github.com/WindowsAzure/azure-sdk-for-java-pr/issues/277") @Test public void downloadFiles() throws Exception { signalSetupStarting(); - AssetInfo asset = wrapper.createAsset(testAssetPrefix + "downloadFiles", EncryptionOption.None); + AssetInfo asset = wrapper.createAsset(testAssetPrefix + "downloadFiles", AssetOption.None); wrapper.uploadFilesToAsset(asset, 10, getTestAssetFiles()); signalSetupFinished(); @@ -103,20 +102,22 @@ public void downloadFiles() throws Exception { @Test public void createJob() throws Exception { signalSetupStarting(); - AssetInfo asset = wrapper.createAsset(testAssetPrefix + "createJob", EncryptionOption.None); + AssetInfo asset = wrapper.createAsset(testAssetPrefix + "createJob", AssetOption.None); wrapper.uploadFilesToAsset(asset, 10, getTestAssetFiles()); signalSetupFinished(); - MediaServiceMocks.JobInfo job = wrapper.createJob("my job createJob", asset, createTasks()); - validator.validateJob(job, "my job", asset, createTasks()); + String jobName = "my job createJob"; + JobInfo job = wrapper.createJob(jobName, asset, createTasks()); + validator.validateJob(job, jobName, asset, createTasks()); } @Test public void transformAsset() throws Exception { signalSetupStarting(); - AssetInfo asset = wrapper.createAsset(testAssetPrefix + "transformAsset", EncryptionOption.None); + AssetInfo asset = wrapper.createAsset(testAssetPrefix + "transformAsset", AssetOption.None); wrapper.uploadFilesToAsset(asset, 10, getTestAssetFiles()); - MediaServiceMocks.JobInfo job = wrapper.createJob("my job transformAsset", asset, createTasks()); + String jobName = "my job transformAsset"; + JobInfo job = wrapper.createJob(jobName, asset, createTasks()); signalSetupFinished(); waitForJobToFinish(job); @@ -124,19 +125,20 @@ public void transformAsset() throws Exception { validator.validateOutputAssets(outputAssets); } - private void waitForJobToFinish(MediaServiceMocks.JobInfo job) throws InterruptedException { + private void waitForJobToFinish(JobInfo job) throws InterruptedException, ServiceException { for (int counter = 0; !wrapper.isJobFinished(job); counter++) { if (counter > 10) { fail("Took took long for the job to finish"); } - Thread.sleep(20000); + Thread.sleep(10000); } } - private List createTasks() throws ServiceException { - List tasks = new ArrayList(); - tasks.add(wrapper.createTaskOptionsMp4ToSmoothStreams("MP4 to SS")); - tasks.add(wrapper.createTaskOptionsSmoothStreamsToHls("SS to HLS")); + private List createTasks() throws ServiceException { + List tasks = new ArrayList(); + + tasks.add(wrapper.createTaskOptionsMp4ToSmoothStreams("MP4 to SS", 0, 0)); + tasks.add(wrapper.createTaskOptionsSmoothStreamsToHls("SS to HLS", 0, 1)); return tasks; } diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/scenarios/MediaServiceValidation.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/scenarios/MediaServiceValidation.java index c2517b8d8c8f2..7de78be033c23 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/scenarios/MediaServiceValidation.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/scenarios/MediaServiceValidation.java @@ -19,34 +19,33 @@ import java.io.IOException; import java.io.InputStream; -import java.net.MalformedURLException; import java.net.URL; import java.security.NoSuchAlgorithmException; import java.util.ArrayList; +import java.util.Date; import java.util.Hashtable; import java.util.List; import com.microsoft.windowsazure.services.core.ServiceException; import com.microsoft.windowsazure.services.media.MediaContract; import com.microsoft.windowsazure.services.media.models.Asset; +import com.microsoft.windowsazure.services.media.models.AssetFile; +import com.microsoft.windowsazure.services.media.models.AssetFileInfo; import com.microsoft.windowsazure.services.media.models.AssetInfo; import com.microsoft.windowsazure.services.media.models.AssetState; -import com.microsoft.windowsazure.services.media.models.EncryptionOption; -import com.microsoft.windowsazure.services.media.models.AssetFileInfo; +import com.microsoft.windowsazure.services.media.models.AssetOption; +import com.microsoft.windowsazure.services.media.models.JobInfo; import com.microsoft.windowsazure.services.media.models.ListResult; -import com.microsoft.windowsazure.services.scenarios.MediaServiceMocks.CreateTaskOptions; -import com.microsoft.windowsazure.services.scenarios.MediaServiceMocks.JobInfo; +import com.microsoft.windowsazure.services.media.models.Task; class MediaServiceValidation { private final MediaContract service; - private final MediaServiceMocks.MockMediaContract serviceMock; public MediaServiceValidation(MediaContract service) { this.service = service; - this.serviceMock = new MediaServiceMocks.MockMediaContract(); } - public void validateAsset(AssetInfo asset, String name, EncryptionOption encryption) throws ServiceException { + public void validateAsset(AssetInfo asset, String name, AssetOption encryption) throws ServiceException { // Check the asset state. assertNotNull("asset", asset); assertNotNull("asset.getId", asset.getId()); @@ -55,7 +54,7 @@ public void validateAsset(AssetInfo asset, String name, EncryptionOption encrypt assertEquals("asset.getOptions", encryption, asset.getOptions()); // Verify no files by default. - List initialFiles = serviceMock.getAssetFiles(asset.getId()); + List initialFiles = service.list(AssetFile.list(asset.getId())); assertNotNull("initialFiles", initialFiles); assertEquals("initialFiles.size", 0, initialFiles.size()); @@ -83,15 +82,15 @@ public void validateAssetSortedPages(List> pages, List inputFiles) throws ServiceException, IOException, NoSuchAlgorithmException { - List assetFiles = serviceMock.getAssetFiles(asset.getId()); + List assetFiles = service.list(AssetFile.list(asset.getId())); assertNotNull("assetFiles", assetFiles); assertEquals("assetFiles.size", inputFiles.size(), assetFiles.size()); @@ -107,7 +106,7 @@ public void validateAssetFiles(AssetInfo asset, Hashtable i // * Compare these properties: IsEncrypted, InitializationVector, EncryptionKeyId, EncryptionScheme, EncryptionVersion // Compare the asset files with all files - List allFiles = serviceMock.getFiles(); + List allFiles = service.list(AssetFile.list()); for (AssetFileInfo assetFile : assetFiles) { assertEquals("fi.getParentAssetId", asset.getId(), assetFile.getParentAssetId()); AssetFileInfo match = null; @@ -132,22 +131,29 @@ public void validateAssetFileUrls(List fileUrls, Hashtable createTasks) { - // Add validation + public void validateJob(JobInfo job, String name, AssetInfo asset, List createTasks) { + assertDateApproxEquals("getEndTime", new Date(), job.getCreated()); + assertEquals("job.getName", name, job.getName()); + + // TODO: Uncomment when fixed: + // https://github.com/WindowsAzure/azure-sdk-for-java-pr/issues/508 + // List inputAssets = job.getInputMediaAssets(); + // assertNotNull("inputAssets", inputAssets); + // assertEquals("inputAssets.size()", 1, inputAssets.size()); + // assertEquals("inputAssets.get(0)", asset.getId(), inputAssets.get(0)); + // + // List outputAssets = job.getOutputMediaAssets(); + // assertNotNull("outputAssets", outputAssets); + // assertEquals("outputAssets.size()", createTasks.size(), outputAssets.size()); } - public void validateOutputAssets(List outputAssets) throws ServiceException, MalformedURLException { - // Add validation for the output assets. Will be simple to do once + public void validateOutputAssets(List outputAssets) throws ServiceException { + // TODO: Uncomment when fixed: + // https://github.com/WindowsAzure/azure-sdk-for-java-pr/issues/508 - // for (AssetInfo outputAsset : outputAssets) { - // List urls = wrapper.createOriginUrlsForAppleHLSContent(outputAsset, 1000); - // for (URL url : urls) { - // System.out.println(url); - // } - // } - // - // for (URL url : wrapper.createOriginUrlsForStreamingContent(asset, 10)) { - // // TODO: What to verify here? + // assertNotNull("outputAssets", outputAssets); + // for (AssetInfo asset : outputAssets) { + // this.validateAsset(asset, null, null); // } } @@ -193,6 +199,22 @@ public void assertFileInfosEqual(String message, AssetFileInfo fi, AssetFileInfo assertEquals(message + ":getParentAssetId", fi.getParentAssetId(), match.getParentAssetId()); } + protected void assertDateApproxEquals(String message, Date expected, Date actual) { + // Default allows for a 30 seconds difference in dates, for clock skew, network delays, etc. + long deltaInMilliseconds = 30000; + + if (expected == null || actual == null) { + assertEquals(message, expected, actual); + } + else { + long diffInMilliseconds = Math.abs(expected.getTime() - actual.getTime()); + + if (diffInMilliseconds > deltaInMilliseconds) { + assertEquals(message, expected, actual); + } + } + } + private void assertStreamsEqual(InputStream inputStream1, InputStream inputStream2) throws IOException { byte[] buffer1 = new byte[1024]; byte[] buffer2 = new byte[1024]; diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/scenarios/MediaServiceWrapper.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/scenarios/MediaServiceWrapper.java index 6348f3b135eff..c0d85220473ed 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/scenarios/MediaServiceWrapper.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/scenarios/MediaServiceWrapper.java @@ -30,7 +30,6 @@ import com.microsoft.windowsazure.services.core.ServiceException; import com.microsoft.windowsazure.services.core.storage.utils.Base64; import com.microsoft.windowsazure.services.media.MediaContract; -import com.microsoft.windowsazure.services.media.MediaService; import com.microsoft.windowsazure.services.media.WritableBlobContainerContract; import com.microsoft.windowsazure.services.media.implementation.content.AssetFileType; import com.microsoft.windowsazure.services.media.implementation.entities.EntityListOperation; @@ -38,24 +37,23 @@ import com.microsoft.windowsazure.services.media.models.AccessPolicyInfo; import com.microsoft.windowsazure.services.media.models.AccessPolicyPermission; import com.microsoft.windowsazure.services.media.models.Asset; +import com.microsoft.windowsazure.services.media.models.AssetFile; import com.microsoft.windowsazure.services.media.models.AssetFileInfo; import com.microsoft.windowsazure.services.media.models.AssetInfo; -import com.microsoft.windowsazure.services.media.models.EncryptionOption; +import com.microsoft.windowsazure.services.media.models.AssetOption; +import com.microsoft.windowsazure.services.media.models.Job; +import com.microsoft.windowsazure.services.media.models.Job.Creator; +import com.microsoft.windowsazure.services.media.models.JobInfo; import com.microsoft.windowsazure.services.media.models.ListResult; import com.microsoft.windowsazure.services.media.models.Locator; import com.microsoft.windowsazure.services.media.models.LocatorInfo; import com.microsoft.windowsazure.services.media.models.LocatorType; import com.microsoft.windowsazure.services.media.models.MediaProcessor; import com.microsoft.windowsazure.services.media.models.MediaProcessorInfo; -import com.microsoft.windowsazure.services.scenarios.MediaServiceMocks.CreateJobOptions; -import com.microsoft.windowsazure.services.scenarios.MediaServiceMocks.CreateTaskOptions; -import com.microsoft.windowsazure.services.scenarios.MediaServiceMocks.JobInfo; -import com.microsoft.windowsazure.services.scenarios.MediaServiceMocks.MockMediaContract; -import com.microsoft.windowsazure.services.scenarios.MediaServiceMocks.TaskCreationOptions; +import com.microsoft.windowsazure.services.media.models.Task; class MediaServiceWrapper { private final MediaContract service; - private final MockMediaContract serviceMock; private static final String accessPolicyPrefix = "scenarioTestPrefix"; @@ -106,11 +104,10 @@ class MediaServiceWrapper { public MediaServiceWrapper(MediaContract service) { this.service = service; - this.serviceMock = new MockMediaContract(); } // Manage - public AssetInfo createAsset(String name, EncryptionOption encryption) throws ServiceException { + public AssetInfo createAsset(String name, AssetOption encryption) throws ServiceException { // Create asset. The SDK's top-level method is the simplest way to do that. return service.create(Asset.create().setName(name).setAlternateId("altId").setOptions(encryption)); } @@ -140,7 +137,11 @@ public void uploadFilesToAsset(AssetInfo asset, int uploadWindowInMinutes, Hasht AccessPolicyInfo accessPolicy = service.create(AccessPolicy.create(accessPolicyPrefix + "tempAccessPolicy", uploadWindowInMinutes, EnumSet.of(AccessPolicyPermission.WRITE))); LocatorInfo locator = service.create(Locator.create(accessPolicy.getId(), asset.getId(), LocatorType.SAS)); - WritableBlobContainerContract uploader = MediaService.createBlobWriter(locator); + + WritableBlobContainerContract uploader = service.createBlobWriter(locator); + + Hashtable infoToUpload = new Hashtable(); + boolean isFirst = true; for (String fileName : inputFiles.keySet()) { MessageDigest digest = MessageDigest.getInstance("MD5"); @@ -159,10 +160,22 @@ public void uploadFilesToAsset(AssetInfo asset, int uploadWindowInMinutes, Hasht AssetFileInfo fi = new AssetFileInfo(null, new AssetFileType().setContentChecksum(md5) .setContentFileSize(new Long(countingStream.getCount())).setIsPrimary(isFirst).setName(fileName) .setParentAssetId(asset.getAlternateId())); - serviceMock.createFileInfo(fi); + infoToUpload.put(fileName, fi); isFirst = false; } + + service.action(AssetFile.createFileInfos(asset.getId())); + for (AssetFileInfo assetFile : service.list(AssetFile.list(asset.getId()))) { + + AssetFileInfo x = infoToUpload.get(assetFile.getName()); + System.out.println(x); + service.update(AssetFile.update(assetFile.getId()).setContentChecksum(x.getContentChecksum()) + .setContentFileSize(x.getContentFileSize()).setIsPrimary(x.getIsPrimary())); + } + + service.list(AssetFile.list(asset.getId())); + service.delete(Locator.delete(locator.getId())); service.delete(AccessPolicy.delete(accessPolicy.getId())); } @@ -188,60 +201,66 @@ public int getCount() { } // Process - public JobInfo createJob(String jobName, AssetInfo inputAsset, List tasks) { - CreateJobOptions jobOptions = new CreateJobOptions().setName(jobName).addInputMediaAsset(inputAsset.getId()); + public JobInfo createJob(String jobName, AssetInfo inputAsset, List tasks) + throws ServiceException { + Creator jobCreator = Job.create(service.getRestServiceUri()).setName(jobName) + .addInputMediaAsset(inputAsset.getId()).setPriority(2); - for (CreateTaskOptions task : tasks) { - jobOptions.addTask(task); + for (Task.CreateBatchOperation task : tasks) { + jobCreator.addTaskCreator(task); } - return serviceMock.createJob(jobOptions); + return service.create(jobCreator); } // Process - public CreateTaskOptions createTaskOptionsWindowsAzureMediaEncoder(String taskName) throws ServiceException { - return new CreateTaskOptions() - .setName(taskName) - .setProcessorId(getMediaProcessorIdByName(MEDIA_PROCESSOR_WINDOWS_AZURE_MEDIA_ENCODER)) - .setConfiguration("H.264 256k DSL CBR") - .setTaskBody( - "JobInputAsset(0)" - + "JobOutputAsset(0)"); + public Task.CreateBatchOperation createTaskOptionsWindowsAzureMediaEncoder(String taskName, int inputAssetId, + int outputAssetId) throws ServiceException { + Task.CreateBatchOperation taskCreate = Task.create().setName(taskName) + .setMediaProcessorId(getMediaProcessorIdByName(MEDIA_PROCESSOR_WINDOWS_AZURE_MEDIA_ENCODER)) + .setConfiguration("H.264 256k DSL CBR"); + setTaskBody(taskCreate, inputAssetId, outputAssetId); + return taskCreate; } // Process - public CreateTaskOptions createTaskOptionsPlayReadyProtection(String taskName, String playReadyConfiguration) - throws ServiceException { - return new CreateTaskOptions() + public Task.CreateBatchOperation createTaskOptionsPlayReadyProtection(String taskName, + String playReadyConfiguration, int inputAssetId, int outputAssetId) throws ServiceException { + Task.CreateBatchOperation taskCreate = Task + .create() .setName(taskName) - .setTaskCreationOptions(TaskCreationOptions.ProtectedConfiguration) - .setProcessorId(getMediaProcessorIdByName(MEDIA_PROCESSOR_PLAYREADY_PROTECTION)) - .setConfiguration(playReadyConfiguration) - .setTaskBody( - "JobInputAsset(0)" - + "JobOutputAsset(0)"); + // TODO: Re-enable + // https://github.com/WindowsAzure/azure-sdk-for-java-pr/issues/499 + // .setTaskCreationOptions(TaskCreationOptions.ProtectedConfiguration) + .setMediaProcessorId(getMediaProcessorIdByName(MEDIA_PROCESSOR_PLAYREADY_PROTECTION)) + .setConfiguration(playReadyConfiguration); + setTaskBody(taskCreate, inputAssetId, outputAssetId); + return taskCreate; } // Process - public CreateTaskOptions createTaskOptionsMp4ToSmoothStreams(String taskName) throws ServiceException { - return new CreateTaskOptions() - .setName(taskName) - .setProcessorId(getMediaProcessorIdByName(MEDIA_PROCESSOR_MP4_TO_SMOOTH_STREAMS)) - .setConfiguration(configMp4ToSmoothStreams) - .setTaskBody( - "JobInputAsset(0)" - + "JobOutputAsset(0)"); + public Task.CreateBatchOperation createTaskOptionsMp4ToSmoothStreams(String taskName, int inputAssetId, + int outputAssetId) throws ServiceException { + Task.CreateBatchOperation taskCreate = Task.create().setName(taskName) + .setMediaProcessorId(getMediaProcessorIdByName(MEDIA_PROCESSOR_MP4_TO_SMOOTH_STREAMS)) + .setConfiguration(configMp4ToSmoothStreams); + setTaskBody(taskCreate, inputAssetId, outputAssetId); + return taskCreate; } // Process - public CreateTaskOptions createTaskOptionsSmoothStreamsToHls(String taskName) throws ServiceException { - return new CreateTaskOptions() - .setName(taskName) - .setProcessorId(getMediaProcessorIdByName(MEDIA_PROCESSOR_SMOOTH_STREAMS_TO_HLS)) - .setConfiguration(configSmoothStreamsToAppleHttpLiveStreams) - .setTaskBody( - "JobInputAsset(0)" - + "JobOutputAsset(0)"); + public Task.CreateBatchOperation createTaskOptionsSmoothStreamsToHls(String taskName, int inputAssetId, + int outputAssetId) throws ServiceException { + Task.CreateBatchOperation taskCreate = Task.create().setName(taskName) + .setMediaProcessorId(getMediaProcessorIdByName(MEDIA_PROCESSOR_SMOOTH_STREAMS_TO_HLS)) + .setConfiguration(configSmoothStreamsToAppleHttpLiveStreams); + setTaskBody(taskCreate, inputAssetId, outputAssetId); + return taskCreate; + } + + private void setTaskBody(Task.CreateBatchOperation taskCreate, int inputAssetId, int outputAssetId) { + taskCreate.setTaskBody("JobInputAsset(" + inputAssetId + ")" + + "JobOutputAsset(" + outputAssetId + ")"); } private String getMediaProcessorIdByName(String processorName) throws ServiceException { @@ -252,8 +271,8 @@ private String getMediaProcessorIdByName(String processorName) throws ServiceExc } // Process - public boolean isJobFinished(JobInfo initialJobInfo) { - JobInfo currentJob = serviceMock.getJob(initialJobInfo.getId()); + public boolean isJobFinished(JobInfo initialJobInfo) throws ServiceException { + JobInfo currentJob = service.get(Job.get(initialJobInfo.getId())); switch (currentJob.getState()) { case Finished: case Canceled: @@ -264,14 +283,22 @@ public boolean isJobFinished(JobInfo initialJobInfo) { } } - public List getJobOutputMediaAssets(JobInfo job) { - return serviceMock.getJobOutputMediaAssets(job.getId()); + public List getJobOutputMediaAssets(JobInfo job) throws ServiceException { + List outputMediaAssets = job.getOutputMediaAssets(); + if (outputMediaAssets == null) { + return null; + } + List ret = new ArrayList(); + for (String assetId : outputMediaAssets) { + ret.add(service.get(Asset.get(assetId))); + } + return ret; } // Process - public void cancelJob(JobInfo job) throws InterruptedException { + public void cancelJob(JobInfo job) throws ServiceException { // Use the service function - serviceMock.cancelJob(job.getId()); + service.action(Job.cancel(job.getId())); } // Deliver @@ -303,7 +330,7 @@ private List createOriginUrlsForStreamingContentWorker(AssetInfo asset, int availabilityWindowInMinutes, EnumSet.of(AccessPolicyPermission.READ))); LocatorInfo readLocator = service.create(Locator.create(readAP.getId(), asset.getId(), locatorType)); - List publishedFiles = serviceMock.getAssetFiles(asset.getId()); + List publishedFiles = service.list(AssetFile.list(asset.getId())); for (AssetFileInfo fi : publishedFiles) { if (isSmooth) { // Smooth Streaming format ends with ".ism*" @@ -343,11 +370,23 @@ public void removeAllAssetsWithPrefix(String assetPrefix) throws ServiceExceptio && asset.getName().substring(0, assetPrefix.length()).equals(assetPrefix)) { for (LocatorInfo locator : locators) { if (locator.getAssetId().equals(asset.getId())) { - service.delete(Locator.delete(locator.getId())); + try { + service.delete(Locator.delete(locator.getId())); + } + catch (ServiceException e) { + // Don't worry if cannot delete now. + // Might be held on to by a running job + } } } - service.delete(Asset.delete(asset.getId())); + try { + service.delete(Asset.delete(asset.getId())); + } + catch (ServiceException e) { + // Don't worry if cannot delete now. + // Might be held on to by a running job + } } } } @@ -357,7 +396,13 @@ public void removeAllAccessPoliciesWithPrefix() throws ServiceException { for (AccessPolicyInfo accessPolicy : accessPolicies) { if (accessPolicy.getName().length() > accessPolicyPrefix.length() && accessPolicy.getName().substring(0, accessPolicyPrefix.length()).equals(accessPolicyPrefix)) { - service.delete(AccessPolicy.delete(accessPolicy.getId())); + try { + service.delete(AccessPolicy.delete(accessPolicy.getId())); + } + catch (ServiceException e) { + // Don't worry if cannot delete now. + // Might be held on to by a running job + } } } } diff --git a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/scenarios/ScenarioTestBase.java b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/scenarios/ScenarioTestBase.java index 0d471e7da87ec..6875d11095297 100644 --- a/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/scenarios/ScenarioTestBase.java +++ b/microsoft-azure-api/src/test/java/com/microsoft/windowsazure/services/scenarios/ScenarioTestBase.java @@ -109,7 +109,8 @@ public void evaluate() throws Throwable { } catch (Throwable e) { if (shouldCapture) { - fail("Error occured during setup: " + e); + e.printStackTrace(); + fail("Error occured during setup: " + e.getMessage()); } else { throw e; diff --git a/microsoft-azure-api/src/test/resources/META-INF/com.microsoft.windowsazure.properties b/microsoft-azure-api/src/test/resources/META-INF/com.microsoft.windowsazure.properties index dccc767257e8b..1abb40b2238c1 100644 --- a/microsoft-azure-api/src/test/resources/META-INF/com.microsoft.windowsazure.properties +++ b/microsoft-azure-api/src/test/resources/META-INF/com.microsoft.windowsazure.properties @@ -12,9 +12,10 @@ table.accountName=%TABLE_ACCOUNTNAME% table.accountKey=%TABLE_ACCOUNTKEY% table.uri=http://%TABLE_ACCOUNTNAME%.table.core.windows.net media.uri=%MEDIA.URI% -oauth.uri=%OAUTH.URI% -oauth.client.id=%OAUTH.CLIENT.ID% -oauth.client.secret=%OAUTH.CLIENT.SECRET% -oauth.scope=urn:WindowsAzureMediaServices +media.oauth.uri=%MEDIA.OAUTH.URI% +media.oauth.client.id=%OMEDIA.AUTH.CLIENT.ID% +media.oauth.client.secret=%MEDIA.OAUTH.CLIENT.SECRET% +media.oauth.scope=urn:WindowsAzureMediaServices testprefix.com.microsoft.windowsazure.services.core.Configuration.connectTimeout=3 testprefix.com.microsoft.windowsazure.services.core.Configuration.readTimeout=7 +