buildframework/helium/sf/java/core/tests/src/com/nokia/helium/core/tests/TestLDAPHelper.java
changeset 628 7c4a911dc066
equal deleted inserted replaced
588:c7c26511138f 628:7c4a911dc066
       
     1 /*
       
     2 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  
       
    15 *
       
    16 */
       
    17 package com.nokia.helium.core.tests;
       
    18 
       
    19 import static org.junit.Assert.assertNotNull;
       
    20 
       
    21 import org.junit.Test;
       
    22 
       
    23 import com.nokia.helium.core.LDAPException;
       
    24 import com.nokia.helium.core.LDAPHelper;
       
    25 
       
    26 /**
       
    27  * Testing the LDAPHelper class. Test are limited to what
       
    28  * can be check locally.
       
    29  * 
       
    30  */
       
    31 public class TestLDAPHelper {
       
    32 
       
    33     /**
       
    34      * Test that construction fails if ldap is null
       
    35      */
       
    36     @Test
       
    37     public void checkContstrutorValidationForLDAP() {
       
    38         IllegalArgumentException error = null;
       
    39         try {
       
    40             new LDAPHelper(null, "");
       
    41         } catch (IllegalArgumentException ex) {
       
    42             error = ex;
       
    43         }
       
    44         assertNotNull(error);
       
    45     }
       
    46 
       
    47     /**
       
    48      * Test that construction fails if rootdn is null
       
    49      */
       
    50     @Test
       
    51     public void checkContstrutorValidationForRootDN() {
       
    52         IllegalArgumentException error = null;
       
    53         try {
       
    54             new LDAPHelper("", null);
       
    55         } catch (IllegalArgumentException ex) {
       
    56             error = ex;
       
    57         }
       
    58         assertNotNull(error);
       
    59     }
       
    60 
       
    61     /**
       
    62      * Test that construction fails if rootdn is null
       
    63      * @throws LDAPException 
       
    64      */
       
    65     @Test
       
    66     public void checkGetAttributeAsStringNullUsername() throws LDAPException {
       
    67         IllegalArgumentException error = null;
       
    68         LDAPHelper helper = new LDAPHelper("", "");
       
    69         try {
       
    70             helper.getAttributeAsString(null, "");
       
    71         } catch (IllegalArgumentException ex) {
       
    72             error = ex;
       
    73         }
       
    74         assertNotNull(error);
       
    75     }
       
    76 
       
    77     /**
       
    78      * Test that construction fails if rootdn is null
       
    79      * @throws LDAPException 
       
    80      */
       
    81     @Test
       
    82     public void checkGetAttributeAsStringNullAttribute() throws LDAPException {
       
    83         IllegalArgumentException error = null;
       
    84         LDAPHelper helper = new LDAPHelper("", "");
       
    85         try {
       
    86             helper.getAttributeAsString("", null);
       
    87         } catch (IllegalArgumentException ex) {
       
    88             error = ex;
       
    89         }
       
    90         assertNotNull(error);
       
    91     }
       
    92 
       
    93     /**
       
    94      * Test that construction fails if rootdn is null
       
    95      * @throws LDAPException 
       
    96      */
       
    97     @Test
       
    98     public void checkGetAttributeAsStringNullAttributeCurrentUser() throws LDAPException {
       
    99         IllegalArgumentException error = null;
       
   100         LDAPHelper helper = new LDAPHelper("", "");
       
   101         try {
       
   102             helper.getUserAttributeAsString(null);
       
   103         } catch (IllegalArgumentException ex) {
       
   104             error = ex;
       
   105         }
       
   106         assertNotNull(error);
       
   107     }
       
   108 
       
   109 
       
   110     /**
       
   111      * Test that construction fails if rootdn is null
       
   112      * @throws LDAPException 
       
   113      */
       
   114     @Test
       
   115     public void checkGetAttributeAsStringInvalidUser() {
       
   116         LDAPException error = null;
       
   117         LDAPHelper helper = new LDAPHelper("", "");
       
   118         try {
       
   119             helper.getAttributeAsString("invaliduser", LDAPHelper.EMAIL_ATTRIBUTE_NAME);
       
   120         } catch (LDAPException ex) {
       
   121             error = ex;
       
   122         }
       
   123         assertNotNull(error);
       
   124     }
       
   125 }