package at.gv.egovernment.moa.id.auth.modules.ehvd.test.utils; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import org.apache.commons.lang3.RandomStringUtils; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.BlockJUnit4ClassRunner; import at.gv.egovernment.moa.id.data.AuthenticationRole; import at.gv.egovernment.moa.id.data.AuthenticationRoleFactory; @RunWith(BlockJUnit4ClassRunner.class) public class AuthenticationRoleFactoryTest { @Test public void simpleRole() { String role = RandomStringUtils.randomAlphabetic(5); AuthenticationRole toCheck = AuthenticationRoleFactory.buildFormPVPole(role); assertEquals("wrong role name", role, toCheck.getRoleName()); assertEquals("wrong raw role", role, toCheck.getRawRoleString()); assertNull("wrong role attr", toCheck.getParams()); } @Test public void complexeRoleEmptyParams() { String role = RandomStringUtils.randomAlphabetic(5); String fullRole = role + "()"; AuthenticationRole toCheck = AuthenticationRoleFactory.buildFormPVPole(fullRole); assertEquals("wrong role name", role, toCheck.getRoleName()); assertEquals("wrong raw role", fullRole, toCheck.getRawRoleString()); assertNull("wrong role attr", toCheck.getParams()); } @Test public void complexeRoleWithParams() { String p1 = RandomStringUtils.randomAlphabetic(5); String v1 = RandomStringUtils.randomAlphabetic(5); String p2 = RandomStringUtils.randomAlphabetic(5); String v2 = RandomStringUtils.randomAlphabetic(5); String role = RandomStringUtils.randomAlphabetic(5); String fullRole = role + "(\"" + p1 + "\"=\"" + v1 + "\"," + p2 + "\"=\"" + v2 + "\"" +")"; AuthenticationRole toCheck = AuthenticationRoleFactory.buildFormPVPole(fullRole); assertEquals("wrong role name", role, toCheck.getRoleName()); assertEquals("wrong raw role", fullRole, toCheck.getRawRoleString()); assertNotNull("wrong role attr", toCheck.getParams()); assertEquals("wrong param size", 2, toCheck.getParams().size()); } }