Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.springframework.context.annotation.Bean;
import org.springframework.core.Ordered;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
Expand Down Expand Up @@ -47,11 +46,6 @@ public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers)
resolvers.add(new HtmxResponseHandlerMethodArgumentResolver());
}

@Override
public void addReturnValueHandlers(List<HandlerMethodReturnValueHandler> handlers) {
handlers.add(new HtmxViewMethodReturnValueHandler());
}

@Override
public ExceptionHandlerExceptionResolver getExceptionHandlerExceptionResolver() {
return new HtmxExceptionHandlerExceptionResolver(handlerMethodHandler);
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,6 @@ public void testExceptionHandler() throws Exception {
.andExpect(content().string("View1\n"));
}

@Test
public void testExceptionHandlerWithHtmxView() throws Exception {

mockMvc.perform(get("/throw-exception-htmx-view").headers(htmxRequest()))
.andExpect(status().isOk())
.andExpect(header().string("HX-Retarget", "#container"))
.andExpect(content().string("View1\n"));
}

@Test
public void testExceptionHandlerUsingAnnotation() throws Exception {

Expand All @@ -69,15 +60,6 @@ public void testExceptionHandlerUsingAnnotation() throws Exception {
.andExpect(content().string("View1\n"));
}

@Test
public void testExceptionHandlerUsingAnnotationWithHtmxView() throws Exception {

mockMvc.perform(get("/throw-exception-annotated-htmx-view").headers(htmxRequest()))
.andExpect(status().isOk())
.andExpect(header().string("HX-Reswap", "none"))
.andExpect(content().string("View1\n"));
}

@Test
public void testLocationRedirect() throws Exception {

Expand Down Expand Up @@ -153,14 +135,6 @@ public void testLocationRedirectWithFlashAttributes() throws Exception {
.andExpect(flash().attribute("flash", "test"));
}

@Test
public void testMultipleViews() throws Exception {

mockMvc.perform(get("/multiple-views").headers(htmxRequest()))
.andExpect(status().isOk())
.andExpect(content().string("View1\nView2\n"));
}

@Test
public void testRedirect() throws Exception {

Expand Down Expand Up @@ -199,7 +173,7 @@ public void testRedirectViewNamePrefixFlashAttributes() throws Exception {
mockMvc.perform(get("/contextpath/redirect-view-name-prefix-flash-attributes").contextPath("/contextpath").headers(htmxRequest()))
.andExpect(status().isOk())
.andExpect(header().string("HX-Redirect", "/contextpath/test"))
.andExpect(flash().attribute("flash", "test"));;
.andExpect(flash().attribute("flash", "test"));
}

@Test
Expand Down Expand Up @@ -235,14 +209,6 @@ public void testRefreshViewName() throws Exception {
.andExpect(header().string("HX-Refresh", HtmxValue.TRUE));
}

@Test
public void testSingleView() throws Exception {

mockMvc.perform(get("/single-view").headers(htmxRequest()))
.andExpect(status().isOk())
.andExpect(content().string("View1\n"));
}

@Controller
static class TestController {

Expand All @@ -254,14 +220,6 @@ public String handleError(RuntimeException ex, HtmxRequest htmxRequest, HtmxResp
return "view1";
}

@ExceptionHandler(TestExceptionForHtmxViewHandler.class)
public HtmxView handleError(TestExceptionForHtmxViewHandler ex, HtmxRequest htmxRequest, HtmxResponse htmxResponse) {
if (htmxRequest.isHtmxRequest()) {
htmxResponse.setRetarget("#container");
}
return new HtmxView("view1");
}

@ExceptionHandler(TestExceptionForAnnotatedHandlerWithAnnotationOverride.class)
@HxRetarget("#container")
public String handleError(TestExceptionForAnnotatedHandlerWithAnnotationOverride ex, HtmxRequest htmxRequest, HtmxResponse htmxResponse) {
Expand All @@ -274,12 +232,6 @@ public String handleError(TestExceptionForAnnotatedHandler ex, HtmxRequest htmxR
return "view1";
}

@ExceptionHandler(TestExceptionForAnnotatedHandlerWithHtmxView.class)
@HxReswap(HxSwapType.NONE)
public HtmxView handleError(TestExceptionForAnnotatedHandlerWithHtmxView ex, HtmxRequest htmxRequest, HtmxResponse htmxResponse) {
return new HtmxView("view1");
}

@HxRequest
@GetMapping("/location-redirect")
public HtmxLocationRedirectView locationRedirect() {
Expand Down Expand Up @@ -370,12 +322,6 @@ public HtmxLocationRedirectView locationRedirectWithFlashAttributes(RedirectAttr
return new HtmxLocationRedirectView("/path");
}

@HxRequest
@GetMapping("/multiple-views")
public HtmxView multipleViews() {
return new HtmxView("view1", "view2");
}

@HxRequest
@GetMapping("/redirect")
public HtmxRedirectView redirect() {
Expand Down Expand Up @@ -430,24 +376,12 @@ public String refreshViewName() {
return "refresh:htmx";
}

@HxRequest
@GetMapping("/single-view")
public HtmxView singleView() {
return new HtmxView("view1");
}

@HxRequest
@GetMapping("/throw-exception")
public void throwException() {
throw new RuntimeException();
}

@HxRequest
@GetMapping("/throw-exception-htmx-view")
public void throwExceptionHtmxView() {
throw new TestExceptionForHtmxViewHandler();
}

@HxRequest
@GetMapping("/throw-exception-annotation-override")
@HxRetarget("controller-method-target")
Expand All @@ -461,26 +395,12 @@ public void throwExceptionForAnnotatedHandler() {
throw new TestExceptionForAnnotatedHandler();
}

@HxRequest
@GetMapping("/throw-exception-annotated-htmx-view")
public void throwExceptionForAnnotatedHandlerWithHtmxView() {
throw new TestExceptionForAnnotatedHandlerWithHtmxView();
}

}

static class TestExceptionForHtmxViewHandler extends RuntimeException {

}

static class TestExceptionForAnnotatedHandler extends RuntimeException {

}

static class TestExceptionForAnnotatedHandlerWithHtmxView extends RuntimeException {

}

static class TestExceptionForAnnotatedHandlerWithAnnotationOverride extends RuntimeException {

}
Expand Down