Skip to content

Commit b5ee40e

Browse files
committed
Fix pinpoint PutEvents response unmarshaller
1 parent 87fa4bd commit b5ee40e

File tree

2 files changed

+95
-1
lines changed

2 files changed

+95
-1
lines changed

aws-android-sdk-pinpoint/src/main/java/com/amazonaws/services/pinpoint/model/transform/PutEventsResultJsonUnmarshaller.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,14 @@ public class PutEventsResultJsonUnmarshaller implements
2727
Unmarshaller<PutEventsResult, JsonUnmarshallerContext> {
2828

2929
public PutEventsResult unmarshall(JsonUnmarshallerContext context) throws Exception {
30+
AwsJsonReader reader = context.getReader();
31+
if (!reader.isContainer()) {
32+
reader.skipValue();
33+
return null;
34+
}
3035
PutEventsResult putEventsResult = new PutEventsResult();
31-
36+
putEventsResult.setEventsResponse(EventsResponseJsonUnmarshaller.getInstance()
37+
.unmarshall(context));
3238
return putEventsResult;
3339
}
3440

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
package com.amazonaws.mobileconnectors.pinpoint;
2+
3+
import android.content.Context;
4+
5+
import com.amazonaws.auth.CognitoCachingCredentialsProvider;
6+
import com.amazonaws.regions.Region;
7+
import com.amazonaws.regions.Regions;
8+
import com.amazonaws.services.pinpoint.AmazonPinpointClient;
9+
import com.amazonaws.services.pinpoint.model.EndpointDemographic;
10+
import com.amazonaws.services.pinpoint.model.EndpointLocation;
11+
import com.amazonaws.services.pinpoint.model.EventsBatch;
12+
import com.amazonaws.services.pinpoint.model.EventsRequest;
13+
import com.amazonaws.services.pinpoint.model.Event;
14+
import com.amazonaws.services.pinpoint.model.PublicEndpoint;
15+
import com.amazonaws.services.pinpoint.model.PutEventsRequest;
16+
import com.amazonaws.services.pinpoint.model.PutEventsResult;
17+
import com.amazonaws.services.pinpoint.model.Session;
18+
19+
import org.junit.Before;
20+
import org.junit.Test;
21+
import org.junit.runner.RunWith;
22+
import org.robolectric.RobolectricTestRunner;
23+
import org.robolectric.RuntimeEnvironment;
24+
import org.robolectric.annotation.Config;
25+
26+
import java.util.HashMap;
27+
28+
/**
29+
* This integration test suite values can be setup with
30+
* amplify init
31+
* amplify add analytics
32+
* amplify push
33+
* Then replacing the redacted static values
34+
*/
35+
@RunWith(RobolectricTestRunner.class)
36+
@Config(manifest = Config.NONE, sdk=23)
37+
public class PinpointAnalyticsIntegrationTest {
38+
39+
public static final String COGNITO_IDENTITY_POOL = "redacted_pinpoint_cognito_identity_pool";
40+
public static final Regions COGNITO_REGION = Regions.US_EAST_1;
41+
public static final String PINPOINT_APP_ID = "redacted_pinpoint_app_id";
42+
public static final Regions PINPOINT_REGION = Regions.US_EAST_1;
43+
44+
AmazonPinpointClient amazonPinpointClient;
45+
46+
@Before
47+
public void setup() {
48+
final Context context = RuntimeEnvironment.application;
49+
CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(context, COGNITO_IDENTITY_POOL, COGNITO_REGION);
50+
amazonPinpointClient = new AmazonPinpointClient(credentialsProvider);
51+
amazonPinpointClient.setRegion(Region.getRegion(PINPOINT_REGION));
52+
}
53+
54+
@Test
55+
public void testSubmitEvents() {
56+
Event event = new Event()
57+
.withSession(new Session()
58+
.withId("abc123ab-20181227-201702280")
59+
.withStartTimestamp("2018-12-27T20:17:02.280Z"))
60+
.withEventType("_session.start")
61+
.withMetrics(new HashMap<String, Double>())
62+
.withTimestamp("2018-12-27T20:17:02:352Z");
63+
String key = "7de7c2a0-062e-4823-a766-4f24d97247fe";
64+
PutEventsRequest putEventsRequest = new PutEventsRequest()
65+
.withEventsRequest(new EventsRequest()
66+
.addBatchItemEntry(key, new EventsBatch()
67+
.withEndpoint(new PublicEndpoint()
68+
.withChannelType("GCM")
69+
.withDemographic(new EndpointDemographic()
70+
.withAppVersion("1.0")
71+
.withLocale("en_US")
72+
.withMake("Google")
73+
.withModel("IntegrationTest")
74+
.withPlatform("ANDROID")
75+
.withPlatformVersion("8.0.0")
76+
.withTimezone("America/Los_Angeles"))
77+
.withEffectiveDate("2018-12-27T20:16:28.893Z")
78+
.withLocation(new EndpointLocation().withCity("").withCountry("USA").withPostalCode("").withRegion(""))
79+
.withMetrics(new HashMap<String, Double>())
80+
.withOptOut("ALL"))
81+
.addEventsEntry("key", event)))
82+
.withApplicationId(PINPOINT_APP_ID);
83+
PutEventsResult putEventsResult = amazonPinpointClient.putEvents(putEventsRequest);
84+
assert putEventsResult.getEventsResponse() != null;
85+
assert putEventsResult.getEventsResponse().getResults() != null;
86+
assert putEventsResult.getEventsResponse().getResults().get(key) != null;
87+
}
88+
}

0 commit comments

Comments
 (0)