Is there any way to use PowerMock with rest-assured, because when I'm trying to test a RESTful API with rest-assured.
I want to PowerMock a static call.
The code of operation:
@POST
@Produces("application/json")
@Consumes(MediaType.APPLICATION_JSON)
public Response createEntity(@Context HttpHeaders hh, String body) {
. . .
String sec = MDI.check(Some_string, ..., ...);
if (sec == null) throw ...
return Response....
}
And the test:
@RunWith(PowerMockRunner.class)
@PrepareForTest(MDI.class)
public class createSOTest {
@Test
public void testStatic() {
mockStatic(MDI.class);
expect(MDI.check(Some_string, ..., ...).andReturn(Some_String);
replay(MDI.class)
given().
contentType(ContentType.JSON).
header("SomeHeader", "something").
body(root).
when().
post("/").
then().
statusCode(...);
}
}
The problem is that I obtain an exception when the test try to run the rest-assured
code (given()....
):
org.apache.http.conn.ssl.SSLInitializationException: class configured for SSLContext: sun.security.ssl.SSLContextImpl$TLS10Context not a SSLContext
at org.apache.http.conn.ssl.SSLContexts.createDefault(SSLContexts.java:58)
at org.apache.http.conn.ssl.SSLSocketFactory.getSocketFactory(SSLSocketFactory.java:162)
at org.apache.http.impl.conn.SchemeRegistryFactory.createDefault(SchemeRegistryFactory.java:52)
at org.apache.http.impl.client.AbstractHttpClient.createClientConnectionManager(AbstractHttpClient.java:305)
at org.apache.http.impl.client.AbstractHttpClient.getConnectionManager(AbstractHttpClient.java:465)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:324)
at org.codehaus.groovy.runtime.metaclass.MethodMetaProperty$GetBeanMethodMetaProperty.getProperty(MethodMetaProperty.java:73)
at org.codehaus.groovy.runtime.callsite.GetEffectivePojoPropertySite.getProperty(GetEffectivePojoPropertySite.java:61)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:227)
at com.jayway.restassured.internal.RequestSpecificationImpl.applyProxySettings(RequestSpecificationImpl.groovy:1794)
It seems to be a problem with the PowerMockRunner.class
.