java/sql-java-prihlasovani/test/cz/frantovo/jaas/sql/SQLRealmTest.java
changeset 7 46bb283a674d
parent 6 aff44e80f418
     1.1 --- a/java/sql-java-prihlasovani/test/cz/frantovo/jaas/sql/SQLRealmTest.java	Tue Feb 07 00:27:39 2012 +0100
     1.2 +++ b/java/sql-java-prihlasovani/test/cz/frantovo/jaas/sql/SQLRealmTest.java	Tue Feb 07 18:03:31 2012 +0100
     1.3 @@ -3,6 +3,7 @@
     1.4  import com.sun.enterprise.security.auth.realm.BadRealmException;
     1.5  import com.sun.enterprise.security.auth.realm.NoSuchRealmException;
     1.6  import java.util.Properties;
     1.7 +import javax.naming.NamingException;
     1.8  import org.junit.Before;
     1.9  import org.junit.Test;
    1.10  import static org.junit.Assert.*;
    1.11 @@ -14,15 +15,30 @@
    1.12  public class SQLRealmTest {
    1.13  
    1.14  	private static final String JAAS_KONTEXT = "sqlRealm_123456";
    1.15 +	private static final String JNDI_DS = "jdbc/test";
    1.16 +	private static final String SQL_HESLO = "SELECT jmeno FROM uzivatel WHERE jmeno = ? AND heslo = ?";
    1.17 +	private static final String SQL_SKUPINY_UŽIVATELE = "SELECT …";
    1.18 +	private static final String SQL_SKUPINY_VŠECHNY = "SELECT …";
    1.19 +	private static final String PARAMETR_NEPOVINNÝ = "nepovinný_parametr";
    1.20 +	private static final String PARAMETR_NEPOVINNÝ_HODNOTA = "hodnota nepovinného parametru";
    1.21  	private SQLRealm realm;
    1.22  
    1.23  	@Before
    1.24 -	public void setUp() throws BadRealmException, NoSuchRealmException {
    1.25 +	public void setUp() throws BadRealmException, NoSuchRealmException, NamingException {
    1.26  		Properties parametry = new Properties();
    1.27 +		
    1.28  		parametry.setProperty(SQLRealm.JAAS_CONTEXT_PARAM, JAAS_KONTEXT);
    1.29 +		parametry.setProperty(SQLRealm.PARAM_JNDI, JNDI_DS);
    1.30 +		parametry.setProperty(SQLRealm.PARAM_SQL_HESLO, SQL_HESLO);
    1.31 +		parametry.setProperty(SQLRealm.PARAM_SQL_SKUPINY_UŽIVATELE, SQL_SKUPINY_UŽIVATELE);
    1.32 +		parametry.setProperty(SQLRealm.PARAM_SQL_SKUPINY_VŠECHNY, SQL_SKUPINY_VŠECHNY);
    1.33 +
    1.34 +		parametry.setProperty(SQLRealm.PARAM_NETESTOVAT_SPOJENÍ, Boolean.TRUE.toString());
    1.35  
    1.36  		realm = new SQLRealm();
    1.37  		realm.init(parametry);
    1.38 +
    1.39 +		realm.setProperty(PARAMETR_NEPOVINNÝ, PARAMETR_NEPOVINNÝ_HODNOTA);
    1.40  	}
    1.41  
    1.42  	@Test
    1.43 @@ -39,4 +55,12 @@
    1.44  		assertTrue("authType musí být nenulový", authType != null);
    1.45  		assertTrue("authType musí být neprázdný", authType.trim().length() > 0);
    1.46  	}
    1.47 +
    1.48 +	@Test
    1.49 +	public void testGetProperty() {
    1.50 +		assertEquals("Neplatná hodnota parametru JAAS_KONTEXT", JAAS_KONTEXT, realm.getProperty(SQLRealm.JAAS_CONTEXT_PARAM));
    1.51 +		assertEquals("Neplatná hodnota parametru SQL_HESLO", SQL_HESLO, realm.getProperty(SQLRealm.PARAM_SQL_HESLO));
    1.52 +		assertEquals("Neplatná hodnota parametru PARAMETR_NEPOVINNÝ", PARAMETR_NEPOVINNÝ_HODNOTA, realm.getProperty(PARAMETR_NEPOVINNÝ));
    1.53 +
    1.54 +	}
    1.55  }