diff --git a/pom.xml.bash b/pom.xml.bash index 51ac2915189..c8093f51585 100644 --- a/pom.xml.bash +++ b/pom.xml.bash @@ -796,6 +796,18 @@ samples/server/petstore/springboot-beanvalidation + + springboot-reactive + + + env + java + + + + samples/server/petstore/springboot-reactive + + springboot diff --git a/pom.xml.circleci b/pom.xml.circleci index 888c505b20b..2f35984a671 100644 --- a/pom.xml.circleci +++ b/pom.xml.circleci @@ -774,6 +774,18 @@ samples/server/petstore/springboot-beanvalidation + + springboot-reactive + + + env + java + + + + samples/server/petstore/springboot-reactive + + springboot diff --git a/pom.xml.circleci.java7 b/pom.xml.circleci.java7 index 2eb9cf4cc80..c01ea9efbc7 100644 --- a/pom.xml.circleci.java7 +++ b/pom.xml.circleci.java7 @@ -780,6 +780,18 @@ samples/server/petstore/springboot-beanvalidation + + springboot-reactive + + + env + java + + + + samples/server/petstore/springboot-reactive + + springboot diff --git a/pom.xml.ios b/pom.xml.ios index bc14cdb58ff..a23f715250e 100644 --- a/pom.xml.ios +++ b/pom.xml.ios @@ -796,6 +796,18 @@ samples/server/petstore/springboot-beanvalidation + + springboot-reactive + + + env + java + + + + samples/server/petstore/springboot-reactive + + springboot diff --git a/pom.xml.shippable b/pom.xml.shippable index 054ca6635e7..eed6bb951d2 100644 --- a/pom.xml.shippable +++ b/pom.xml.shippable @@ -790,6 +790,18 @@ samples/server/petstore/springboot-beanvalidation + + springboot-reactive + + + env + java + + + + samples/server/petstore/springboot-reactive + + springboot diff --git a/samples/client/petstore/spring-cloud/src/test/java/org/openapitools/Application.java b/samples/client/petstore/spring-cloud/src/test/java/org/openapitools/Application.java new file mode 100644 index 00000000000..5ca1b2ba5e7 --- /dev/null +++ b/samples/client/petstore/spring-cloud/src/test/java/org/openapitools/Application.java @@ -0,0 +1,20 @@ +package org.openapitools; + +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; + } +} \ No newline at end of file diff --git a/samples/client/petstore/spring-cloud/src/test/java/org/openapitools/TestUtils.java b/samples/client/petstore/spring-cloud/src/test/java/org/openapitools/TestUtils.java new file mode 100644 index 00000000000..19900267268 --- /dev/null +++ b/samples/client/petstore/spring-cloud/src/test/java/org/openapitools/TestUtils.java @@ -0,0 +1,17 @@ +package org.openapitools; + +import java.util.Random; +import java.util.concurrent.atomic.AtomicLong; + +public class TestUtils { + private static final AtomicLong atomicId = createAtomicId(); + + public static long nextId() { + return atomicId.getAndIncrement(); + } + + private static AtomicLong createAtomicId() { + int baseId = new Random(System.currentTimeMillis()).nextInt(1000000) + 20000; + return new AtomicLong((long) baseId); + } +} \ No newline at end of file diff --git a/samples/client/petstore/spring-cloud/src/test/java/org/openapitools/api/PetApiTest.java b/samples/client/petstore/spring-cloud/src/test/java/org/openapitools/api/PetApiTest.java new file mode 100644 index 00000000000..23febe02ace --- /dev/null +++ b/samples/client/petstore/spring-cloud/src/test/java/org/openapitools/api/PetApiTest.java @@ -0,0 +1,190 @@ +package org.openapitools.api; + +import com.netflix.hystrix.exception.HystrixRuntimeException; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.openapitools.Application; +import org.openapitools.TestUtils; +import org.openapitools.model.Category; +import org.openapitools.model.Pet; +import org.openapitools.model.Tag; +import org.springframework.beans.factory.annotation.Autowired; +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) +@SpringBootTest(classes = Application.class) +public class PetApiTest { + + @Autowired + private PetApiClient client; + + @Test + public void testCreateAndGetPet() { + Pet pet = createRandomPet(); + client.addPet(pet).execute(); + Pet fetched = client.getPetById(pet.getId()).execute().getBody(); + assertNotNull(fetched); + assertEquals(pet.getId(), fetched.getId()); + assertNotNull(fetched.getCategory()); + assertEquals(fetched.getCategory().getName(), pet.getCategory().getName()); + } + + @Test + public void testUpdatePet() throws Exception { + Pet pet = createRandomPet(); + pet.setName("programmer"); + + client.updatePet(pet).execute(); + + Pet fetched = client.getPetById(pet.getId()).execute().getBody(); + assertNotNull(fetched); + assertEquals(pet.getId(), fetched.getId()); + assertNotNull(fetched.getCategory()); + assertEquals(fetched.getCategory().getName(), pet.getCategory().getName()); + } + + @Ignore + @Test + public void testFindPetsByStatus() throws Exception { + Pet pet = createRandomPet(); + pet.setName("programmer"); + pet.setStatus(Pet.StatusEnum.AVAILABLE); + + client.updatePet(pet).execute(); + + List pets = client.findPetsByStatus(Collections.singletonList("available")).execute().getBody(); + assertNotNull(pets); + + boolean found = false; + for (Pet fetched : pets) { + if (fetched.getId().equals(pet.getId())) { + found = true; + break; + } + } + + assertTrue(found); + } + + @Ignore + @Test + public void testFindPetsByTags() throws Exception { + Pet pet = createRandomPet(); + pet.setName("monster"); + pet.setStatus(Pet.StatusEnum.AVAILABLE); + + List tags = new ArrayList<>(); + Tag tag1 = new Tag(); + tag1.setName("friendly"); + tags.add(tag1); + pet.setTags(tags); + + client.updatePet(pet).execute(); + + List pets = client.findPetsByTags(Collections.singletonList("friendly")).execute().getBody(); + assertNotNull(pets); + + boolean found = false; + for (Pet fetched : pets) { + if (fetched.getId().equals(pet.getId())) { + found = true; + break; + } + } + assertTrue(found); + } + + @Test + public void testUpdatePetWithForm() throws Exception { + Pet pet = createRandomPet(); + pet.setName("frank"); + client.addPet(pet).execute(); + + Pet fetched = client.getPetById(pet.getId()).execute().getBody(); + + client.updatePetWithForm(fetched.getId(), "furt", null).execute(); + Pet updated = client.getPetById(fetched.getId()).execute().getBody(); + + assertEquals(updated.getName(), "furt"); + } + + @Test + public void testDeletePet() throws Exception { + Pet pet = createRandomPet(); + client.addPet(pet).execute(); + + Pet fetched = client.getPetById(pet.getId()).execute().getBody(); + client.deletePet(fetched.getId(), null).execute(); + + try { + client.getPetById(fetched.getId()).execute(); + fail("expected an error"); + } catch (HystrixRuntimeException e) { + assertTrue(e.getCause().getMessage().startsWith("status 404 ")); + } + } + + @Ignore("Multipart form is not supported by spring-cloud yet.") + @Test + public void testUploadFile() throws Exception { + Pet pet = createRandomPet(); + client.addPet(pet).execute(); + + MockMultipartFile filePart = new MockMultipartFile("file", "bar".getBytes()); + client.uploadFile(pet.getId(), "a test file", filePart).execute(); + } + + @Test + public void testEqualsAndHashCode() { + Pet pet1 = new Pet(); + Pet pet2 = new Pet(); + assertTrue(pet1.equals(pet2)); + assertTrue(pet2.equals(pet1)); + assertTrue(pet1.hashCode() == pet2.hashCode()); + assertTrue(pet1.equals(pet1)); + assertTrue(pet1.hashCode() == pet1.hashCode()); + + pet2.setName("really-happy"); + 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())); + assertTrue(pet2.equals(pet2)); + assertTrue(pet2.hashCode() == pet2.hashCode()); + + pet1.setName("really-happy"); + 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()); + assertTrue(pet1.equals(pet1)); + assertTrue(pet1.hashCode() == pet1.hashCode()); + } + + private Pet createRandomPet() { + Pet pet = new Pet(); + pet.setId(TestUtils.nextId()); + pet.setName("gorilla"); + + Category category = new Category(); + category.setName("really-happy"); + + pet.setCategory(category); + pet.setStatus(Pet.StatusEnum.AVAILABLE); + List photos = Arrays.asList("http://foo.bar.com/1", "http://foo.bar.com/2"); + pet.setPhotoUrls(photos); + + return pet; + } + +} \ No newline at end of file diff --git a/samples/client/petstore/spring-cloud/src/test/java/org/openapitools/api/StoreApiTest.java b/samples/client/petstore/spring-cloud/src/test/java/org/openapitools/api/StoreApiTest.java new file mode 100644 index 00000000000..3d578309aff --- /dev/null +++ b/samples/client/petstore/spring-cloud/src/test/java/org/openapitools/api/StoreApiTest.java @@ -0,0 +1,72 @@ +package org.openapitools.api; + +import com.netflix.hystrix.exception.HystrixRuntimeException; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.openapitools.Application; +import org.openapitools.TestUtils; +import org.openapitools.model.Order; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import java.time.OffsetDateTime; +import java.util.Map; + +import static org.junit.Assert.*; + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringBootTest(classes = Application.class) +public class StoreApiTest { + + @Autowired + private StoreApiClient client; + + @Test + public void testGetInventory() { + Map inventory = client.getInventory().execute().getBody(); + assertTrue(inventory.keySet().size() > 0); + } + + @Test + public void testPlaceOrder() { + Order order = createOrder(); + client.placeOrder(order).execute(); + + Order fetched = client.getOrderById(order.getId()).execute().getBody(); + assertEquals(order.getId(), fetched.getId()); + assertEquals(order.getPetId(), fetched.getPetId()); + assertEquals(order.getQuantity(), fetched.getQuantity()); + assertEquals(order.getShipDate().toInstant(), fetched.getShipDate().toInstant()); + } + + @Test + public void testDeleteOrder() { + Order order = createOrder(); + client.placeOrder(order).execute(); + + Order fetched = client.getOrderById(order.getId()).execute().getBody(); + assertEquals(fetched.getId(), order.getId()); + + client.deleteOrder(String.valueOf(order.getId())).execute(); + + try { + client.getOrderById(order.getId()).execute(); + fail("expected an error"); + } catch (HystrixRuntimeException e) { + assertTrue(e.getCause().getMessage().startsWith("status 404 ")); + } + } + + private Order createOrder() { + return new Order() + .id(TestUtils.nextId()) + .petId(200L) + .quantity(13) + //Ensure 3 fractional digits because of a bug in the petstore server + .shipDate(OffsetDateTime.now().withNano(123000000)) + .status(Order.StatusEnum.PLACED) + .complete(true); + } + +} \ No newline at end of file diff --git a/samples/client/petstore/spring-cloud/src/test/java/org/openapitools/api/UserApiTest.java b/samples/client/petstore/spring-cloud/src/test/java/org/openapitools/api/UserApiTest.java new file mode 100644 index 00000000000..868b87716b9 --- /dev/null +++ b/samples/client/petstore/spring-cloud/src/test/java/org/openapitools/api/UserApiTest.java @@ -0,0 +1,88 @@ +package org.openapitools.api; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.openapitools.Application; +import org.openapitools.TestUtils; +import org.openapitools.model.User; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import java.util.Arrays; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringBootTest(classes = Application.class) +public class UserApiTest { + + @Autowired + private UserApiClient client; + + @Test + public void testCreateUser() { + User user = createUser(); + + client.createUser(user).execute(); + + User fetched = client.getUserByName(user.getUsername()).execute().getBody(); + assertEquals(user.getId(), fetched.getId()); + } + + @Test + public void testCreateUsersWithArray() { + User user1 = createUser(); + user1.setUsername("user" + user1.getId()); + User user2 = createUser(); + user2.setUsername("user" + user2.getId()); + + client.createUsersWithArrayInput(Arrays.asList(user1, user2)).execute(); + + User fetched = client.getUserByName(user1.getUsername()).execute().getBody(); + assertEquals(user1.getId(), fetched.getId()); + } + + @Test + public void testCreateUsersWithList() { + User user1 = createUser(); + user1.setUsername("user" + user1.getId()); + User user2 = createUser(); + user2.setUsername("user" + user2.getId()); + + client.createUsersWithListInput(Arrays.asList(user1, user2)).execute(); + + User fetched = client.getUserByName(user1.getUsername()).execute().getBody(); + assertEquals(user1.getId(), fetched.getId()); + } + + @Test + public void testLoginUser() { + User user = createUser(); + client.createUser(user).execute(); + + String token = client.loginUser(user.getUsername(), user.getPassword()).execute().getBody(); + assertTrue(token.startsWith("logged in user session:")); + } + + @Test + public void logoutUser() { + client.logoutUser().execute(); + } + + private User createUser() { + User user = new User(); + user.setId(TestUtils.nextId()); + user.setUsername("fred"); + user.setFirstName("Fred"); + user.setLastName("Meyer"); + user.setEmail("fred@fredmeyer.com"); + user.setPassword("xxXXxx"); + user.setPhone("408-867-5309"); + user.setUserStatus(123); + + return user; + } + +} diff --git a/samples/client/petstore/spring-cloud/src/test/resources/application.yml b/samples/client/petstore/spring-cloud/src/test/resources/application.yml new file mode 100644 index 00000000000..05444fc2669 --- /dev/null +++ b/samples/client/petstore/spring-cloud/src/test/resources/application.yml @@ -0,0 +1,11 @@ +spring: + application: + name: petstore-test + jackson: + serialization.WRITE_DATES_AS_TIMESTAMPS: false + +hystrix.command.default.execution.timeout.enabled: false + +logging.level.io.swagger.api: DEBUG + +feign.hystrix.enabled: true \ No newline at end of file