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
2 changes: 1 addition & 1 deletion build.savant
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ logbackVersion = "1.5.13"
slf4jVersion = "2.0.13"
testngVersion = "7.8.0"

project(group: "org.primeframework", name: "prime-mvc", version: "5.5.1", licenses: ["ApacheV2_0"]) {
project(group: "org.primeframework", name: "prime-mvc", version: "5.5.2", licenses: ["ApacheV2_0"]) {
workflow {
fetch {
// Dependency resolution order:
Expand Down
61 changes: 61 additions & 0 deletions src/test/java/org/example/action/RouterAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2025, Inversoft Inc., All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific
* language governing permissions and limitations under the License.
*/
package org.example.action;

import org.example.action.store.BaseStoreAction;
import org.primeframework.mvc.action.annotation.Action;
import org.primeframework.mvc.action.result.annotation.Forward;
import org.primeframework.mvc.action.result.annotation.Redirect;
import org.primeframework.mvc.action.result.annotation.Status;

/**
* @author Daniel DeGroff
*/
@Action("{action}/{counter}")
@Redirect(code = "redirect", uri = "/router/redirect/${counter}")
@Status(code = "stop")
@Forward.List({
@Forward(code = "submit-form", page = "/submit-form.ftl"),
@Forward(code = "meta-refresh", page = "/meta-refresh.ftl")
})
public class RouterAction extends BaseStoreAction {
public String action;

public int counter;

public String uri;

public String get() {
if ("redirect".equals(action)) {
counter++;
return counter < 6
? "redirect"
: "stop";
}

uri = "/router/redirect/" + counter;

if ("submit-form".equals(action)) {
return "submit-form";
}

if ("meta-refresh".equals(action)) {
return "meta-refresh";
}

throw new IllegalStateException();
}
}
158 changes: 158 additions & 0 deletions src/test/java/org/primeframework/mvc/GlobalTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1245,6 +1245,164 @@ public void get_redirect_withActual() throws Exception {
.with("bing", "bam")));
}

@Test
public void get_redirects_nested() throws Exception {
// See if we can nest many redirects
test.simulate(() -> simulator
.test("/router/redirect")
.get()
.assertStatusCode(302)
.assertRedirect("/router/redirect/1")
.followRedirect(r1 -> r1
.assertStatusCode(302)
.assertRedirect("/router/redirect/2")
.followRedirect(r2 -> r2
.assertStatusCode(302)
.assertRedirect("/router/redirect/3")
.followRedirect(r3 -> r3
.assertStatusCode(302)
.assertRedirect("/router/redirect/4")
.followRedirect(r4 -> r4
.assertStatusCode(302)
.assertRedirect("/router/redirect/5")
.followRedirect(r5 -> r5
.assertStatusCode(200)
.assertBodyIsEmpty()))))));

// See if we can be more civilized and come back out to the top level as well
test.simulate(() -> simulator
.test("/router/redirect")
.get()
.assertStatusCode(302)
.assertRedirect("/router/redirect/1")
.followRedirect(r1 -> r1
.assertStatusCode(302)
.assertRedirect("/router/redirect/2"))
.followRedirect(r2 -> r2
.assertStatusCode(302)
.assertRedirect("/router/redirect/3"))
.followRedirect(r3 -> r3
.assertStatusCode(302)
.assertRedirect("/router/redirect/4"))
.followRedirect(r4 -> r4
.assertStatusCode(302)
.assertRedirect("/router/redirect/5"))
.followRedirect(r5 -> r5
.assertStatusCode(200)
.assertBodyIsEmpty())
);

// Mix it up, go deep but not all the way
test.simulate(() -> simulator
.test("/router/redirect/")
.get()
.assertStatusCode(302)
.assertRedirect("/router/redirect/1")
.followRedirect(r1 -> r1
.assertStatusCode(302)
.assertRedirect("/router/redirect/2")
.followRedirect(r2 -> r2
.assertStatusCode(302)
.assertRedirect("/router/redirect/3")
.followRedirect(r3 -> r3
.assertStatusCode(302)
.assertRedirect("/router/redirect/4")
.followRedirect(r4 -> r4
.assertStatusCode(302)
.assertRedirect("/router/redirect/5")))))
.followRedirect(r5 -> r5
.assertStatusCode(200)
.assertBodyIsEmpty())
);

// Mix in a submitForm
test.simulate(() -> simulator
.test("/router/submit-form")
.get()
.assertStatusCode(200)
.assertHTML(html -> html.assertElementExists("form"))
.submitForm("form", r1 -> r1
.assertStatusCode(302)
.assertRedirect("/router/redirect/1")
.followRedirect(r2 -> r2
.assertStatusCode(302)
.assertRedirect("/router/redirect/2")
.followRedirect(r3 -> r3
.assertStatusCode(302)
.assertRedirect("/router/redirect/3")
.followRedirect(r4 -> r4
.assertStatusCode(302)
.assertRedirect("/router/redirect/4")
.followRedirect(r5 -> r5
.assertStatusCode(302)
.assertRedirect("/router/redirect/5")))))
.followRedirect(r6 -> r6
.assertStatusCode(200)
.assertBodyIsEmpty())
)
);

// Mix in a metaRefresh
test.simulate(() -> simulator
.test("/router/meta-refresh")
.get()
.assertStatusCode(200)
.assertHTML(html -> html.assertElementExists("meta[http-equiv=Refresh]"))
.followMetaRefresh(r1 -> r1
.assertStatusCode(302)
.assertRedirect("/router/redirect/1")
.followRedirect(r2 -> r2
.assertStatusCode(302)
.assertRedirect("/router/redirect/2")
.followRedirect(r3 -> r3
.assertStatusCode(302)
.assertRedirect("/router/redirect/3"))
.followRedirect(r4 -> r4
.assertStatusCode(302)
.assertRedirect("/router/redirect/4")
.followRedirect(r5 -> r5
.assertStatusCode(302)
.assertRedirect("/router/redirect/5"))))
.followRedirect(r6 -> r6
.assertStatusCode(200)
.assertBodyIsEmpty())
)
);

// Perform assertions on top-level
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Top level options

test.simulate(() -> simulator
.test("/router/meta-refresh")
.get()
.assertStatusCode(200)
.assertHTML(html -> html.assertElementExists("meta[http-equiv=Refresh]"))

// top-level
.followMetaRefresh()
.assertStatusCode(302)
.assertRedirect("/router/redirect/1")

// nested
.followRedirect(r2 -> r2
.assertStatusCode(302)
.assertRedirect("/router/redirect/2")
.followRedirect()
.assertStatusCode(302)
.assertRedirect("/router/redirect/3"))
.followRedirect(r4 -> r4
.assertStatusCode(302)
.assertRedirect("/router/redirect/4")
.followRedirect(r5 -> r5
.assertStatusCode(302)
.assertRedirect("/router/redirect/5")))

// top-level
.followRedirect()
.assertStatusCode(200)
.assertBodyIsEmpty()

);
}

@Test
public void get_secure() throws Exception {
test.simulate(() -> simulator.test("/secure")
Expand Down
Loading