CVS: plexus-container-new/src/test/org/apache/plexus DefaultServiceD.java,NONE,1.1 ServiceD.java,NONE,1.1 DefaultPlexusContainerTest.java,1.2,1.3 configuration.xml,1.3,1.4

[email protected] Thu, 1 May 2003 14:35:39 -0500
Newsgroups gmane.comp.java.plexus.devel
Message-ID <[email protected]>
Update of /cvsroot/plexus/plexus-container-new/src/test/org/apache/plexus
In directory eng.werken.com:/tmp/cvs-serv18124/src/test/org/apache/plexus

Modified Files:
	DefaultPlexusContainerTest.java configuration.xml 
Added Files:
	DefaultServiceD.java ServiceD.java 
Log Message:
o This will require a separate message as more than a few changes have
occurred in order to support handling for various instantiation strategies
and scriptable components.



--- NEW FILE: DefaultServiceD.java ---
package org.apache.plexus;

public class DefaultServiceD
    implements ServiceD
{
}

--- NEW FILE: ServiceD.java ---
package org.apache.plexus;

public interface ServiceD
{
    static String ROLE = ServiceD.class.getName();
}

Index: DefaultPlexusContainerTest.java
===================================================================
RCS file: /cvsroot/plexus/plexus-container-new/src/test/org/apache/plexus/DefaultPlexusContainerTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- DefaultPlexusContainerTest.java	27 Apr 2003 16:27:43 -0000	1.2
+++ DefaultPlexusContainerTest.java	1 May 2003 19:35:36 -0000	1.3
@@ -5,6 +5,9 @@
 import java.io.InputStream;
 import java.io.InputStreamReader;
 
+import org.apache.plexus.service.repository.instance.InstanceManager;
+import org.apache.plexus.service.repository.factory.ComponentFactory;
+
 /**
  *  @author <a href="mailto:[email protected]">Jason van Zyl</a>
  */
@@ -50,16 +53,46 @@
         container.initialize();
         container.start();
 
+        int defaultComponents = 0;
+
+        // These are some default components that we used internally. These components don't
+        // usually need to be replaced but they can be if the user desires.
+
+        // Per-lookup instance manager.
+        InstanceManager plim =
+            (InstanceManager) container.getComponentRepository().lookup( InstanceManager.ROLE + "per-lookup" );
+        assertNotNull( plim );
+        defaultComponents++;
+
+        // Poolable instance manager.
+        InstanceManager pim =
+            (InstanceManager) container.getComponentRepository().lookup( InstanceManager.ROLE + "poolable" );
+        assertNotNull( pim );
+        defaultComponents++;
+
+        // Singleton instance manager.
+        InstanceManager sim =
+            (InstanceManager) container.getComponentRepository().lookup( InstanceManager.ROLE + "singleton" );
+        assertNotNull( sim );
+        defaultComponents++;
+
+        // Java Component factory.
+        // Singleton instance manager.
+        ComponentFactory jcf =
+            (ComponentFactory) container.getComponentRepository().lookup( ComponentFactory.ROLE + "java" );
+        assertNotNull( jcf );
+        defaultComponents++;
+
         // Make sure all our service descriptors are present.
-        assertEquals( 3, container.getServiceRepository().configuredServices() );
+        assertEquals( 4 + defaultComponents, container.getComponentRepository().configuredComponents() );
 
         // ----------------------------------------------------------------------
         //  ServiceDescriptors
         // ----------------------------------------------------------------------
 
-        assertEquals( true, container.getServiceRepository().hasService( ServiceA.ROLE ) );
-        assertEquals( true, container.getServiceRepository().hasService( ServiceB.ROLE ) );
-        assertEquals( true, container.getServiceRepository().hasService( ServiceC.ROLE + "only-instance" ) );
+        assertEquals( true, container.getComponentRepository().hasService( ServiceA.ROLE ) );
+        assertEquals( true, container.getComponentRepository().hasService( ServiceB.ROLE ) );
+        assertEquals( true, container.getComponentRepository().hasService( ServiceC.ROLE + "only-instance" ) );
 
         // ----------------------------------------------------------------------
         //  ServiceA
@@ -68,13 +101,13 @@
         // ----------------------------------------------------------------------
 
         // Retrieve an instance of service a.
-        DefaultServiceA serviceA = (DefaultServiceA) container.getServiceRepository().lookup( ServiceA.ROLE );
+        DefaultServiceA serviceA = (DefaultServiceA) container.getComponentRepository().lookup( ServiceA.ROLE );
 
         // Make sure the service is alive.
         assertNotNull( serviceA );
 
         // After the above lookup we should have one instantiated service.
-        assertEquals( 1, container.getServiceRepository().instantiatedServices() );
+        assertEquals( 1 + defaultComponents, container.getComponentRepository().instantiatedComponents() );
 
         assertEquals( true, serviceA.enableLogging );
         assertEquals( true, serviceA.contextualize );
@@ -85,13 +118,13 @@
 
         // Now how do we make sure it has been released and decomissioned
         // properly.
-        container.getServiceRepository().release( serviceA );
+        container.getComponentRepository().release( serviceA );
 
         // Now we have released the component so there should be no instantiated services.
-        assertEquals( 0, container.getServiceRepository().instantiatedServices() );
+        assertEquals( 0 + defaultComponents, container.getComponentRepository().instantiatedComponents() );
 
         // Make sure the number of configured components is still 3.
-        assertEquals( 3, container.getServiceRepository().configuredServices() );
+        assertEquals( 4 + defaultComponents , container.getComponentRepository().configuredComponents() );
 
         // ----------------------------------------------------------------------
         //  ServiceB
@@ -101,7 +134,7 @@
         // ----------------------------------------------------------------------
 
         // Retrieve an instance of service b.
-        DefaultServiceB serviceB1 = (DefaultServiceB) container.getServiceRepository().lookup( ServiceB.ROLE );
+        DefaultServiceB serviceB1 = (DefaultServiceB) container.getComponentRepository().lookup( ServiceB.ROLE );
 
         // Make sure the service is alive.
         assertNotNull( serviceB1 );
@@ -116,26 +149,45 @@
         assertNotNull( serviceB1.getClassLoader() );
 
         // Retrieve another
-        DefaultServiceB serviceB2 = (DefaultServiceB) container.getServiceRepository().lookup( ServiceB.ROLE );
+        DefaultServiceB serviceB2 = (DefaultServiceB) container.getComponentRepository().lookup( ServiceB.ROLE );
 
         // ----------------------------------------------------------------------
         //  ServiceC
         // ----------------------------------------------------------------------
 
-        // Retrieve an instance of service b.
-        DefaultServiceC serviceC1 = (DefaultServiceC) container.getServiceRepository().lookup( ServiceC.ROLE, "only-instance" );
+        // Retrieve an instance of service c.
+        DefaultServiceC serviceC1 =
+            (DefaultServiceC) container.getComponentRepository().lookup( ServiceC.ROLE, "only-instance" );
 
         // Make sure the service is alive.
         assertNotNull( serviceC1 );
 
         // Retrieve the only instance again from the service repository.
-        DefaultServiceC serviceC2 = (DefaultServiceC) container.getServiceRepository().lookup( ServiceC.ROLE, "only-instance" );
+        DefaultServiceC serviceC2 =
+            (DefaultServiceC) container.getComponentRepository().lookup( ServiceC.ROLE, "only-instance" );
+
+        // Make sure component is alive.
+        assertNotNull( serviceC2 );
 
         // Let's make sure it gave us back the same instance.
-        assertEquals( serviceC1, serviceC2 );
+        assertSame( serviceC1, serviceC2 );
 
-        // Now how to enforce the lifecycle
-        // Assembly contracts
+        // ----------------------------------------------------------------------
+        //  ServiceD
+        // ----------------------------------------------------------------------
 
+        // Retrieve an instance of service c.
+        ServiceD serviceD1 = (ServiceD) container.getComponentRepository().lookup( ServiceD.ROLE );
+        assertNotNull( serviceD1 );
+
+        ServiceD serviceD2 = (ServiceD) container.getComponentRepository().lookup( ServiceD.ROLE );
+        assertNotNull( serviceD2 );
+
+        ServiceD serviceD3 = (ServiceD) container.getComponentRepository().lookup( ServiceD.ROLE );
+        assertNotNull( serviceD3 );
+
+        assertNotSame( serviceD1, serviceD2 );
+        assertNotSame( serviceD2, serviceD3 );
+        assertNotSame( serviceD1, serviceD3 );
     }
 }

Index: configuration.xml
===================================================================
RCS file: /cvsroot/plexus/plexus-container-new/src/test/org/apache/plexus/configuration.xml,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- configuration.xml	27 Apr 2003 20:20:04 -0000	1.3
+++ configuration.xml	1 May 2003 19:35:36 -0000	1.4
@@ -12,7 +12,6 @@
     <component>
       <role>org.apache.plexus.ServiceA</role>
       <implementation>org.apache.plexus.DefaultServiceA</implementation>
-      <instantiation>per-lookup</instantiation>
       <configuration>
         <host>localhost</host>
         <port>10000</port>
@@ -27,7 +26,6 @@
     <component>
       <role>org.apache.plexus.ServiceB</role>
       <implementation>org.apache.plexus.DefaultServiceB</implementation>
-      <instantiation>singleton</instantiation>
       <configuration>
         <host>localhost</host>
         <port>10000</port>
@@ -43,13 +41,26 @@
       <role>org.apache.plexus.ServiceC</role>
       <id>only-instance</id>
       <implementation>org.apache.plexus.DefaultServiceC</implementation>
-      <instantiation>per-lookup</instantiation>
       <configuration>
         <host>localhost</host>
         <port>10000</port>
       </configuration>
     </component>
 
+    <!--
+     |
+     | D Service
+     |
+     -->
+    <component>
+      <role>org.apache.plexus.ServiceD</role>
+      <implementation>org.apache.plexus.DefaultServiceD</implementation>
+      <instantiation-strategy>poolable</instantiation-strategy>
+      <configuration>
+        <host>localhost</host>
+        <port>10000</port>
+      </configuration>
+    </component>
   </components>
 
 </plexus>