Search in sources :

Example 16 with AuthorizationValue

use of io.swagger.models.auth.AuthorizationValue in project swagger-parser by swagger-api.

the class RemoteUrlTest method testHostHeader.

@Test
public void testHostHeader() throws Exception {
    final String expectedBody = setupStub();
    final String headerName = "Authorization";
    final String headerValue = "foobar";
    final AuthorizationValue authorizationValue = new HostAuthorizationValue(LOCALHOST, headerName, headerValue, "header");
    final String actualBody = RemoteUrl.urlToString(getUrl(), Arrays.asList(authorizationValue));
    assertEquals(actualBody, expectedBody);
    verify(getRequestedFor(urlEqualTo("/v2/pet/1")).withHeader("Accept", equalTo(EXPECTED_ACCEPTS_HEADER)).withHeader(headerName, equalTo(headerValue)));
}
Also used : AuthorizationValue(io.swagger.models.auth.AuthorizationValue) Test(org.testng.annotations.Test)

Example 17 with AuthorizationValue

use of io.swagger.models.auth.AuthorizationValue in project swagger-parser by swagger-api.

the class RemoteUrlTest method testAppendQueryParam.

@Test
public void testAppendQueryParam() throws Exception {
    final String firstParamName = "first";
    final String firstParamValue = "first-value";
    final String queryParamName = "Authorization";
    final String queryParamValue = "foobar";
    final String expectedBody = "a really good body";
    stubFor(get(urlPathEqualTo("/v2/pet/1")).withQueryParam(firstParamName, equalTo(firstParamValue)).withQueryParam(queryParamName, equalTo(queryParamValue)).willReturn(aResponse().withBody(expectedBody).withHeader("Content-Type", "application/json")));
    final AuthorizationValue authorizationValue = new HostAuthorizationValue(LOCALHOST, queryParamName, queryParamValue, "query");
    final String actualBody = RemoteUrl.urlToString(String.format("%s?%s=%s", getUrl(), firstParamName, firstParamValue), Arrays.asList(authorizationValue));
    assertEquals(actualBody, expectedBody);
    verify(getRequestedFor(urlPathEqualTo("/v2/pet/1")).withHeader("Accept", equalTo(EXPECTED_ACCEPTS_HEADER)).withQueryParam(firstParamName, equalTo(firstParamValue)).withQueryParam(queryParamName, equalTo(queryParamValue)));
}
Also used : AuthorizationValue(io.swagger.models.auth.AuthorizationValue) Test(org.testng.annotations.Test)

Example 18 with AuthorizationValue

use of io.swagger.models.auth.AuthorizationValue in project swagger-parser by swagger-api.

the class RemoteUrlTest method testSkippedQueryParam.

@Test
public void testSkippedQueryParam() throws Exception {
    final String queryParamName = "Authorization";
    final String queryParamValue = "foobar";
    final String expectedBody = "a really good body";
    stubFor(get(urlPathEqualTo("/v2/pet/1")).willReturn(aResponse().withBody(expectedBody).withHeader("Content-Type", "application/json")));
    final AuthorizationValue authorizationValue = new HostAuthorizationValue(SOME_HOST, queryParamName, queryParamValue, "query");
    final String actualBody = RemoteUrl.urlToString(getUrl(), Arrays.asList(authorizationValue));
    assertEquals(actualBody, expectedBody);
    verify(getRequestedFor(urlPathEqualTo("/v2/pet/1")).withHeader("Accept", equalTo(EXPECTED_ACCEPTS_HEADER)).withoutHeader(queryParamName));
}
Also used : AuthorizationValue(io.swagger.models.auth.AuthorizationValue) Test(org.testng.annotations.Test)

Aggregations

AuthorizationValue (io.swagger.models.auth.AuthorizationValue)18 Test (org.testng.annotations.Test)15 SwaggerDeserializationResult (io.swagger.parser.util.SwaggerDeserializationResult)10 Expectations (mockit.Expectations)8 Swagger (io.swagger.models.Swagger)6 SwaggerParser (io.swagger.parser.SwaggerParser)2 ArrayList (java.util.ArrayList)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ModelImpl (io.swagger.models.ModelImpl)1 Path (io.swagger.models.Path)1 Response (io.swagger.models.Response)1 Parameter (io.swagger.models.parameters.Parameter)1 Property (io.swagger.models.properties.Property)1 RefProperty (io.swagger.models.properties.RefProperty)1 StringProperty (io.swagger.models.properties.StringProperty)1 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1