forked from Azure/azure-sdk-for-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Azure#545 from christav/dev
Exposing Links as public properties on entities
- Loading branch information
Showing
3 changed files
with
248 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...ft-azure-api/src/main/java/com/microsoft/windowsazure/services/media/models/LinkInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
114 changes: 114 additions & 0 deletions
114
...test/java/com/microsoft/windowsazure/services/media/implementation/LinkRetrievalTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<LinkType>(linkName, LinkType.class, link1)); | ||
entry.getEntryChildren().add(new JAXBElement<LinkType>(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<MediaProcessorType>(Constants.ODATA_PROPERTIES_ELEMENT_NAME, MediaProcessorType.class, | ||
payload)); | ||
|
||
entry.getEntryChildren().add( | ||
new JAXBElement<ContentType>(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<LinkInfo> 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()); | ||
} | ||
} |