|
62 | 62 | import org.springframework.core.annotation.AnnotationAwareOrderComparator;
|
63 | 63 | import org.springframework.core.annotation.AnnotationConfigurationException;
|
64 | 64 | import org.springframework.core.annotation.Order;
|
| 65 | +import org.springframework.data.domain.Page; |
| 66 | +import org.springframework.data.domain.PageImpl; |
| 67 | +import org.springframework.data.domain.Slice; |
| 68 | +import org.springframework.data.domain.SliceImpl; |
| 69 | +import org.springframework.data.geo.Distance; |
| 70 | +import org.springframework.data.geo.GeoPage; |
| 71 | +import org.springframework.data.geo.GeoResult; |
| 72 | +import org.springframework.data.geo.GeoResults; |
65 | 73 | import org.springframework.http.HttpStatusCode;
|
66 | 74 | import org.springframework.http.ResponseEntity;
|
67 | 75 | import org.springframework.security.access.AccessDeniedException;
|
@@ -733,6 +741,28 @@ public void findByIdWhenUnauthorizedResultThenDenies() {
|
733 | 741 | assertThatExceptionOfType(AccessDeniedException.class).isThrownBy(flight::getAltitude);
|
734 | 742 | }
|
735 | 743 |
|
| 744 | + @Test |
| 745 | + @WithMockUser(authorities = "airplane:read") |
| 746 | + public void findGeoResultByIdWhenAuthorizedResultThenAuthorizes() { |
| 747 | + this.spring.register(AuthorizeResultConfig.class).autowire(); |
| 748 | + FlightRepository flights = this.spring.getContext().getBean(FlightRepository.class); |
| 749 | + GeoResult<Flight> geoResultFlight = flights.findGeoResultFlightById("1"); |
| 750 | + Flight flight = geoResultFlight.getContent(); |
| 751 | + assertThatNoException().isThrownBy(flight::getAltitude); |
| 752 | + assertThatNoException().isThrownBy(flight::getSeats); |
| 753 | + } |
| 754 | + |
| 755 | + @Test |
| 756 | + @WithMockUser(authorities = "seating:read") |
| 757 | + public void findGeoResultByIdWhenUnauthorizedResultThenDenies() { |
| 758 | + this.spring.register(AuthorizeResultConfig.class).autowire(); |
| 759 | + FlightRepository flights = this.spring.getContext().getBean(FlightRepository.class); |
| 760 | + GeoResult<Flight> geoResultFlight = flights.findGeoResultFlightById("1"); |
| 761 | + Flight flight = geoResultFlight.getContent(); |
| 762 | + assertThatNoException().isThrownBy(flight::getSeats); |
| 763 | + assertThatExceptionOfType(AccessDeniedException.class).isThrownBy(flight::getAltitude); |
| 764 | + } |
| 765 | + |
736 | 766 | @Test
|
737 | 767 | @WithMockUser(authorities = "airplane:read")
|
738 | 768 | public void findByIdWhenAuthorizedResponseEntityThenAuthorizes() {
|
@@ -804,6 +834,46 @@ public void findAllWhenPostFilterThenFilters() {
|
804 | 834 | .doesNotContain("Kevin Mitnick"));
|
805 | 835 | }
|
806 | 836 |
|
| 837 | + @Test |
| 838 | + @WithMockUser(authorities = "airplane:read") |
| 839 | + public void findPageWhenPostFilterThenFilters() { |
| 840 | + this.spring.register(AuthorizeResultConfig.class).autowire(); |
| 841 | + FlightRepository flights = this.spring.getContext().getBean(FlightRepository.class); |
| 842 | + flights.findPage() |
| 843 | + .forEach((flight) -> assertThat(flight.getPassengers()).extracting(Passenger::getName) |
| 844 | + .doesNotContain("Kevin Mitnick")); |
| 845 | + } |
| 846 | + |
| 847 | + @Test |
| 848 | + @WithMockUser(authorities = "airplane:read") |
| 849 | + public void findSliceWhenPostFilterThenFilters() { |
| 850 | + this.spring.register(AuthorizeResultConfig.class).autowire(); |
| 851 | + FlightRepository flights = this.spring.getContext().getBean(FlightRepository.class); |
| 852 | + flights.findSlice() |
| 853 | + .forEach((flight) -> assertThat(flight.getPassengers()).extracting(Passenger::getName) |
| 854 | + .doesNotContain("Kevin Mitnick")); |
| 855 | + } |
| 856 | + |
| 857 | + @Test |
| 858 | + @WithMockUser(authorities = "airplane:read") |
| 859 | + public void findGeoPageWhenPostFilterThenFilters() { |
| 860 | + this.spring.register(AuthorizeResultConfig.class).autowire(); |
| 861 | + FlightRepository flights = this.spring.getContext().getBean(FlightRepository.class); |
| 862 | + flights.findGeoPage() |
| 863 | + .forEach((flight) -> assertThat(flight.getContent().getPassengers()).extracting(Passenger::getName) |
| 864 | + .doesNotContain("Kevin Mitnick")); |
| 865 | + } |
| 866 | + |
| 867 | + @Test |
| 868 | + @WithMockUser(authorities = "airplane:read") |
| 869 | + public void findGeoResultsWhenPostFilterThenFilters() { |
| 870 | + this.spring.register(AuthorizeResultConfig.class).autowire(); |
| 871 | + FlightRepository flights = this.spring.getContext().getBean(FlightRepository.class); |
| 872 | + flights.findGeoResults() |
| 873 | + .forEach((flight) -> assertThat(flight.getContent().getPassengers()).extracting(Passenger::getName) |
| 874 | + .doesNotContain("Kevin Mitnick")); |
| 875 | + } |
| 876 | + |
807 | 877 | @Test
|
808 | 878 | @WithMockUser(authorities = "airplane:read")
|
809 | 879 | public void findAllWhenPreFilterThenFilters() {
|
@@ -1688,10 +1758,39 @@ Iterator<Flight> findAll() {
|
1688 | 1758 | return this.flights.values().iterator();
|
1689 | 1759 | }
|
1690 | 1760 |
|
| 1761 | + Page<Flight> findPage() { |
| 1762 | + return new PageImpl<>(new ArrayList<>(this.flights.values())); |
| 1763 | + } |
| 1764 | + |
| 1765 | + Slice<Flight> findSlice() { |
| 1766 | + return new SliceImpl<>(new ArrayList<>(this.flights.values())); |
| 1767 | + } |
| 1768 | + |
| 1769 | + GeoPage<Flight> findGeoPage() { |
| 1770 | + List<GeoResult<Flight>> results = new ArrayList<>(); |
| 1771 | + for (Flight flight : this.flights.values()) { |
| 1772 | + results.add(new GeoResult<>(flight, new Distance(flight.altitude))); |
| 1773 | + } |
| 1774 | + return new GeoPage<>(new GeoResults<>(results)); |
| 1775 | + } |
| 1776 | + |
| 1777 | + GeoResults<Flight> findGeoResults() { |
| 1778 | + List<GeoResult<Flight>> results = new ArrayList<>(); |
| 1779 | + for (Flight flight : this.flights.values()) { |
| 1780 | + results.add(new GeoResult<>(flight, new Distance(flight.altitude))); |
| 1781 | + } |
| 1782 | + return new GeoResults<>(results); |
| 1783 | + } |
| 1784 | + |
1691 | 1785 | Flight findById(String id) {
|
1692 | 1786 | return this.flights.get(id);
|
1693 | 1787 | }
|
1694 | 1788 |
|
| 1789 | + GeoResult<Flight> findGeoResultFlightById(String id) { |
| 1790 | + Flight flight = this.flights.get(id); |
| 1791 | + return new GeoResult<>(flight, new Distance(flight.altitude)); |
| 1792 | + } |
| 1793 | + |
1695 | 1794 | Flight save(Flight flight) {
|
1696 | 1795 | this.flights.put(flight.getId(), flight);
|
1697 | 1796 | return flight;
|
|
0 commit comments