forked from snowplow/snowplow-java-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelfDescribingJsonTest.java
More file actions
66 lines (59 loc) · 2.55 KB
/
SelfDescribingJsonTest.java
File metadata and controls
66 lines (59 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* Copyright (c) 2015 Snowplow Analytics Ltd. All rights reserved.
*
* This program is licensed to you under the Apache License Version 2.0,
* and you may not use this file except in compliance with the Apache License Version 2.0.
* You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the Apache License Version 2.0 is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
*/
package com.snowplowanalytics.snowplow.tracker.payload;
// Java
import java.util.HashMap;
import java.util.Map;
// JUnit
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
public class SelfDescribingJsonTest {
@Test
public void testMakeSdjWithoutData() {
SelfDescribingJson sdj = new SelfDescribingJson("schema_string");
String expected = "{\"schema\":\"schema_string\",\"data\":{}}";
String sdjString = sdj.toString();
assertNotNull(sdj);
assertEquals(expected, sdjString);
}
@Test
public void testMakeSdjWithObject() {
Map<String, Object> data = new HashMap<>();
data.put("key", "value");
SelfDescribingJson sdj = new SelfDescribingJson("schema_string", data);
String expected = "{\"schema\":\"schema_string\",\"data\":{\"key\":\"value\"}}";
String sdjString = sdj.toString();
assertNotNull(sdj);
assertEquals(expected, sdjString);
}
@Test
public void testMakeSdjWithTrackerPayload() {
TrackerPayload data = new TrackerPayload();
data.add("value", "key");
SelfDescribingJson sdj = new SelfDescribingJson("schema_string", data);
String expected = "{\"schema\":\"schema_string\",\"data\":{\"value\":\"key\"}}";
String sdjString = sdj.toString();
assertNotNull(sdj);
assertEquals(expected, sdjString);
}
@Test
public void testMakeSdjWithSdj() {
SelfDescribingJson data = new SelfDescribingJson("nested_schema_string");
SelfDescribingJson sdj = new SelfDescribingJson("schema_string", data);
String expected = "{\"schema\":\"schema_string\",\"data\":{\"schema\":\"nested_schema_string\",\"data\":{}}}";
String sdjString = sdj.toString();
assertNotNull(sdj);
assertEquals(expected, sdjString);
}
}