Skip to content

Commit

Permalink
[Java][Jersey2] add petstore integration tests (#6508)
Browse files Browse the repository at this point in the history
* add tests to jersey2 client

* remove import
  • Loading branch information
wing328 committed Jun 1, 2020
1 parent e3eb3c2 commit 15be875
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 59 deletions.
5 changes: 0 additions & 5 deletions bin/java-petstore-jersey2-java7.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
*
* The version of the OpenAPI document: 1.0.0
*
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
Expand All @@ -13,97 +13,142 @@

package org.openapitools.client.api;

import org.openapitools.client.*;
import org.openapitools.client.auth.*;
import java.io.File;
import org.openapitools.client.model.ModelApiResponse;
import org.openapitools.client.model.Pet;
import org.junit.Assert;
import org.junit.Test;
import org.junit.Ignore;
import org.openapitools.client.ApiClient;
import org.openapitools.client.ApiException;
import org.openapitools.client.Configuration;
import org.openapitools.client.auth.ApiKeyAuth;
import org.openapitools.client.model.Category;
import org.openapitools.client.model.Pet;
import org.openapitools.client.model.Tag;

import java.util.ArrayList;
import java.util.HashMap;
import java.io.File;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
* API tests for PetApi
*/
@Ignore
public class PetApiTest {

private final PetApi api = new PetApi();
private final long petId = 5638l;


/**
* Add a new pet to the store
*
*
*
* @throws ApiException
* if the Api call fails
* @throws ApiException if the Api call fails
*/
@Test
public void addPetTest() throws ApiException {
Pet body = null;
// add pet
Pet body = new Pet();
body.setId(petId);
body.setName("jersey2 java8 pet");
Category category = new Category();
category.setId(petId);
category.setName("jersey2 java8 category");
body.setCategory(category);
body.setStatus(Pet.StatusEnum.AVAILABLE);
body.setPhotoUrls(new HashSet<>(Arrays.asList("A", "B", "C")));
Tag tag = new Tag();
tag.setId(petId);
tag.setName("jersey2 java8 tag");
body.setTags(Arrays.asList(tag));

api.addPet(body);
// TODO: test validations

//get pet by ID
Pet result = api.getPetById(petId);
Assert.assertEquals(result.getId(), body.getId());
Assert.assertEquals(result.getCategory(), category);
Assert.assertEquals(result.getName(), body.getName());
Assert.assertEquals(result.getPhotoUrls(), body.getPhotoUrls());
Assert.assertEquals(result.getStatus(), body.getStatus());
Assert.assertEquals(result.getTags(), body.getTags());

// update pet
api.updatePetWithForm(petId, "jersey2 java8 pet 2", "sold");

//get pet by ID
Pet result2 = api.getPetById(petId);
Assert.assertEquals(result2.getId(), body.getId());
Assert.assertEquals(result2.getCategory(), category);
Assert.assertEquals(result2.getName(), "jersey2 java8 pet 2");
Assert.assertEquals(result2.getPhotoUrls(), body.getPhotoUrls());
Assert.assertEquals(result2.getStatus(), Pet.StatusEnum.SOLD);
Assert.assertEquals(result2.getTags(), body.getTags());

// delete pet
api.deletePet(petId, "empty api key");

try {
Pet result3 = api.getPetById(petId);
Assert.assertEquals(false, true);
} catch (ApiException e) {
// System.err.println("Exception when calling PetApi#getPetById");
// System.err.println("Status code: " + e.getCode());
// System.err.println("Reason: " + e.getResponseBody());
// System.err.println("Response headers: " + e.getResponseHeaders());

Assert.assertEquals(e.getCode(), 404);
Assert.assertEquals(e.getResponseBody(), "{\"code\":1,\"type\":\"error\",\"message\":\"Pet not found\"}");

}

}

/**
* Deletes a pet
*
*
*
* @throws ApiException
* if the Api call fails
* @throws ApiException if the Api call fails
*/
@Test
public void deletePetTest() throws ApiException {
Long petId = null;
String apiKey = null;
api.deletePet(petId, apiKey);
// TODO: test validations
//api.deletePet(petId, apiKey);
}

/**
* Finds Pets by status
*
* <p>
* Multiple status values can be provided with comma separated strings
*
* @throws ApiException
* if the Api call fails
* @throws ApiException if the Api call fails
*/
@Test
public void findPetsByStatusTest() throws ApiException {
List<String> status = null;
List<Pet> response = api.findPetsByStatus(status);
//List<Pet> response = api.findPetsByStatus(status);
// TODO: test validations
}

/**
* Finds Pets by tags
*
* <p>
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
*
* @throws ApiException
* if the Api call fails
* @throws ApiException if the Api call fails
*/
@Test
public void findPetsByTagsTest() throws ApiException {
Set<String> tags = null;
Set<Pet> response = api.findPetsByTags(tags);
//Set<Pet> response = api.findPetsByTags(tags);
// TODO: test validations
}

/**
* Find pet by ID
*
* <p>
* Returns a single pet
*
* @throws ApiException
* if the Api call fails
* @throws ApiException if the Api call fails
*/
@Test
public void getPetByIdTest() throws ApiException {
Expand All @@ -126,74 +171,61 @@ public void getPetByIdTest() throws ApiException {
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}

}

/**
* Update an existing pet
*
*
*
* @throws ApiException
* if the Api call fails
* @throws ApiException if the Api call fails
*/
@Test
public void updatePetTest() throws ApiException {
Pet body = null;
api.updatePet(body);
//api.updatePet(body);
// TODO: test validations
}

/**
* Updates a pet in the store with form data
*
*
*
* @throws ApiException
* if the Api call fails
* @throws ApiException if the Api call fails
*/
@Test
public void updatePetWithFormTest() throws ApiException {
Long petId = null;
String name = null;
String status = null;
api.updatePetWithForm(petId, name, status);
//api.updatePetWithForm(petId, name, status);
// TODO: test validations
}

/**
* uploads an image
*
*
*
* @throws ApiException
* if the Api call fails
* @throws ApiException if the Api call fails
*/
@Test
public void uploadFileTest() throws ApiException {
Long petId = null;
String additionalMetadata = null;
File file = null;
ModelApiResponse response = api.uploadFile(petId, additionalMetadata, file);
//ModelApiResponse response = api.uploadFile(petId, additionalMetadata, file);
// TODO: test validations
}

/**
* uploads an image (required)
*
*
*
* @throws ApiException
* if the Api call fails
* @throws ApiException if the Api call fails
*/
@Test
public void uploadFileWithRequiredFileTest() throws ApiException {
Long petId = null;
File requiredFile = null;
String additionalMetadata = null;
ModelApiResponse response = api.uploadFileWithRequiredFile(petId, requiredFile, additionalMetadata);
//ModelApiResponse response = api.uploadFileWithRequiredFile(petId, requiredFile, additionalMetadata);
// TODO: test validations
}

Expand Down

0 comments on commit 15be875

Please sign in to comment.