diff --git a/htmx-spring-boot/src/test/java/io/github/wimdeblauwe/htmx/spring/boot/mvc/HtmxHandlerInterceptorTest.java b/htmx-spring-boot/src/test/java/io/github/wimdeblauwe/htmx/spring/boot/mvc/HtmxHandlerInterceptorTest.java index cf296ee..fa610f4 100644 --- a/htmx-spring-boot/src/test/java/io/github/wimdeblauwe/htmx/spring/boot/mvc/HtmxHandlerInterceptorTest.java +++ b/htmx-spring-boot/src/test/java/io/github/wimdeblauwe/htmx/spring/boot/mvc/HtmxHandlerInterceptorTest.java @@ -4,7 +4,12 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.security.test.context.support.WithMockUser; +import org.springframework.stereotype.Controller; +import org.springframework.test.context.ContextConfiguration; import org.springframework.test.web.servlet.MockMvc; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; import static org.hamcrest.Matchers.not; import static org.hamcrest.collection.IsIterableContainingInRelativeOrder.containsInRelativeOrder; @@ -12,7 +17,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -@WebMvcTest(TestController.class) +@WebMvcTest(HtmxHandlerInterceptorTest.TestController.class) +@ContextConfiguration(classes = HtmxHandlerInterceptorTest.TestController.class) @WithMockUser class HtmxHandlerInterceptorTest { @@ -231,4 +237,176 @@ public void testHxReselect() throws Exception { .andExpect(header().string("HX-Reselect", "#target")); } + @Controller + @RequestMapping("/") + static class TestController { + + @GetMapping("/without-trigger") + @ResponseBody + public String methodWithoutAnnotations() { + return ""; + } + + @GetMapping("/with-trigger") + @HxTrigger("eventTriggered") + @ResponseBody + public String methodWithHxTrigger() { + return ""; + } + + @GetMapping("/with-trigger-multiple-events") + @HxTrigger({ "event1", "event2" }) + @ResponseBody + public String methodWithHxTriggerAndMultipleEvents() { + return ""; + } + + @GetMapping("/with-trigger-after-settle") + @HxTriggerAfterSettle("eventTriggered") + @ResponseBody + public String methodWithHxTriggerAfterSettle() { + return ""; + } + + @GetMapping("/with-trigger-after-settle-multiple-events") + @HxTriggerAfterSettle({ "event1", "event2" }) + @ResponseBody + public String methodWithHxTriggerAfterSettleAndMultipleEvents() { + return ""; + } + + @GetMapping("/with-trigger-after-swap") + @HxTriggerAfterSwap("eventTriggered") + @ResponseBody + public String methodWithHxTriggerAfterSwap() { + return ""; + } + + @GetMapping("/with-trigger-after-swap-multiple-events") + @HxTriggerAfterSwap({ "event1", "event2" }) + @ResponseBody + public String methodWithHxTriggerAfterSwapAndMultipleEvents() { + return ""; + } + + @GetMapping("/with-triggers") + @HxTrigger({ "event1", "event2" }) + @HxTriggerAfterSettle({ "event1", "event2" }) + @HxTriggerAfterSwap({ "event1", "event2" }) + @ResponseBody + public String methodWithHxTriggers() { + return ""; + } + + @GetMapping("/updates-sidebar") + @HxUpdatesSidebar + @ResponseBody + public String updatesSidebar() { + return ""; + } + + @GetMapping("/hx-trigger-alias-for") + @HxTriggerWithAliasFor(event = "updateTrigger") + @ResponseBody + public String hxTriggerWithAliasForOverride() { + return ""; + } + + @GetMapping("/hx-refresh") + @HxRefresh + @ResponseBody + public String hxRefresh() { + return ""; + } + + @GetMapping("/hx-vary") + @ResponseBody + public String hxVary() { + return ""; + } + + @GetMapping("/hx-location-without-context-data") + @HxLocation("/path") + @ResponseBody + public String hxLocationWithoutContextData() { + return ""; + } + + @GetMapping("/hx-location-with-context-data") + @HxLocation(path = "/path", source = "source", event = "event", handler = "handler", target = "target", swap = "swap", select = "select") + @ResponseBody + public String hxLocationWithContextData() { + return ""; + } + + @GetMapping("/hx-push-url-path") + @HxPushUrl("/path") + @ResponseBody + public String hxPushUrlPath() { + return ""; + } + + @GetMapping("/hx-push-url") + @HxPushUrl + @ResponseBody + public String hxPushUrl() { + return ""; + } + + @GetMapping("/hx-push-url-false") + @HxPushUrl(HtmxValue.FALSE) + @ResponseBody + public String hxPushUrlFalse() { + return ""; + } + + @GetMapping("/hx-redirect") + @HxRedirect("/path") + @ResponseBody + public String hxRedirect() { + return ""; + } + + @GetMapping("/hx-replace-url-path") + @HxReplaceUrl("/path") + @ResponseBody + public String hxReplaceUrlPath() { + return ""; + } + @GetMapping("/hx-replace-url") + @HxReplaceUrl + @ResponseBody + public String hxReplaceUrl() { + return ""; + } + @GetMapping("/hx-replace-url-false") + @HxReplaceUrl(HtmxValue.FALSE) + @ResponseBody + public String hxReplaceUrlFalse() { + return ""; + } + + @GetMapping("/hx-reswap") + @HxReswap(value = HxSwapType.INNER_HTML, swap = 300) + @ResponseBody + public String hxReswap() { + return ""; + } + + @GetMapping("/hx-retarget") + @HxRetarget("#target") + @ResponseBody + public String hxRetarget() { + return ""; + } + + @GetMapping("/hx-reselect") + @HxReselect("#target") + @ResponseBody + public String hxReselect() { + return ""; + } + + } + } diff --git a/htmx-spring-boot/src/test/java/io/github/wimdeblauwe/htmx/spring/boot/mvc/HtmxHandlerMethodArgumentResolverTest.java b/htmx-spring-boot/src/test/java/io/github/wimdeblauwe/htmx/spring/boot/mvc/HtmxHandlerMethodArgumentResolverTest.java index 5908013..d9d2e20 100644 --- a/htmx-spring-boot/src/test/java/io/github/wimdeblauwe/htmx/spring/boot/mvc/HtmxHandlerMethodArgumentResolverTest.java +++ b/htmx-spring-boot/src/test/java/io/github/wimdeblauwe/htmx/spring/boot/mvc/HtmxHandlerMethodArgumentResolverTest.java @@ -5,8 +5,14 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.security.test.context.support.WithMockUser; +import org.springframework.stereotype.Controller; +import org.springframework.stereotype.Service; +import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.bean.override.mockito.MockitoBean; import org.springframework.test.web.servlet.MockMvc; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.verify; @@ -14,7 +20,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view; -@WebMvcTest(HtmxHandlerMethodArgumentResolverTestController.class) +@WebMvcTest(HtmxHandlerMethodArgumentResolverTest.TestController.class) +@ContextConfiguration(classes = HtmxHandlerMethodArgumentResolverTest.TestController.class) @WithMockUser class HtmxHandlerMethodArgumentResolverTest { @Autowired @@ -165,7 +172,6 @@ void testHxRequestAnnotation() throws Exception { mockMvc.perform(get("/method-arg-resolver/users") .header("HX-Request", "true")) .andExpect(view().name("users :: list")); - ; } @Test @@ -173,13 +179,63 @@ void testHxRequestAnnotationInheritance() throws Exception { mockMvc.perform(get("/method-arg-resolver/users/inherited") .header("HX-Request", "true")) .andExpect(view().name("users :: list")); - ; } @Test void testHxRequestSameUrlNoAnnotation() throws Exception { mockMvc.perform(get("/method-arg-resolver/users")) .andExpect(view().name("users")); - ; } + + @Controller + @RequestMapping("/method-arg-resolver") + static class TestController { + + @Autowired + private TestService service; + + @GetMapping + @ResponseBody + public String htmxRequestDetails(HtmxRequest details) { + service.doSomething(details); + + return ""; + } + + @GetMapping("/users") + @HxRequest + public String htmxRequest(HtmxRequest details) { + service.doSomething(details); + + return "users :: list"; + } + + @GetMapping("/users") + public String normalRequest(HtmxRequest details) { + service.doSomething(details); + + return "users"; + } + + @HxGetMapping("/users/inherited") + public String htmxRequestInheritance(HtmxRequest details) { + service.doSomething(details); + + return "users :: list"; + } + + @GetMapping("/users/inherited") + public String normalRequestInheritance(HtmxRequest details) { + service.doSomething(details); + + return "users"; + } + } + + @Service + public class TestService { + void doSomething(HtmxRequest details) { + } + } + } diff --git a/htmx-spring-boot/src/test/java/io/github/wimdeblauwe/htmx/spring/boot/mvc/HtmxHandlerMethodArgumentResolverTestController.java b/htmx-spring-boot/src/test/java/io/github/wimdeblauwe/htmx/spring/boot/mvc/HtmxHandlerMethodArgumentResolverTestController.java deleted file mode 100644 index d85acd1..0000000 --- a/htmx-spring-boot/src/test/java/io/github/wimdeblauwe/htmx/spring/boot/mvc/HtmxHandlerMethodArgumentResolverTestController.java +++ /dev/null @@ -1,54 +0,0 @@ -package io.github.wimdeblauwe.htmx.spring.boot.mvc; - -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.ResponseBody; - -@Controller -@RequestMapping("/method-arg-resolver") -public class HtmxHandlerMethodArgumentResolverTestController { - - private final TestService service; - - public HtmxHandlerMethodArgumentResolverTestController(TestService service) { - this.service = service; - } - - @GetMapping - @ResponseBody - public String htmxRequestDetails(HtmxRequest details) { - service.doSomething(details); - - return ""; - } - - @GetMapping("/users") - @HxRequest - public String htmxRequest(HtmxRequest details) { - service.doSomething(details); - - return "users :: list"; - } - - @GetMapping("/users") - public String normalRequest(HtmxRequest details) { - service.doSomething(details); - - return "users"; - } - - @HxGetMapping("/users/inherited") - public String htmxRequestInheritance(HtmxRequest details) { - service.doSomething(details); - - return "users :: list"; - } - - @GetMapping("/users/inherited") - public String normalRequestInheritance(HtmxRequest details) { - service.doSomething(details); - - return "users"; - } -} diff --git a/htmx-spring-boot/src/test/java/io/github/wimdeblauwe/htmx/spring/boot/mvc/HtmxRequestMappingHandlerMappingTest.java b/htmx-spring-boot/src/test/java/io/github/wimdeblauwe/htmx/spring/boot/mvc/HtmxRequestMappingHandlerMappingTest.java index 8381498..2f22f7b 100644 --- a/htmx-spring-boot/src/test/java/io/github/wimdeblauwe/htmx/spring/boot/mvc/HtmxRequestMappingHandlerMappingTest.java +++ b/htmx-spring-boot/src/test/java/io/github/wimdeblauwe/htmx/spring/boot/mvc/HtmxRequestMappingHandlerMappingTest.java @@ -4,14 +4,19 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.security.test.context.support.WithMockUser; +import org.springframework.stereotype.Controller; +import org.springframework.test.context.ContextConfiguration; import org.springframework.test.web.servlet.MockMvc; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ResponseBody; import static io.github.wimdeblauwe.htmx.spring.boot.mvc.HtmxRequestHeader.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -@WebMvcTest(HtmxRequestMappingHandlerMappingTestController.class) +@WebMvcTest(HtmxRequestMappingHandlerMappingTest.TestController.class) +@ContextConfiguration(classes = HtmxRequestMappingHandlerMappingTest.TestController.class) @WithMockUser public class HtmxRequestMappingHandlerMappingTest { @@ -132,4 +137,80 @@ void testHxRequestValueWithHxHeaderTriggerFoo() throws Exception { .andExpect(content().string("foo")); } + + @Controller + static class TestController { + + @HxRequest + @GetMapping("/hx-request") + @ResponseBody + public String hxRequest() { + return "hx-request"; + } + + @HxRequest(boosted = false) + @GetMapping("/hx-request-ignore-boosted") + @ResponseBody + public String hxRequestIgnoreBoosted() { + return "boosted-ignored"; + } + + @HxRequest(target = "bar") + @GetMapping("/hx-request-target") + @ResponseBody + public String hxRequestTargetBar() { + return "bar"; + } + + @HxRequest(target = "foo") + @GetMapping("/hx-request-target") + @ResponseBody + public String hxRequestTargetFoo() { + return "foo"; + } + + @HxRequest(triggerId = "bar") + @GetMapping("/hx-request-trigger") + @ResponseBody + public String hxRequestTriggerIdBar() { + return "bar"; + } + + @HxRequest(triggerId = "foo") + @GetMapping("/hx-request-trigger") + @ResponseBody + public String hxRequestTriggerIdFoo() { + return "foo"; + } + + @HxRequest(triggerName = "bar") + @GetMapping("/hx-request-trigger") + @ResponseBody + public String hxRequestTriggerNameBar() { + return "bar"; + } + + @HxRequest(triggerName = "foo") + @GetMapping("/hx-request-trigger") + @ResponseBody + public String hxRequestTriggerNameFoo() { + return "foo"; + } + + @HxRequest("bar") + @GetMapping("/hx-request-value") + @ResponseBody + public String hxRequestValueBar() { + return "bar"; + } + + @HxRequest("foo") + @GetMapping("/hx-request-value") + @ResponseBody + public String hxRequestValueFoo() { + return "foo"; + } + + } + } diff --git a/htmx-spring-boot/src/test/java/io/github/wimdeblauwe/htmx/spring/boot/mvc/HtmxRequestMappingHandlerMappingTestController.java b/htmx-spring-boot/src/test/java/io/github/wimdeblauwe/htmx/spring/boot/mvc/HtmxRequestMappingHandlerMappingTestController.java deleted file mode 100644 index aaaba6c..0000000 --- a/htmx-spring-boot/src/test/java/io/github/wimdeblauwe/htmx/spring/boot/mvc/HtmxRequestMappingHandlerMappingTestController.java +++ /dev/null @@ -1,80 +0,0 @@ -package io.github.wimdeblauwe.htmx.spring.boot.mvc; - -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.ResponseBody; - -@Controller -public class HtmxRequestMappingHandlerMappingTestController { - - @HxRequest - @GetMapping("/hx-request") - @ResponseBody - public String hxRequest() { - return "hx-request"; - } - - @HxRequest(boosted = false) - @GetMapping("/hx-request-ignore-boosted") - @ResponseBody - public String hxRequestIgnoreBoosted() { - return "boosted-ignored"; - } - - @HxRequest(target = "bar") - @GetMapping("/hx-request-target") - @ResponseBody - public String hxRequestTargetBar() { - return "bar"; - } - - @HxRequest(target = "foo") - @GetMapping("/hx-request-target") - @ResponseBody - public String hxRequestTargetFoo() { - return "foo"; - } - - @HxRequest(triggerId = "bar") - @GetMapping("/hx-request-trigger") - @ResponseBody - public String hxRequestTriggerIdBar() { - return "bar"; - } - - @HxRequest(triggerId = "foo") - @GetMapping("/hx-request-trigger") - @ResponseBody - public String hxRequestTriggerIdFoo() { - return "foo"; - } - - @HxRequest(triggerName = "bar") - @GetMapping("/hx-request-trigger") - @ResponseBody - public String hxRequestTriggerNameBar() { - return "bar"; - } - - @HxRequest(triggerName = "foo") - @GetMapping("/hx-request-trigger") - @ResponseBody - public String hxRequestTriggerNameFoo() { - return "foo"; - } - - @HxRequest("bar") - @GetMapping("/hx-request-value") - @ResponseBody - public String hxRequestValueBar() { - return "bar"; - } - - @HxRequest("foo") - @GetMapping("/hx-request-value") - @ResponseBody - public String hxRequestValueFoo() { - return "foo"; - } - -} diff --git a/htmx-spring-boot/src/test/java/io/github/wimdeblauwe/htmx/spring/boot/mvc/TestController.java b/htmx-spring-boot/src/test/java/io/github/wimdeblauwe/htmx/spring/boot/mvc/TestController.java deleted file mode 100644 index 23aeee9..0000000 --- a/htmx-spring-boot/src/test/java/io/github/wimdeblauwe/htmx/spring/boot/mvc/TestController.java +++ /dev/null @@ -1,178 +0,0 @@ -package io.github.wimdeblauwe.htmx.spring.boot.mvc; - -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.ResponseBody; - -@Controller -@RequestMapping("/") -public class TestController { - - @GetMapping("/without-trigger") - @ResponseBody - public String methodWithoutAnnotations() { - return ""; - } - - @GetMapping("/with-trigger") - @HxTrigger("eventTriggered") - @ResponseBody - public String methodWithHxTrigger() { - return ""; - } - - @GetMapping("/with-trigger-multiple-events") - @HxTrigger({ "event1", "event2" }) - @ResponseBody - public String methodWithHxTriggerAndMultipleEvents() { - return ""; - } - - @GetMapping("/with-trigger-after-settle") - @HxTriggerAfterSettle("eventTriggered") - @ResponseBody - public String methodWithHxTriggerAfterSettle() { - return ""; - } - - @GetMapping("/with-trigger-after-settle-multiple-events") - @HxTriggerAfterSettle({ "event1", "event2" }) - @ResponseBody - public String methodWithHxTriggerAfterSettleAndMultipleEvents() { - return ""; - } - - @GetMapping("/with-trigger-after-swap") - @HxTriggerAfterSwap("eventTriggered") - @ResponseBody - public String methodWithHxTriggerAfterSwap() { - return ""; - } - - @GetMapping("/with-trigger-after-swap-multiple-events") - @HxTriggerAfterSwap({ "event1", "event2" }) - @ResponseBody - public String methodWithHxTriggerAfterSwapAndMultipleEvents() { - return ""; - } - - @GetMapping("/with-triggers") - @HxTrigger({ "event1", "event2" }) - @HxTriggerAfterSettle({ "event1", "event2" }) - @HxTriggerAfterSwap({ "event1", "event2" }) - @ResponseBody - public String methodWithHxTriggers() { - return ""; - } - - @GetMapping("/updates-sidebar") - @HxUpdatesSidebar - @ResponseBody - public String updatesSidebar() { - return ""; - } - - @GetMapping("/hx-trigger-alias-for") - @HxTriggerWithAliasFor(event = "updateTrigger") - @ResponseBody - public String hxTriggerWithAliasForOverride() { - return ""; - } - - @GetMapping("/hx-refresh") - @HxRefresh - @ResponseBody - public String hxRefresh() { - return ""; - } - - @GetMapping("/hx-vary") - @ResponseBody - public String hxVary() { - return ""; - } - - @GetMapping("/hx-location-without-context-data") - @HxLocation("/path") - @ResponseBody - public String hxLocationWithoutContextData() { - return ""; - } - - @GetMapping("/hx-location-with-context-data") - @HxLocation(path = "/path", source = "source", event = "event", handler = "handler", target = "target", swap = "swap", select = "select") - @ResponseBody - public String hxLocationWithContextData() { - return ""; - } - - @GetMapping("/hx-push-url-path") - @HxPushUrl("/path") - @ResponseBody - public String hxPushUrlPath() { - return ""; - } - - @GetMapping("/hx-push-url") - @HxPushUrl - @ResponseBody - public String hxPushUrl() { - return ""; - } - - @GetMapping("/hx-push-url-false") - @HxPushUrl(HtmxValue.FALSE) - @ResponseBody - public String hxPushUrlFalse() { - return ""; - } - - @GetMapping("/hx-redirect") - @HxRedirect("/path") - @ResponseBody - public String hxRedirect() { - return ""; - } - - @GetMapping("/hx-replace-url-path") - @HxReplaceUrl("/path") - @ResponseBody - public String hxReplaceUrlPath() { - return ""; - } - @GetMapping("/hx-replace-url") - @HxReplaceUrl - @ResponseBody - public String hxReplaceUrl() { - return ""; - } - @GetMapping("/hx-replace-url-false") - @HxReplaceUrl(HtmxValue.FALSE) - @ResponseBody - public String hxReplaceUrlFalse() { - return ""; - } - - @GetMapping("/hx-reswap") - @HxReswap(value = HxSwapType.INNER_HTML, swap = 300) - @ResponseBody - public String hxReswap() { - return ""; - } - - @GetMapping("/hx-retarget") - @HxRetarget("#target") - @ResponseBody - public String hxRetarget() { - return ""; - } - - @GetMapping("/hx-reselect") - @HxReselect("#target") - @ResponseBody - public String hxReselect() { - return ""; - } - -} diff --git a/htmx-spring-boot/src/test/java/io/github/wimdeblauwe/htmx/spring/boot/mvc/TestService.java b/htmx-spring-boot/src/test/java/io/github/wimdeblauwe/htmx/spring/boot/mvc/TestService.java deleted file mode 100644 index 1025a6d..0000000 --- a/htmx-spring-boot/src/test/java/io/github/wimdeblauwe/htmx/spring/boot/mvc/TestService.java +++ /dev/null @@ -1,10 +0,0 @@ -package io.github.wimdeblauwe.htmx.spring.boot.mvc; - -import org.springframework.stereotype.Service; - -@Service -public class TestService { - void doSomething(HtmxRequest details) { - - } -}