Search in sources :

Example 1 with Pet

use of com.baeldung.petstore.client.model.Pet in project tutorials by eugenp.

the class PetApi method findPetsByStatus.

/**
 * Finds Pets by status
 * Multiple status values can be provided with comma separated strings
 * <p><b>200</b> - successful operation
 * <p><b>400</b> - Invalid status value
 * @param status Status values that need to be considered for filter
 * @return List&lt;Pet&gt;
 * @throws RestClientException if an error occurs while attempting to invoke the API
 */
public List<Pet> findPetsByStatus(List<String> status) throws RestClientException {
    Object postBody = null;
    // verify the required parameter 'status' is set
    if (status == null) {
        throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'status' when calling findPetsByStatus");
    }
    String path = UriComponentsBuilder.fromPath("/pet/findByStatus").build().toUriString();
    final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
    final HttpHeaders headerParams = new HttpHeaders();
    final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();
    queryParams.putAll(apiClient.parameterToMultiValueMap(ApiClient.CollectionFormat.valueOf("multi".toUpperCase()), "status", status));
    final String[] accepts = { "application/xml", "application/json" };
    final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
    final String[] contentTypes = {};
    final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);
    String[] authNames = new String[] { "petstore_auth" };
    ParameterizedTypeReference<List<Pet>> returnType = new ParameterizedTypeReference<List<Pet>>() {
    };
    return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) ParameterizedTypeReference(org.springframework.core.ParameterizedTypeReference) MediaType(org.springframework.http.MediaType) ArrayList(java.util.ArrayList) List(java.util.List) Pet(com.baeldung.petstore.client.model.Pet)

Example 2 with Pet

use of com.baeldung.petstore.client.model.Pet in project tutorials by eugenp.

the class PetApi method findPetsByTags.

/**
 * Finds Pets by tags
 * Muliple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
 * <p><b>200</b> - successful operation
 * <p><b>400</b> - Invalid tag value
 * @param tags Tags to filter by
 * @return List&lt;Pet&gt;
 * @throws RestClientException if an error occurs while attempting to invoke the API
 */
public List<Pet> findPetsByTags(List<String> tags) throws RestClientException {
    Object postBody = null;
    // verify the required parameter 'tags' is set
    if (tags == null) {
        throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'tags' when calling findPetsByTags");
    }
    String path = UriComponentsBuilder.fromPath("/pet/findByTags").build().toUriString();
    final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
    final HttpHeaders headerParams = new HttpHeaders();
    final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();
    queryParams.putAll(apiClient.parameterToMultiValueMap(ApiClient.CollectionFormat.valueOf("multi".toUpperCase()), "tags", tags));
    final String[] accepts = { "application/xml", "application/json" };
    final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
    final String[] contentTypes = {};
    final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);
    String[] authNames = new String[] { "petstore_auth" };
    ParameterizedTypeReference<List<Pet>> returnType = new ParameterizedTypeReference<List<Pet>>() {
    };
    return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) ParameterizedTypeReference(org.springframework.core.ParameterizedTypeReference) MediaType(org.springframework.http.MediaType) ArrayList(java.util.ArrayList) List(java.util.List) Pet(com.baeldung.petstore.client.model.Pet)

Example 3 with Pet

use of com.baeldung.petstore.client.model.Pet in project tutorials by eugenp.

the class PetApi method getPetById.

/**
 * Find pet by ID
 * Returns a single pet
 * <p><b>200</b> - successful operation
 * <p><b>400</b> - Invalid ID supplied
 * <p><b>404</b> - Pet not found
 * @param petId ID of pet to return
 * @return Pet
 * @throws RestClientException if an error occurs while attempting to invoke the API
 */
public Pet getPetById(Long petId) throws RestClientException {
    Object postBody = null;
    // verify the required parameter 'petId' is set
    if (petId == null) {
        throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'petId' when calling getPetById");
    }
    // create path and map variables
    final Map<String, Object> uriVariables = new HashMap<String, Object>();
    uriVariables.put("petId", petId);
    String path = UriComponentsBuilder.fromPath("/pet/{petId}").buildAndExpand(uriVariables).toUriString();
    final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
    final HttpHeaders headerParams = new HttpHeaders();
    final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();
    final String[] accepts = { "application/xml", "application/json" };
    final List<MediaType> accept = apiClient.selectHeaderAccept(accepts);
    final String[] contentTypes = {};
    final MediaType contentType = apiClient.selectHeaderContentType(contentTypes);
    String[] authNames = new String[] { "api_key" };
    ParameterizedTypeReference<Pet> returnType = new ParameterizedTypeReference<Pet>() {
    };
    return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) HashMap(java.util.HashMap) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) ParameterizedTypeReference(org.springframework.core.ParameterizedTypeReference) MediaType(org.springframework.http.MediaType) Pet(com.baeldung.petstore.client.model.Pet)

Example 4 with Pet

use of com.baeldung.petstore.client.model.Pet in project tutorials by eugenp.

the class PetApiTest method getPetByIdTest.

/**
 * Find pet by ID
 *
 * Returns a single pet
 *
 * @throws ApiException
 *          if the Api call fails
 */
@Test
public void getPetByIdTest() {
    Long petId = null;
    Pet response = api.getPetById(petId);
// TODO: test validations
}
Also used : Pet(com.baeldung.petstore.client.model.Pet) Test(org.junit.Test)

Example 5 with Pet

use of com.baeldung.petstore.client.model.Pet in project tutorials by eugenp.

the class PetApiTest method addPetTest.

/**
 * Add a new pet to the store
 *
 * @throws ApiException
 *          if the Api call fails
 */
@Test
public void addPetTest() {
    Pet body = null;
    api.addPet(body);
// TODO: test validations
}
Also used : Pet(com.baeldung.petstore.client.model.Pet) Test(org.junit.Test)

Aggregations

Pet (com.baeldung.petstore.client.model.Pet)6 Test (org.junit.Test)3 ParameterizedTypeReference (org.springframework.core.ParameterizedTypeReference)3 HttpHeaders (org.springframework.http.HttpHeaders)3 MediaType (org.springframework.http.MediaType)3 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)3 HttpClientErrorException (org.springframework.web.client.HttpClientErrorException)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 HashMap (java.util.HashMap)1