-
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.
- Loading branch information
Showing
15 changed files
with
490 additions
and
144 deletions.
There are no files selected for viewing
37 changes: 0 additions & 37 deletions
37
data/src/main/java/ch/srg/dataProvider/integrationlayer/data/IlImage.kt
This file was deleted.
Oops, something went wrong.
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
46 changes: 46 additions & 0 deletions
46
...src/androidTest/java/ch/srg/dataProvider/integrationlayer/TestDefaultImageUrlDecorator.kt
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,46 @@ | ||
package ch.srg.dataProvider.integrationlayer | ||
|
||
import android.net.Uri | ||
import ch.srg.dataProvider.integrationlayer.data.ImageUrl | ||
import ch.srg.dataProvider.integrationlayer.request.IlHost | ||
import ch.srg.dataProvider.integrationlayer.request.image.DefaultImageUrlDecorator | ||
import org.junit.Assert | ||
import org.junit.Test | ||
|
||
class TestDefaultImageUrlDecorator { | ||
private val decorator = DefaultImageUrlDecorator(ilHost = IlHost.PROD) | ||
|
||
@Test | ||
fun testNonRtsUrl() { | ||
val input = ImageUrl("https://ws.srf.ch/asset/image/audio/123") | ||
val encodedInput = Uri.encode("https://ws.srf.ch/asset/image/audio/123") | ||
val expected = "https://il.srgssr.ch/images/?imageUrl=${encodedInput}&format=webp&width=480" | ||
Assert.assertEquals(expected, input.url(decorator, 480)) | ||
} | ||
|
||
@Test | ||
fun testRtsUrlWithoutImage() { | ||
val input = ImageUrl("https://ws.rts.ch/asset/image/audio/123") | ||
val encodedInput = Uri.encode("https://ws.rts.ch/asset/image/audio/123") | ||
val expected = "https://il.srgssr.ch/images/?imageUrl=${encodedInput}&format=webp&width=480" | ||
Assert.assertEquals(expected, input.url(decorator, 480)) | ||
} | ||
|
||
@Test | ||
fun testUrlWithImageOnly() { | ||
val input = ImageUrl("https://ws.srf.ch/asset/image/audio/123.image") | ||
val encodedInput = Uri.encode("https://ws.srf.ch/asset/image/audio/123.image") | ||
val expected = "https://il.srgssr.ch/images/?imageUrl=${encodedInput}&format=webp&width=480" | ||
Assert.assertEquals(expected, input.url(decorator, 480)) | ||
} | ||
|
||
@Test | ||
fun testRtsUrlWithImage() { | ||
val input = ImageUrl("https://ws.rts.ch/asset/image/audio/123.image") | ||
val expected = "https://ws.rts.ch/asset/image/audio/123.image/scale/width/460" | ||
Assert.assertEquals(expected, input.url(decorator, 460)) | ||
} | ||
|
||
|
||
|
||
} |
72 changes: 72 additions & 0 deletions
72
.../src/androidTest/java/ch/srg/dataProvider/integrationlayer/TestIlHostImageUrlDecorator.kt
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,72 @@ | ||
package ch.srg.dataProvider.integrationlayer | ||
|
||
import android.net.Uri | ||
import ch.srg.dataProvider.integrationlayer.data.ImageUrl | ||
import ch.srg.dataProvider.integrationlayer.request.IlHost | ||
import ch.srg.dataProvider.integrationlayer.request.image.IlHostImageUrlDecorator | ||
import ch.srg.dataProvider.integrationlayer.request.image.ImageSize | ||
import ch.srg.dataProvider.integrationlayer.request.image.ImageWidth | ||
import ch.srg.dataProvider.integrationlayer.request.image.url | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
|
||
class TestIlHostImageUrlDecorator { | ||
|
||
private val decorator = IlHostImageUrlDecorator(ilHost = IlHost.PROD) | ||
|
||
@Test | ||
fun testPixelValid() { | ||
val input = ImageUrl("https://ws.srf.ch/asset/image/audio/123") | ||
val encodedInput = Uri.encode("https://ws.srf.ch/asset/image/audio/123") | ||
val expected = "https://il.srgssr.ch/images/?imageUrl=${encodedInput}&format=webp&width=480" | ||
assertEquals(expected, input.url(decorator, 480)) | ||
} | ||
|
||
@Test | ||
fun testPixelWidthInvalid() { | ||
val input = ImageUrl("https://ws.srf.ch/asset/image/audio/123") | ||
val encodedInput = Uri.encode("https://ws.srf.ch/asset/image/audio/123") | ||
val expected = "https://il.srgssr.ch/images/?imageUrl=${encodedInput}&format=webp&width=480" | ||
assertEquals(expected, input.url(decorator, 460)) | ||
} | ||
|
||
@Test | ||
fun testImageSize() { | ||
val input = ImageUrl("https://ws.srf.ch/asset/image/audio/123") | ||
val encodedInput = Uri.encode("https://ws.srf.ch/asset/image/audio/123") | ||
val expected = "https://il.srgssr.ch/images/?imageUrl=${encodedInput}&format=webp&width=480" | ||
assertEquals(expected, input.url(decorator, ImageSize.MEDIUM)) | ||
} | ||
|
||
@Test | ||
fun testImageWidth() { | ||
val input = ImageUrl("https://ws.srf.ch/asset/image/audio/123") | ||
val encodedInput = Uri.encode("https://ws.srf.ch/asset/image/audio/123") | ||
val expected = "https://il.srgssr.ch/images/?imageUrl=${encodedInput}&format=webp&width=1920" | ||
assertEquals(expected, input.url(decorator, ImageWidth.W1920)) | ||
} | ||
|
||
@Test | ||
fun testOtherIlHost() { | ||
val input = ImageUrl("https://ws.srf.ch/asset/image/audio/123") | ||
val encodedInput = Uri.encode("https://ws.srf.ch/asset/image/audio/123") | ||
val expected = "https://il-stage.srgssr.ch/images/?imageUrl=${encodedInput}&format=webp&width=1920" | ||
assertEquals(expected, input.url(decorator = IlHostImageUrlDecorator(IlHost.STAGE), width = ImageWidth.W1920)) | ||
} | ||
|
||
@Test | ||
fun testExtensionImageWidthWithIlHost() { | ||
val input = ImageUrl("https://ws.srf.ch/asset/image/audio/123") | ||
val encodedInput = Uri.encode("https://ws.srf.ch/asset/image/audio/123") | ||
val expected = "https://il-stage.srgssr.ch/images/?imageUrl=${encodedInput}&format=webp&width=1920" | ||
assertEquals(expected, input.url(ilHost = IlHost.STAGE, width = ImageWidth.W1920)) | ||
} | ||
|
||
@Test | ||
fun testExtensionImageSizeWithIlHost() { | ||
val input = ImageUrl("https://ws.srf.ch/asset/image/audio/123") | ||
val encodedInput = Uri.encode("https://ws.srf.ch/asset/image/audio/123") | ||
val expected = "https://il-test.srgssr.ch/images/?imageUrl=${encodedInput}&format=webp&width=480" | ||
assertEquals(expected, input.url(ilHost = IlHost.TEST, imageSize = ImageSize.MEDIUM)) | ||
} | ||
} |
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
36 changes: 36 additions & 0 deletions
36
.../androidTest/java/ch/srg/dataProvider/integrationlayer/TestScaleWidthImageUrlDecorator.kt
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,36 @@ | ||
package ch.srg.dataProvider.integrationlayer | ||
|
||
import ch.srg.dataProvider.integrationlayer.data.ImageUrl | ||
import ch.srg.dataProvider.integrationlayer.request.image.ImageSize | ||
import ch.srg.dataProvider.integrationlayer.request.image.ImageWidth | ||
import ch.srg.dataProvider.integrationlayer.request.image.ScaleWidthImageUrlDecorator | ||
import ch.srg.dataProvider.integrationlayer.request.image.url | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
|
||
class TestScaleWidthImageUrlDecorator { | ||
|
||
private val decorator = ScaleWidthImageUrlDecorator | ||
|
||
@Test | ||
fun testScaleWidth() { | ||
val input = ImageUrl("https://www.data.com/images/images.png") | ||
val width = 458 | ||
val expected = "https://www.data.com/images/images.png/scale/width/458" | ||
assertEquals(expected, input.url(decorator, width)) | ||
} | ||
|
||
@Test | ||
fun testScaleWidthImageSize() { | ||
val input = ImageUrl("https://www.data.com/images/images.png") | ||
val expected = "https://www.data.com/images/images.png/scale/width/480" | ||
assertEquals(expected, input.url(decorator, ImageSize.MEDIUM)) | ||
} | ||
|
||
@Test | ||
fun testScaleWidthImageWidth() { | ||
val input = ImageUrl("https://www.data.com/images/images.png") | ||
val expected = "https://www.data.com/images/images.png/scale/width/1920" | ||
assertEquals(expected, input.url(decorator, ImageWidth.W1920)) | ||
} | ||
} |
101 changes: 0 additions & 101 deletions
101
...ider-retrofit/src/main/java/ch/srg/dataProvider/integrationlayer/request/ImageProvider.kt
This file was deleted.
Oops, something went wrong.
31 changes: 31 additions & 0 deletions
31
.../main/java/ch/srg/dataProvider/integrationlayer/request/image/DefaultImageUrlDecorator.kt
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,31 @@ | ||
package ch.srg.dataProvider.integrationlayer.request.image | ||
|
||
import ch.srg.dataProvider.integrationlayer.data.ImageUrlDecorator | ||
import ch.srg.dataProvider.integrationlayer.request.IlHost | ||
|
||
/** | ||
* Copyright (c) SRG SSR. All rights reserved. | ||
* | ||
* | ||
* License information is available from the LICENSE file. | ||
*/ | ||
|
||
/** | ||
* Default image url decorator | ||
* | ||
* For specific RTS image url the old [ScaleWidthImageUrlDecorator] is used, but it should be fixed soon or later. | ||
* * | ||
* @param ilHost The [IlHost] to use with [ilHostImageUrlDecorator]. | ||
*/ | ||
class DefaultImageUrlDecorator(ilHost: IlHost = IlHost.PROD) : ImageUrlDecorator { | ||
private val ilHostImageUrlDecorator = IlHostImageUrlDecorator(ilHost) | ||
|
||
override fun decorate(imageUrl: String, size: Int): String { | ||
// FIXME https://github.com/SRGSSR/srgdataprovider-apple/issues/47 once RTS image service is well connected to Il Play image service. | ||
return if (imageUrl.contains("rts.ch") && imageUrl.contains(".image")) { | ||
ScaleWidthImageUrlDecorator.decorate(imageUrl, size) | ||
} else { | ||
ilHostImageUrlDecorator.decorate(imageUrl, size) | ||
} | ||
} | ||
} |
Oops, something went wrong.