Hi All,
Code is as below :
public String execute(String url)
{
try{
HttpClient httpClient = new HttpClient();
httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(this.timeOut);
getMethod = new GetMethod(url);
String encoding = Base64.encode(this.name + ":" + this.password);
getMethod.setRequestHeader("Authorization", "Basic " + encoding);
int code = httpClient.executeMethod(getMethod);
....and so on.
}
The control is coming[when run as Junit test] till the line "getMethod.setRequestHeader("Authorization", "Basic " + encoding);" along with the error java.lang.LinkageError: loader constraint violation: loader (instance of org/powermock/core/classloader/MockClassLoader) previously initiated loading for a different type with name "javax/net/SocketFactory" and not going beyond it. Googled out and have been trying multiple options for the past one day, but no luck.
Any thoughts/pointers on how to solve this will be helpful.
Solved! Go to Solution.
Views
Replies
Total Likes
a) PowerMock is evil, try to use Mockito as much as you can.
b) Having Junit test to rely on external(as I presume REST call) makes your unit tests flaky. Junit tests are supposed to work with your class code, not external system calls.
c) Better move it as an external service and inject it's Interface as a mock to test it.
Views
Replies
Total Likes
Hi
Java.lang.LinkageError occurs when there is a problem in ClassLoading. Actually, this happens when same class is loaded by multiple class loader. As you know, in OSGI, Each bundle has their own class loader.
Below post could guide you more on this. Also, check all your POM.xml and make sure, there are no circular dependencies between bundles.
Link:- http://stackoverflow.com/questions/244482/how-to-deal-with-linkageerrors-in-java
Old Forum Post:- http://help-forums.adobe.com/content/adobeforums/en/experience-manager-forum/adobe-experience-manage...
I hope this would help you.
Thanks and Regards
Kautuk Sahni
Views
Replies
Total Likes
a) PowerMock is evil, try to use Mockito as much as you can.
b) Having Junit test to rely on external(as I presume REST call) makes your unit tests flaky. Junit tests are supposed to work with your class code, not external system calls.
c) Better move it as an external service and inject it's Interface as a mock to test it.
Views
Replies
Total Likes
Hi Kautuk/PuzanovsP,
Thank you for your replies.
@PuzanovsP : You have mentioned that using PowerMock is not a recommended approach. I do not have much insight into this. Any thoughts on why it is not recommended would be helpful.
Views
Replies
Total Likes
These two desribe it pretty well [1]. [2],
[1] http://stackoverflow.com/questions/30162200/why-not-powermock
Views
Replies
Total Likes
Hi PuzanovsP,
Thank you for your reply.
Views
Replies
Total Likes