Commit dff62c88 authored by Sunil Kumar's avatar Sunil Kumar
Browse files

Junit Test Cases for recent Bug Fixes.

parent 0daf650f
/*******************************************************************************
* $OpenLDAP: pkg/jldap/com/novell/ldap/util/DSMLWriter.java,v 1.42 2004/01/23
* 10:12:51 sunilk Exp $
*
* Copyright (C) 2002 - 2003 Novell, Inc. All Rights Reserved.
*
* THIS WORK IS SUBJECT TO U.S. AND INTERNATIONAL COPYRIGHT LAWS AND TREATIES.
* USE, MODIFICATION, AND REDISTRIBUTION OF THIS WORK IS SUBJECT TO VERSION
* 2.0.1 OF THE OPENLDAP PUBLIC LICENSE, A COPY OF WHICH IS AVAILABLE AT
* HTTP://WWW.OPENLDAP.ORG/LICENSE.HTML OR IN THE FILE "LICENSE" IN THE
* TOP-LEVEL DIRECTORY OF THE DISTRIBUTION. ANY USE OR EXPLOITATION OF THIS WORK
* OTHER THAN AS AUTHORIZED IN VERSION 2.0.1 OF THE OPENLDAP PUBLIC LICENSE, OR
* OTHER PRIOR WRITTEN CONSENT FROM NOVELL, COULD SUBJECT THE PERPETRATOR TO
* CRIMINAL AND CIVIL LIABILITY.
*/
import com.novell.ldap.LDAPUrlTest;
import com.novell.ldap.util.DSMLReaderTest;
import com.novell.ldap.util.DSMLWriterTest;
import junit.framework.Test;
import junit.framework.TestSuite;
/**
* This class is the Junit Test Suite of all the junit tests.
*/
public class AllTestSuite {
public static void main(String[] args) {
junit.textui.TestRunner.run(AllTestSuite.suite());
}
public static Test suite() {
TestSuite suite = new TestSuite("Test for default package");
//$JUnit-BEGIN$
suite.addTest(new TestSuite(LDAPUrlTest.class));
suite.addTest(new TestSuite(DSMLReaderTest.class));
suite.addTest(new TestSuite(DSMLWriterTest.class));
//$JUnit-END$
return suite;
}
}
\ No newline at end of file
/*******************************************************************************
* $OpenLDAP: pkg/jldap/com/novell/ldap/util/DSMLWriter.java,v 1.42 2004/01/23
* 10:12:51 sunilk Exp $
*
* Copyright (C) 2002 - 2003 Novell, Inc. All Rights Reserved.
*
* THIS WORK IS SUBJECT TO U.S. AND INTERNATIONAL COPYRIGHT LAWS AND TREATIES.
* USE, MODIFICATION, AND REDISTRIBUTION OF THIS WORK IS SUBJECT TO VERSION
* 2.0.1 OF THE OPENLDAP PUBLIC LICENSE, A COPY OF WHICH IS AVAILABLE AT
* HTTP://WWW.OPENLDAP.ORG/LICENSE.HTML OR IN THE FILE "LICENSE" IN THE
* TOP-LEVEL DIRECTORY OF THE DISTRIBUTION. ANY USE OR EXPLOITATION OF THIS WORK
* OTHER THAN AS AUTHORIZED IN VERSION 2.0.1 OF THE OPENLDAP PUBLIC LICENSE, OR
* OTHER PRIOR WRITTEN CONSENT FROM NOVELL, COULD SUBJECT THE PERPETRATOR TO
* CRIMINAL AND CIVIL LIABILITY.
*/
package com.novell.ldap;
import junit.framework.TestCase;
/**
* This Class contains some testcases for LDAPUrl primarily based on patches and
* other bugs found.
*/
public class LDAPUrlTest extends TestCase {
/*
* @see TestCase#setUp()
*/
protected void setUp() throws Exception {
super.setUp();
}
/*
* @see TestCase#tearDown()
*/
protected void tearDown() throws Exception {
super.tearDown();
}
/**
* This testcase is for the resolving the following: <b>LDAPUrl fails to
* parse attribute correctly (ITS#3049) </b>
*
* @throws Exception
* When error occurs.
*/
public void testparseAttribute() throws Exception {
//Check normal url.
checkurl("ldap://hostname:389");
checkurl("ldap://hostname:389/dc=examples,dc=com?uid");
//Use the second data.
checkurl("ldap://hostname:389/dc=examples");
}
private void checkurl(String urlstring) throws Exception {
LDAPUrl url = new LDAPUrl(urlstring);
assertTrue("LDAPURL fails for " + urlstring + " ldapurl="
+ url.toString(), urlstring.equals(url.toString()));
}
}
\ No newline at end of file
/*******************************************************************************
* $OpenLDAP: pkg/jldap/com/novell/ldap/util/DSMLWriter.java,v 1.42 2004/01/23
* 10:12:51 sunilk Exp $
*
* Copyright (C) 2002 - 2003 Novell, Inc. All Rights Reserved.
*
* THIS WORK IS SUBJECT TO U.S. AND INTERNATIONAL COPYRIGHT LAWS AND TREATIES.
* USE, MODIFICATION, AND REDISTRIBUTION OF THIS WORK IS SUBJECT TO VERSION
* 2.0.1 OF THE OPENLDAP PUBLIC LICENSE, A COPY OF WHICH IS AVAILABLE AT
* HTTP://WWW.OPENLDAP.ORG/LICENSE.HTML OR IN THE FILE "LICENSE" IN THE
* TOP-LEVEL DIRECTORY OF THE DISTRIBUTION. ANY USE OR EXPLOITATION OF THIS WORK
* OTHER THAN AS AUTHORIZED IN VERSION 2.0.1 OF THE OPENLDAP PUBLIC LICENSE, OR
* OTHER PRIOR WRITTEN CONSENT FROM NOVELL, COULD SUBJECT THE PERPETRATOR TO
* CRIMINAL AND CIVIL LIABILITY.
*/
package com.novell.ldap.util;
import java.io.ByteArrayInputStream;
import com.novell.ldap.LDAPExtendedResponse;
import com.novell.ldap.LDAPSearchRequest;
import junit.framework.TestCase;
/**
* This Class contains some testcases for DSMLReader primarily based on patches
* and other bugs found.
*/
public class DSMLReaderTest extends TestCase {
private DSMLReader reader = null;
/*
* (non-Javadoc)
*
* @see junit.framework.TestCase#setUp()
*/
protected void setUp() throws Exception {
super.setUp();
}
/*
* (non-Javadoc)
*
* @see junit.framework.TestCase#tearDown()
*/
protected void tearDown() throws Exception {
super.tearDown();
}
/**
* This testcases checks whether the dsml can handle namespace for the dsml
* request.
*
* @throws Exception
*/
public void testnameprefixtest() throws Exception {
String xml = "<Envelope><Body><dsml:batchRequest xmlns=\"urn:oasis:names:tc:DSML:2:0:core\""
+ " xmlns:dsml=\"urn:oasis:names:tc:DSML:2:0:core\""
+ " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\""
+ " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" >"
+ "<dsml:searchRequest derefAliases=\"derefAlways\""
+ " dn=\"ou=peons,dc=idrs,dc=com\" requestID=\"1\" scope=\"singleLevel\">"
+ "<dsml:filter>"
+ "<dsml:present name=\"objectclass\"/>"
+ "</dsml:filter>"
+ "</dsml:searchRequest>"
+ "</dsml:batchRequest></Body></Envelope>";
reader = new DSMLReader(new ByteArrayInputStream(xml.getBytes()));
LDAPSearchRequest request = (LDAPSearchRequest) reader.readMessage();
assertEquals(request.getDN(), "ou=peons,dc=idrs,dc=com");
assertEquals(request.getStringFilter(), "(objectclass=*)");
}
/**
* This tests checks that the extendedresponse is decoded correctly.
*
* @throws Exception
*/
public void testreadExtendedResponse() throws Exception {
String xml = "<batchResponse xmlns=\"urn:oasis:names:tc:DSML:2:0:core\""
+ " xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">"
+ "<extendedResponse requestID=\"1\"> "
+ "<resultCode code=\"34\" descr=\"Invalid DN Syntax\"/>"
+ "<errorMessage>Could not convert to NDS Name</errorMessage>"
+ "<responseName>2.16.840.1.113719.1.27.100.38</responseName>"
+ "<response>hello</response>"
+ "</extendedResponse>"
+ "</batchResponse>";
reader = new DSMLReader(new ByteArrayInputStream(xml.getBytes()));
LDAPExtendedResponse response = (LDAPExtendedResponse) reader
.readMessage();
assertEquals(response.getResultCode(), 34);
assertEquals(response.getErrorMessage(),
"Could not convert to NDS Name");
assertEquals(response.getID(), "2.16.840.1.113719.1.27.100.38");
byte arr1[] = response.getValue();
byte arr2[] = new String("hello").getBytes("UTF-8");
for (int i = 0; i < arr1.length; i++)
assertEquals(arr1[i], arr2[i]);
}
}
\ No newline at end of file
/*******************************************************************************
* $OpenLDAP: pkg/jldap/com/novell/ldap/util/DSMLWriter.java,v 1.42 2004/01/23
* 10:12:51 sunilk Exp $
*
* Copyright (C) 2002 - 2003 Novell, Inc. All Rights Reserved.
*
* THIS WORK IS SUBJECT TO U.S. AND INTERNATIONAL COPYRIGHT LAWS AND TREATIES.
* USE, MODIFICATION, AND REDISTRIBUTION OF THIS WORK IS SUBJECT TO VERSION
* 2.0.1 OF THE OPENLDAP PUBLIC LICENSE, A COPY OF WHICH IS AVAILABLE AT
* HTTP://WWW.OPENLDAP.ORG/LICENSE.HTML OR IN THE FILE "LICENSE" IN THE
* TOP-LEVEL DIRECTORY OF THE DISTRIBUTION. ANY USE OR EXPLOITATION OF THIS WORK
* OTHER THAN AS AUTHORIZED IN VERSION 2.0.1 OF THE OPENLDAP PUBLIC LICENSE, OR
* OTHER PRIOR WRITTEN CONSENT FROM NOVELL, COULD SUBJECT THE PERPETRATOR TO
* CRIMINAL AND CIVIL LIABILITY.
*/
package com.novell.ldap.util;
import java.io.ByteArrayOutputStream;
import com.novell.ldap.LDAPAttribute;
import com.novell.ldap.LDAPAttributeSet;
import com.novell.ldap.LDAPEntry;
import com.novell.ldap.LDAPSearchResult;
import com.novell.ldap.util.DSMLWriter;
import junit.framework.TestCase;
/**
* This Class contains some testcases for DSMLWriter primarily based on patches
* and other bugs found.
*/
public class DSMLWriterTest extends TestCase {
private DSMLWriter writer = null;
private ByteArrayOutputStream stream = null;
/*
* @see TestCase#setUp()
*/
protected void setUp() throws Exception {
super.setUp();
stream = new ByteArrayOutputStream();
writer = new DSMLWriter(stream);
writer.useIndent(true);
}
/*
* @see TestCase#tearDown()
*/
protected void tearDown() throws Exception {
super.tearDown();
writer.finish();
stream.close();
stream = null;
}
/**
* This test cases is based on the ITS#3102. The actual issue is JLDAP
* DSMLWriter replacing special characters.
*
* The JLDAP library should handle special characters. Current patch is only
* for SearchResult.
*/
public void testPredefinedEntities() throws Exception {
String values[] = {"somevalue", "ampersand&", "greaterthan<",
"lessthan>", "apos'", "quot\""};
LDAPAttribute a = new LDAPAttribute("test", values);
LDAPAttributeSet attributeset = new LDAPAttributeSet();
attributeset.add(a);
LDAPSearchResult result = new LDAPSearchResult(new LDAPEntry(
"o=novell", attributeset), null);
writer.writeMessage(result);
writer.finish();
stream.flush();
String data = stream.toString();
System.out.println("xml = " + data);
assertTrue("The xml should contain ampersand&amp", data
.indexOf("ampersand&amp") != -1);
for (int i = 2; i < values.length; i++)
assertTrue("The xml should not contain" + values[i], data
.indexOf(values[i]) == -1);
}
/**
* If the batchrequest contains a empty set then a batch response of empty
* set must be returned.
*
* @throws Exception
*/
public void testEmptyBatchresponse() throws Exception {
writer.finish();
stream.flush();
String data = stream.toString();
System.out.println("xml = " + data);
assertTrue("Should contain batchresponse", data
.indexOf("batchResponse") != -1);
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment