[
https://issues.apache.org/jira/browse/CLK-585?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Bob Schellink resolved CLK-585.
-------------------------------
Resolution: Fixed
fixed in trunk
> Implement mock support for Principal and Roles
> ----------------------------------------------
>
> Key: CLK-585
> URL: https://issues.apache.org/jira/browse/CLK-585
> Project: Click
> Issue Type: Improvement
> Components: mock
> Affects Versions: 2.1.0
> Reporter: Bob Schellink
> Assignee: Bob Schellink
> Fix For: 2.2.0
>
>
> Currently there is no way to provide a Principal (user) and Roles for mock
> tests.
> Sven Pfeiffer provided the following impl on the mainlig list which can be
> added to the Mock API:
> ====================
> public class AuthenticatedMockRequest extends MockRequest {
> MockPrincipal userPrincipal;
> public AuthenticatedMockRequest(MockPrincipal userPrincipal) {
> this.userPrincipal = userPrincipal;
> }
> @Override
> public boolean isUserInRole(String name) {
> return userPrincipal.getRoles().contains(name);
> }
> @Override
> public Principal getUserPrincipal() {
> return userPrincipal;
> }
> }
> and
> MockPrincipal:
> public class MockPrincipal implements Principal {
> private String name;
> private List<String> roles = new ArrayList<String>();
> public MockPrincipal(String userName) {
> this.name = userName;
> }
> public MockPrincipal(String userName, List<String> roles) {
> this.name = userName;
> this.roles = roles;
> }
> @Override
> public String getName() {
> return name;
> }
> public List<String> getRoles() {
> return roles;
> }
> public void setRoles(String... newRoles) {
> roles.clear();
> for (String role : newRoles) {
> roles.add(role);
> }
> }
> }
> And I added the following lines to my testcase:
> MockPrincipal principal = new MockPrincipal("admin");
> principal.setRoles("admin", "user");
> container.setRequest(new AuthenticatedMockRequest(principal));
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.