Skip to content

Commit

Permalink
Add tests for cookie behavior verification
Browse files Browse the repository at this point in the history
It seems that the problem described in #354 is some client specific
issue. Both tests could not reproduce the error on framework level, so
we might close this issue for now.

see: #354
  • Loading branch information
erdlet committed Dec 5, 2022
1 parent 6a1c40f commit df1ca9c
Show file tree
Hide file tree
Showing 14 changed files with 480 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.eclipse.krazo.test.redirectboundary;

import jakarta.ws.rs.ApplicationPath;
import jakarta.ws.rs.core.Application;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.krazo.Properties;

@ApplicationPath("resources")
public class RedirectApplication extends Application {

@Override
public Map<String, Object> getProperties() {
final Map<String, Object> props = new HashMap<>();
props.put(Properties.REDIRECT_SCOPE_COOKIES, true);
props.put(Properties.REDIRECT_SCOPE_COOKIE_NAME, "custom_cookie");
return props;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.eclipse.krazo.test.redirectboundary;

import jakarta.mvc.RedirectScoped;
import java.io.Serializable;
import java.util.Objects;

@RedirectScoped
public class RedirectBean implements Serializable {

private static final long serialVersionUID = -1;

private String message;

public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
RedirectBean that = (RedirectBean) o;
return Objects.equals(message, that.message);
}

@Override
public int hashCode() {
return Objects.hash(message);
}

@Override
public String toString() {
return "RedirectBean{" +
"message='" + message + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.eclipse.krazo.test.redirectboundary;

import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Inject;
import jakarta.mvc.Controller;
import jakarta.mvc.Models;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;

@Path("/a")
@RequestScoped
@Controller
public class RedirectBoundaryAController {

@Inject
RedirectBean bean;

@Inject
Models models;

@GET
public String index() {
models.put("redirectBeanValue", bean.getMessage());
return "a.jsp";
}

@POST
@Path("/toA")
public String postA() {
bean.setMessage("Redirect to A!");

return "redirect:/a";
}

@POST
@Path("/toB")
public String postB() {
bean.setMessage("Redirect to B!");

return "redirect:/b";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.eclipse.krazo.test.redirectboundary;

import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Inject;
import jakarta.mvc.Controller;
import jakarta.mvc.Models;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;

@Path("/b")
@RequestScoped
@Controller
public class RedirectBoundaryBController {

@Inject
RedirectBean bean;

@Inject
Models models;

@GET
public String index() {
models.put("redirectBeanValue", bean.getMessage());
return "b.jsp";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.eclipse.krazo.test.redirectboundaryonroot;

import jakarta.ws.rs.ApplicationPath;
import jakarta.ws.rs.core.Application;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.krazo.Properties;

@ApplicationPath("")
public class RedirectApplication extends Application {

@Override
public Map<String, Object> getProperties() {
final Map<String, Object> props = new HashMap<>();
props.put(Properties.REDIRECT_SCOPE_COOKIES, true);
props.put(Properties.REDIRECT_SCOPE_COOKIE_NAME, "custom_cookie");
return props;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.eclipse.krazo.test.redirectboundaryonroot;

import jakarta.mvc.RedirectScoped;
import java.io.Serializable;
import java.util.Objects;

@RedirectScoped
public class RedirectBean implements Serializable {

private static final long serialVersionUID = -1;

private String message;

public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
RedirectBean that = (RedirectBean) o;
return Objects.equals(message, that.message);
}

@Override
public int hashCode() {
return Objects.hash(message);
}

@Override
public String toString() {
return "RedirectBean{" +
"message='" + message + '\'' +
'}';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.eclipse.krazo.test.redirectboundaryonroot;

import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Inject;
import jakarta.mvc.Controller;
import jakarta.mvc.Models;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;

@Path("/a")
@RequestScoped
@Controller
public class RedirectBoundaryAController {

@Inject
RedirectBean bean;

@Inject
Models models;

@GET
public String index() {
models.put("redirectBeanValue", bean.getMessage());
return "a.jsp";
}

@POST
@Path("/toA")
public String postA() {
bean.setMessage("Redirect to A!");

return "redirect:/a";
}

@POST
@Path("/toB")
public String postB() {
bean.setMessage("Redirect to B!");

return "redirect:/b";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.eclipse.krazo.test.redirectboundaryonroot;

import jakarta.enterprise.context.RequestScoped;
import jakarta.inject.Inject;
import jakarta.mvc.Controller;
import jakarta.mvc.Models;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;

@Path("/b")
@RequestScoped
@Controller
public class RedirectBoundaryBController {

@Inject
RedirectBean bean;

@Inject
Models models;

@GET
public String index() {
models.put("redirectBeanValue", bean.getMessage());
return "b.jsp";
}
}
20 changes: 20 additions & 0 deletions testsuite/src/main/resources/redirectboundary/views/a.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!doctype html>
<html>
<head>
<title>Redirect boundary test</title>
</head>
<body>
<h1>Page A</h1>

<p id="result">${redirectBeanValue}</p>

<form name="toAForm" action="${mvc.basePath}/a/toA" method="post">
<button name="submit">Submit</button>
</form>

<form name="toBForm" action="${mvc.basePath}/a/toB" method="post">
<button name="submit">Submit</button>
</form>
</body>
</html>
13 changes: 13 additions & 0 deletions testsuite/src/main/resources/redirectboundary/views/b.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!doctype html>
<html>
<head>
<title>Redirect boundary test</title>
</head>
<body>
<h1>Page B</h1>

<p id="result">${redirectBeanValue}</p>

</body>
</html>
20 changes: 20 additions & 0 deletions testsuite/src/main/resources/redirectboundaryonroot/views/a.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!doctype html>
<html>
<head>
<title>Redirect boundary test</title>
</head>
<body>
<h1>Page A</h1>

<p id="result">${redirectBeanValue}</p>

<form name="toAForm" action="${mvc.basePath}/a/toA" method="post">
<button name="submit">Submit</button>
</form>

<form name="toBForm" action="${mvc.basePath}/a/toB" method="post">
<button name="submit">Submit</button>
</form>
</body>
</html>
13 changes: 13 additions & 0 deletions testsuite/src/main/resources/redirectboundaryonroot/views/b.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!doctype html>
<html>
<head>
<title>Redirect boundary test</title>
</head>
<body>
<h1>Page B</h1>

<p id="result">${redirectBeanValue}</p>

</body>
</html>
Loading

0 comments on commit df1ca9c

Please sign in to comment.