Skip to Content.
Sympa Menu

notify-dpml - svn commit: r2611 - in development/main/test/unit/simple: . src/test/net/dpml/test/acme

notify-dpml AT lists.ibiblio.org

Subject: DPML Notify

List archive

Chronological Thread  
  • From: mcconnell AT dpml.net
  • To: notify-dpml AT lists.ibiblio.org
  • Subject: svn commit: r2611 - in development/main/test/unit/simple: . src/test/net/dpml/test/acme
  • Date: Thu, 19 May 2005 01:32:46 +0000

Author: mcconnell AT dpml.net
Date: Thu May 19 01:32:29 2005
New Revision: 2611

Added:

development/main/test/unit/simple/src/test/net/dpml/test/acme/CompositeTestCase.java
Modified:
development/main/test/unit/simple/build.xml
Log:
add composite testcase

Modified: development/main/test/unit/simple/build.xml
==============================================================================
--- development/main/test/unit/simple/build.xml (original)
+++ development/main/test/unit/simple/build.xml Thu May 19 01:32:29 2005
@@ -122,6 +122,88 @@
</parts>
</component>

+ <!--
+ Composite component example.
+ This is a example of a composite component (the AcmeContainer class)
+ with parts that it manages. The parts include a gizmo and widget
+ component which are automatically resolved by the container and supplied
+ to the AcmeContainer component via the Parts constructor argument.
+ Note that we are not including the Dimension arguments in the context
+ thereby demonstrating optional context entry semantic. A feature of
+ this example is the usage of a reference element as the mechanisms
+ to wire the context 'widget' part into the context supplied to the
+ 'gizmo' component. Wiring of dependencies is explicit and handled
+ by the reference element within Gizmo's context. The reference element
+ declares that the context entry for the key 'widget', supplied to
+ Gizmo shall be the selected from the 'parts' of the enclosing component
+ using the name 'widget' (where the uri is in the form [scope]:[name] and
+ scope may be one of 'context' or 'parts' refering respectivly to the
+ enclosing components parts or context).
+ -->
+ <component dest="target/test/acme-container.part"
+ xmlns="plugin:dpml/composition/dpml-composition-builder"
+ type="net.dpml.test.acme.AcmeContainer"
+ name="acme">
+ <parts>
+ <component name="widget" type="net.dpml.test.acme.WidgetComponent">
+ <context>
+ <value key="workingDirectory">
+ <param class="java.io.File" value="urn:system:work.dir"/>
+ <param value="acme/workspace"/>
+ </value>
+ <value key="name" value="urn:model:name"/>
+ <value key="partition" value="urn:model:partition"/>
+ <value key="uri" value="urn:model:uri"/>
+ </context>
+ </component>
+ <component name="gizmo" type="net.dpml.test.acme.GizmoComponent">
+ <context>
+ <value key="color" value="red"/>
+ <reference key="widget" uri="parts:widget"/>
+ </context>
+ </component>
+ </parts>
+ </component>
+
+ <!--
+ Composite component example.
+ Using the same container as above, the following example demonstrates
the
+ replacement of the DefaultWidget component with an alternative
implementation
+ using the SimpleWidget type.
+ -->
+ <component dest="target/test/acme-test-container.part"
+ xmlns="plugin:dpml/composition/dpml-composition-builder"
+ type="net.dpml.test.acme.AcmeContainer"
+ name="acme">
+ <parts>
+ <component name="widget" type="net.dpml.test.acme.SimpleWidget"/>
+ <component name="gizmo" type="net.dpml.test.acme.GizmoComponent">
+ <context>
+ <value key="color" value="red"/>
+ <reference key="widget" uri="parts:widget"/>
+ </context>
+ </component>
+ </parts>
+ </component>
+
+ <!--
+ Example using the BadWidget
+ -->
+ <component dest="target/test/acme-bad-widget.part"
+ xmlns="plugin:dpml/composition/dpml-composition-builder"
+ type="net.dpml.test.acme.AcmeContainer"
+ name="acme">
+ <parts>
+ <component name="widget" type="net.dpml.test.acme.BadWidget"/>
+ <component name="gizmo" type="net.dpml.test.acme.GizmoComponent">
+ <context>
+ <value key="color" value="red"/>
+ <reference key="widget" uri="parts:widget"/>
+ </context>
+ </component>
+ </parts>
+ </component>
+
</target>

<target name="package" depends="build"/>

Added:
development/main/test/unit/simple/src/test/net/dpml/test/acme/CompositeTestCase.java
==============================================================================
--- (empty file)
+++
development/main/test/unit/simple/src/test/net/dpml/test/acme/CompositeTestCase.java
Thu May 19 01:32:29 2005
@@ -0,0 +1,104 @@
+/*
+ * Copyright 2004 Stephen J. McConnell.
+ * Copyright 1999-2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ *
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.dpml.test.acme;
+
+import java.net.URI;
+import java.util.Hashtable;
+import java.util.Map.Entry;
+
+import junit.framework.TestCase;
+
+import net.dpml.parts.model.Model;
+import net.dpml.parts.model.Component;
+import net.dpml.parts.control.Controller;
+import net.dpml.parts.control.Manager;
+
+import net.dpml.composition.unit.CompositionHelper;
+
+/**
+ * Test a simple component case.
+ *
+ * @author <a href="mailto:dev-dpml AT lists.ibiblio.org";>The Digital Product
Meta Library</a>
+ * @version $Id: AbstractDescriptorTestCase.java 1556 2005-01-22 12:43:42Z
niclas $
+ */
+public class CompositeTestCase extends TestCase
+{
+ /**
+ * Test the construction of a component that contains two child components
+ * widget and gizmo where both are components and gizmo declares a
dependency
+ * on widget.
+ */
+ public void testAcmeContainerUsingComponent() throws Exception
+ {
+ executeTestOnPart( "acme-container.part" );
+ }
+
+ /**
+ * Test the construction of a component that contains two child components
+ * (widget and gizmo) where the widget is a value object.
+ */
+ public void testAcmeContainerUsingValue() throws Exception
+ {
+ executeTestOnPart( "acme-test-container.part" );
+ }
+
+ /**
+ * Test the construction of a component that contains two child components
+ * widget and gizmo where both are components and gizmo declares a
dependency
+ * on widget.
+ */
+ public void testBadWidget() throws Exception
+ {
+ CompositionHelper helper = new CompositionHelper();
+ URI uri = helper.toURI( "acme-bad-widget.part" );
+ Component component = helper.getCompositionManager().addComponent(
uri, "acme" );
+ AcmeContainer container = (AcmeContainer) component.resolve( false );
+ try
+ {
+ container.execute();
+ }
+ catch( BadColorException e )
+ {
+ // success
+ }
+ finally
+ {
+ component.release( container );
+ helper.dispose();
+ }
+ }
+
+ private void executeTestOnPart( String path ) throws Exception
+ {
+ CompositionHelper helper = new CompositionHelper();
+ URI uri = helper.toURI( path );
+ Component component = helper.getCompositionManager().addComponent(
uri, "acme" );
+ AcmeContainer container = (AcmeContainer) component.resolve( false );
+ try
+ {
+ container.execute();
+ }
+ finally
+ {
+ component.release( container );
+ helper.dispose();
+ }
+ }
+}



  • svn commit: r2611 - in development/main/test/unit/simple: . src/test/net/dpml/test/acme, mcconnell, 05/18/2005

Archive powered by MHonArc 2.6.24.

Top of Page