Skip to content
This repository has been archived by the owner on Jun 4, 2021. It is now read-only.

Commit

Permalink
Updated SnowplowAdapter to accept "charset=UTF-8" (closes snowplow/sn…
Browse files Browse the repository at this point in the history
  • Loading branch information
fblundun committed Feb 19, 2015
1 parent 97a7c1c commit 6132918
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ object SnowplowAdapter {

// Expected content types for a request body
private object ContentTypes {
val list = List("application/json", "application/json; charset=utf-8")
val list = List("application/json", "application/json; charset=utf-8", "application/json; charset=UTF-8")
val str = list.mkString(", ")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ class SnowplowAdapterSpec extends Specification with DataTables with ValidationM
"Tp2.toRawEvents should return a NEL containing one RawEvent if only the querystring is populated" ! e3^
"Tp2.toRawEvents should return a NEL containing one RawEvent if the querystring is empty but the body contains one event" ! e4^
"Tp2.toRawEvents should return a NEL containing three RawEvents consolidating body's events and querystring's parameters" ! e5^
"Tp2.toRawEvents should return a Validation Failure if querystring, body and content type are mismatching" ! e6^
"Tp2.toRawEvents should return a Validation Failure if the body is not a self-describing JSON" ! e7^
"Tp2.toRawEvents should return a Validation Failure if the body is in a JSON Schema other than payload_data" ! e8^
"Tp2.toRawEvents should return a Validation Failure if the body fails payload_data JSON Schema validation" ! e9^
"Tp1.toRawEvents should return a NEL containing one RawEvent if the Content-Type is application/json; charset=UTF-8" ! e6^
"Tp2.toRawEvents should return a Validation Failure if querystring, body and content type are mismatching" ! e8^
"Tp2.toRawEvents should return a Validation Failure if the body is not a self-describing JSON" ! e8^
"Tp2.toRawEvents should return a Validation Failure if the body is in a JSON Schema other than payload_data" ! e9^
"Tp2.toRawEvents should return a Validation Failure if the body fails payload_data JSON Schema validation" ! e10^
end

implicit val resolver = SpecHelpers.IgluResolver
Expand All @@ -61,6 +62,7 @@ class SnowplowAdapterSpec extends Specification with DataTables with ValidationM

val ApplicationJson = "application/json"
val ApplicationJsonWithCharset = "application/json; charset=utf-8"
val ApplicationJsonWithCapitalCharset = "application/json; charset=UTF-8"

object Shared {
val source = CollectorSource("clj-tomcat", "UTF-8", None)
Expand Down Expand Up @@ -94,18 +96,25 @@ class SnowplowAdapterSpec extends Specification with DataTables with ValidationM

def e5 = {
val body = toSelfDescJson("""[{"tv":"1","p":"1","e":"1"},{"tv":"2","p":"2","e":"2"},{"tv":"3","p":"3","e":"3"}]""", "payload_data")
val payload = CollectorPayload(Snowplow.Tp2, toNameValuePairs("tv" -> "0", "nuid" -> "123"), ApplicationJson.some, body.some, Shared.source, Shared.context)
val payload = CollectorPayload(Snowplow.Tp2, toNameValuePairs("tv" -> "0", "nuid" -> "123"), ApplicationJsonWithCapitalCharset.some, body.some, Shared.source, Shared.context)
val actual = SnowplowAdapter.Tp2.toRawEvents(payload)

val rawEvent: RawEventParameters => RawEvent = params => RawEvent(Snowplow.Tp2, params, ApplicationJson.some, Shared.source, Shared.context)
val rawEvent: RawEventParameters => RawEvent = params => RawEvent(Snowplow.Tp2, params, ApplicationJsonWithCapitalCharset.some, Shared.source, Shared.context)
actual must beSuccessful(NonEmptyList(
rawEvent(Map("tv" -> "0", "p" -> "1", "e" -> "1", "nuid" -> "123")),
rawEvent(Map("tv" -> "0", "p" -> "2", "e" -> "2", "nuid" -> "123")),
rawEvent(Map("tv" -> "0", "p" -> "3", "e" -> "3", "nuid" -> "123"))
))
}

def e6 =
def e6 = {
val body = toSelfDescJson("""[{"tv":"ios-0.1.0","p":"mob","e":"se"}]""", "payload_data")
val payload = CollectorPayload(Snowplow.Tp2, Nil, ApplicationJsonWithCapitalCharset.some, body.some, Shared.source, Shared.context)
val actual = SnowplowAdapter.Tp2.toRawEvents(payload)
actual must beSuccessful(NonEmptyList(RawEvent(Snowplow.Tp2, Map("tv" -> "ios-0.1.0", "p" -> "mob", "e" -> "se"), ApplicationJsonWithCapitalCharset.some, Shared.source, Shared.context)))
}

def e7 =
"SPEC NAME" || "IN QUERYSTRING" | "IN CONTENT TYPE" | "IN BODY" | "EXP. FAILURE" |
"Invalid content type" !! Nil ! "text/plain".some ! "body".some ! "Content type of text/plain provided, expected one of: application/json, application/json; charset=utf-8" |
"Neither querystring nor body populated" !! Nil ! None ! None ! "Request body and querystring parameters empty, expected at least one populated" |
Expand All @@ -121,7 +130,7 @@ class SnowplowAdapterSpec extends Specification with DataTables with ValidationM
}
}

def e7 = {
def e8 = {
val payload = CollectorPayload(Snowplow.Tp2, toNameValuePairs("aid" -> "test"), ApplicationJson.some, """{"not":"self-desc"}""".some, Shared.source, Shared.context)
val actual = SnowplowAdapter.Tp2.toRawEvents(payload)
actual must beFailing(NonEmptyList("""error: object instance has properties which are not allowed by the schema: ["not"]
Expand All @@ -143,7 +152,7 @@ class SnowplowAdapterSpec extends Specification with DataTables with ValidationM
"""))
}

def e8 = {
def e9 = {
val body = toSelfDescJson("""{"longitude":20.1234}""", "geolocation_context")
val payload = CollectorPayload(Snowplow.Tp2, Nil, ApplicationJson.some, body.some, Shared.source, Shared.context)
val actual = SnowplowAdapter.Tp2.toRawEvents(payload)
Expand All @@ -152,7 +161,7 @@ class SnowplowAdapterSpec extends Specification with DataTables with ValidationM
"""))
}

def e9 =
def e10 =
"SPEC NAME" || "IN JSON DATA" | "EXP. FAILURES" |
"JSON object instead of array" !! "{}" ! NonEmptyList("""error: instance type (object) does not match any allowed primitive type (allowed: ["array"])
level: "error"
Expand Down

0 comments on commit 6132918

Please sign in to comment.