mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-05-29 13:00:51 +00:00
[Java][Jersey2] add petstore integration tests (#6508)
* add tests to jersey2 client * remove import
This commit is contained in:
parent
e3eb3c2f7d
commit
15be875275
@ -1,5 +0,0 @@
|
|||||||
{
|
|
||||||
"library": "jersey2",
|
|
||||||
"java8": false,
|
|
||||||
"artifactId": "petstore-jersey2-java7"
|
|
||||||
}
|
|
@ -13,97 +13,142 @@
|
|||||||
|
|
||||||
package org.openapitools.client.api;
|
package org.openapitools.client.api;
|
||||||
|
|
||||||
import org.openapitools.client.*;
|
import org.junit.Assert;
|
||||||
import org.openapitools.client.auth.*;
|
|
||||||
import java.io.File;
|
|
||||||
import org.openapitools.client.model.ModelApiResponse;
|
|
||||||
import org.openapitools.client.model.Pet;
|
|
||||||
import org.junit.Test;
|
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.io.File;
|
||||||
import java.util.HashMap;
|
import java.util.Arrays;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API tests for PetApi
|
* API tests for PetApi
|
||||||
*/
|
*/
|
||||||
@Ignore
|
|
||||||
public class PetApiTest {
|
public class PetApiTest {
|
||||||
|
|
||||||
private final PetApi api = new PetApi();
|
private final PetApi api = new PetApi();
|
||||||
|
private final long petId = 5638l;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a new pet to the store
|
* Add a new pet to the store
|
||||||
*
|
*
|
||||||
*
|
* @throws ApiException if the Api call fails
|
||||||
*
|
|
||||||
* @throws ApiException
|
|
||||||
* if the Api call fails
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void addPetTest() throws ApiException {
|
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);
|
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
|
* Deletes a pet
|
||||||
*
|
*
|
||||||
*
|
* @throws ApiException if the Api call fails
|
||||||
*
|
|
||||||
* @throws ApiException
|
|
||||||
* if the Api call fails
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void deletePetTest() throws ApiException {
|
public void deletePetTest() throws ApiException {
|
||||||
Long petId = null;
|
Long petId = null;
|
||||||
String apiKey = null;
|
String apiKey = null;
|
||||||
api.deletePet(petId, apiKey);
|
|
||||||
// TODO: test validations
|
// TODO: test validations
|
||||||
|
//api.deletePet(petId, apiKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds Pets by status
|
* Finds Pets by status
|
||||||
*
|
* <p>
|
||||||
* Multiple status values can be provided with comma separated strings
|
* Multiple status values can be provided with comma separated strings
|
||||||
*
|
*
|
||||||
* @throws ApiException
|
* @throws ApiException if the Api call fails
|
||||||
* if the Api call fails
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void findPetsByStatusTest() throws ApiException {
|
public void findPetsByStatusTest() throws ApiException {
|
||||||
List<String> status = null;
|
List<String> status = null;
|
||||||
List<Pet> response = api.findPetsByStatus(status);
|
//List<Pet> response = api.findPetsByStatus(status);
|
||||||
// TODO: test validations
|
// TODO: test validations
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds Pets by tags
|
* Finds Pets by tags
|
||||||
*
|
* <p>
|
||||||
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
* Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
|
||||||
*
|
*
|
||||||
* @throws ApiException
|
* @throws ApiException if the Api call fails
|
||||||
* if the Api call fails
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void findPetsByTagsTest() throws ApiException {
|
public void findPetsByTagsTest() throws ApiException {
|
||||||
Set<String> tags = null;
|
Set<String> tags = null;
|
||||||
Set<Pet> response = api.findPetsByTags(tags);
|
//Set<Pet> response = api.findPetsByTags(tags);
|
||||||
// TODO: test validations
|
// TODO: test validations
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find pet by ID
|
* Find pet by ID
|
||||||
*
|
* <p>
|
||||||
* Returns a single pet
|
* Returns a single pet
|
||||||
*
|
*
|
||||||
* @throws ApiException
|
* @throws ApiException if the Api call fails
|
||||||
* if the Api call fails
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void getPetByIdTest() throws ApiException {
|
public void getPetByIdTest() throws ApiException {
|
||||||
@ -126,7 +171,6 @@ public class PetApiTest {
|
|||||||
System.err.println("Status code: " + e.getCode());
|
System.err.println("Status code: " + e.getCode());
|
||||||
System.err.println("Reason: " + e.getResponseBody());
|
System.err.println("Reason: " + e.getResponseBody());
|
||||||
System.err.println("Response headers: " + e.getResponseHeaders());
|
System.err.println("Response headers: " + e.getResponseHeaders());
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -134,66 +178,54 @@ public class PetApiTest {
|
|||||||
/**
|
/**
|
||||||
* Update an existing pet
|
* Update an existing pet
|
||||||
*
|
*
|
||||||
*
|
* @throws ApiException if the Api call fails
|
||||||
*
|
|
||||||
* @throws ApiException
|
|
||||||
* if the Api call fails
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void updatePetTest() throws ApiException {
|
public void updatePetTest() throws ApiException {
|
||||||
Pet body = null;
|
Pet body = null;
|
||||||
api.updatePet(body);
|
//api.updatePet(body);
|
||||||
// TODO: test validations
|
// TODO: test validations
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates a pet in the store with form data
|
* Updates a pet in the store with form data
|
||||||
*
|
*
|
||||||
*
|
* @throws ApiException if the Api call fails
|
||||||
*
|
|
||||||
* @throws ApiException
|
|
||||||
* if the Api call fails
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void updatePetWithFormTest() throws ApiException {
|
public void updatePetWithFormTest() throws ApiException {
|
||||||
Long petId = null;
|
Long petId = null;
|
||||||
String name = null;
|
String name = null;
|
||||||
String status = null;
|
String status = null;
|
||||||
api.updatePetWithForm(petId, name, status);
|
//api.updatePetWithForm(petId, name, status);
|
||||||
// TODO: test validations
|
// TODO: test validations
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* uploads an image
|
* uploads an image
|
||||||
*
|
*
|
||||||
*
|
* @throws ApiException if the Api call fails
|
||||||
*
|
|
||||||
* @throws ApiException
|
|
||||||
* if the Api call fails
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void uploadFileTest() throws ApiException {
|
public void uploadFileTest() throws ApiException {
|
||||||
Long petId = null;
|
Long petId = null;
|
||||||
String additionalMetadata = null;
|
String additionalMetadata = null;
|
||||||
File file = null;
|
File file = null;
|
||||||
ModelApiResponse response = api.uploadFile(petId, additionalMetadata, file);
|
//ModelApiResponse response = api.uploadFile(petId, additionalMetadata, file);
|
||||||
// TODO: test validations
|
// TODO: test validations
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* uploads an image (required)
|
* uploads an image (required)
|
||||||
*
|
*
|
||||||
*
|
* @throws ApiException if the Api call fails
|
||||||
*
|
|
||||||
* @throws ApiException
|
|
||||||
* if the Api call fails
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void uploadFileWithRequiredFileTest() throws ApiException {
|
public void uploadFileWithRequiredFileTest() throws ApiException {
|
||||||
Long petId = null;
|
Long petId = null;
|
||||||
File requiredFile = null;
|
File requiredFile = null;
|
||||||
String additionalMetadata = null;
|
String additionalMetadata = null;
|
||||||
ModelApiResponse response = api.uploadFileWithRequiredFile(petId, requiredFile, additionalMetadata);
|
//ModelApiResponse response = api.uploadFileWithRequiredFile(petId, requiredFile, additionalMetadata);
|
||||||
// TODO: test validations
|
// TODO: test validations
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user