1/* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18/** 19* @author Vera Y. Petrashkova 20*/ 21 22package org.apache.harmony.auth.tests.javax.security.sasl; 23 24import java.security.Provider; 25import java.security.Security; 26import java.util.Enumeration; 27 28import javax.security.sasl.Sasl; 29import javax.security.sasl.SaslClientFactory; 30import javax.security.sasl.SaslServerFactory; 31 32import junit.framework.TestCase; 33 34/** 35 * Test for Sasl class 36 */ 37public class Sasl1Test extends TestCase { 38 39 private Provider [] provs; 40 private boolean initProvs; 41 42 43 @Override 44 protected void setUp() throws Exception { 45 super.setUp(); 46 if (!initProvs) { 47 provs = Security.getProviders(); 48 initProvs = true; 49 } 50 if (provs != null) { 51 for (Provider element : provs) { 52 Security.removeProvider(element.getName()); 53 } 54 } 55 } 56 57 @Override 58 protected void tearDown() throws Exception { 59 super.tearDown(); 60 if (provs != null) { 61 for (int i = 0; i < provs.length; i++) { 62 Security.insertProviderAt(provs[i], (i+1)); 63 } 64 } 65 } 66 67 /** 68 * Test for <code>getSaslClientFactories()</code> method 69 * 70 * Assertion: 71 * returns enumeration without any element 72 * 73 * All providers are previously removed. 74 */ 75 public void testGetClient() { 76 Enumeration<SaslClientFactory> en = Sasl.getSaslClientFactories(); 77 assertNotNull("List of SaslClientFactories should not be null", en); 78 assertFalse("List of SaslClientFactories should not haves elements", en 79 .hasMoreElements()); 80 } 81 82 /** 83 * Test for <code>getSaslServerFactories()</code> method 84 * 85 * Assertion: 86 * returns enumeration without any element 87 * 88 * All providers are previously removed. 89 */ 90 public void testGetSertver() { 91 Enumeration<SaslServerFactory> en = Sasl.getSaslServerFactories(); 92 assertNotNull("List of SaslServerFactories should not be null", en); 93 assertFalse("List of SaslServerFactories should not have elements", en 94 .hasMoreElements()); 95 } 96} 97