Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

addRequestSpecification thows error if baseUri is not set #1011

Open
detvetdu opened this issue May 9, 2018 · 3 comments
Open

addRequestSpecification thows error if baseUri is not set #1011

detvetdu opened this issue May 9, 2018 · 3 comments

Comments

@detvetdu
Copy link

detvetdu commented May 9, 2018

If i want to merge a RequestSpecification to a RequestSpecBuilder it will throw an exeption java.net.MalformedURLException: no protocol: if the requestSpecification has no baseUri set.

Example:

        RequestSpecBuilder addBuilder = new RequestSpecBuilder();
        addBuilder.addHeader("test","test");
        RequestSpecification addSpec = addBuilder.build();

        RequestSpecBuilder builder = new RequestSpecBuilder();
        builder.addHeaders(headers);
        builder.addRequestSpecification(addSpec);
        builder.setBaseUri(uri); 

If i set a baseUri to addBuilder

addBuilder.setBaseUri("https://localhost");

the addRequestSpecification(addSpec); works fine.

@Bisk1
Copy link
Contributor

Bisk1 commented May 20, 2018

@detvetdu
Your example is incomplete and if I try to fix it, it works without exception:

RequestSpecBuilder addBuilder = new RequestSpecBuilder();
addBuilder.addHeader("test","test");
RequestSpecification addSpec = addBuilder.build();

RequestSpecBuilder builder = new RequestSpecBuilder();
builder.addHeaders(new HashMap<String, String>() {{ put("header", "headerValue"); }});
builder.addRequestSpecification(addSpec);
builder.setBaseUri("https://www.google.com");

given(builder.build()).get("/");

Maybe your URI is really malformed? What is the value of uri variable?

@detvetdu
Copy link
Author

The uri is not set in addBuilder, i suppose it is null then.
In the RequestSpecBuilder builder it is not set before i call for addRequestSpecification.

@egovedarov
Copy link

Hello @Bisk1 and @detvetdu,
I have tried reproducing the problem with rest-assured version 3.3.0. Here's what I found:

1st scenario:
"I have not set the baseUri at all and I try to add the RequestSpecification to the other RequestSpecification."

            String emptyString="";
	String nullString=null;
	
	RequestSpecBuilder addBuilder = new RequestSpecBuilder();
    addBuilder.addHeader("test","test");
    //addBuilder.setBaseUri(emptyString);
    RequestSpecification addSpec = addBuilder.build();

    RequestSpecBuilder builder = new RequestSpecBuilder();
    builder.addHeaders(new HashMap<String, String>() {{ put("header", "headerValue"); }});
    builder.addRequestSpecification(addSpec);`

There is no error what so ever. The code is executed and the first RequestSpecification is added to the second one.

2nd scenario:
"I have tried to set an empty string as baseUri and I get java.net.MalformedURLException: no protocol: exception, when I try to set the baseUri. Not when I try to add the first RequestSpecification to the second one"

            String empty="";
	String nullString=null;
	
	RequestSpecBuilder addBuilder = new RequestSpecBuilder();
    addBuilder.addHeader("test","test");
    addBuilder.setBaseUri(empty);
    RequestSpecification addSpec = addBuilder.build();

    RequestSpecBuilder builder = new RequestSpecBuilder();
    builder.addHeaders(new HashMap<String, String>() {{ put("header", "headerValue"); }});
    builder.addRequestSpecification(addSpec);`

3rd scenario:
"I have tried to set a null string as baseUri and I get a java.lang.IllegalArgumentException: Base URI cannot be null exception, when I try to set the baseUri. Not when I try to add the first RequestSpecification to the second one"

            String empty="";
	String nullString=null;
	
	RequestSpecBuilder addBuilder = new RequestSpecBuilder();
    addBuilder.addHeader("test","test");
    addBuilder.setBaseUri(nullString);
    RequestSpecification addSpec = addBuilder.build();

    RequestSpecBuilder builder = new RequestSpecBuilder();
    builder.addHeaders(new HashMap<String, String>() {{ put("header", "headerValue"); }});
    builder.addRequestSpecification(addSpec);` 

I cannot reproduce the problem that was described. Again I am using version 3.3.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants