Let's say I'm testing an API, but I want to save my port, base URI, default headers and parameters to a RequestSpecification:
RequestSpecification baseCase = given().baseUri( " http://api.twitter.com/1.1" ).port( 8080 ).param( "user_id", "12345" ).header( "Content-Type", "application/vnd+twitter.category+json" );
now I want to build a RequestSpecification built on baseCase. How would I copy baseCase over to another object? I thought I could just do:
RequestSpecification specificCase1 = baseCase.given();
b/c I assumed that .given() just returned a copy of itself, but I guess it returns a reference to itself (which means specificCase1 and baseCase both point to the same object)? This is a problem b/c when I have path parameters for the specificCase:
specificCase1.pathParam("id", "149305" ).when().post( "/statuses/retweet/{id}" );
then baseCase is mutated too. Every case built off of baseCase thereafter throws an "Invalid number of path parameters. Expected 0, was 1. Redundant path parameters" exception.
Any input would be appreciated.
-Jeffrey Ji