Skip to content
This repository has been archived by the owner on Feb 12, 2022. It is now read-only.

Problem running test #28

Closed
ghost opened this issue Feb 19, 2016 · 16 comments
Closed

Problem running test #28

ghost opened this issue Feb 19, 2016 · 16 comments

Comments

@ghost
Copy link

ghost commented Feb 19, 2016

Hi, we are trying to run the example you provided in the README file as follows:

mvn compile exec:java -Dexec.mainClass="com.sforce.cd.apexUnit.ApexUnitRunner" -Dexec.args="-org.login.url ‘https://medctr-ucsf--stage.cs8.my.salesforce.com’ -org.username user@test.com -org.password xXxXxXxX -org.client.id xXxXxXxXxX -org.client.secret xXxXxXxXxXxX -org.wide.code.coverage.threshold 50 -team.code.coverage.threshold 50 -regex.for.selecting.source.classes.for.code.coverage.computation Test1 -regex.for.selecting.test.classes.to.execute Class1"

However, we got the following exception:

.. WARNING: Cookie rejected: "$Version=0; BrowserId=WoAiW7M7Ru2XYetBKiFLEw; $Path=/; $Domain=.salesforce.com". Domain attribute ".salesforce.com" violates RFC 2109: host minus domain may not contain any dots Feb 18, 2016 4:58:11 PM org.apache.commons.httpclient.HttpMethodBase getResponseBody WARNING: Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended. [com.sforce.cd.apexUnit.ApexUnitRunner.main()] ERROR com.sforce.cd.apexUnit.ApexUnitUtils - Unable to get access_token for OAuth authentication and hence unable to establish connection with the web services.Terminating the process.. [com.sforce.cd.apexUnit.ApexUnitRunner.main()] INFO com.sforce.cd.apexUnit.ApexUnitUtils - Shutting down ApexUnit java.lang.Exception: Stack trace ..

I hope you can help us with this issue, probably we are missing something.

Thanks

@tfuda
Copy link
Contributor

tfuda commented Feb 19, 2016

Just a suggestion... no idea if it will work, but try https://cs8.salesforce.com in place of https://your-domain.cs8.my.salesforce.com. And does the cs8 really belong there? In other orgs where I have "my domain" activated, the URLs look like https://my-domain.my.salesforce.com. The pod identifier isn't part of the URL. If my first suggestion doesn't work, try https://your-domain.my.salesforce.com.

@ghost
Copy link
Author

ghost commented Feb 20, 2016

I changed the hostname as you said and now I got the following exception:

[INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building ApexUnit 2.3.1.0 [INFO] ------------------------------------------------------------------------ [WARNING] The artifact org.apache.commons:commons-io:jar:1.3.2 has been relocated to commons-io:commons-io:jar:1.3.2 [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ ApexUnit-core --- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! [INFO] Copying 7 resources [INFO] [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ ApexUnit-core --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] >>> exec-maven-plugin:1.2.1:java (default-cli) > validate @ ApexUnit-core >>> [INFO] [INFO] <<< exec-maven-plugin:1.2.1:java (default-cli) < validate @ ApexUnit-core <<< [INFO] [INFO] --- exec-maven-plugin:1.2.1:java (default-cli) @ ApexUnit-core --- [com.sforce.cd.apexUnit.ApexUnitRunner.main()] INFO com.sforce.cd.apexUnit.ApexUnitRunner - #################################### Processing the Apex test classes specified by the user #################################### [com.sforce.cd.apexUnit.ApexUnitRunner.main()] INFO com.sforce.cd.apexUnit.client.utils.ApexClassFetcherUtils - Using regex(es): CarewebRemotingTest,CareWeb_Custom_Setting_Test to fetch apex classes [com.sforce.cd.apexUnit.ApexUnitRunner.main()] INFO com.sforce.cd.apexUnit.client.utils.ApexClassFetcherUtils - Using regex: "CarewebRemotingTest" to fetch apex classes [com.sforce.cd.apexUnit.ApexUnitRunner.main()] INFO com.sforce.cd.apexUnit.client.utils.ApexClassFetcherUtils - Using regex: "CareWeb_Custom_Setting_Test" to fetch apex classes [com.sforce.cd.apexUnit.ApexUnitRunner.main()] INFO com.sforce.cd.apexUnit.client.connection.ConnectionHandler - Bulk connection established. [com.sforce.cd.apexUnit.ApexUnitRunner.main()] INFO com.sforce.cd.apexUnit.client.testEngine.AsyncBulkApiHandler - Creating batch for the test classes to execute using bulk connection.... [com.sforce.cd.apexUnit.ApexUnitRunner.main()] INFO com.sforce.cd.apexUnit.client.testEngine.AsyncBulkApiHandler - Async test parent job Id : 707L000000bPEy1IAG [com.sforce.cd.apexUnit.ApexUnitRunner.main()] INFO com.sforce.cd.apexUnit.client.testEngine.AsyncBulkApiHandler - ############################# List of Apex test classes successfully submitted to the Force.com test execution engine ############################# [com.sforce.cd.apexUnit.ApexUnitRunner.main()] INFO com.sforce.cd.apexUnit.client.testEngine.TestExecutor - Parent job ID for the submission of the test classes to the Force.com platform is: 707L000000bPEy1IAG [com.sforce.cd.apexUnit.ApexUnitRunner.main()] INFO com.sforce.cd.apexUnit.client.testEngine.TestExecutor - ############################# Now executing - Apex tests.. ############################# [com.sforce.cd.apexUnit.ApexUnitRunner.main()] INFO com.sforce.cd.apexUnit.client.testEngine.TestStatusPollerAndResultHandler - Total test classes to execute: 1 [com.sforce.cd.apexUnit.ApexUnitRunner.main()] INFO com.sforce.cd.apexUnit.client.testEngine.TestStatusPollerAndResultHandler - Now executing the test class: CareWebRemotingTest (https://cs8.salesforce.com/01pF0000002QhAVIA0 ) Status : Queued [com.sforce.cd.apexUnit.ApexUnitRunner.main()] INFO com.sforce.cd.apexUnit.client.testEngine.TestStatusPollerAndResultHandler - Test status for CareWebRemotingTest:(3/3) [com.sforce.cd.apexUnit.ApexUnitRunner.main()] INFO com.sforce.cd.apexUnit.client.testEngine.TestStatusPollerAndResultHandler - Completed executing the test class: CareWebRemotingTest. Time taken by the test: 0 minutes,13 seconds [com.sforce.cd.apexUnit.ApexUnitRunner.main()] INFO com.sforce.cd.apexUnit.client.testEngine.TestStatusPollerAndResultHandler - Total tests executed 1 , Remaining tests 0 [com.sforce.cd.apexUnit.ApexUnitRunner.main()] INFO com.sforce.cd.apexUnit.client.testEngine.TestStatusPollerAndResultHandler - All tests have now completed executing!! [com.sforce.cd.apexUnit.ApexUnitRunner.main()] INFO com.sforce.cd.apexUnit.ApexUnitRunner - #################################### Computing code coverage for the team based on the Apex Class names(source class names) provided #################################### [com.sforce.cd.apexUnit.ApexUnitRunner.main()] INFO com.sforce.cd.apexUnit.client.utils.ApexClassFetcherUtils - Using regex(es): CareWebRemoting,CareWeb_Custom_Settings to fetch apex classes [com.sforce.cd.apexUnit.ApexUnitRunner.main()] INFO com.sforce.cd.apexUnit.client.utils.ApexClassFetcherUtils - Using regex: "CareWebRemoting" to fetch apex classes [com.sforce.cd.apexUnit.ApexUnitRunner.main()] INFO com.sforce.cd.apexUnit.client.utils.ApexClassFetcherUtils - Using regex: "CareWeb_Custom_Settings" to fetch apex classes Feb 19, 2016 1:49:19 PM org.apache.commons.httpclient.HttpMethodBase getResponseBody WARNING: Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended. [com.sforce.cd.apexUnit.ApexUnitRunner.main()] ERROR com.sforce.cd.apexUnit.ApexUnitUtils - Unable to get access_token for OAuth authentication and hence unable to establish connection with the web services.Terminating the process.. [com.sforce.cd.apexUnit.ApexUnitRunner.main()] INFO com.sforce.cd.apexUnit.ApexUnitUtils - Shutting down ApexUnit java.lang.Exception: Stack trace at java.lang.Thread.dumpStack(Thread.java:1329) at com.sforce.cd.apexUnit.ApexUnitUtils.shutDownWithErrMsg(ApexUnitUtils.java:68) at com.sforce.cd.apexUnit.client.codeCoverage.OAuthTokenGenerator.doPostAndGetOrgToken(OAuthTokenGenerator.java:73) at com.sforce.cd.apexUnit.client.codeCoverage.OAuthTokenGenerator.getOrgToken(OAuthTokenGenerator.java:55) at com.sforce.cd.apexUnit.client.codeCoverage.CodeCoverageComputer.calculateAggregatedCodeCoverageUsingToolingAPI(CodeCoverageComputer.java:124) at com.sforce.cd.apexUnit.ApexUnitRunner.main(ApexUnitRunner.java:107) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:297) at java.lang.Thread.run(Thread.java:745)

@adarsh-ramakrishna-sfdc
Copy link
Contributor

@focadizUCSF The error indicates that the OAuth setup is incorrect. Please try out the curl command : curl -v (Salesforce_Org_URL)/services/oauth2/token -d "grant_type=password" -d "client_id=" -d "client_secret= ***_" -d "username=_" -d "password= ***" as mentioned in the README file and check if you are able to get Access token successfully. If you do get issues , please follow the links in the README file : http://salesforce.stackexchange.com/questions/40346/where-do-i-find-the-client-id-and-client-secret-of-an-existing-connected-app
http://stackoverflow.com/questions/18464598/where-to-get-client-id-and-client-secret-of-salesforce-api-for-rails-3-2-11
http://www.calvinfroedge.com/salesforce-how-to-generate-api-credentials/ to setup the connected app. Please pay special attention to the redirect url in the connected app settings. Let me know if you face any issues.

@ghost
Copy link
Author

ghost commented Feb 22, 2016

Hi @adarsh-ramakrishna-sfdc and @tfuda, thanks for your support and help, I truly appreciate it.

After we ran curl we were able to get the access token and after we ran maven we saw the test started running in Salesforce, however, looks like something breaks in the middle because we don't get response back from Salesforce.

In the stacktrace I attached you can see some entries like:

INFO com.sforce.cd.apexUnit.client.testEngine.TestExecutor - ############################# Now executing - Apex tests.. #############################

But after some tests running we got:

INFO com.sforce.cd.apexUnit.client.utils.ApexClassFetcherUtils - Using regex: "CareWeb_Custom_Settings" to fetch apex classes Feb 19, 2016 1:49:19 PM org.apache.commons.httpclient.HttpMethodBase getResponseBody WARNING: Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended. [com.sforce.cd.apexUnit.ApexUnitRunner.main()]
ERROR com.sforce.cd.apexUnit.ApexUnitUtils - Unable to get access_token for OAuth authentication and hence unable to establish connection with the web services.Terminating the process.. [com.sforce.cd.apexUnit.ApexUnitRunner.main()] INFO com.sforce.cd.apexUnit.ApexUnitUtils - Shutting down ApexUnit java.lang.Exception: Stack trace at java.lang.Thread.dumpStack(Thread.java:1329) at com.sforce.cd.apexUnit.ApexUnitUtils.shutDownWithErrMsg(ApexUnitUtils.java:68) at

@adarsh-ramakrishna-sfdc
Copy link
Contributor

@focadizUCSF This is interesting .. Because, this step in the execution should proceed if the curl command is returning access token for you. Can you please confirm if you are using the exact same combination of username, password, client id and client secret while executing the ApexUnit ? Once you confirm, do you mind sharing the command you are using to execute the tool? Of course, please mask the sensitive login credentials before you share it here..
Also, Debug logs might help.. To obtain debug logs, "Find and Replace" all "INFO"s to "DEBUG"s in src->main->resources->logback.xml
Let me know how it goes!

@ghost
Copy link
Author

ghost commented Feb 23, 2016

Hello again,

This is what I got after running curl:

curl -v https://cs8.salesforce.com/services/oauth2/token -d "grant_type=password" -d "client_id=********************umvQreBt69XZTWUKlaWqHsoIeNKJQUYRdIv4Oji..0EPbYqjDe.dJneSfc.UbsSs1" -d "client_secret=**********815327780" -d "username=user@domain" -d "password= Pa55word"
* Trying 96.43.144.48...
* Connected to cs8.salesforce.com (96.43.144.48) port 443 (#0)
* TLS 1.2 connection using TLS_RSA_WITH_AES_256_CBC_SHA256
* Server certificate: *.salesforce.com
* Server certificate: Symantec Class 3 Secure Server CA - G4
* Server certificate: VeriSign Class 3 Public Primary Certification Authority - G5
> POST /services/oauth2/token HTTP/1.1
> Host: cs8.salesforce.com
> User-Agent: curl/7.43.0
> Accept: */*
> Content-Length: 205
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 205 out of 205 bytes
< HTTP/1.1 200 OK
< Date: Mon, 22 Feb 2016 23:53:25 GMT
< Set-Cookie: BrowserId=FGms_D2BRxC6C1iug6Sw3g;Path=/;Domain=.salesforce.com;Expires=Fri, 22-Apr-2016 23:53:25 GMT
< Expires: Thu, 01 Jan 1970 00:00:00 GMT
< Pragma: no-cache
< Cache-Control: no-cache, no-store
< Content-Type: application/json;charset=UTF-8
< Transfer-Encoding: chunked
<
* Connection #0 to host cs8.salesforce.com left intact
{"access_token":"*******************QA3MxOWuwtq99t4ysxeGaV86zK3xukh67TNQWFC5Y28NxPMtPa9qVw1_4_SMBOD.LOEiJvZCXlibjWzxQFAZ4NJBE9P_","instance_url":"https://xXxXxX-xXxX--stage.cs8.my.salesforce.com","id":"https://test.salesforce.com/id/*******************/005F0000001gLY2IAM","token_type":"Bearer","issued_at":"**********5","signature":"********************h2jaY4bHEuMcFJZrxpwhkaBc="}

The only weird thing I can see is that curl returned a different hostname in the instance_url property.

I also changed the log level to DEBUG but still see the same results. I also checked the client_id and client_secret and they are the same. I'm wondering if it's because the Salesforce org has a custom domain that uses a double dash.

Thanks.

@adarsh-ramakrishna-sfdc
Copy link
Contributor

Yes.. That might be the reason; not sure though.. Can you try providing the url that you got from the curl command, for executing the ApexUnit? I assume that you are trying both the operations: executing curl command and executing ApexUnit from the same system and network configuration; just making sure that there is no firewall/reachability issue..
A recap.. You are able to run the tests. But the code coverage logic is failing since ApexUnit is unable to establish OAuth connection which is required for code coverage computation..

@ghost
Copy link
Author

ghost commented Feb 23, 2016

When I run curl and mvn using my custom domain I get the following messages:

WARNING: Cookie rejected: "$Version=0; BrowserId=zJfWcijETsS6_pO-8Y0ZYA; $Path=/; $Domain=.salesforce.com". Domain attribute ".salesforce.com" violates RFC 2109: host minus domain may not contain any dots
Feb 22, 2016 6:28:48 PM org.apache.commons.httpclient.HttpMethodBase getResponseBody
WARNING: Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.
[com.sforce.cd.apexUnit.ApexUnitRunner.main()] ERROR com.sforce.cd.apexUnit.ApexUnitUtils - Unable to get access_token for OAuth authentication and hence unable to establish connection with the web services.Terminating the process..

Actually that error was the reason I opened the ticket and @tfuda recommended to use the other url convention (cs8.calesforce.com).

I'm also wondering if the message: WARNING: Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended. might be related to the root cause.

@ghost
Copy link
Author

ghost commented Feb 23, 2016

Since the command runs using arguments that are denoted by - I think that any dash in the url might be breaking the value in a new argument.

Is that true?

@adarsh-ramakrishna-sfdc
Copy link
Contributor

@focadizUCSF Having - in the command wouldn't cause any problem. Space is used as delimiter . I verified the same by providing a - in command line parameters "-regex.for.selecting.source.classes.for.code.coverage.computation Sample,Mobile,-Wrapper" ; it didnt cause any issues for me

@milters
Copy link

milters commented Feb 24, 2016

Hi Adarsh, thank you for your prompt responses. I'm working with Felipe to roll it out.

We were also wondering if the message: WARNING: Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended. might be related to the root cause.

@adarsh-ramakrishna-sfdc
Copy link
Contributor

Hello @milters
We get that warning message during successful runs too. Here is the console output of my run :
Feb 23, 2016 1:51:20 PM org.apache.commons.httpclient.HttpMethodBase getResponseBody
WARNING: Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.
[com.sforce.cd.apexUnit.ApexUnitRunner.main()] INFO com.sforce.cd.apexUnit.client.codeCoverage.WebServiceInvoker - Status code : 200 Status message from the get request:OK Reason phrase: OK
Feb 23, 2016 1:51:21 PM org.apache.commons.httpclient.HttpMethodBase getResponseBody
WARNING: Going to buffer response body of large or unknown size. Using getResponseBodyAsStream instead is recommended.
[com.sforce.cd.apexUnit.ApexUnitRunner.main()] INFO com.sforce.cd.apexUnit.client.codeCoverage.CodeCoverageComputer - Record number # 1 : coveredLines : 0 : unCoveredLines : 118 : code coverage % : 0.0 : apexClassOrTriggerId : 01pd0000002mb4wAAA : apexClassName : SampleClass2 : apiVersion : 28.0 : lengthWithoutComments : 2356

I don't see 200 OK status message printed in the console output shared by @focadizUCSF . This indicates that the authentication for OAuth is most likely to be the issue. But the fact that curl command returns access token but the same parameters doesn't work for executing the tool is baffling ..
I have helped over 50 teams with ApexUnit adoption. In all those cases, the teams found it easy as soon as they got the curl command working. This needs further analysis.

Also the below warning message in the console output shared by @focadizUCSF caught my attention(I don't get this warning message):
WARNING: Cookie rejected: "$Version=0; BrowserId=zJfWcijETsS6_pO-8Y0ZYA; $Path=/; $Domain=.salesforce.com". Domain attribute ".salesforce.com" violates RFC 2109: host minus domain may not contain any dots
I found couple of links upon googling : https://community.oracle.com/thread/1150555?start=0&tstart=0
https://developer.salesforce.com/forums/?id=906F0000000AcfgIAC

Few of the suggested solutions in these posts :

  1. You MUST remove the dots and domain (DOMAIN=xyz) NOT (DOMAIN=.xyz.com)
  2. The error you get shows that 1) you are declaring a DOMAIN w/out a HOST in it, and 2) the DOMAIN value is NOT correct according to the RFC. The DOMAIN should be either "xyz" or "www.xyz.com"
  3. "I get a similar warning from Java when making use of salesforce's partner API. And salesforce's my domain feature.
    Cookie rejected: "$Version=0; BrowserId=lYtxlM2XS7uKFuJtsC9pyQ; $Path=/; $Domain=.salesforce.com". Domain attribute ".salesforce.com" violates RFC 2109: host minus domain may not contain any dots
    Basically the cookie is saying it comes from .salesforce.com and the host is reporting that it is abc-1-dev-ed.my.salesforce.com.
    According to RFC 2109 when the domain of the cookie is removed from the host the result should contain no dots. And in this case it does, so the cookie is rejected.
    It only appears to be an issue with the BrowserId cookie from salesforce.
    This does not seem to have any adverse affects (except for putting a lot of warnings into my logs.)."

Can you guys try playing around with Domain value?

@adarsh-ramakrishna-sfdc
Copy link
Contributor

@focadizUCSF @milters Any update on this issue? We haven't heard back from you guys since a couple of weeks..

@adarsh-ramakrishna-sfdc
Copy link
Contributor

Hello @focadizUCSF and @milters
We will have to close this issue if we do not hear back from you by 3/14 . Please let us know if you are still facing issues with the setup

@ghost
Copy link
Author

ghost commented Mar 10, 2016

Hi @adarsh-ramakrishna-sfdc, @milters and I ran the tool using a different Salesforce org and it worked perfectly. We could see the report! However, in the sandbox with custom domain we couldn't make it work and tried changing multiple configurations for the user and the Connected App. A Salesforce engineer said that he would need to check the user and Connected app permissions because everything else looked fine.

Seems like you can close the issue. Thanks so much for being supportive with us, your help was very helpful.

@adarsh-ramakrishna-sfdc
Copy link
Contributor

Thanks @focadizUCSF . Glad to be of any help..
You might want to check the entries for redirect URL and connected app permission is definitely a candidate worth looking at.
I will close this issue for now. Please let us know if you face any other issues. Thanks

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

No branches or pull requests

4 participants