forked from loafle/openapi-generator-original
[spring] add an option to choose the response wrapper type
Also generate the spring-cloud sample with a HystrixCommand wrapper
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>1.3.6.RELEASE</version>
|
||||
<version>1.4.1.RELEASE</version>
|
||||
</parent>
|
||||
<build>
|
||||
<sourceDirectory>src/main/java</sourceDirectory>
|
||||
@@ -25,7 +25,7 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-parent</artifactId>
|
||||
<version>Brixton.SR2</version>
|
||||
<version>Camden.SR1</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -33,7 +33,7 @@ public interface PetApi {
|
||||
produces = "application/json",
|
||||
consumes = "application/json",
|
||||
method = RequestMethod.POST)
|
||||
ResponseEntity<Void> addPet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true ) @RequestBody Pet body);
|
||||
com.netflix.hystrix.HystrixCommand<ResponseEntity<Void>> addPet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true ) @RequestBody Pet body);
|
||||
|
||||
|
||||
@ApiOperation(value = "Deletes a pet", notes = "", response = Void.class, authorizations = {
|
||||
@@ -48,7 +48,7 @@ public interface PetApi {
|
||||
produces = "application/json",
|
||||
consumes = "application/json",
|
||||
method = RequestMethod.DELETE)
|
||||
ResponseEntity<Void> deletePet(@ApiParam(value = "Pet id to delete",required=true ) @PathVariable("petId") Long petId,
|
||||
com.netflix.hystrix.HystrixCommand<ResponseEntity<Void>> deletePet(@ApiParam(value = "Pet id to delete",required=true ) @PathVariable("petId") Long petId,
|
||||
@ApiParam(value = "" ) @RequestHeader(value="api_key", required=false) String apiKey);
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ public interface PetApi {
|
||||
produces = "application/json",
|
||||
consumes = "application/json",
|
||||
method = RequestMethod.GET)
|
||||
ResponseEntity<List<Pet>> findPetsByStatus(@ApiParam(value = "Status values that need to be considered for filter", required = true, allowableValues = "AVAILABLE, PENDING, SOLD") @RequestParam(value = "status", required = true) List<String> status);
|
||||
com.netflix.hystrix.HystrixCommand<ResponseEntity<List<Pet>>> findPetsByStatus(@ApiParam(value = "Status values that need to be considered for filter", required = true, allowableValues = "AVAILABLE, PENDING, SOLD") @RequestParam(value = "status", required = true) List<String> status);
|
||||
|
||||
|
||||
@ApiOperation(value = "Finds Pets by tags", notes = "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.", response = Pet.class, responseContainer = "List", authorizations = {
|
||||
@@ -81,7 +81,7 @@ public interface PetApi {
|
||||
produces = "application/json",
|
||||
consumes = "application/json",
|
||||
method = RequestMethod.GET)
|
||||
ResponseEntity<List<Pet>> findPetsByTags(@ApiParam(value = "Tags to filter by", required = true) @RequestParam(value = "tags", required = true) List<String> tags);
|
||||
com.netflix.hystrix.HystrixCommand<ResponseEntity<List<Pet>>> findPetsByTags(@ApiParam(value = "Tags to filter by", required = true) @RequestParam(value = "tags", required = true) List<String> tags);
|
||||
|
||||
|
||||
@ApiOperation(value = "Find pet by ID", notes = "Returns a single pet", response = Pet.class, authorizations = {
|
||||
@@ -95,7 +95,7 @@ public interface PetApi {
|
||||
produces = "application/json",
|
||||
consumes = "application/json",
|
||||
method = RequestMethod.GET)
|
||||
ResponseEntity<Pet> getPetById(@ApiParam(value = "ID of pet to return",required=true ) @PathVariable("petId") Long petId);
|
||||
com.netflix.hystrix.HystrixCommand<ResponseEntity<Pet>> getPetById(@ApiParam(value = "ID of pet to return",required=true ) @PathVariable("petId") Long petId);
|
||||
|
||||
|
||||
@ApiOperation(value = "Update an existing pet", notes = "", response = Void.class, authorizations = {
|
||||
@@ -112,7 +112,7 @@ public interface PetApi {
|
||||
produces = "application/json",
|
||||
consumes = "application/json",
|
||||
method = RequestMethod.PUT)
|
||||
ResponseEntity<Void> updatePet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true ) @RequestBody Pet body);
|
||||
com.netflix.hystrix.HystrixCommand<ResponseEntity<Void>> updatePet(@ApiParam(value = "Pet object that needs to be added to the store" ,required=true ) @RequestBody Pet body);
|
||||
|
||||
|
||||
@ApiOperation(value = "Updates a pet in the store with form data", notes = "", response = Void.class, authorizations = {
|
||||
@@ -127,7 +127,7 @@ public interface PetApi {
|
||||
produces = "application/json",
|
||||
consumes = "application/x-www-form-urlencoded",
|
||||
method = RequestMethod.POST)
|
||||
ResponseEntity<Void> updatePetWithForm(@ApiParam(value = "ID of pet that needs to be updated",required=true ) @PathVariable("petId") Long petId,
|
||||
com.netflix.hystrix.HystrixCommand<ResponseEntity<Void>> updatePetWithForm(@ApiParam(value = "ID of pet that needs to be updated",required=true ) @PathVariable("petId") Long petId,
|
||||
@ApiParam(value = "Updated name of the pet" ) @RequestParam(value="name", required=false) String name,
|
||||
@ApiParam(value = "Updated status of the pet" ) @RequestParam(value="status", required=false) String status);
|
||||
|
||||
@@ -144,7 +144,7 @@ public interface PetApi {
|
||||
produces = "application/json",
|
||||
consumes = "multipart/form-data",
|
||||
method = RequestMethod.POST)
|
||||
ResponseEntity<ModelApiResponse> uploadFile(@ApiParam(value = "ID of pet to update",required=true ) @PathVariable("petId") Long petId,
|
||||
com.netflix.hystrix.HystrixCommand<ResponseEntity<ModelApiResponse>> uploadFile(@ApiParam(value = "ID of pet to update",required=true ) @PathVariable("petId") Long petId,
|
||||
@ApiParam(value = "Additional data to pass to server" ) @RequestParam(value="additionalMetadata", required=false) String additionalMetadata,
|
||||
@ApiParam(value = "file detail") @RequestParam("file") MultipartFile file);
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ public interface StoreApi {
|
||||
produces = "application/json",
|
||||
consumes = "application/json",
|
||||
method = RequestMethod.DELETE)
|
||||
ResponseEntity<Void> deleteOrder(@ApiParam(value = "ID of the order that needs to be deleted",required=true ) @PathVariable("orderId") String orderId);
|
||||
com.netflix.hystrix.HystrixCommand<ResponseEntity<Void>> deleteOrder(@ApiParam(value = "ID of the order that needs to be deleted",required=true ) @PathVariable("orderId") String orderId);
|
||||
|
||||
|
||||
@ApiOperation(value = "Returns pet inventories by status", notes = "Returns a map of status codes to quantities", response = Integer.class, responseContainer = "Map", authorizations = {
|
||||
@@ -40,7 +40,7 @@ public interface StoreApi {
|
||||
produces = "application/json",
|
||||
consumes = "application/json",
|
||||
method = RequestMethod.GET)
|
||||
ResponseEntity<Map<String, Integer>> getInventory();
|
||||
com.netflix.hystrix.HystrixCommand<ResponseEntity<Map<String, Integer>>> getInventory();
|
||||
|
||||
|
||||
@ApiOperation(value = "Find purchase order by ID", notes = "For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions", response = Order.class, tags={ "store", })
|
||||
@@ -52,7 +52,7 @@ public interface StoreApi {
|
||||
produces = "application/json",
|
||||
consumes = "application/json",
|
||||
method = RequestMethod.GET)
|
||||
ResponseEntity<Order> getOrderById(@ApiParam(value = "ID of pet that needs to be fetched",required=true ) @PathVariable("orderId") Long orderId);
|
||||
com.netflix.hystrix.HystrixCommand<ResponseEntity<Order>> getOrderById(@ApiParam(value = "ID of pet that needs to be fetched",required=true ) @PathVariable("orderId") Long orderId);
|
||||
|
||||
|
||||
@ApiOperation(value = "Place an order for a pet", notes = "", response = Order.class, tags={ "store", })
|
||||
@@ -63,6 +63,6 @@ public interface StoreApi {
|
||||
produces = "application/json",
|
||||
consumes = "application/json",
|
||||
method = RequestMethod.POST)
|
||||
ResponseEntity<Order> placeOrder(@ApiParam(value = "order placed for purchasing the pet" ,required=true ) @RequestBody Order body);
|
||||
com.netflix.hystrix.HystrixCommand<ResponseEntity<Order>> placeOrder(@ApiParam(value = "order placed for purchasing the pet" ,required=true ) @RequestBody Order body);
|
||||
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public interface UserApi {
|
||||
produces = "application/json",
|
||||
consumes = "application/json",
|
||||
method = RequestMethod.POST)
|
||||
ResponseEntity<Void> createUser(@ApiParam(value = "Created user object" ,required=true ) @RequestBody User body);
|
||||
com.netflix.hystrix.HystrixCommand<ResponseEntity<Void>> createUser(@ApiParam(value = "Created user object" ,required=true ) @RequestBody User body);
|
||||
|
||||
|
||||
@ApiOperation(value = "Creates list of users with given input array", notes = "", response = Void.class, tags={ "user", })
|
||||
@@ -37,7 +37,7 @@ public interface UserApi {
|
||||
produces = "application/json",
|
||||
consumes = "application/json",
|
||||
method = RequestMethod.POST)
|
||||
ResponseEntity<Void> createUsersWithArrayInput(@ApiParam(value = "List of user object" ,required=true ) @RequestBody List<User> body);
|
||||
com.netflix.hystrix.HystrixCommand<ResponseEntity<Void>> createUsersWithArrayInput(@ApiParam(value = "List of user object" ,required=true ) @RequestBody List<User> body);
|
||||
|
||||
|
||||
@ApiOperation(value = "Creates list of users with given input array", notes = "", response = Void.class, tags={ "user", })
|
||||
@@ -47,7 +47,7 @@ public interface UserApi {
|
||||
produces = "application/json",
|
||||
consumes = "application/json",
|
||||
method = RequestMethod.POST)
|
||||
ResponseEntity<Void> createUsersWithListInput(@ApiParam(value = "List of user object" ,required=true ) @RequestBody List<User> body);
|
||||
com.netflix.hystrix.HystrixCommand<ResponseEntity<Void>> createUsersWithListInput(@ApiParam(value = "List of user object" ,required=true ) @RequestBody List<User> body);
|
||||
|
||||
|
||||
@ApiOperation(value = "Delete user", notes = "This can only be done by the logged in user.", response = Void.class, tags={ "user", })
|
||||
@@ -58,7 +58,7 @@ public interface UserApi {
|
||||
produces = "application/json",
|
||||
consumes = "application/json",
|
||||
method = RequestMethod.DELETE)
|
||||
ResponseEntity<Void> deleteUser(@ApiParam(value = "The name that needs to be deleted",required=true ) @PathVariable("username") String username);
|
||||
com.netflix.hystrix.HystrixCommand<ResponseEntity<Void>> deleteUser(@ApiParam(value = "The name that needs to be deleted",required=true ) @PathVariable("username") String username);
|
||||
|
||||
|
||||
@ApiOperation(value = "Get user by user name", notes = "", response = User.class, tags={ "user", })
|
||||
@@ -70,7 +70,7 @@ public interface UserApi {
|
||||
produces = "application/json",
|
||||
consumes = "application/json",
|
||||
method = RequestMethod.GET)
|
||||
ResponseEntity<User> getUserByName(@ApiParam(value = "The name that needs to be fetched. Use user1 for testing. ",required=true ) @PathVariable("username") String username);
|
||||
com.netflix.hystrix.HystrixCommand<ResponseEntity<User>> getUserByName(@ApiParam(value = "The name that needs to be fetched. Use user1 for testing. ",required=true ) @PathVariable("username") String username);
|
||||
|
||||
|
||||
@ApiOperation(value = "Logs user into the system", notes = "", response = String.class, tags={ "user", })
|
||||
@@ -81,7 +81,7 @@ public interface UserApi {
|
||||
produces = "application/json",
|
||||
consumes = "application/json",
|
||||
method = RequestMethod.GET)
|
||||
ResponseEntity<String> loginUser(@ApiParam(value = "The user name for login", required = true) @RequestParam(value = "username", required = true) String username,
|
||||
com.netflix.hystrix.HystrixCommand<ResponseEntity<String>> loginUser(@ApiParam(value = "The user name for login", required = true) @RequestParam(value = "username", required = true) String username,
|
||||
@ApiParam(value = "The password for login in clear text", required = true) @RequestParam(value = "password", required = true) String password);
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ public interface UserApi {
|
||||
produces = "application/json",
|
||||
consumes = "application/json",
|
||||
method = RequestMethod.GET)
|
||||
ResponseEntity<Void> logoutUser();
|
||||
com.netflix.hystrix.HystrixCommand<ResponseEntity<Void>> logoutUser();
|
||||
|
||||
|
||||
@ApiOperation(value = "Updated user", notes = "This can only be done by the logged in user.", response = Void.class, tags={ "user", })
|
||||
@@ -103,7 +103,7 @@ public interface UserApi {
|
||||
produces = "application/json",
|
||||
consumes = "application/json",
|
||||
method = RequestMethod.PUT)
|
||||
ResponseEntity<Void> updateUser(@ApiParam(value = "name that need to be deleted",required=true ) @PathVariable("username") String username,
|
||||
com.netflix.hystrix.HystrixCommand<ResponseEntity<Void>> updateUser(@ApiParam(value = "name that need to be deleted",required=true ) @PathVariable("username") String username,
|
||||
@ApiParam(value = "Updated user object" ,required=true ) @RequestBody User body);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package io.swagger;
|
||||
|
||||
import feign.Logger;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.cloud.netflix.feign.EnableFeignClients;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableFeignClients
|
||||
public class Application {
|
||||
public static void main(String[] args) {
|
||||
new SpringApplicationBuilder(Application.class).run(args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
Logger.Level feignLoggerLevel() {
|
||||
return Logger.Level.FULL;
|
||||
}
|
||||
}
|
||||
@@ -1,30 +1,28 @@
|
||||
package io.swagger.api;
|
||||
|
||||
import feign.FeignException;
|
||||
import com.netflix.hystrix.exception.HystrixRuntimeException;
|
||||
import io.swagger.Application;
|
||||
import io.swagger.TestUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import io.swagger.model.Category;
|
||||
import io.swagger.model.Pet;
|
||||
import io.swagger.model.Tag;
|
||||
import org.junit.*;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.cloud.netflix.feign.EnableFeignClients;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.mock.web.MockMultipartFile;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes = PetApiTest.Application.class)
|
||||
@SpringBootTest(classes = Application.class)
|
||||
public class PetApiTest {
|
||||
|
||||
@Autowired
|
||||
@@ -33,9 +31,8 @@ public class PetApiTest {
|
||||
@Test
|
||||
public void testCreateAndGetPet() {
|
||||
Pet pet = createRandomPet();
|
||||
client.addPet(pet);
|
||||
ResponseEntity<Pet> rp = client.getPetById(pet.getId());
|
||||
Pet fetched = rp.getBody();
|
||||
client.addPet(pet).execute();
|
||||
Pet fetched = client.getPetById(pet.getId()).execute().getBody();
|
||||
assertNotNull(fetched);
|
||||
assertEquals(pet.getId(), fetched.getId());
|
||||
assertNotNull(fetched.getCategory());
|
||||
@@ -47,9 +44,9 @@ public class PetApiTest {
|
||||
Pet pet = createRandomPet();
|
||||
pet.setName("programmer");
|
||||
|
||||
client.updatePet(pet);
|
||||
client.updatePet(pet).execute();
|
||||
|
||||
Pet fetched = client.getPetById(pet.getId()).getBody();
|
||||
Pet fetched = client.getPetById(pet.getId()).execute().getBody();
|
||||
assertNotNull(fetched);
|
||||
assertEquals(pet.getId(), fetched.getId());
|
||||
assertNotNull(fetched.getCategory());
|
||||
@@ -63,9 +60,9 @@ public class PetApiTest {
|
||||
pet.setName("programmer");
|
||||
pet.setStatus(Pet.StatusEnum.AVAILABLE);
|
||||
|
||||
client.updatePet(pet);
|
||||
client.updatePet(pet).execute();
|
||||
|
||||
List<Pet> pets = client.findPetsByStatus(Arrays.asList(new String[]{"available"})).getBody();
|
||||
List<Pet> pets = client.findPetsByStatus(Collections.singletonList("available")).execute().getBody();
|
||||
assertNotNull(pets);
|
||||
|
||||
boolean found = false;
|
||||
@@ -92,9 +89,9 @@ public class PetApiTest {
|
||||
tags.add(tag1);
|
||||
pet.setTags(tags);
|
||||
|
||||
client.updatePet(pet);
|
||||
client.updatePet(pet).execute();
|
||||
|
||||
List<Pet> pets = client.findPetsByTags(Arrays.asList(new String[]{"friendly"})).getBody();
|
||||
List<Pet> pets = client.findPetsByTags(Collections.singletonList("friendly")).execute().getBody();
|
||||
assertNotNull(pets);
|
||||
|
||||
boolean found = false;
|
||||
@@ -111,12 +108,12 @@ public class PetApiTest {
|
||||
public void testUpdatePetWithForm() throws Exception {
|
||||
Pet pet = createRandomPet();
|
||||
pet.setName("frank");
|
||||
client.addPet(pet);
|
||||
client.addPet(pet).execute();
|
||||
|
||||
Pet fetched = client.getPetById(pet.getId()).getBody();
|
||||
Pet fetched = client.getPetById(pet.getId()).execute().getBody();
|
||||
|
||||
client.updatePetWithForm(fetched.getId(), "furt", null);
|
||||
Pet updated = client.getPetById(fetched.getId()).getBody();
|
||||
client.updatePetWithForm(fetched.getId(), "furt", null).execute();
|
||||
Pet updated = client.getPetById(fetched.getId()).execute().getBody();
|
||||
|
||||
assertEquals(updated.getName(), "furt");
|
||||
}
|
||||
@@ -124,16 +121,16 @@ public class PetApiTest {
|
||||
@Test
|
||||
public void testDeletePet() throws Exception {
|
||||
Pet pet = createRandomPet();
|
||||
client.addPet(pet);
|
||||
client.addPet(pet).execute();
|
||||
|
||||
Pet fetched = client.getPetById(pet.getId()).getBody();
|
||||
client.deletePet(fetched.getId(), null);
|
||||
Pet fetched = client.getPetById(pet.getId()).execute().getBody();
|
||||
client.deletePet(fetched.getId(), null).execute();
|
||||
|
||||
try {
|
||||
client.getPetById(fetched.getId());
|
||||
client.getPetById(fetched.getId()).execute();
|
||||
fail("expected an error");
|
||||
} catch (FeignException e) {
|
||||
assertTrue(e.getMessage().startsWith("status 404 "));
|
||||
} catch (HystrixRuntimeException e) {
|
||||
assertTrue(e.getCause().getMessage().startsWith("status 404 "));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,10 +138,10 @@ public class PetApiTest {
|
||||
@Test
|
||||
public void testUploadFile() throws Exception {
|
||||
Pet pet = createRandomPet();
|
||||
client.addPet(pet);
|
||||
client.addPet(pet).execute();
|
||||
|
||||
MockMultipartFile filePart = new MockMultipartFile("file", "bar".getBytes());
|
||||
client.uploadFile(pet.getId(), "a test file", filePart);
|
||||
client.uploadFile(pet.getId(), "a test file", filePart).execute();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -158,7 +155,7 @@ public class PetApiTest {
|
||||
assertTrue(pet1.hashCode() == pet1.hashCode());
|
||||
|
||||
pet2.setName("really-happy");
|
||||
pet2.setPhotoUrls(Arrays.asList(new String[]{"http://foo.bar.com/1", "http://foo.bar.com/2"}));
|
||||
pet2.setPhotoUrls(Arrays.asList("http://foo.bar.com/1", "http://foo.bar.com/2"));
|
||||
assertFalse(pet1.equals(pet2));
|
||||
assertFalse(pet2.equals(pet1));
|
||||
assertFalse(pet1.hashCode() == (pet2.hashCode()));
|
||||
@@ -166,7 +163,7 @@ public class PetApiTest {
|
||||
assertTrue(pet2.hashCode() == pet2.hashCode());
|
||||
|
||||
pet1.setName("really-happy");
|
||||
pet1.setPhotoUrls(Arrays.asList(new String[]{"http://foo.bar.com/1", "http://foo.bar.com/2"}));
|
||||
pet1.setPhotoUrls(Arrays.asList("http://foo.bar.com/1", "http://foo.bar.com/2"));
|
||||
assertTrue(pet1.equals(pet2));
|
||||
assertTrue(pet2.equals(pet1));
|
||||
assertTrue(pet1.hashCode() == pet2.hashCode());
|
||||
@@ -184,24 +181,10 @@ public class PetApiTest {
|
||||
|
||||
pet.setCategory(category);
|
||||
pet.setStatus(Pet.StatusEnum.AVAILABLE);
|
||||
List<String> photos = Arrays.asList(new String[]{"http://foo.bar.com/1", "http://foo.bar.com/2"});
|
||||
List<String> photos = Arrays.asList("http://foo.bar.com/1", "http://foo.bar.com/2");
|
||||
pet.setPhotoUrls(photos);
|
||||
|
||||
return pet;
|
||||
}
|
||||
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableFeignClients
|
||||
protected static class Application {
|
||||
public static void main(String[] args) {
|
||||
new SpringApplicationBuilder(Application.class).run(args);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
package io.swagger.api;
|
||||
|
||||
import feign.FeignException;
|
||||
import com.netflix.hystrix.exception.HystrixRuntimeException;
|
||||
import io.swagger.Application;
|
||||
import io.swagger.TestUtils;
|
||||
import io.swagger.model.Order;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.cloud.netflix.feign.EnableFeignClients;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
@@ -18,7 +16,7 @@ import java.util.Map;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes = StoreApiTest.Application.class)
|
||||
@SpringBootTest(classes = Application.class)
|
||||
public class StoreApiTest {
|
||||
|
||||
@Autowired
|
||||
@@ -26,16 +24,16 @@ public class StoreApiTest {
|
||||
|
||||
@Test
|
||||
public void testGetInventory() {
|
||||
Map<String, Integer> inventory = client.getInventory().getBody();
|
||||
Map<String, Integer> inventory = client.getInventory().execute().getBody();
|
||||
assertTrue(inventory.keySet().size() > 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPlaceOrder() {
|
||||
Order order = createOrder();
|
||||
client.placeOrder(order);
|
||||
client.placeOrder(order).execute();
|
||||
|
||||
Order fetched = client.getOrderById(order.getId()).getBody();
|
||||
Order fetched = client.getOrderById(order.getId()).execute().getBody();
|
||||
assertEquals(order.getId(), fetched.getId());
|
||||
assertEquals(order.getPetId(), fetched.getPetId());
|
||||
assertEquals(order.getQuantity(), fetched.getQuantity());
|
||||
@@ -45,25 +43,25 @@ public class StoreApiTest {
|
||||
@Test
|
||||
public void testDeleteOrder() {
|
||||
Order order = createOrder();
|
||||
client.placeOrder(order);
|
||||
client.placeOrder(order).execute();
|
||||
|
||||
Order fetched = client.getOrderById(order.getId()).getBody();
|
||||
Order fetched = client.getOrderById(order.getId()).execute().getBody();
|
||||
assertEquals(fetched.getId(), order.getId());
|
||||
|
||||
client.deleteOrder(String.valueOf(order.getId()));
|
||||
client.deleteOrder(String.valueOf(order.getId())).execute();
|
||||
|
||||
try {
|
||||
client.getOrderById(order.getId());
|
||||
client.getOrderById(order.getId()).execute();
|
||||
fail("expected an error");
|
||||
} catch (FeignException e) {
|
||||
assertTrue(e.getMessage().startsWith("status 404 "));
|
||||
} catch (HystrixRuntimeException e) {
|
||||
assertTrue(e.getCause().getMessage().startsWith("status 404 "));
|
||||
}
|
||||
}
|
||||
|
||||
private Order createOrder() {
|
||||
Order order = new Order();
|
||||
order.setPetId(new Long(200));
|
||||
order.setQuantity(new Integer(13));
|
||||
order.setPetId(200L);
|
||||
order.setQuantity(13);
|
||||
order.setShipDate(org.joda.time.DateTime.now());
|
||||
order.setStatus(Order.StatusEnum.PLACED);
|
||||
order.setComplete(true);
|
||||
@@ -79,11 +77,4 @@ public class StoreApiTest {
|
||||
return order;
|
||||
}
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableFeignClients
|
||||
protected static class Application {
|
||||
public static void main(String[] args) {
|
||||
new SpringApplicationBuilder(StoreApiTest.Application.class).run(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,23 +1,21 @@
|
||||
package io.swagger.api;
|
||||
|
||||
import io.swagger.Application;
|
||||
import io.swagger.TestUtils;
|
||||
import io.swagger.model.User;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.cloud.netflix.feign.EnableFeignClients;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes = UserApiTest.Application.class)
|
||||
|
||||
@SpringBootTest(classes = Application.class)
|
||||
public class UserApiTest {
|
||||
|
||||
@Autowired
|
||||
@@ -27,9 +25,9 @@ public class UserApiTest {
|
||||
public void testCreateUser() {
|
||||
User user = createUser();
|
||||
|
||||
client.createUser(user);
|
||||
client.createUser(user).execute();
|
||||
|
||||
User fetched = client.getUserByName(user.getUsername()).getBody();
|
||||
User fetched = client.getUserByName(user.getUsername()).execute().getBody();
|
||||
assertEquals(user.getId(), fetched.getId());
|
||||
}
|
||||
|
||||
@@ -40,9 +38,9 @@ public class UserApiTest {
|
||||
User user2 = createUser();
|
||||
user2.setUsername("user" + user2.getId());
|
||||
|
||||
client.createUsersWithArrayInput(Arrays.asList(new User[]{user1, user2}));
|
||||
client.createUsersWithArrayInput(Arrays.asList(user1, user2)).execute();
|
||||
|
||||
User fetched = client.getUserByName(user1.getUsername()).getBody();
|
||||
User fetched = client.getUserByName(user1.getUsername()).execute().getBody();
|
||||
assertEquals(user1.getId(), fetched.getId());
|
||||
}
|
||||
|
||||
@@ -53,24 +51,24 @@ public class UserApiTest {
|
||||
User user2 = createUser();
|
||||
user2.setUsername("user" + user2.getId());
|
||||
|
||||
client.createUsersWithListInput(Arrays.asList(new User[]{user1, user2}));
|
||||
client.createUsersWithListInput(Arrays.asList(user1, user2)).execute();
|
||||
|
||||
User fetched = client.getUserByName(user1.getUsername()).getBody();
|
||||
User fetched = client.getUserByName(user1.getUsername()).execute().getBody();
|
||||
assertEquals(user1.getId(), fetched.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoginUser() {
|
||||
User user = createUser();
|
||||
client.createUser(user);
|
||||
client.createUser(user).execute();
|
||||
|
||||
String token = client.loginUser(user.getUsername(), user.getPassword()).getBody();
|
||||
String token = client.loginUser(user.getUsername(), user.getPassword()).execute().getBody();
|
||||
assertTrue(token.startsWith("logged in user session:"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void logoutUser() {
|
||||
client.logoutUser();
|
||||
client.logoutUser().execute();
|
||||
}
|
||||
|
||||
private User createUser() {
|
||||
@@ -87,11 +85,4 @@ public class UserApiTest {
|
||||
return user;
|
||||
}
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableFeignClients
|
||||
protected static class Application {
|
||||
public static void main(String[] args) {
|
||||
new SpringApplicationBuilder(UserApiTest.Application.class).run(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,7 @@ spring:
|
||||
application:
|
||||
name: petstore-test
|
||||
|
||||
feign.hystrix.enabled: false
|
||||
hystrix.command.default.execution.timeout.enabled: false
|
||||
|
||||
logging.level.io.swagger.api: DEBUG
|
||||
|
||||
logging.level.io.swagger.api:
|
||||
PetApiClient: DEBUG
|
||||
StoreApiClient: DEBUG
|
||||
UserApiClient: DEBUG
|
||||
|
||||
Reference in New Issue
Block a user