Created
June 18, 2015 10:31
-
-
Save TobyRet/db5f73286ddc99bcb1e4 to your computer and use it in GitHub Desktop.
System Test - Deezer Meta
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
package me.crowdmix.media | |
import javax.ws.rs.client.Client | |
import javax.ws.rs.client.ClientBuilder | |
import com.fasterxml.jackson.databind.ObjectMapper | |
import com.github.tomakehurst.wiremock.junit.WireMockRule | |
import com.jayway.awaitility.groovy.AwaitilityTrait | |
import me.crowdmix.media.tracks.SourceTrackId | |
import me.crowdmix.media.tracks.TrackMetadata | |
import me.crowdmix.media.tracks.matching.deezer.* | |
import org.junit.Rule | |
import spock.lang.Specification | |
import static com.github.tomakehurst.wiremock.client.WireMock.* | |
import static me.crowdmix.media.testing.optional.OptionalAssert.assertOptional | |
@SuppressWarnings("GrEqualsBetweenInconvertibleTypes") | |
class RetrieveMetadataFromDeezerAPISpec extends Specification implements AwaitilityTrait { | |
private static final String DEEZER = "deezer"; | |
@Rule | |
public WireMockRule wireMockRule = new WireMockRule(); | |
@SuppressWarnings("GroovyAssignabilityCheck") | |
def "retrieve track information by track id"() { | |
given: "There is track meta data for 'Never Gonna Give You Up' track on Deezer" | |
def response = new ObjectMapper().readValue(trackSearchResults(), Map) | |
println(response) | |
wireMockRule.givenThat(get(urlPathEqualTo( | |
"/search/artist")) | |
.withQueryParam("q", equalTo("Rick Astley")) | |
.willReturn(aResponse() | |
.withStatus(200) | |
.withHeader("Content-Type", "application/json") | |
.withBody(artistSearchResults()) | |
)); | |
wireMockRule.givenThat(get(urlPathEqualTo( | |
"/search/track")) | |
.withQueryParam("q", equalTo("Never Gonna Give You Up")) | |
.willReturn(aResponse() | |
.withStatus(200) | |
.withHeader("Content-Type", "application/json") | |
.withBody(trackSearchResults()) | |
)); | |
when: "I search for 'Never Gonna Give You Up'" | |
DeezerMatcher deezer = new DeezerMatcher(new DeezerClient() { | |
private final Client client = ClientBuilder.newClient(); | |
@Override | |
public List<DeezerTrackDto> searchTrack(String trackQuery) { | |
return client.target("http://localhost:8080") | |
.path("/search/track") | |
.queryParam("q", trackQuery) | |
.request() | |
.get(DeezerTracksDto.class) | |
.data(); | |
} | |
@Override | |
public List<DeezerArtistDto> searchArtist(String artistQuery) { | |
return client.target("http://localhost:8080") | |
.path("/search/artist") | |
.queryParam("q", artistQuery) | |
.request() | |
.get(DeezerArtistsDto.class) | |
.data(); | |
} | |
}); | |
def match = deezer.searchForMetadata("Never gonna give you up ", "Rick Astley"); | |
then: "I should see metadata on 'Never Gonna Give You Up'" | |
assertOptional(match).hasValue( | |
TrackMetadata.create( | |
"Never Gonna Give You Up", | |
"Rick Astley", | |
"The Best Of Rick Astley", | |
Optional.of("http://api.deezer.com/artist/6160/image"), | |
Optional.of("http://cdn-preview-2.deezer.com/stream/2bf3eafb1c1d8fe861ffc886f642a14f-1.mp3"), | |
SourceTrackId.create(DEEZER, "5404528") | |
) | |
); | |
} | |
def trackSearchResults() { | |
"{" + | |
"\"data\":[" + | |
"{" + | |
"\"id\":84840917," + | |
"\"readable\":true," + | |
"\"title\":\"Never Gonna Give You Up\"," + | |
"\"link\":\"http://www.deezer.com/track/84840917\"," + | |
"\"duration\":213," + | |
"\"rank\":726631," + | |
"\"explicit_lyrics\":false," + | |
"\"preview\":\"http://cdn-preview-2.deezer.com/stream/2bf3eafb1c1d8fe861ffc886f642a14f-1.mp3\"," + | |
"\"artist\":{" + | |
"\"id\":6160," + | |
"\"name\":\"Rick Astley\"," + | |
"\"link\":\"http://www.deezer.com/artist/6160\"," + | |
"\"picture\":\"http://api.deezer.com/artist/6160/image\"," + | |
"\"tracklist\":\"http://api.deezer.com/artist/6160/top?limit=50\"," + | |
"\"type\":\"artist\"" + | |
"}," + | |
"\"album\":{" + | |
"\"id\":8554401," + | |
"\"title\":\"The Best Of Rick Astley\"," + | |
"\"cover\":\"http://api.deezer.com/album/8554401/image\"," + | |
"\"tracklist\":\"http://api.deezer.com/album/8554401/tracks\"," + | |
"\"type\":\"album\"" + | |
"}," + | |
"\"type\":\"track\"" + | |
"}" + | |
"]," + | |
"\"total\":417," + | |
"\"next\":\"http://api.deezer.com/search/track?q=never%20gonna%20give%20you%20up&index=25\"" + | |
"}" | |
} | |
def artistSearchResults() { | |
"{" + | |
"\"data\":[" + | |
"{" + | |
"\"id\":6160," + | |
"\"name\":\"Rick Astley\"," + | |
"\"link\":\"http://www.deezer.com/artist/6160\"," + | |
"\"picture\":\"http://api.deezer.com/artist/6160/image\","+ | |
"\"nb_album\":9," + | |
"\"nb_fan\":18694," + | |
"\"radio\":true," + | |
"\"tracklist\":\"http://api.deezer.com/artist/6160/top?limit=50\"," + | |
"\"type\":\"artist\"" | |
"}," + | |
"]," + | |
"\"total\":3" + | |
"}" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment