diff --git a/README.md b/README.md index 5a3fc1879..1039cea07 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ The game will also offer a customization where the user can create a game from i - [x] Create a Github repository - [x] Setup all Github feature (params, ...) - [x] Add continuous integration -- [ ] +- [ ] @@ -49,8 +49,8 @@ The game will also offer a customization where the user can create a game from i | Name | GitHub username | |:--------|---------:| | Derin Arda Alpay | [Tsathogguaa](https://github.com/Tsathogguaa) | -| Kamila Babayeva | [kamilababayeva14](https://github.com/kamilababayeva14) | +| Kamila Babayeva | [kamilababayeva](https://github.com/kamilababayeva) | | Laurynas Lopata | [laurislopata](https://github.com/laurislopata) | | Jiabao Wen | [jiabaow](https://github.com/jiabaow) | | Maxime Zammit | [MaximeZmt](https://github.com/MaximeZmt) | -| Margaux Zwierski | [zwierski](https://github.com/zwierski) | +| Margaux Zwierski | [zwierski](https://github.com/zwierski) | \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index bc93ccf3e..530f79359 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -10,7 +10,7 @@ android { defaultConfig { applicationId "ch.sdp.vibester" - minSdk 23 + minSdk 24 targetSdk 31 versionCode 1 versionName "1.0" @@ -50,7 +50,9 @@ dependencies { implementation 'androidx.appcompat:appcompat:1.4.1' implementation 'com.google.android.material:material:1.5.0' implementation 'androidx.constraintlayout:constraintlayout:2.1.3' + implementation 'com.squareup.okhttp3:okhttp:4.9.0' testImplementation 'junit:junit:4.13.2' + testImplementation 'org.json:json:20180813' testImplementation 'org.robolectric:robolectric:4.6' testImplementation 'androidx.test:core:1.4.0' testImplementation 'org.mockito.kotlin:mockito-kotlin:4.0.0' diff --git a/app/src/androidTest/java/ch/sdp/vibester/MusicTemporaryTest.kt b/app/src/androidTest/java/ch/sdp/vibester/MusicTemporaryTest.kt new file mode 100644 index 000000000..e17ef6f00 --- /dev/null +++ b/app/src/androidTest/java/ch/sdp/vibester/MusicTemporaryTest.kt @@ -0,0 +1,37 @@ +package ch.sdp.vibester + +import android.content.Intent +import androidx.test.core.app.ActivityScenario +import androidx.test.core.app.ApplicationProvider +import androidx.test.espresso.Espresso +import androidx.test.espresso.Espresso.onView +import androidx.test.espresso.action.ViewActions +import androidx.test.espresso.action.ViewActions.* +import androidx.test.espresso.assertion.ViewAssertions +import androidx.test.espresso.assertion.ViewAssertions.matches +import androidx.test.espresso.matcher.ViewMatchers +import androidx.test.espresso.matcher.ViewMatchers.withId +import androidx.test.espresso.matcher.ViewMatchers.withText +import androidx.test.ext.junit.runners.AndroidJUnit4 +import org.junit.Test +import org.junit.runner.RunWith + +@RunWith(AndroidJUnit4::class) +class MusicTemporaryTest{ + + // Temporary test + @Test + fun musicTemporaryTest() { + val inputName = "Imagine Dragons Believer" + val intent = + Intent(ApplicationProvider.getApplicationContext(), MusicTemporary::class.java) + val scn: ActivityScenario = ActivityScenario.launch(intent) + onView(withId(R.id.musicName)) + .perform(typeText(inputName), closeSoftKeyboard()) + onView(withId(R.id.validate)).perform(click()) + onView(withId(R.id.textViewPlaying)) + .check(matches(withText("Imagine Dragons - Believer"))) + } + + +} \ No newline at end of file diff --git a/app/src/androidTest/java/ch/sdp/vibester/api/ItunesMusicApiTest.kt b/app/src/androidTest/java/ch/sdp/vibester/api/ItunesMusicApiTest.kt new file mode 100644 index 000000000..625f563f1 --- /dev/null +++ b/app/src/androidTest/java/ch/sdp/vibester/api/ItunesMusicApiTest.kt @@ -0,0 +1,50 @@ +package ch.sdp.vibester.api + + + +import ch.sdp.vibester.model.Song +import okhttp3.OkHttpClient +import org.junit.Assert.assertEquals +import org.junit.Rule +import org.junit.Test +import org.junit.rules.ExpectedException +import java.lang.Exception + + +class ItunesMusicApiTest{ + + @Test + fun itunesAPIQueryWorks() { + var songFut = ItunesMusicApi.querySong("imagine dragons believer", OkHttpClient()) + val song = Song(songFut.get()) + assertEquals("Imagine Dragons", song.getArtistName()) + } + + @get:Rule + var exception = ExpectedException.none() + + @Test + fun itunesAPIQueryError() { + exception.expect(Exception::class.java) + var songFut = ItunesMusicApi.querySong("imagine dragons believer", OkHttpClient(), "https://ThisIsNotAnURL666.notADomain") + songFut.get() + } + + @Test + fun itunesAPIQueryWorksComplete() { + var songFut = ItunesMusicApi.querySong("imagine dragons believer", OkHttpClient()) + val song = Song(songFut.get()) + val mediaFut = ItunesMusicApi.playAudio(song.getPreviewUrl()) + val player = mediaFut.get() + assertEquals(true, player.isPlaying) + } + + @Test + fun itunesAPIQueryCompleteError() { + exception.expect(Exception::class.java) + val mediaFut = ItunesMusicApi.playAudio("https://ThisIsNotAnURL666.notADomain") + mediaFut.get() + } + + +} diff --git a/app/src/androidTest/java/ch/sdp/vibester/model/SongTest.kt b/app/src/androidTest/java/ch/sdp/vibester/model/SongTest.kt new file mode 100644 index 000000000..a80a26337 --- /dev/null +++ b/app/src/androidTest/java/ch/sdp/vibester/model/SongTest.kt @@ -0,0 +1,48 @@ +package ch.sdp.vibester.model + + +import org.junit.Assert.assertEquals +import org.junit.Rule +import org.junit.Test +import org.junit.rules.ExpectedException + + +class SongTest{ + + @Test + fun jsonPreviewParseBasic() { + val inputTxt = """ + { + "resultCount":1, + "results": [ + {"wrapperType":"track", "kind":"song", "artistId":358714030, "collectionId":1574210519, "trackId":1574210894, "artistName":"Imagine Dragons", "collectionName":"Mercury - Act 1", "trackName":"Monday", "collectionCensoredName":"Mercury - Act 1", "trackCensoredName":"Monday", "artistViewUrl":"https://music.apple.com/us/artist/imagine-dragons/358714030?uo=4", "collectionViewUrl":"https://music.apple.com/us/album/monday/1574210519?i=1574210894&uo=4", "trackViewUrl":"https://music.apple.com/us/album/monday/1574210519?i=1574210894&uo=4", + "previewUrl":"https://audio-ssl.itunes.apple.com/itunes-assets/AudioPreview125/v4/bc/71/fc/bc71fca4-e0bb-609b-5b6e-92296df7b4b6/mzaf_8907306752631175088.plus.aac.p.m4a", "artworkUrl30":"https://is3-ssl.mzstatic.com/image/thumb/Music115/v4/3e/04/c4/3e04c4e7-1863-34cb-e8f3-f168ae5b213e/source/30x30bb.jpg", "artworkUrl60":"https://is3-ssl.mzstatic.com/image/thumb/Music115/v4/3e/04/c4/3e04c4e7-1863-34cb-e8f3-f168ae5b213e/source/60x60bb.jpg", "artworkUrl100":"https://is3-ssl.mzstatic.com/image/thumb/Music115/v4/3e/04/c4/3e04c4e7-1863-34cb-e8f3-f168ae5b213e/source/100x100bb.jpg", "releaseDate":"2021-09-03T12:00:00Z", "collectionExplicitness":"notExplicit", "trackExplicitness":"notExplicit", "discCount":1, "discNumber":1, "trackCount":13, "trackNumber":4, "trackTimeMillis":187896, "country":"USA", "currency":"USD", "primaryGenreName":"Alternative", "isStreamable":true}] + } + """ + + val mySong = Song(inputTxt) + + val previewUrl = "https://audio-ssl.itunes.apple.com/itunes-assets/AudioPreview125/v4/bc/71/fc/bc71fca4-e0bb-609b-5b6e-92296df7b4b6/mzaf_8907306752631175088.plus.aac.p.m4a" + val artworkUrl = "https://is3-ssl.mzstatic.com/image/thumb/Music115/v4/3e/04/c4/3e04c4e7-1863-34cb-e8f3-f168ae5b213e/source/100x100bb.jpg" + val artistName = "Imagine Dragons" + val trackName = "Monday" + + + assertEquals(previewUrl, mySong.getPreviewUrl()) + assertEquals(artworkUrl, mySong.getArtworkUrl()) + assertEquals(artistName, mySong.getArtistName()) + assertEquals(trackName, mySong.getTrackName()) + } + + + @get:Rule + var exception = ExpectedException.none() + + @Test + fun jsonPreviewParseErrorText() { + exception.expect(IllegalArgumentException::class.java) + exception.expectMessage("Song constructor, bad argument") + Song("") + } + +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index c87538314..2e1753304 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -12,6 +12,9 @@ android:supportsRtl="true" android:theme="@style/Theme.MyApplication"> + (R.id.musicName) + + val btnValidate = findViewById