Skip to content

Commit 0ef3d31

Browse files
author
Karthikeyan
authored
[Pinpoint] Add test for endpoint profile (#908)
1 parent a4e5b46 commit 0ef3d31

File tree

1 file changed

+125
-0
lines changed

1 file changed

+125
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
/**
2+
* Copyright 2019-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package com.amazonaws.mobileconnectors.pinpoint.analytics;
17+
18+
import android.content.Context;
19+
import android.net.wifi.WifiManager;
20+
import android.support.test.InstrumentationRegistry;
21+
import android.support.test.runner.AndroidJUnit4;
22+
23+
import com.amazonaws.auth.CognitoCachingCredentialsProvider;
24+
import com.amazonaws.mobileconnectors.pinpoint.PinpointConfiguration;
25+
import com.amazonaws.mobileconnectors.pinpoint.PinpointManager;
26+
import com.amazonaws.mobileconnectors.pinpoint.targeting.TargetingClient;
27+
import com.amazonaws.mobileconnectors.pinpoint.targeting.endpointProfile.EndpointProfile;
28+
import com.amazonaws.mobileconnectors.pinpoint.targeting.endpointProfile.EndpointProfileUser;
29+
import com.amazonaws.regions.Regions;
30+
import com.amazonaws.testutils.AWSTestBase;
31+
32+
import org.junit.After;
33+
import org.junit.Before;
34+
import org.junit.Test;
35+
import org.junit.runner.RunWith;
36+
37+
import java.util.Arrays;
38+
39+
import static junit.framework.TestCase.assertTrue;
40+
import static org.junit.Assert.assertEquals;
41+
import static org.junit.Assert.assertNotNull;
42+
import static org.junit.Assert.assertNull;
43+
44+
/**
45+
* Instrumented test, which will execute on an Android device.
46+
*
47+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
48+
*/
49+
@RunWith(AndroidJUnit4.class)
50+
public class EndpointProfileIntegrationTest extends AWSTestBase {
51+
52+
private static Context appContext;
53+
54+
private PinpointManager pinpointManager;
55+
private PinpointConfiguration pinpointConfiguration;
56+
private CognitoCachingCredentialsProvider credentialsProvider;
57+
private WifiManager wifiManager;
58+
59+
private String appId;
60+
private Regions regions;
61+
62+
private static String TAG = EndpointProfileIntegrationTest.class.getSimpleName();
63+
64+
@Before
65+
public void setUp() throws Exception {
66+
appContext = InstrumentationRegistry.getTargetContext();
67+
appContext.deleteDatabase("awspinpoint.db");
68+
69+
wifiManager = (WifiManager) InstrumentationRegistry
70+
.getContext().getSystemService(Context.WIFI_SERVICE);
71+
assertTrue(wifiManager.setWifiEnabled(true));
72+
73+
appId = getPackageConfigure("pinpoint")
74+
.getString("AppId");
75+
regions = Regions.fromName(getPackageConfigure("pinpoint")
76+
.getString("Region"));
77+
78+
credentialsProvider = new CognitoCachingCredentialsProvider(
79+
appContext,
80+
getPackageConfigure("core")
81+
.getString("identity_pool_id"),
82+
Regions.US_EAST_1);
83+
pinpointConfiguration = new PinpointConfiguration(appContext,
84+
appId,
85+
regions,
86+
credentialsProvider);
87+
pinpointManager = new PinpointManager(pinpointConfiguration);
88+
}
89+
90+
@After
91+
public void tearDown() {
92+
assertTrue(wifiManager.setWifiEnabled(true));
93+
pinpointManager.getAnalyticsClient().closeDB();
94+
appContext.deleteDatabase("awspinpoint.db");
95+
}
96+
97+
@Test
98+
public void testEndpointProfileUpdate() {
99+
TargetingClient targetingClient = pinpointManager.getTargetingClient();
100+
assertNotNull(targetingClient);
101+
102+
targetingClient.updateEndpointProfile();
103+
EndpointProfile endpointProfile = targetingClient.currentEndpoint();
104+
assertNotNull(endpointProfile);
105+
assertNull(endpointProfile.getUser().getUserId());
106+
107+
EndpointProfileUser user = new EndpointProfileUser();
108+
user.setUserId(credentialsProvider.getIdentityId());
109+
endpointProfile.setUser(user);
110+
111+
targetingClient.updateEndpointProfile();
112+
endpointProfile = targetingClient.currentEndpoint();
113+
assertNotNull(endpointProfile);
114+
assertEquals(credentialsProvider.getIdentityId(),
115+
endpointProfile.getUser().getUserId());
116+
117+
endpointProfile.addAttribute("key", Arrays.asList("value"));
118+
targetingClient.updateEndpointProfile();
119+
endpointProfile = targetingClient.currentEndpoint();
120+
assertNotNull(endpointProfile);
121+
assertEquals(credentialsProvider.getIdentityId(),
122+
endpointProfile.getUser().getUserId());
123+
assertEquals("value", endpointProfile.getAllAttributes().get("key").get(0));
124+
}
125+
}

0 commit comments

Comments
 (0)