Skip to content
This repository has been archived by the owner on Nov 19, 2019. It is now read-only.

ant deployment failure #48

Open
EmilioGalicia opened this issue Apr 15, 2015 · 19 comments
Open

ant deployment failure #48

EmilioGalicia opened this issue Apr 15, 2015 · 19 comments

Comments

@EmilioGalicia
Copy link

Hi, I'm getting the following errors when I try to deploy to a dev org using ANT:

All Test Failures:

  1. Twilio_TestApplication.testTwilioAplications_filter -- TwilioRestException:
    Script-thrown exception
    Stack trace: Class.TwilioRestClient: line 591, column 1
    Class.TwilioResource: line 82, column 1
    Class.TwilioResource.ListResource: line 463, column 1
    Class.TwilioApplicationList: line 80, column 1
    Class.Twilio_TestApplication.testTwilioAplications_filter: line 139, column
    1
  2. Twilio_TestPhoneNumbers.testTwilioAvailablePhoneNumbers_AreaCodeFilter -- Tw
    ilioRestException: Script-thrown exception
    Stack trace: Class.TwilioRestClient: line 591, column 1
    Class.TwilioResource: line 82, column 1
    Class.TwilioResource.ListResource: line 463, column 1
    Class.TwilioAvailablePhoneNumberList: line 106, column 1
    Class.Twilio_TestPhoneNumbers.testTwilioAvailablePhoneNumbers_AreaCodeFilter
    : line 274, column 1
  3. TwilioCapability.testGenerateParamString -- System.AssertException: Assertio
    n Failed: Expected: cat=dog&foo=bar, Actual: foo=bar&cat=dog
    Stack trace: Class.TwilioCapability.testGenerateParamString: line 273, colum
    n 1

I have traced the error by running just the Twilio_TestPhoneNumbers.testTwilioAvailablePhoneNumbers_AreaCodeFilter method. What I found is the following message:

"Did not find Resource for GET https://api.twilio.com/2010-04-01/Accounts/ACba8bc05eacf94afdae398e642c9cc32d/AvailablePhoneNumbers/US/Local.json"

And that's because the uri passed to the Twilio_TestHTTPMock Reponse is not contained in the resourceMap.keySet();

Params:
(uri:)HTTPS://API.TWILIO.COM/2010-04-01/ACCOUNTS/ACBA8BC05EACF94AFDAE398E642C9CC32D/AVAILABLEPHONENUMBERS/US/LOCAL.JSON

(resourceMap().keySet()) Keys :{HTTPS://API.TWILIO.COM/2010-04-01/ACCOUNTS/ACBA8BC05EACF94AFDAE398E642C9CC32D/AVAILABLEPHONENUMBERS/US/LOCAL.JSON?AREACODE=510&CONTAINS=51034*****

Need help!

@EmilioGalicia
Copy link
Author

I forgot to say, I have this code working in other dev orgs and tests run fine, this is when I try to deploy to a new dev org, is there something I need to update/change with new Salesforce releases?

@hhai
Copy link
Contributor

hhai commented Apr 16, 2015

https://help.salesforce.com/apex/HTViewSolution?id=000213516&language=en_US

If you have accepted the critical update on those orgs for "Predictable Iteration Order for Apex Unordered Collections", then the test classes will fail because the order no longer matches what is returned. In these cases I would re-order the parameters in the MAP in most of the cases, until we can patch the code.

This is re-ordered to match the URL.

        map<string,string> params=new map<string,string>();
        params.put('AreaCode','510');
        params.put('Contains','51034*****');

@EmilioGalicia
Copy link
Author

Thanks for your response it helped us alot, we followed your steps and the errors are gone

@EmilioGalicia
Copy link
Author

I need to add that we had to add a validation for the orgs that hasn't accepted the update yet in order to work in both scenarios.

static testMethod void testGenerateParamString() {
    Boolean firstKey = true;
    Boolean isOrdered = false;
    Map<String, String> ordMap = new Map<String, String>{'a' => 'b', 'c' => 'd'};
    for(String key: ordMap.keySet()){
        if(ordMap.get(key) == 'b' && firstKey){ isOrdered = true; }
        firstKey = false;
    }

    if(isOrdered){
                    //Update accepted
        System.assertEquals('', generateParamString(new Map<String,String>()));
        System.assertEquals('a=b', generateParamString(new Map<String,String> {'a'=>'b'} ));
        System.assertEquals('foo=bar&cat=dog', generateParamString(new Map<String,String> {'foo'=>'bar', 'cat' => 'dog'} ));
        System.assertEquals('a=b&c=d&e=f', generateParamString(new Map<String,String> {'a'=>'b', 'c'=>'d', 'e'=>'f' } ));
        System.assertEquals('split+key1=split+val1&split+key2=split+val2', generateParamString(new Map<String,String> {'split key1'=>'split val1', 'split key2'=>'split val2'} ));
    }else{
                    //Update not accepted
        System.assertEquals('', generateParamString(new Map<String,String>()));
        System.assertEquals('a=b', generateParamString(new Map<String,String> {'a'=>'b'} ));
        System.assertEquals('cat=dog&foo=bar', generateParamString(new Map<String,String> {'foo'=>'bar', 'cat' => 'dog'} ));
        System.assertEquals('e=f&c=d&a=b', generateParamString(new Map<String,String> {'a'=>'b', 'c'=>'d', 'e'=>'f' } ));
        System.assertEquals('split+key2=split+val2&split+key1=split+val1', generateParamString(new Map<String,String> {'split key1'=>'split val1', 'split key2'=>'split val2'} ));
    }
}

@dschach
Copy link
Contributor

dschach commented May 7, 2015

Please reopen this and change

if(ordMap.get(key) == 'b' && firstKey)isOrdered = true;

to

if(ordMap.get(key) == 'b' && firstKey){ isOrdered = true; }

This is the error that created a major security hole in OSX, and best-practice is to use curly brackets for every if statement, even on one line.

@skimbrel
Copy link
Contributor

skimbrel commented May 7, 2015

I'd be happy to review a pull request for that :)

@EmilioGalicia EmilioGalicia reopened this May 7, 2015
@EmilioGalicia
Copy link
Author

re-opened issue and updated the comment and our code, thanks for the heads up

@EmilioGalicia
Copy link
Author

I have sent the request

@dschach
Copy link
Contributor

dschach commented May 11, 2015

Thank you. Apologies for asking someone else to make the change (faux pas, I know) but I wasn't at a machine that would let me do it myself. Go team!

@EmilioGalicia
Copy link
Author

no prob, I just haven't had enough time to figure out how to remove whitespacing and indentation :P

@Harishgudipudi
Copy link

Hi,

I'm new to this twilio stuff but when I'm trying to deploy I'm getting the same errors in the salesforce production and also we have the update our org with critical updates.

Can you pls let me know on which class I have to update these Lines:

map<string,string> params=new map<string,string>();
params.put('AreaCode','510');
params.put('Contains','51034*****');

@Harishgudipudi
Copy link

Here is the test class failures:
twilio errors

@EmilioGalicia
Copy link
Author

Hi,

You need to modify both files: Twilio_TestApplication and Twilio_TestPhoneNumbers

@kushkella
Copy link

Is it possible if we can get an updated managed package with this bug fix?

@hhai
Copy link
Contributor

hhai commented Jun 10, 2015

We currently aren't releasing managed packages for salesforce.

@kushkella
Copy link

Sorry, I meant unmanaged package. Is v4.0.0 with this bug fix?

@hhai
Copy link
Contributor

hhai commented Jun 10, 2015

The latest version has many updates in it, including support for some of our new APIs, and re-ordering the test data expected to the Salesforce Unordered Lists patch which is auto activated on 6/5 by salesforce. However, it also has some restructuring of classes so if you have already installed and are leveraging an older version I would advise you to update the test class yourself versus using v4.0.

@saamabbas
Copy link

To Fix the issue quickly:

  1. Re - Order Map values in Twilio_TestApplication class near line no. 130 and 219 as given below:
    params.put('VoiceMethod','POST');
    params.put('FriendlyName','Testapp1');

  2. Re - Order Map values in Twilio_TestPhoneNumbers class near line no. 264 as given below:
    params.put('AreaCode','510');
    params.put('Contains','51034*****');

  3. Comment the 5 line code from line no. 271 to 275 in TwilioCapability class and all the error will be gone.

@crashdebit
Copy link

@saamabbas very clear on the directions listed above, wanted to comment that this fix worked perfectly.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants