This is an automated email from the ASF dual-hosted git repository.

jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau-petstore.git

commit e63b584e30a30baf5b8f8a909f762e6d131f373e
Author: JamesBognar <[email protected]>
AuthorDate: Fri Dec 20 13:48:46 2019 -0500

    Remove findPetByTags (since it doesn't work in Derby)
    
    Also minor formatting changes.
---
 .../java/org/apache/juneau/petstore/PetStore.java  |  44 ++++----
 .../petstore/repository/OrderRepository.java       |   4 +-
 .../juneau/petstore/repository/PetRepository.java  |   6 +-
 .../juneau/petstore/repository/UserRepository.java |   3 +-
 .../juneau/petstore/rest/PetStoreResource.java     | 112 +++++++++------------
 .../juneau/petstore/service/PetStoreService.java   |  79 +++++++--------
 .../org/apache/juneau/petstore/test/MockTest.java  |  24 +----
 7 files changed, 111 insertions(+), 161 deletions(-)

diff --git 
a/juneau-petstore-api/src/main/java/org/apache/juneau/petstore/PetStore.java 
b/juneau-petstore-api/src/main/java/org/apache/juneau/petstore/PetStore.java
index ce8a0a1..5db76c5 100644
--- a/juneau-petstore-api/src/main/java/org/apache/juneau/petstore/PetStore.java
+++ b/juneau-petstore-api/src/main/java/org/apache/juneau/petstore/PetStore.java
@@ -129,26 +129,6 @@ public interface PetStore {
        ) throws NotAcceptable;
 
        /**
-        * Find all pets with the specified tags.
-        *
-        * @param tags The tags to match against.
-        * @return The pets that match the specified tags.
-        * @throws InvalidTag Invalid tag was specified.
-        * @throws NotAcceptable Unsupported <c>Accept</c> header specified.
-        */
-       @RemoteMethod(method=GET, path="/pet/findByTags")
-       @Deprecated
-       public Collection<Pet> findPetsByTags(
-               @Query(
-                       name="tags",
-                       description="Tags to filter by",
-                       required=true,
-                       example="['tag1','tag2']"
-               )
-               String[] tags
-       ) throws InvalidTag, NotAcceptable;
-
-       /**
         * Deletes the specified pet.
         *
         * @param apiKey Security key.
@@ -174,6 +154,14 @@ public interface PetStore {
                long petId
        ) throws IdNotFound, NotAcceptable;
 
+       /**
+        * Deletes all pets in the database.
+        *
+        * @return {@link Ok} if successful.
+        */
+       @RemoteMethod(method=DELETE, path="/pet")
+       public Ok deleteAllPets();
+
        
//------------------------------------------------------------------------------------------------------------------
        // Orders
        
//------------------------------------------------------------------------------------------------------------------
@@ -253,6 +241,14 @@ public interface PetStore {
        ) throws InvalidId, IdNotFound, NotAcceptable;
 
        /**
+        * Deletes all orders in the database.
+        *
+        * @return {@link Ok} if successful.
+        */
+       @RemoteMethod(method=DELETE, path="/store/order")
+       public Ok deleteAllOrders();
+
+       /**
         * Returns an inventory of pet statuses and counts.
         *
         * @return An inventory of pet statuses and counts.
@@ -371,6 +367,14 @@ public interface PetStore {
        ) throws InvalidUsername, IdNotFound, NotAcceptable;
 
        /**
+        * Deletes all users in the database.
+        *
+        * @return {@link Ok} if successful.
+        */
+       @RemoteMethod(method=DELETE, path="/user")
+       public Ok deleteAllUsers();
+
+       /**
         * User login.
         *
         * @param username The username for login.
diff --git 
a/juneau-petstore-server/src/main/java/org/apache/juneau/petstore/repository/OrderRepository.java
 
b/juneau-petstore-server/src/main/java/org/apache/juneau/petstore/repository/OrderRepository.java
index bbcfa6d..4a11b51 100644
--- 
a/juneau-petstore-server/src/main/java/org/apache/juneau/petstore/repository/OrderRepository.java
+++ 
b/juneau-petstore-server/src/main/java/org/apache/juneau/petstore/repository/OrderRepository.java
@@ -8,6 +8,4 @@ import org.springframework.stereotype.Repository;
  * TODO - Needs documentation
  */
 @Repository
-public interface OrderRepository  extends JpaRepository <Order, Long>{
-
-}
+public interface OrderRepository  extends JpaRepository <Order, Long>{}
diff --git 
a/juneau-petstore-server/src/main/java/org/apache/juneau/petstore/repository/PetRepository.java
 
b/juneau-petstore-server/src/main/java/org/apache/juneau/petstore/repository/PetRepository.java
index b200f71..9e5c6ff 100644
--- 
a/juneau-petstore-server/src/main/java/org/apache/juneau/petstore/repository/PetRepository.java
+++ 
b/juneau-petstore-server/src/main/java/org/apache/juneau/petstore/repository/PetRepository.java
@@ -13,13 +13,9 @@ import org.springframework.stereotype.Repository;
  * TODO - Needs documentation
  */
 @Repository
+@SuppressWarnings("javadoc")
 public interface PetRepository extends JpaRepository <Pet, Long> {
 
-       @SuppressWarnings("javadoc")
-       @Query("select X from PetstorePet X where X.tags in :tags")
-       List<Pet> findByTags(@Param("tags") String[] tags);
-
-       @SuppressWarnings("javadoc")
        @Query("select X from PetstorePet X where X.status in :status")
        List<Pet> findByStatus(@Param("status") PetStatus[] status);
 }
diff --git 
a/juneau-petstore-server/src/main/java/org/apache/juneau/petstore/repository/UserRepository.java
 
b/juneau-petstore-server/src/main/java/org/apache/juneau/petstore/repository/UserRepository.java
index a292a6a..538ced4 100644
--- 
a/juneau-petstore-server/src/main/java/org/apache/juneau/petstore/repository/UserRepository.java
+++ 
b/juneau-petstore-server/src/main/java/org/apache/juneau/petstore/repository/UserRepository.java
@@ -12,11 +12,10 @@ import org.springframework.stereotype.Repository;
  * TODO - Needs documentation
  */
 @Repository
+@SuppressWarnings("javadoc")
 public interface UserRepository  extends JpaRepository <User, Long>{
 
-       @SuppressWarnings("javadoc")
        Optional<User> findByUsername(String username);
 
-       @SuppressWarnings("javadoc")
        Long deleteByUsername(String username);
 }
diff --git 
a/juneau-petstore-server/src/main/java/org/apache/juneau/petstore/rest/PetStoreResource.java
 
b/juneau-petstore-server/src/main/java/org/apache/juneau/petstore/rest/PetStoreResource.java
index b0a28ea..51d287f 100644
--- 
a/juneau-petstore-server/src/main/java/org/apache/juneau/petstore/rest/PetStoreResource.java
+++ 
b/juneau-petstore-server/src/main/java/org/apache/juneau/petstore/rest/PetStoreResource.java
@@ -245,44 +245,29 @@ public class PetStoreResource extends BasicRest 
implements PetStore {
 
        @Override /* PetStore */
        @RestMethod(
-               name=GET,
-               path="/pet/findByTags",
-               summary="Finds Pets by tags",
-               description="Multiple tags can be provided with comma separated 
strings. Use tag1, tag2, tag3 for testing.",
+               name=DELETE,
+               path="/pet/{petId}",
+               summary="Deletes a pet",
                swagger=@MethodSwagger(
                        tags="pet"
                )
        )
-       @Deprecated
-       public Collection<Pet> findPetsByTags(String[] tags) throws InvalidTag, 
NotAcceptable {
-               return store.getPetsByTags(tags);
+       public Ok deletePet(String apiKey, long petId) throws IdNotFound, 
NotAcceptable {
+               store.deletePet(petId);
+               return OK;
        }
 
        @Override /* PetStore */
        @RestMethod(
                name=DELETE,
-               path="/pet/{petId}",
-               summary="Deletes a pet",
-               swagger=@MethodSwagger(
-                       tags="pet"
-               )
+               path="/pets",
+               summary="Delete all pets",
+               description="This can be done only by the logged in user."
        )
-       public Ok deletePet(String apiKey, long petId) throws IdNotFound, 
NotAcceptable {
-               store.removePet(petId);
+       public Ok deleteAllPets() {
+               store.deleteAllPets();
                return OK;
        }
-       
-       @RestMethod(
-                       name=DELETE,
-                       path="/pets",
-                       summary="Delete all pets",
-                       description="This can be done only by the logged in 
user."
-                                               
-                               )
-               public Ok deleteAllPets() {
-                       store.deleteAllPets();
-                       return OK;
-               }
 
        
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
        // Orders
@@ -306,7 +291,7 @@ public class PetStoreResource extends BasicRest implements 
PetStore {
                ;
        }
 
-       @Override
+       @Override /* PetStore */
        @RestMethod(
                name=GET,
                path="/store/order",
@@ -329,7 +314,7 @@ public class PetStoreResource extends BasicRest implements 
PetStore {
                return store.getOrders();
        }
 
-       @Override
+       @Override /* PetStore */
        @RestMethod(
                name=GET,
                path="/store/order/{orderId}",
@@ -345,7 +330,7 @@ public class PetStoreResource extends BasicRest implements 
PetStore {
                return store.getOrder(orderId);
        }
 
-       @Override
+       @Override /* PetStore */
        @RestMethod(
                name=POST,
                path="/store/order",
@@ -362,7 +347,7 @@ public class PetStoreResource extends BasicRest implements 
PetStore {
                return store.create(co).getId();
        }
 
-       @Override
+       @Override /* PetStore */
        @RestMethod(
                name=DELETE,
                path="/store/order/{orderId}",
@@ -378,23 +363,23 @@ public class PetStoreResource extends BasicRest 
implements PetStore {
        public Ok deleteOrder(long orderId) throws InvalidId, IdNotFound, 
NotAcceptable {
                if (orderId < 0)
                        throw new InvalidId();
-               store.removeOrder(orderId);
+               store.deleteOrder(orderId);
                return OK;
        }
-       
+
+       @Override /* PetStore */
        @RestMethod(
-                       name=DELETE,
-                       path="/orders",
-                       summary="Delete all orders",
-                       description="This can be done only by the logged in 
user."
-                                               
-                               )
-               public Ok deleteAllOrders() {
-                       store.deleteAllOrders();
-                       return OK;
-               }
+               name=DELETE,
+               path="/orders",
+               summary="Delete all orders",
+               description="This can be done only by the logged in user."
+       )
+       public Ok deleteAllOrders() {
+               store.deleteAllOrders();
+               return OK;
+       }
 
-       @Override
+       @Override /* PetStore */
        @RestMethod(
                name=GET,
                path="/store/inventory",
@@ -415,7 +400,7 @@ public class PetStoreResource extends BasicRest implements 
PetStore {
        // Users
        
//-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 
-       @Override
+       @Override /* PetStore */
        @RestMethod(
                name=GET,
                path="/user",
@@ -429,7 +414,7 @@ public class PetStoreResource extends BasicRest implements 
PetStore {
                return store.getUsers();
        }
 
-       @Override
+       @Override /* PetStore */
        @RestMethod(
                name=GET,
                path="/user/{username}",
@@ -442,7 +427,7 @@ public class PetStoreResource extends BasicRest implements 
PetStore {
                return store.getUser(username);
        }
 
-       @Override
+       @Override /* PetStore */
        @RestMethod(
                name=POST,
                path="/user",
@@ -457,7 +442,7 @@ public class PetStoreResource extends BasicRest implements 
PetStore {
                return OK;
        }
 
-       @Override
+       @Override /* PetStore */
        @RestMethod(
                name=POST,
                path="/user/createWithArray",
@@ -472,7 +457,7 @@ public class PetStoreResource extends BasicRest implements 
PetStore {
                return OK;
        }
 
-       @Override
+       @Override /* PetStore */
        @RestMethod(
                name=PUT,
                path="/user/{username}",
@@ -487,7 +472,7 @@ public class PetStoreResource extends BasicRest implements 
PetStore {
                return OK;
        }
 
-       @Override
+       @Override /* PetStore */
        @RestMethod(
                name=DELETE,
                path="/user/{username}",
@@ -498,22 +483,23 @@ public class PetStoreResource extends BasicRest 
implements PetStore {
                )
        )
        public Ok deleteUser(String username) throws InvalidUsername, 
IdNotFound, NotAcceptable {
-               store.removeUser(username);
+               store.deleteUser(username);
                return OK;
        }
+
+       @Override /* PetStore */
        @RestMethod(
-                       name=DELETE,
-                       path="/users",
-                       summary="Delete all users",
-                       description="This can be done only by the admin."
-                                               
-                               )
-               public Ok deleteAllUsers() {
-                       store.deleteAllUsers();
-                       return OK;
-               }
+               name=DELETE,
+               path="/users",
+               summary="Delete all users",
+               description="This can be done only by the admin."
+       )
+       public Ok deleteAllUsers() {
+               store.deleteAllUsers();
+               return OK;
+       }
 
-       @Override
+       @Override /* PetStore */
        @RestMethod(
                name=GET,
                path="/user/login",
@@ -522,8 +508,6 @@ public class PetStoreResource extends BasicRest implements 
PetStore {
                        tags="user"
                )
        )
-       
-       
        public Ok login(
                        String username,
                        String password,
@@ -543,7 +527,7 @@ public class PetStoreResource extends BasicRest implements 
PetStore {
                return OK;
        }
 
-       @Override
+       @Override /* PetStore */
        @RestMethod(
                name=GET,
                path="/user/logout",
diff --git 
a/juneau-petstore-server/src/main/java/org/apache/juneau/petstore/service/PetStoreService.java
 
b/juneau-petstore-server/src/main/java/org/apache/juneau/petstore/service/PetStoreService.java
index 540b75b..b030238 100644
--- 
a/juneau-petstore-server/src/main/java/org/apache/juneau/petstore/service/PetStoreService.java
+++ 
b/juneau-petstore-server/src/main/java/org/apache/juneau/petstore/service/PetStoreService.java
@@ -17,7 +17,6 @@ import static java.text.MessageFormat.*;
 import java.io.*;
 import java.util.*;
 
-
 import org.apache.juneau.json.*;
 import org.apache.juneau.parser.*;
 import org.apache.juneau.petstore.dto.*;
@@ -27,10 +26,6 @@ import org.apache.juneau.petstore.repository.UserRepository;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 
-
-
-
-
 /**
  * Pet store database application.
  * <p>
@@ -43,7 +38,6 @@ import 
org.springframework.transaction.annotation.Transactional;
  */
 public class PetStoreService {
 
-
        @Autowired
        private PetRepository petRepository;
 
@@ -52,6 +46,7 @@ public class PetStoreService {
 
        @Autowired
        private OrderRepository orderRepository;
+
        
//-----------------------------------------------------------------------------------------------------------------
        // Initialization methods.
        
//-----------------------------------------------------------------------------------------------------------------
@@ -66,7 +61,6 @@ public class PetStoreService {
         */
        public PetStoreService initDirect(PrintWriter w) throws ParseException, 
IOException {
 
-
                JsonParser parser = JsonParser.create().build();
 
                for (Pet x : petRepository.findAll()) {
@@ -204,7 +198,7 @@ public class PetStoreService {
         * @return The updated {@link Pet} object.
         * @throws IdNotFound Pet was not found.
         */
-    @Transactional(rollbackFor=Exception.class)
+       @Transactional(rollbackFor=Exception.class)
        public Pet update(UpdatePet u) throws IdNotFound {
                Pet pet =  petRepository.findById(u.getId()).orElseThrow(() -> 
new IdNotFound(u.getId(), Pet.class));
                return petRepository.save(pet.apply(u));
@@ -217,7 +211,7 @@ public class PetStoreService {
         * @return The updated {@link Order} object.
         * @throws IdNotFound Order was not found.
         */
-    @Transactional(rollbackFor=Exception.class)
+       @Transactional(rollbackFor=Exception.class)
        public Order update(Order o) throws IdNotFound {
                Order order =  
orderRepository.findById(o.getId()).orElseThrow(() -> new IdNotFound(o.getId(), 
Order.class));
                return orderRepository.save(order.apply(o));
@@ -231,7 +225,7 @@ public class PetStoreService {
         * @throws IdNotFound User was not found.
         * @throws InvalidUsername The username was not valid.
         */
-    @Transactional(rollbackFor=Exception.class)
+       @Transactional(rollbackFor=Exception.class)
        public User update(User u) throws IdNotFound, InvalidUsername {
                User user =  
userRepository.findByUsername(u.getUsername()).orElseThrow(() -> new 
IdNotFound(u.getUsername(), Order.class));
                return userRepository.save(user.apply(u));
@@ -243,34 +237,58 @@ public class PetStoreService {
         * @param id The pet ID.
         * @throws IdNotFound Pet was not found.
         */
-    @Transactional(rollbackFor=Exception.class)
-       public void removePet(long id) throws IdNotFound {
+       @Transactional(rollbackFor=Exception.class)
+       public void deletePet(long id) throws IdNotFound {
                petRepository.deleteById(id);
        }
 
        /**
+        * Removes all pets from the database.
+        */
+       @Transactional(rollbackFor=Exception.class)
+       public void deleteAllPets() {
+               petRepository.deleteAll();
+       }
+
+       /**
         * Removes an order from the database.
         *
         * @param id The order ID.
         * @throws IdNotFound Order was not found.
         */
-    @Transactional(rollbackFor=Exception.class)
-       public void removeOrder(long id) throws IdNotFound {
+       @Transactional(rollbackFor=Exception.class)
+       public void deleteOrder(long id) throws IdNotFound {
                orderRepository.deleteById(id);
        }
 
        /**
+        * Removes all orders from the database.
+        */
+       @Transactional(rollbackFor=Exception.class)
+       public void deleteAllOrders() {
+               orderRepository.deleteAll();
+       }
+
+       /**
         * Removes a user from the database.
         *
         * @param username The username.
         * @throws IdNotFound User was not found.
         */
-    @Transactional(rollbackFor=Exception.class)
-       public void removeUser(String username) throws IdNotFound {
+       @Transactional(rollbackFor=Exception.class)
+       public void deleteUser(String username) throws IdNotFound {
                userRepository.deleteByUsername(username);
        }
 
        /**
+        * Removes all users from the database.
+        */
+       @Transactional(rollbackFor=Exception.class)
+       public void deleteAllUsers() {
+               userRepository.deleteAll();
+       }
+
+       /**
         * Returns all pets with the specified statuses.
         *
         * @param status Pet statuses.
@@ -281,17 +299,6 @@ public class PetStoreService {
        }
 
        /**
-        * Returns all pets with the specified tags.
-        *
-        * @param tags Pet tags.
-        * @return Pets with the specified tags.
-        * @throws InvalidTag Tag name was invalid.
-        */
-       public Collection<Pet> getPetsByTags(String[] tags) throws InvalidTag {
-               return petRepository.findByTags(tags);
-       }
-
-       /**
         * Returns a summary of pet statuses and counts.
         *
         * @return A summary of pet statuses and counts.
@@ -331,22 +338,4 @@ public class PetStoreService {
        private InputStream getStream(String fileName) {
                return getClass().getResourceAsStream(fileName);
        }
-
-
-       public void deleteAllPets() {
-               petRepository.deleteAll();
-               
-       }
-
-
-       public void deleteAllUsers() {
-               userRepository.deleteAll();
-               
-       }
-
-
-       public void deleteAllOrders() {
-               orderRepository.deleteAll();
-               
-       }
 }
\ No newline at end of file
diff --git 
a/juneau-petstore-server/src/test/java/org/apache/juneau/petstore/test/MockTest.java
 
b/juneau-petstore-server/src/test/java/org/apache/juneau/petstore/test/MockTest.java
index 3131ad8..0416b2a 100644
--- 
a/juneau-petstore-server/src/test/java/org/apache/juneau/petstore/test/MockTest.java
+++ 
b/juneau-petstore-server/src/test/java/org/apache/juneau/petstore/test/MockTest.java
@@ -3,7 +3,6 @@ package org.apache.juneau.petstore.test;
 import java.io.IOException;
 import javax.servlet.ServletException;
 import org.apache.juneau.petstore.App;
-import org.apache.juneau.petstore.dto.PetStatus;
 import org.apache.juneau.petstore.repository.UserRepository;
 import org.apache.juneau.petstore.rest.PetStoreResource;
 import org.apache.juneau.rest.mock2.MockRest;
@@ -15,6 +14,7 @@ import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.ContextConfiguration;
 import org.springframework.test.context.junit4.SpringRunner;
 
+@SuppressWarnings("javadoc")
 @RunWith(SpringRunner.class)
 @ContextConfiguration(classes = { App.class })
 @SpringBootTest
@@ -121,35 +121,15 @@ public class MockTest {
        public void testfindPetByStatus() throws Exception {
 
                String petId = createTestPet();
-               PetStatus[] status = { PetStatus.AVAILABLE };
 
                petStoreRest
-               .request("GET", "/pet/findByStatus", status)
-               .execute()
-               .assertStatus(200)
-               .assertBody(
-                               "[{id:" + petId + 
",species:'BIRD',name:'Sunshine',tags:[],price:100.0,status:'AVAILABLE'}]");
-
-               deleteTestPets();
-       }
-
-       // Find pet by tags
-
-       @Test
-       public void testFindPetByTags() throws Exception {
-
-               String petId = createTestPet();
-               String[] tags = { "nice" };
-
-               petStoreRest
-               .request("GET", "/pet/findByTags", tags)
+               .get("/pet/findByStatus?status=AVAILABLE")
                .execute()
                .assertStatus(200)
                .assertBody(
                                "[{id:" + petId + 
",species:'BIRD',name:'Sunshine',tags:['nice'],price:100.0,status:'AVAILABLE'}]");
 
                deleteTestPets();
-
        }
 
        // Updating pet

Reply via email to