-
Notifications
You must be signed in to change notification settings - Fork 10
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
7 changed files
with
257 additions
and
96 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
16 changes: 15 additions & 1 deletion
16
visitorservice/src/main/java/com/tealium/visitorservice/momentsapi/ErrorCode.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 |
---|---|---|
@@ -1,10 +1,24 @@ | ||
package com.tealium.visitorservice.momentsapi | ||
|
||
import com.tealium.core.LogLevel | ||
import java.util.Locale | ||
|
||
enum class ErrorCode(val value: Int) { | ||
BAD_REQUEST(400 ), | ||
ENGINE_NOT_ENABLED(403), | ||
VISITOR_NOT_FOUND(404), | ||
NOT_CONNECTED (0), | ||
INVALID_JSON (1), | ||
UNKNOWN_ERROR(2) | ||
UNKNOWN_ERROR(2); | ||
|
||
companion object { | ||
fun fromInt(int: Int) : ErrorCode { | ||
return when(int) { | ||
400 -> BAD_REQUEST | ||
403 -> ENGINE_NOT_ENABLED | ||
404 -> VISITOR_NOT_FOUND | ||
else -> UNKNOWN_ERROR | ||
} | ||
} | ||
} | ||
} |
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
86 changes: 0 additions & 86 deletions
86
visitorservice/src/main/java/com/tealium/visitorservice/momentsapi/MomentsApiManager.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
82 changes: 82 additions & 0 deletions
82
visitorservice/src/test/java/com/tealium/visitorservice/momentsapi/EngineResponseTest.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,82 @@ | ||
package com.tealium.visitorservice.momentsapi | ||
|
||
import org.json.JSONObject | ||
import org.junit.Assert.* | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.robolectric.RobolectricTestRunner | ||
|
||
@RunWith(RobolectricTestRunner::class) | ||
class EngineResponseTest { | ||
val validEngineResponseString = """ | ||
{ | ||
"audiences": [ | ||
"audience_1", | ||
"audience_2", | ||
"audience_3" | ||
], | ||
"badges": [ | ||
"13" | ||
], | ||
"properties": { | ||
"45": "Android", | ||
"46": "Android", | ||
"47": "mobile application", | ||
"5135": "blue_shoes" | ||
} | ||
} | ||
""" | ||
|
||
@Test | ||
fun engineResponseDecodeAudiencesSuccess() { | ||
val json = JSONObject(validEngineResponseString) | ||
val engineResponse = EngineResponse.fromJson(json) | ||
|
||
assertEquals(engineResponse.audiences?.get(0), "audience_1") | ||
assertEquals(engineResponse.audiences?.get(1), "audience_2") | ||
assertEquals(engineResponse.audiences?.get(2), "audience_3") | ||
} | ||
|
||
@Test | ||
fun engineResponseDecodeNullAudience() { | ||
val json = JSONObject(validEngineResponseString) | ||
val engineResponse = EngineResponse.fromJson(json) | ||
|
||
engineResponse.audiences?.contains("audience_4")?.let { assertFalse(it) } | ||
} | ||
|
||
@Test | ||
fun engineResponseDecodeBadgesSuccess() { | ||
val json = JSONObject(validEngineResponseString) | ||
val engineResponse = EngineResponse.fromJson(json) | ||
|
||
engineResponse.badges?.contains("13")?.let { assertTrue(it) } | ||
} | ||
|
||
@Test | ||
fun engineResponseDecodeNullBadge() { | ||
val json = JSONObject(validEngineResponseString) | ||
val engineResponse = EngineResponse.fromJson(json) | ||
|
||
engineResponse.badges?.contains("33")?.let { assertFalse(it) } | ||
} | ||
|
||
@Test | ||
fun engineResponseDecodePropertiesSuccess() { | ||
val json = JSONObject(validEngineResponseString) | ||
val engineResponse = EngineResponse.fromJson(json) | ||
|
||
assertEquals(engineResponse.properties?.getValue("45"), "Android") | ||
assertEquals(engineResponse.properties?.getValue("46"), "Android") | ||
assertEquals(engineResponse.properties?.getValue("47"), "mobile application") | ||
assertEquals(engineResponse.properties?.getValue("5135"), "blue_shoes") | ||
} | ||
|
||
@Test | ||
fun engineResponseDecodeNullProperty() { | ||
val json = JSONObject(validEngineResponseString) | ||
val engineResponse = EngineResponse.fromJson(json) | ||
|
||
assertNull(engineResponse.properties?.get("333")) | ||
} | ||
} |
Oops, something went wrong.