getting red underlined error for pathParam() method in RestAssured get request & how to solve this - rest-assured

need help for the below issue in RestAssured.
Why am I getting error underlined in red for pathParam() method & how to solve this
import static io.restassured.RestAssured.given;
import static io.restassured.RestAssured.*;
public class TC005_GetRequest {
#Test
public void getReaponse() {
Response response = given()
.pathParam("R1", "albums")
.when()
.get("https://jsonplaceholder.typicode.com/{R1}")
.then()
.log().all();
}
}

Because there is a mismatch type.
.then().log().all() --> return instance of ValidatableResponse
What you want is Response response
To fix that:
.then().log().all(); -> .then().log().all().extract().response();

Related

RestAssured LogConfig.blacklistedHeaders error

I am getting below error when run serenity-cucumber6 test with rest-assured.
Step failed
java.lang.NoSuchMethodError: io.restassured.config.LogConfig.blacklistedHeaders()Ljava/util/Set;
at net.serenitybdd.rest.utils.RestReportingHelper.registerCall(RestReportingHelper.java:69)
at net.serenitybdd.rest.decorators.request.RequestSpecificationDecorated.reportQuery(RequestSpecificationDecorated.java:292)
at net.serenitybdd.rest.decorators.request.RequestSpecificationDecorated.execute(RequestSpecificationDecorated.java:284)
at net.serenitybdd.rest.decorators.request.RequestSpecificationDecorated.get(RequestSpecificationDecorated.java:67)
at net.serenitybdd.rest.decorators.request.RequestSpecificationDecorated.get(RequestSpecificationDecorated.java:38)
The versions I am using are:
<spring-boot.version>2.4.5</spring-boot.version>
<serenity.plugin.version>2.4.34</serenity.plugin.version>
<serenity.version>2.4.34</serenity.version>
<serenity.cucumber.version>2.4.34</serenity.cucumber.version>
<cucumber.version>6.10.4</cucumber.version>
<java.version>11</java.version>
The test main class
import org.junit.runner.RunWith;
import io.cucumber.junit.CucumberOptions;
import net.serenitybdd.cucumber.CucumberWithSerenity;
#RunWith(CucumberWithSerenity.class)
#CucumberOptions(
plugin = {"pretty", "html:target/reports/cucumber-html-report",
"html:target/cucumber-reports/cucumber-pretty",
"json:target/cucumber.json"},
tags = "not #skip",
glue = {"my.stepdefinitions"},
features = "src/it/resources/features/")
public class MyServiceCucumberTests {
}
Request call method
public static Response request(Function<RequestSpecification, Response> method, RequestSpecification spec) {
RequestSpecification call = rest()
.spec(spec)
.when();
return method.apply(call)
.then()
.extract().response();
}

Dart: Using Interface gives the error: "isn't a valid override of"

I've created a small interface:
import ...
abstract class IController {
void navigateTo(BuildContext context, String routeName);
Future<LocationData> get location;
// registration process
void registerGender(Gender gender);
void registerBirthday(DateTime birthday);
Future<bool> register(String email, String password);
}
And then I tried to implement this:
import ...
class Controller implements IController {
static final Controller _instance = Controller._internal();
final ServiceAuthenticate _serviceAuth = ServiceAuthenticate();
final ServiceDatabase _serviceDb = ServiceDatabase();
final ServiceGPS _serviceGPS = ServiceGPS();
User _user;
String _routeName;
UserData _userData;
Controller._internal() {
this._routeName = ROUTE_WELCOME;
}
factory Controller() => _instance;
void navigateTo(BuildContext context, String routeName) {
this._routeName = routeName;
Navigator.pushReplacementNamed(context, routeName);
}
Future<LocationData> get location async{
this._userData.location = await this._serviceGPS.location;
print(this._userData.location);
return this._userData.location;
}
void registerGender(Gender gender){
this._userData = UserData();
this._userData.gender = gender;
}
void registerBirthday(DateTime birthday) {
this._userData.birthday = birthday;
}
Future<bool> register(String email, String password) async {
User user = await this._serviceAuth.registerWithEmailAndPassword(email, password);
if(user == null){
return false;
}
this._user = user;
return true;
}
}
But that code produces the following error:
error: 'Controller.navigateTo' ('void Function(BuildContext, String)') isn't a valid override of 'IController.navigateTo' ('void Function(dynamic, String)'). (invalid_override at [prototype] lib\controller\controller.dart:30)
It looks like Dart thinks, that the BuildContext in the IController is dynamic, but this is obviously not the case.
How can I fix this? I'm new to Dart and don't know what to do.
Thanks for help :)
I'm stupid.
My import statement was wrong.
The line
import 'package:prototype/Controller/IController.dart';
produced this error, because the folder controller starts with a lowercase Letter.
The correct import statement is
import 'package:prototype/controller/IController.dart';
But regardless of my stupid mistake is the error message quite interesting.
A had a similar error and in my case the problem was that the return type of the buggy function was such that there were two different classes in the codebase with the same name. And the interface was using one and the implementation the other.
The one line answer is :
Your import statement is wrong.
But now , you need to take care in which file the import statement is going wrong.
There can be many scenarios, but I would like to give an example where I was stuck.
I had two different files in different package, but both files were importing some method where the method names were same.
So while importing the file which contain this method, I had imported the same name method from one file, and at other place, the same name method from second file.
So that's where everything went wrong!
So if import file is correct in the file which is giving some error, check the other dependent file, where same method import statement is written, that may be wrong.

Get method does not return any response in RestAssured Java in eclipse

Can someone please help me here, below is the code:
package student.profile.picture;
import io.restassured.RestAssured;
import io.restassured.response.Response;
import static io.restassured.RestAssured.given;
import org.testng.annotations.Test;
public class GetProfilePicture {
#Test
void Fetch()
{
RestAssured.baseURI="http://localhost:5100"; // giving base URI
Response res=given().
header("tenantId","Augusta-PT").
when().
get("/ProfilePicture").
then().assertThat().statusCode(200).extract().response();
String responsestring=res.asString();
System.out.println(responsestring);
/*JsonPath js = new JsonPath(responsestring);
String FileContentType = js.get("fileContentType");
String ExpectedFilecontenttype = "image/png";
System.out.println(FileContentType);
Assert.assertEquals(FileContentType, ExpectedFilecontenttype); */
}
}
It does not show any error, it is a simple get method to show response, nothing shows up in console.
Any help please?
It is recommended to break up your statement in two parts,
First, get the response,
RestAssured.baseURI = "http://localhost:5100";
Response res = given()
.header("tenantId","Augusta-PT")
.when()
.get("/ProfilePicture");
And second part to assert,
res.then()
.assertThat()
.statusCode(200);
System.out.println(res.asString());
This will solve your issue and you should be able to get the response in console.

How to use get keyword as a class instance method name?

I know that get is one of the keywords in Dart, but I wanna wrap an HTTP client class with an instance method named get in my flutter app, it's semantic。 How can I do this?
Works for me:
void main() {
Http().get('');
}
class Http {
String get(String list) {
print('get called');
}
}
Maybe this will help
class HttpClient {
HttpClient.get() {
...
}
}

Swagger with Dropwizard APIs that use Generic types

I have a generic response object in my Dropwizard API with Response which is a wrapper containing a status enum and a value. The API operations have a reponse like Response or Response>.
I have been trying to find a way to handle this and saw some mentions that this is handled for Spring Rest / Swagger?
I am using:
com.wordnik
swagger-jaxrs_2.10
1.3.5
Has anyone resolved this in a nice generic way?
I think you might be looking for something like this:
#GET
#Path("/pets")
#ApiOperation(value = "Get all pets.", response = Pet.class)
public Response<List<Pet>> getPets() {
...
}
Came around this old question as I was looking for a solution for the same issue.
Here is my workaround :
Create a wrapper class :
#ApiModel
public class PetListResponse extends Response<List<Pet>> {
#Override
#ApiModelProperty
public List<Pet> getValue() {
return super.getValue()
}
}
Override the response in the API :
#GET
#Path("/pets")
#ApiOperation(value = "Get all pets.", response = PetListResponse.class)
public Response<List<Pet>> getPets() {
...
}
Success :)

Resources