directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ersi...@apache.org
Subject svn commit: r415451 - in /directory/trunks/apacheds/server-unit/src/test/java/org/apache/directory/server: HelloWorldProcedure.java StoredProcedureTest.java
Date Mon, 19 Jun 2006 22:55:28 GMT
Author: ersiner
Date: Mon Jun 19 15:55:27 2006
New Revision: 415451

URL: http://svn.apache.org/viewvc?rev=415451&view=rev
Log:
Modified SP test case to handle returning results.
And also it now uses new SP Utils.
The tests fail getting results back for now!

Modified:
    directory/trunks/apacheds/server-unit/src/test/java/org/apache/directory/server/HelloWorldProcedure.java
    directory/trunks/apacheds/server-unit/src/test/java/org/apache/directory/server/StoredProcedureTest.java

Modified: directory/trunks/apacheds/server-unit/src/test/java/org/apache/directory/server/HelloWorldProcedure.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/server-unit/src/test/java/org/apache/directory/server/HelloWorldProcedure.java?rev=415451&r1=415450&r2=415451&view=diff
==============================================================================
--- directory/trunks/apacheds/server-unit/src/test/java/org/apache/directory/server/HelloWorldProcedure.java
(original)
+++ directory/trunks/apacheds/server-unit/src/test/java/org/apache/directory/server/HelloWorldProcedure.java
Mon Jun 19 15:55:27 2006
@@ -3,13 +3,13 @@
 
 public class HelloWorldProcedure
 {
-    public static void sayHello()
+    public static String sayHello()
     {
-        System.out.println( "Hello World!" );
+        return "Hello World!";
     }
     
-    public static void sayHelloTo( String name )
+    public static String sayHelloTo( String name )
     {
-        System.out.println( "Hello " + name + "!" );
+        return "Hello " + name + "!";
     }
 }

Modified: directory/trunks/apacheds/server-unit/src/test/java/org/apache/directory/server/StoredProcedureTest.java
URL: http://svn.apache.org/viewvc/directory/trunks/apacheds/server-unit/src/test/java/org/apache/directory/server/StoredProcedureTest.java?rev=415451&r1=415450&r2=415451&view=diff
==============================================================================
--- directory/trunks/apacheds/server-unit/src/test/java/org/apache/directory/server/StoredProcedureTest.java
(original)
+++ directory/trunks/apacheds/server-unit/src/test/java/org/apache/directory/server/StoredProcedureTest.java
Mon Jun 19 15:55:27 2006
@@ -17,26 +17,18 @@
 package org.apache.directory.server;
 
 
-import java.io.ByteArrayOutputStream;
-import java.io.File;
 import java.io.IOException;
-import java.io.InputStream;
-import java.io.ObjectOutputStream;
-import java.net.URL;
 import java.util.HashSet;
 import java.util.Hashtable;
 import java.util.Set;
 
 import javax.naming.NamingException;
-import javax.naming.directory.Attributes;
-import javax.naming.directory.BasicAttributes;
 import javax.naming.ldap.InitialLdapContext;
 import javax.naming.ldap.LdapContext;
 
 import org.apache.directory.server.ldap.support.extended.StoredProcedureExtendedOperationHandler;
 import org.apache.directory.server.unit.AbstractServerTest;
-import org.apache.directory.shared.ldap.message.extended.StoredProcedureRequest;
-import org.apache.directory.shared.ldap.message.extended.StoredProcedureResponse;
+import org.apache.directory.shared.ldap.sp.StoredProcedureUtils;
 
 
 /**
@@ -64,20 +56,7 @@
         env.put( "java.naming.security.authentication", "simple" );
         ctx = new InitialLdapContext( env, null );
 
-        URL url = getClass().getResource( "HelloWorldProcedure.class" );
-        InputStream in = getClass().getResourceAsStream( "HelloWorldProcedure.class" );
-        File file = new File( url.getFile() );
-        int size = ( int ) file.length();
-        byte[] buf = new byte[size];
-        in.read( buf );
-        in.close();
-        
-        // set up
-        Attributes attributes = new BasicAttributes( "objectClass", "top", true );
-        attributes.get( "objectClass" ).add( "javaClass" );
-        attributes.put( "fullyQualifiedClassName", HelloWorldProcedure.class.getName() );
-        attributes.put( "byteCode", buf );
-        ctx.createSubcontext( "fullyQualifiedClassName=" + HelloWorldProcedure.class.getName(),
attributes );
+        StoredProcedureUtils.loadStoredProcedureClass( ctx, HelloWorldProcedure.class.getName(),
getClass() );
     }
 
 
@@ -92,31 +71,21 @@
 
     public void testExecuteProcedure() throws NamingException
     {
-        String language = "java";
-        String procedure = "org.apache.directory.server.HelloWorldProcedure.sayHello";
-        StoredProcedureRequest req = new StoredProcedureRequest( 0, procedure, language );
-        StoredProcedureResponse resp = ( StoredProcedureResponse ) ctx.extendedOperation(
req );
-        assertNotNull( resp );
+        String procedureName = HelloWorldProcedure.class.getName() + ".sayHello";
+        
+        Object response = StoredProcedureUtils.callStoredProcedure( ctx, procedureName, new
Object[] { } );
+        
+        assertEquals( "Hello World!", response );
     }
     
 
     public void testExecuteProcedureWithParameters() throws NamingException, IOException
     {
-        String language = "java";
-        String procedure = "org.apache.directory.server.HelloWorldProcedure.sayHelloTo";
-        
-        byte[] type = "java.lang.String".getBytes( "UTF-8" );
-        
-        StoredProcedureRequest req = new StoredProcedureRequest( 0, procedure, language );
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        ObjectOutputStream oos = new ObjectOutputStream( baos );
-        oos.writeObject( new String( "Ersin" ) );
-        byte[] value = baos.toByteArray();
+        String procedureName = HelloWorldProcedure.class.getName() + ".sayHelloTo";
         
-        req.addParameter( type, value );
+        Object response = StoredProcedureUtils.callStoredProcedure( ctx, procedureName, new
Object[] { "Ersin" } );
         
-        StoredProcedureResponse resp = ( StoredProcedureResponse ) ctx.extendedOperation(
req );
-        assertNotNull( resp );
+        assertEquals( "Hello Ersin!", response );
     }
     
 }



Mime
View raw message