// Path: src/test/java/at/pollux/thymeleaf/shiro/test/AbstractThymeleafShiroDialectTest.java
// public class AbstractThymeleafShiroDialectTest extends ShiroTest {
// 
//     private static final String PACKAGE_PATH = "at/pollux/thymeleaf/shiro/dialect/test";
// 
//     private static TemplateEngine templateEngine;
// 
//     @BeforeClass
//     public static void beforeClass() {
//         setupShiro();
//         setupThymeleaf();
//     }
// 
//     @After
//     public void tearDownSubject() {
//         clearSubject();
//     }
// 
//     protected String processThymeleafFile(String fileName, Context context) {
//         return templateEngine.process(PACKAGE_PATH + "/" + fileName, context);
//     }
// 
//     protected Subject createSubject() {
//         final Subject subjectUnderTest = new Subject.Builder(getSecurityManager()).buildSubject();
// 
//         setSubject(subjectUnderTest);
// 
//         return subjectUnderTest;
//     }
// 
//     protected Subject createAndLoginSubject(TestUsers userOrNull) {
//         final Subject subjectUnderTest = createSubject();
// 
//         if (userOrNull != null) {
//             subjectUnderTest.login(new UsernamePasswordToken(userOrNull.email(), userOrNull.password()));
//         }
//         return subjectUnderTest;
//     }
// 
//     private static void setupShiro() {
//         Ini ini = new Ini();
//         Ini.Section usersSection = ini.addSection("users");
// 
//         usersSection.put(ALICE.email(), ALICE.roles());
//         usersSection.put(BOB.email(), BOB.roles());
//         usersSection.put(CAESAR.email(), CAESAR.roles());
// 
//         Ini.Section rolesSection = ini.addSection("roles");
//         rolesSection.put(ROLE_A.label(), ROLE_A.permissions());
//         rolesSection.put(ROLE_B.label(), ROLE_B.permissions());
//         rolesSection.put(ROLE_C.label(), ROLE_C.permissions());
//         rolesSection.put(ROLE_D.label(), ROLE_D.permissions());
// 
//         Factory<SecurityManager> factory = new TestIniSecurityManagerFactory(ini);
//         SecurityManager secMgr = factory.getInstance();
//         setSecurityManager(secMgr);
//     }
// 
//     private static void setupThymeleaf() {
//         ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
//         templateResolver.setCacheable(false);
//         templateResolver.setCharacterEncoding(Charsets.UTF_8.name());
//         templateResolver.setTemplateMode(TemplateMode.HTML);
// 
//         templateEngine = new TemplateEngine();
//         templateEngine.setTemplateResolver(templateResolver);
//         final ShiroDialect dialect = new ShiroDialect();
//         templateEngine.addDialect(dialect.getPrefix(), dialect);
// 
//     }
// }
// 
// Path: src/test/java/at/pollux/thymeleaf/shiro/test/user/TestUsers.java
// public enum TestUsers {
//     ALICE(new TestUser("u1", "p1", Sets.newHashSet(
//             TestRoles.ROLE_A, TestRoles.ROLE_D
//     ))),
//     BOB(new TestUser("u2", "p2", Sets.newHashSet(
//             TestRoles.ROLE_B, TestRoles.ROLE_C
//     ))),
//     CAESAR(new TestUser("u3", "p3", Sets.newHashSet(
//             TestRoles.ROLE_C, TestRoles.ROLE_E
//     )));
// 
//     private static Joiner comaJoiner = Joiner.on(",");
// 
//     private final TestUser delegate;
// 
//     TestUsers(TestUser user) {
//         this.delegate = user;
//     }
// 
//     public String email() {
//         return delegate.getEmail();
//     }
// 
//     public String password() {
//         return delegate.getPassword();
//     }
// 
//     public String roles() {
//         return comaJoiner.join(
//                 delegate.getPassword(), comaJoiner.join(
//                         Collections2.transform(delegate.getRoles(), new Function<TestRoles, String>() {
//                             public String apply(TestRoles input) {
//                                 return input.label();
//                             }
//                         }))
//         );
//     }
// 
//     public Collection<String> permissions() {
//         return Collections2.transform(delegate.getRoles(), new Function<TestRoles, String>() {
//             public String apply(TestRoles input) {
//                 return input.permissions();
//             }
//         });
//     }
// }


import at.pollux.thymeleaf.shiro.test.AbstractThymeleafShiroDialectTest;
import at.pollux.thymeleaf.shiro.test.user.TestUsers;
import com.google.common.collect.Lists;
import junitparams.JUnitParamsRunner;
import org.apache.shiro.subject.Subject;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.thymeleaf.context.Context;
import static at.pollux.thymeleaf.shiro.test.user.TestRoles.ROLE_B;
import static at.pollux.thymeleaf.shiro.test.user.TestRoles.ROLE_C;
import static com.google.common.base.Preconditions.checkArgument;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.not;
package at.pollux.thymeleaf.shiro.dialect;



/**
 * @author tbk
 */
@RunWith(JUnitParamsRunner.class)
public class HasAllRolesTagTest extends AbstractThymeleafShiroDialectTest {

    private static final String FILE_UNDER_TEST = "shiro_hasAllRoles.html";

    private static Subject hasAllRolesSanityCheck(Subject subject) {
        checkArgument(subject.hasAllRoles(Lists.newArrayList(ROLE_B.label(), ROLE_C.label())));
        return subject;
    }

    @Test
    public void itShouldNotRenderWithoutSubject() {
        String result = processThymeleafFile(FILE_UNDER_TEST, new Context());

        assertThat(result, not(containsString("shiro:")));
        assertThat(result, not(containsString("HASALLROLES_ATTRIBUTE_STATIC")));
        assertThat(result, not(containsString("HASALLROLES_ELEMENT_STATIC")));
    }

    @Test
    public void itShouldRenderForUserAlice() {
// Path: src/test/java/at/pollux/thymeleaf/shiro/test/AbstractThymeleafShiroDialectTest.java
// public class AbstractThymeleafShiroDialectTest extends ShiroTest {
// 
//     private static final String PACKAGE_PATH = "at/pollux/thymeleaf/shiro/dialect/test";
// 
//     private static TemplateEngine templateEngine;
// 
//     @BeforeClass
//     public static void beforeClass() {
//         setupShiro();
//         setupThymeleaf();
//     }
// 
//     @After
//     public void tearDownSubject() {
//         clearSubject();
//     }
// 
//     protected String processThymeleafFile(String fileName, Context context) {
//         return templateEngine.process(PACKAGE_PATH + "/" + fileName, context);
//     }
// 
//     protected Subject createSubject() {
//         final Subject subjectUnderTest = new Subject.Builder(getSecurityManager()).buildSubject();
// 
//         setSubject(subjectUnderTest);
// 
//         return subjectUnderTest;
//     }
// 
//     protected Subject createAndLoginSubject(TestUsers userOrNull) {
//         final Subject subjectUnderTest = createSubject();
// 
//         if (userOrNull != null) {
//             subjectUnderTest.login(new UsernamePasswordToken(userOrNull.email(), userOrNull.password()));
//         }
//         return subjectUnderTest;
//     }
// 
//     private static void setupShiro() {
//         Ini ini = new Ini();
//         Ini.Section usersSection = ini.addSection("users");
// 
//         usersSection.put(ALICE.email(), ALICE.roles());
//         usersSection.put(BOB.email(), BOB.roles());
//         usersSection.put(CAESAR.email(), CAESAR.roles());
// 
//         Ini.Section rolesSection = ini.addSection("roles");
//         rolesSection.put(ROLE_A.label(), ROLE_A.permissions());
//         rolesSection.put(ROLE_B.label(), ROLE_B.permissions());
//         rolesSection.put(ROLE_C.label(), ROLE_C.permissions());
//         rolesSection.put(ROLE_D.label(), ROLE_D.permissions());
// 
//         Factory<SecurityManager> factory = new TestIniSecurityManagerFactory(ini);
//         SecurityManager secMgr = factory.getInstance();
//         setSecurityManager(secMgr);
//     }
// 
//     private static void setupThymeleaf() {
//         ClassLoaderTemplateResolver templateResolver = new ClassLoaderTemplateResolver();
//         templateResolver.setCacheable(false);
//         templateResolver.setCharacterEncoding(Charsets.UTF_8.name());
//         templateResolver.setTemplateMode(TemplateMode.HTML);
// 
//         templateEngine = new TemplateEngine();
//         templateEngine.setTemplateResolver(templateResolver);
//         final ShiroDialect dialect = new ShiroDialect();
//         templateEngine.addDialect(dialect.getPrefix(), dialect);
// 
//     }
// }
// 
// Path: src/test/java/at/pollux/thymeleaf/shiro/test/user/TestUsers.java
// public enum TestUsers {
//     ALICE(new TestUser("u1", "p1", Sets.newHashSet(
//             TestRoles.ROLE_A, TestRoles.ROLE_D
//     ))),
//     BOB(new TestUser("u2", "p2", Sets.newHashSet(
//             TestRoles.ROLE_B, TestRoles.ROLE_C
//     ))),
//     CAESAR(new TestUser("u3", "p3", Sets.newHashSet(
//             TestRoles.ROLE_C, TestRoles.ROLE_E
//     )));
// 
//     private static Joiner comaJoiner = Joiner.on(",");
// 
//     private final TestUser delegate;
// 
//     TestUsers(TestUser user) {
//         this.delegate = user;
//     }
// 
//     public String email() {
//         return delegate.getEmail();
//     }
// 
//     public String password() {
//         return delegate.getPassword();
//     }
// 
//     public String roles() {
//         return comaJoiner.join(
//                 delegate.getPassword(), comaJoiner.join(
//                         Collections2.transform(delegate.getRoles(), new Function<TestRoles, String>() {
//                             public String apply(TestRoles input) {
//                                 return input.label();
//                             }
//                         }))
//         );
//     }
// 
//     public Collection<String> permissions() {
//         return Collections2.transform(delegate.getRoles(), new Function<TestRoles, String>() {
//             public String apply(TestRoles input) {
//                 return input.permissions();
//             }
//         });
//     }
// }


// Path: src/test/java/at/pollux/thymeleaf/shiro/dialect/HasAllRolesTagTest.java
import at.pollux.thymeleaf.shiro.test.AbstractThymeleafShiroDialectTest;
import at.pollux.thymeleaf.shiro.test.user.TestUsers;
import com.google.common.collect.Lists;
import junitparams.JUnitParamsRunner;
import org.apache.shiro.subject.Subject;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.thymeleaf.context.Context;
import static at.pollux.thymeleaf.shiro.test.user.TestRoles.ROLE_B;
import static at.pollux.thymeleaf.shiro.test.user.TestRoles.ROLE_C;
import static com.google.common.base.Preconditions.checkArgument;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.not;

package at.pollux.thymeleaf.shiro.dialect;



/**
 * @author tbk
 */
@RunWith(JUnitParamsRunner.class)
public class HasAllRolesTagTest extends AbstractThymeleafShiroDialectTest {

    private static final String FILE_UNDER_TEST = "shiro_hasAllRoles.html";

    private static Subject hasAllRolesSanityCheck(Subject subject) {
        checkArgument(subject.hasAllRoles(Lists.newArrayList(ROLE_B.label(), ROLE_C.label())));
        return subject;
    }

    @Test
    public void itShouldNotRenderWithoutSubject() {
        String result = processThymeleafFile(FILE_UNDER_TEST, new Context());

        assertThat(result, not(containsString("shiro:")));
        assertThat(result, not(containsString("HASALLROLES_ATTRIBUTE_STATIC")));
        assertThat(result, not(containsString("HASALLROLES_ELEMENT_STATIC")));
    }

    @Test
    public void itShouldRenderForUserAlice() {
        TestUsers user = TestUsers.ALICE;