REST Assured Assertion code 415

1,193 views
Skip to first unread message

manranp....@gmail.com

unread,
Oct 24, 2017, 10:50:20 AM10/24/17
to REST assured
Hi,

I am new to RESTAssured trying to build automation framework using TestNG+RESTAssured.

I have below mentioned code:

package RESTPOCPackage;
import org.testng.annotations.*;
import io.restassured.http.ContentType;
import static io.restassured.RestAssured.*;
import java.io.IOException;


public class RegisterAStore {
  @Test
  public void firstPostTest() throws IOException {
  String myXML = "/store/store.xml";
  given().
    header("Accept","application/xml").
  contentType("/store/store.xml").
  when().log().ifValidationFails().
  post(myAppURI).
  then().
  statusCode(200)   ;  
  }
  
}

Post running above test I get assertion code as 415:
[RemoteTestNG] detected TestNG version 6.12.0
Request method: POST
Proxy: <none>
Request params: <none>
Query params: <none>
Form params: <none>
Path params: <none>
Headers: Accept=application/xml
Content-Type=/store/store.xml; charset=ISO-8859-1
Cookies: <none>
Multiparts: <none>
Body: <none>
FAILED: firstPostTest
java.lang.AssertionError: 1 expectation failed.
Expected status code <200> but was <415>.

at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:83)
at org.codehaus.groovy.reflection.CachedConstructor.doConstructorInvoke(CachedConstructor.java:77)
at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrap.callConstructor(ConstructorSite.java:84)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallConstructor(CallSiteArray.java:60)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:235)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:247)
at io.restassured.internal.ResponseSpecificationImpl$HamcrestAssertionClosure.validate(ResponseSpecificationImpl.groovy:471)
at io.restassured.internal.ResponseSpecificationImpl$HamcrestAssertionClosure$validate$1.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
at io.restassured.internal.ResponseSpecificationImpl.validateResponseIfRequired(ResponseSpecificationImpl.groovy:643)
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:498)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:210)
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:59)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:166)
at io.restassured.internal.ResponseSpecificationImpl.statusCode(ResponseSpecificationImpl.groovy:122)
at io.restassured.specification.ResponseSpecification$statusCode$0.callCurrent(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:52)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:154)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:166)
at io.restassured.internal.ResponseSpecificationImpl.statusCode(ResponseSpecificationImpl.groovy:130)
at io.restassured.internal.ValidatableResponseOptionsImpl.statusCode(ValidatableResponseOptionsImpl.java:117)
at RESTPOCPackage.RegisterAStore.firstPostTest(RegisterAStore.java:21)
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:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:669)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:877)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1201)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:776)
at org.testng.TestRunner.run(TestRunner.java:634)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:425)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:420)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:385)
at org.testng.SuiteRunner.run(SuiteRunner.java:334)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1318)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1243)
at org.testng.TestNG.runSuites(TestNG.java:1161)
at org.testng.TestNG.run(TestNG.java:1129)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:114)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)


===============================================
    Default test
    Tests run: 1, Failures: 1, Skips: 0
===============================================


===============================================
Default suite
Total tests run: 1, Failures: 1, Skips: 0
===============================================


Kindly suggest where am I going wrong.

satapathy....@gmail.com

unread,
Oct 24, 2017, 1:48:24 PM10/24/17
to REST assured
Is the contentType correct?

Johan Haleby

unread,
Oct 25, 2017, 5:30:04 AM10/25/17
to rest-a...@googlegroups.com
Depends on what the server is expecting, you could try to disable the automatic adding of charset. See docs here.

--
You received this message because you are subscribed to the Google Groups "REST assured" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

pratheep kumar

unread,
Dec 27, 2018, 8:51:50 AM12/27/18
to REST assured


Hi i am also facing the same issue how to solve it.

Content-Type : application/json




package tgapi;

import static io.restassured.RestAssured.given;

import org.testng.annotations.Test;
import io.restassured.http.ContentType;
import  static org.hamcrest.Matchers.*;

public class Pmethod  extends BaseClass{
@Test
public void pMethod() {
given().auth().preemptive().basic("user", "password").contentType(ContentType.JSON).
body("{ "+
  " \"company\": {"+ 
"\"address\": { "+
 
  " \"addressLine1\": \"23 C, Sankari Main Road\", "+ 
" \"addressLine2\": \"Pallipalayam\"," + 
 
"   \"city\": \"Erode\"," + 
"   \"country\": \"India\"," + 
"   \"state\": \"Tamil Nadu\"," + 
 
"   \"zipCode\": \"638006\" " + 
" }," + 
 
" \"adminEmail\": \"ad...@FP3.com\"," + 
 
" \"companyId\": \"FP3\"," + 
 
" \"companyIdType\": \"Company Reg No\"," + 
" \"companyName\": \"FP3\"," + 
" \"email\": \"in...@FP3.com\"," + 

" \"roleList\": [\"FIBER_PRODUCER\"]," + 
" \"status\": \"PENDING\"," + 
" \"telephoneNumber\": \"+914288245525\"," + 
 
" \"website\": \"http://www.karunanroup.com/\"" + 
"   }," + 
"   \"user\": {" + 
" \"address\": {" + 
"   \"addressLine1\": \"Neotown\"," + 
 
"   \"addressLine2\": \"E-City\"," + 
"   \"city\": \"Bangalore\"," + 
"   \"country\": \"India\"," + 
"   \"state\": \"Karnataka\", " + 
"   \"zipCode\": \"560100\" " + 
" }," + 
" \"email\": \"F...@textile.com\"," + 
" \"firstName\": \"FP3\"," + 
" \"lastName\": \"karan\"," + 
" \"role\": \"COMPANY_ADMIN\"," + 
" \"status\": \"INACTIVE\"," + 
" \"telephoneNumber\": \"000001\" " + 
"   }," + 
"   \"userCredentials\": {" + 
" \"password\": \"12345\"," + 
" \"userId\": \"F...@textile.com\" "+ 
"   } " + 
" }+"  ).
when().
post("/company/onboard").
then().assertThat().statusCode(201);

}

}



Kindly let me know whats the cause, 
Thanks in Advance.
Reply all
Reply to author
Forward
0 new messages