@@ -1612,4 +1612,63 @@ public void testMessageBodyFromContextGetsCorrectBodyForKeyTextValue() {
16121612 assertEquals (body , messageBody );
16131613 }
16141614
1615+ @ Test
1616+ public void testVariantsForceContentUpdate () throws Exception {
1617+ final Semaphore semaphore = new Semaphore (1 );
1618+ semaphore .acquire ();
1619+
1620+ // Seed response from the file.
1621+ ResponseHelper .seedResponse ("/responses/simple_start_response.json" );
1622+
1623+ // Expected request params.
1624+ final HashMap <String , Object > expectedRequestParams = CollectionUtil .newHashMap (
1625+ "city" , "(detect)" ,
1626+ "country" , "(detect)" ,
1627+ "location" , "(detect)" ,
1628+ "region" , "(detect)" ,
1629+ "locale" , "en_US"
1630+ );
1631+
1632+ // Validate request.
1633+ RequestHelper .addRequestHandler (new RequestHelper .RequestHandler () {
1634+ @ Override
1635+ public void onRequest (String httpMethod , String apiMethod , Map <String , Object > params ) {
1636+ assertEquals (Constants .Methods .START , apiMethod );
1637+ assertTrue (params .keySet ().containsAll (expectedRequestParams .keySet ()));
1638+ assertTrue (params .values ().containsAll (expectedRequestParams .values ()));
1639+ }
1640+ });
1641+
1642+ Leanplum .start (mContext , new StartCallback () {
1643+ @ Override
1644+ public void onResponse (boolean success ) {
1645+ assertTrue (success );
1646+ semaphore .release ();
1647+ }
1648+ });
1649+ assertTrue (Leanplum .hasStarted ());
1650+
1651+ assertEquals (0 , VarCache .variants ().size ());
1652+
1653+ semaphore .acquire ();
1654+
1655+ // Seed getVars response.
1656+ ResponseHelper .seedResponse ("/responses/variants_response.json" );
1657+
1658+ RequestHelper .addRequestHandler (new RequestHelper .RequestHandler () {
1659+ @ Override
1660+ public void onRequest (String httpMethod , String apiMethod , Map <String , Object > params ) {
1661+ assertEquals (Constants .Methods .GET_VARS , apiMethod );
1662+ }
1663+ });
1664+
1665+ Leanplum .forceContentUpdate (new VariablesChangedCallback () {
1666+ @ Override
1667+ public void variablesChanged () {
1668+ semaphore .release ();
1669+ }
1670+ });
1671+
1672+ assertEquals (4 , VarCache .variants ().size ());
1673+ }
16151674}
0 commit comments