Author: gtrasuk
Date: Tue Dec  7 07:58:36 2010
New Revision: 1042929

URL: http://svn.apache.org/viewvc?rev=1042929&view=rev
Log:
Work in progress.  A little more work on the configuration subsystem.

Added:
    
incubator/river/jtsk/skunk/surrogate/test/org/apache/river/container/config/config-test-bad-doc.xml
Modified:
    incubator/river/jtsk/skunk/surrogate/schemas/config.xsd
    
incubator/river/jtsk/skunk/surrogate/src/org/apache/river/container/AnnotatedClassDeployer.java
    
incubator/river/jtsk/skunk/surrogate/src/org/apache/river/container/ConfigurationException.java
    
incubator/river/jtsk/skunk/surrogate/src/org/apache/river/container/DeployedObject.java
    
incubator/river/jtsk/skunk/surrogate/src/org/apache/river/container/Injected.java
    
incubator/river/jtsk/skunk/surrogate/src/org/apache/river/container/LocalizedRuntimeException.java
    
incubator/river/jtsk/skunk/surrogate/src/org/apache/river/container/MessageNames.java
    
incubator/river/jtsk/skunk/surrogate/src/org/apache/river/container/Messages.properties
    
incubator/river/jtsk/skunk/surrogate/test/org/apache/river/container/AnnotatedClassDeployerTest.java
    
incubator/river/jtsk/skunk/surrogate/test/org/apache/river/container/config/ConfigurationParserTest.java
    
incubator/river/jtsk/skunk/surrogate/test/org/apache/river/container/config/config-test-doc.xml

Modified: incubator/river/jtsk/skunk/surrogate/schemas/config.xsd
URL: 
http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/surrogate/schemas/config.xsd?rev=1042929&r1=1042928&r2=1042929&view=diff
==============================================================================
--- incubator/river/jtsk/skunk/surrogate/schemas/config.xsd (original)
+++ incubator/river/jtsk/skunk/surrogate/schemas/config.xsd Tue Dec  7 07:58:36 
2010
@@ -1,13 +1,25 @@
 <?xml version="1.0" encoding="UTF-8"?>
 
 <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema";
+    xmlns:jaxb="http://java.sun.com/xml/ns/jaxb";
     targetNamespace="http://river.apache.org/xml/ns/container/config/1.0";
     xmlns:tns="http://river.apache.org/xml/ns/container/config/1.0";
-    elementFormDefault="qualified">
+    jaxb:version="2.0" elementFormDefault="qualified">
     <xsd:element name="container-config">
         <xsd:complexType>
             <xsd:sequence>
                 <xsd:element ref="tns:classpath"/>
+                <xsd:choice maxOccurs="unbounded">
+                    <xsd:annotation>
+                        <xsd:appinfo>
+                            <jaxb:property name="elements"/>
+                       </xsd:appinfo>
+                    </xsd:annotation>
+                    <xsd:element ref="tns:property"/>
+                    <xsd:element ref="tns:component"/>
+                    <xsd:element name="discovery-context"
+                    type="tns:DiscoveryContextType"/>
+                </xsd:choice>
                 
             </xsd:sequence>
         </xsd:complexType>
@@ -23,4 +35,19 @@
     </xsd:complexType>
     
     <xsd:element name="classpath" type="xsd:string"/>
+
+    <xsd:element name="property">
+        <xsd:complexType>
+            <xsd:attribute name="name" type="xsd:string" use="required"/>
+            <xsd:attribute name="value" type="xsd:string" use="required"/>
+        </xsd:complexType>
+    </xsd:element>
+
+    <xsd:element name="component">
+        <xsd:complexType>
+            <xsd:attribute name="name" type="xsd:string" use="optional"/>
+            <xsd:attribute name="class" type="xsd:string" use="required"/>
+        </xsd:complexType>
+    </xsd:element>
+
 </xsd:schema>

Modified: 
incubator/river/jtsk/skunk/surrogate/src/org/apache/river/container/AnnotatedClassDeployer.java
URL: 
http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/surrogate/src/org/apache/river/container/AnnotatedClassDeployer.java?rev=1042929&r1=1042928&r2=1042929&view=diff
==============================================================================
--- 
incubator/river/jtsk/skunk/surrogate/src/org/apache/river/container/AnnotatedClassDeployer.java
 (original)
+++ 
incubator/river/jtsk/skunk/surrogate/src/org/apache/river/container/AnnotatedClassDeployer.java
 Tue Dec  7 07:58:36 2010
@@ -57,11 +57,17 @@ public class AnnotatedClassDeployer impl
              */
             resolve();
         } catch (IllegalArgumentException ex) {
-            log.log(Level.SEVERE, null, ex);
+            throw new ConfigurationException(
+                    ex,
+                    MessageNames.ILLEGAL_ARGUMENT_EXCEPTION);
         } catch (IllegalAccessException ex) {
-            log.log(Level.SEVERE, null, ex);
+            throw new ConfigurationException(
+                    ex,
+                    MessageNames.ILLEGAL_ACCESS_EXCEPTION);
         } catch (InvocationTargetException ex) {
-            log.log(Level.SEVERE, null, ex);
+            throw new ConfigurationException(
+                    ex,
+                    MessageNames.INVOCATION_TARGET_EXCEPTION);
         }
     }
 
@@ -73,8 +79,18 @@ public class AnnotatedClassDeployer impl
         this.context = ctx;
     }
 
+    private void initializeIfFullyResolved(DeployedObject deployed) throws 
IllegalAccessException, IllegalArgumentException, InvocationTargetException {
+        if (deployed.getUnresolvedDependencies().isEmpty()) {
+            for(Method initMethod: deployed.getInitMethods()) {
+                initMethod.invoke(deployed.getDeployedObject());
+            }
+            uninitializedObjects.remove(deployed);
+            initializedObjects.put(deployed.getName(), deployed);
+        }
+    }
+
     private void readInObject(String name, Object o) {
-        log.logp(Level.FINER, "AnnotatedClassDeployer", "readInObject",
+        log.log(Level.FINER, 
                 MessageNames.READING_OBJECT,
                 new Object[]{name, o.getClass().getName()});
 
@@ -85,17 +101,17 @@ public class AnnotatedClassDeployer impl
         deployed.setName(name);
         List<Member> members = buildMemberList(cls);
         List<Member> unresolved = deployed.getUnresolvedDependencies();
-        log.logp(Level.FINER, "AnnotatedClassDeployer", "readInObject",
+        log.log(Level.FINER,
                 MessageNames.READING_OBJECT_MEMBER_COUNT, members.size());
 
         for (Member m : members) {
             if (isAnnotatedAsInjected(m)) {
-                log.logp(Level.FINER, "AnnotatedClassDeployer", "readInObject",
+                log.log(Level.FINER,
                         MessageNames.READING_OBJECT_ANNOTATED_MEMBER_FOUND, 
m.toString());
                 unresolved.add(m);
             }
             if (isInitMethod(m)) {
-                deployed.getInitMethods().add(m);
+                deployed.getInitMethods().add((Method) m);
             }
         }
         /* Add the object and list to our unsatisfied group. */
@@ -118,29 +134,17 @@ public class AnnotatedClassDeployer impl
         if (annEm.getAnnotation(Init.class) == null) {
             return false;
         }
-        if (m instanceof Field) {
-            /* Really can't happen since the annotation is marked as
-             method-only.
-             */
-            throw new ConfigurationException(MessageNames.FIELD_ANNOTATED_INIT,
-                    new Object[] {
-                        m.getDeclaringClass().getName(),
-                        m.getName()});
-
-        }
         Method method=(Method) m;
         if (method.getReturnType() != void.class) {
             throw new ConfigurationException(MessageNames.INIT_METHOD_NOT_VOID,
-                    new Object[] {
                         m.getDeclaringClass().getName(),
                         m.getName(),
-                        method.getReturnType()});
+                        method.getReturnType());
         }
         if (method.getParameterTypes().length != 0) {
             throw new 
ConfigurationException(MessageNames.INIT_METHOD_HAS_PARAMETERS,
-                    new Object[] {
                         m.getDeclaringClass().getName(),
-                        m.getName()});
+                        m.getName());
         }
         return true;
     }
@@ -178,30 +182,41 @@ public class AnnotatedClassDeployer impl
         return members;
     }
 
+    private void removeDependencyFromUnresolvedList(DeployedObject deployed, 
Member m) {
+        deployed.getUnresolvedDependencies().remove(m);
+    }
+
     private void resolve() throws IllegalArgumentException, 
IllegalAccessException, InvocationTargetException {
-        boolean changed = false;
+        boolean changed;
         do {
+            changed=false;
             /* For each object in the unsatisfied group, */
             /* Group of uninitialized objects may change while we're going
             through them, so use a copy of the array.
              */
             for (DeployedObject deployed : new 
ArrayList<DeployedObject>(uninitializedObjects)) {
+                /* Attempt to resolve unsatisfied dependencies. */
                 for (Member m : new 
ArrayList<Member>(deployed.getUnresolvedDependencies())) {
                     /* If there's a name annotated, lookup by name. */
                     String name = nameAnnotation(m);
                     Object val = null;
                     if (!name.equals(Strings.EMPTY)) {
-                        val = initializedObjects.get(name);
+                        DeployedObject deployedCandidate= 
initializedObjects.get(name);
+                        if (deployedCandidate!=null) {
+                            val=deployedCandidate.getDeployedObject();
+                        }
                     } else {
                         val = findAssignable(m);
                     }
                     if (val != null) {
+                        changed=true;
                         inject(deployed, m, val);
+                        removeDependencyFromUnresolvedList(deployed, m);
                     }
                 }
-                /* Attempt to resolve unsatisfied dependencies. */
                 /* If satisfied, remove from unsatisfied group and
-                put into candidate group, setting changed=true. */
+                put into candidate group, then initialize. */
+                initializeIfFullyResolved(deployed);
             }
         } while (changed);
 
@@ -210,7 +225,7 @@ public class AnnotatedClassDeployer impl
     private String nameAnnotation(Member m) {
         AnnotatedElement annEm = (AnnotatedElement) m;
         Injected inj = (Injected) annEm.getAnnotation(Injected.class);
-        return inj.name();
+        return inj.value();
     }
 
     /**
@@ -232,6 +247,11 @@ public class AnnotatedClassDeployer impl
         if (Context.class.isAssignableFrom(requiredType)) {
             return context;
         }
+        for (DeployedObject candidate: initializedObjects.values()) {
+            if 
(candidate.getDeployedObject().getClass().isAssignableFrom(requiredType)) {
+                return candidate.getDeployedObject();
+            }
+        }
         return null;
     }
 
@@ -246,16 +266,10 @@ public class AnnotatedClassDeployer impl
     @param val The value to set.
      */
     private void inject(DeployedObject deployed, Member m, Object val) throws 
IllegalArgumentException, IllegalAccessException, InvocationTargetException {
-        log.logp(Level.FINER, "AnnotatedClassDeployer", "inject",
+        log.log(Level.FINER, 
                 MessageNames.INJECT,
                 new Object[]{deployed.getName(), m.getName(), val});
         memberSet(deployed.getDeployedObject(), m, val);
-        deployed.getUnresolvedDependencies().remove(m);
-        if (deployed.getUnresolvedDependencies().isEmpty()) {
-            // TODO: Invoke init method.
-            uninitializedObjects.remove(deployed);
-            initializedObjects.put(deployed.getName(), deployed);
-        }
     }
 
     private void memberSet(Object target, Member member, Object value) throws 
IllegalArgumentException, IllegalAccessException, InvocationTargetException {

Modified: 
incubator/river/jtsk/skunk/surrogate/src/org/apache/river/container/ConfigurationException.java
URL: 
http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/surrogate/src/org/apache/river/container/ConfigurationException.java?rev=1042929&r1=1042928&r2=1042929&view=diff
==============================================================================
--- 
incubator/river/jtsk/skunk/surrogate/src/org/apache/river/container/ConfigurationException.java
 (original)
+++ 
incubator/river/jtsk/skunk/surrogate/src/org/apache/river/container/ConfigurationException.java
 Tue Dec  7 07:58:36 2010
@@ -24,7 +24,11 @@ package org.apache.river.container;
  * @author trasukg
  */
 public class ConfigurationException extends LocalizedRuntimeException {
-   public ConfigurationException(String messageKey, Object[] parameters) {
+   public ConfigurationException(String messageKey, Object ... parameters) {
        super(MessageNames.BUNDLE_NAME, messageKey, parameters);
    }
+
+   public ConfigurationException(Throwable rootCause, String messageKey, 
Object ... parameters) {
+       super(rootCause, MessageNames.BUNDLE_NAME, messageKey, parameters);
+   }
 }

Modified: 
incubator/river/jtsk/skunk/surrogate/src/org/apache/river/container/DeployedObject.java
URL: 
http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/surrogate/src/org/apache/river/container/DeployedObject.java?rev=1042929&r1=1042928&r2=1042929&view=diff
==============================================================================
--- 
incubator/river/jtsk/skunk/surrogate/src/org/apache/river/container/DeployedObject.java
 (original)
+++ 
incubator/river/jtsk/skunk/surrogate/src/org/apache/river/container/DeployedObject.java
 Tue Dec  7 07:58:36 2010
@@ -19,6 +19,7 @@
 package org.apache.river.container;
 
 import java.lang.reflect.Member;
+import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -31,9 +32,9 @@ public class DeployedObject {
     private Object deployedObject=null;
     private String name;
     private List<Member> unresolvedDependencies=new ArrayList<Member>();
-    private List<Member> initMethods=new ArrayList<Member>();
+    private List<Method> initMethods=new ArrayList<Method>();
 
-    public List<Member> getInitMethods() {
+    public List<Method> getInitMethods() {
         return initMethods;
     }
 

Modified: 
incubator/river/jtsk/skunk/surrogate/src/org/apache/river/container/Injected.java
URL: 
http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/surrogate/src/org/apache/river/container/Injected.java?rev=1042929&r1=1042928&r2=1042929&view=diff
==============================================================================
--- 
incubator/river/jtsk/skunk/surrogate/src/org/apache/river/container/Injected.java
 (original)
+++ 
incubator/river/jtsk/skunk/surrogate/src/org/apache/river/container/Injected.java
 Tue Dec  7 07:58:36 2010
@@ -57,5 +57,5 @@ import java.lang.annotation.Target;
 @Retention(RetentionPolicy.RUNTIME)
 @Target({ElementType.FIELD, ElementType.METHOD})
 public @interface Injected {
-    String name() default Strings.EMPTY;
+    String value() default Strings.EMPTY;
 }

Modified: 
incubator/river/jtsk/skunk/surrogate/src/org/apache/river/container/LocalizedRuntimeException.java
URL: 
http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/surrogate/src/org/apache/river/container/LocalizedRuntimeException.java?rev=1042929&r1=1042928&r2=1042929&view=diff
==============================================================================
--- 
incubator/river/jtsk/skunk/surrogate/src/org/apache/river/container/LocalizedRuntimeException.java
 (original)
+++ 
incubator/river/jtsk/skunk/surrogate/src/org/apache/river/container/LocalizedRuntimeException.java
 Tue Dec  7 07:58:36 2010
@@ -46,6 +46,22 @@ public class LocalizedRuntimeException e
     }
 
     /**
+     Construct a runtime exception with a localized message.
+     @param messageBundleName
+     @param messageKey
+     @param messageParameters
+     */
+    public LocalizedRuntimeException(Throwable rootCause,
+            String messageBundleName,
+            String messageKey,
+            Object[] messageParameters) {
+        super(rootCause);
+        this.messageBundleName=messageBundleName;
+        this.messageKey=messageKey;
+        this.messageParameters=messageParameters;
+    }
+
+    /**
      Localize and return the error message, according to the default Locale.
      Note that the resolution of the resource bundle and the localization is
      deferred until this method is called, allowing the existence of different

Modified: 
incubator/river/jtsk/skunk/surrogate/src/org/apache/river/container/MessageNames.java
URL: 
http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/surrogate/src/org/apache/river/container/MessageNames.java?rev=1042929&r1=1042928&r2=1042929&view=diff
==============================================================================
--- 
incubator/river/jtsk/skunk/surrogate/src/org/apache/river/container/MessageNames.java
 (original)
+++ 
incubator/river/jtsk/skunk/surrogate/src/org/apache/river/container/MessageNames.java
 Tue Dec  7 07:58:36 2010
@@ -26,7 +26,9 @@ public class MessageNames {
     public static final String 
BUNDLE_NAME="org.apache.river.container.Messages";
 
     public static final String
-            FIELD_ANNOTATED_INIT="fieldAnnotatedInit",
+            ILLEGAL_ARGUMENT_EXCEPTION="illegalArgumentException",
+            ILLEGAL_ACCESS_EXCEPTION="illegalAccessException",
+            INVOCATION_TARGET_EXCEPTION="invocationTargetException",
             INIT_METHOD_HAS_PARAMETERS="initMethodHasParameters",
             INIT_METHOD_NOT_VOID="initMethodIsntVoid",
             INJECT="inject",

Modified: 
incubator/river/jtsk/skunk/surrogate/src/org/apache/river/container/Messages.properties
URL: 
http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/surrogate/src/org/apache/river/container/Messages.properties?rev=1042929&r1=1042928&r2=1042929&view=diff
==============================================================================
--- 
incubator/river/jtsk/skunk/surrogate/src/org/apache/river/container/Messages.properties
 (original)
+++ 
incubator/river/jtsk/skunk/surrogate/src/org/apache/river/container/Messages.properties
 Tue Dec  7 07:58:36 2010
@@ -16,12 +16,13 @@
  * limitations under the License.
  */
 
-fieldAnnotatedInit=File {1} on class {0} is incorrectly marked with the @Init \
-annotation.  Only methods of form ''void m()'' can be marked @Init.
+illegalArgumentException=An operation threw an IllegalArgumentException.
+illegalAccessException=An operation threw an IllegalAccessException.
+invocationTargetException=An operation threw an InvocationTargetException.
 initMethodHasParameters=A method flagged as @Init must take no parameters.  \
-Method {1} on class {0} has parameters.
+Method ''{1}'' on class ''{0}'' has parameters.
 initMethodIsntVoid=A method flagged as @Init must be void return type.  \
-Method {1} on class {0} returns {2}.
+Method ''{1}'' on class ''{0}'' returns ''{2}''.
 inject=Injecting {2} into member ''{1}'' of deployed object {0}.
 readingObject=Reading instance of {1} named ''{0}'' for unresolved 
dependencies.
 readingObject.memberCount={0} members found.

Modified: 
incubator/river/jtsk/skunk/surrogate/test/org/apache/river/container/AnnotatedClassDeployerTest.java
URL: 
http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/surrogate/test/org/apache/river/container/AnnotatedClassDeployerTest.java?rev=1042929&r1=1042928&r2=1042929&view=diff
==============================================================================
--- 
incubator/river/jtsk/skunk/surrogate/test/org/apache/river/container/AnnotatedClassDeployerTest.java
 (original)
+++ 
incubator/river/jtsk/skunk/surrogate/test/org/apache/river/container/AnnotatedClassDeployerTest.java
 Tue Dec  7 07:58:36 2010
@@ -95,6 +95,21 @@ public class AnnotatedClassDeployerTest 
     }
 
     /**
+    Init method must take no parameters and we should get an exception if it
+    has parameters;
+     */
+    @Test
+    public void testInitMethodWithParameters() {
+        try {
+            Object harness = new InjectionHarnessWithInitParameters();
+            UUT.put(harness.getClass().getName(), harness);
+            fail("Should have got a ConfigurationException");
+        } catch (ConfigurationException cfe) {
+            log.log(Level.FINE, "ConfigurationException caught correctly", 
cfe);
+        }
+    }
+
+    /**
     Test whether a single injected value is set on a component.
      */
     @Test
@@ -102,6 +117,7 @@ public class AnnotatedClassDeployerTest 
         InjectionHarness harness = new InjectionHarness();
         UUT.put(harness.getClass().getName(), harness);
         assertTrue("Init method wasn't called", harness.initialized);
+        assertTrue("Second init method wasn't called", 
harness.secondInitCalled);
     }
 
     /**
@@ -110,7 +126,27 @@ public class AnnotatedClassDeployerTest 
      */
     @Test
     public void testResourceInjected() {
-        fail("Implement me");
+        log.info("testResourceInjected()");
+        InjectionHarness harness=new InjectionHarness();
+        InjectionHarnessWithDependencies harness2=
+                new InjectionHarnessWithDependencies();
+        UUT.put(harness.getClass().getName(), harness);
+        UUT.put(harness2.getClass().getName(), harness2);
+        assertEquals(harness, harness2.harness);
+    }
+
+    /**
+    Test that if we have two items deployed, one will be injected into the
+    other.
+     */
+    @Test
+    public void testResourceInjectedByName() {
+        InjectionHarness harness=new InjectionHarness();
+        InjectionHarnessWithNamedDependencies harness2=
+                new InjectionHarnessWithNamedDependencies();
+        UUT.put("this.is.a.name", "Bob");
+        UUT.put(harness2.getClass().getName(), harness2);
+        assertEquals("Bob", harness2.injectedVariable);
     }
 
     private class InjectionHarness {
@@ -118,11 +154,16 @@ public class AnnotatedClassDeployerTest 
         @Injected
         Context context = null;
         boolean initialized = false;
+        boolean secondInitCalled=false;
 
         @Init
         void init() {
             initialized = true;
         }
+
+        @Init void initAgain() {
+            secondInitCalled=true;
+        }
     }
 
     private class InjectionHarnessWithNonVoidInit {
@@ -132,6 +173,25 @@ public class AnnotatedClassDeployerTest 
             return -1;
         }
 
-        ;
+    }
+
+    private class InjectionHarnessWithInitParameters {
+
+        @Init
+        public void init(int j) {
+
+        }
+     }
+
+    private class InjectionHarnessWithDependencies {
+
+        @Injected InjectionHarness harness=null;
+
+    }
+
+    private class InjectionHarnessWithNamedDependencies {
+
+        @Injected("this.is.a.name") String injectedVariable=null;
+
     }
 }

Modified: 
incubator/river/jtsk/skunk/surrogate/test/org/apache/river/container/config/ConfigurationParserTest.java
URL: 
http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/surrogate/test/org/apache/river/container/config/ConfigurationParserTest.java?rev=1042929&r1=1042928&r2=1042929&view=diff
==============================================================================
--- 
incubator/river/jtsk/skunk/surrogate/test/org/apache/river/container/config/ConfigurationParserTest.java
 (original)
+++ 
incubator/river/jtsk/skunk/surrogate/test/org/apache/river/container/config/ConfigurationParserTest.java
 Tue Dec  7 07:58:36 2010
@@ -5,6 +5,9 @@
 package org.apache.river.container.config;
 
 import java.io.InputStream;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.xml.bind.JAXBException;
 import org.junit.After;
 import org.junit.AfterClass;
 import static org.junit.Assert.*;
@@ -20,7 +23,7 @@ import javax.xml.bind.Unmarshaller;
  */
 public class ConfigurationParserTest {
 
-    public ConfigurationParserTest() {
+    public ConfigurationParserTest() throws Exception {
     }
 
     @BeforeClass
@@ -39,13 +42,27 @@ public class ConfigurationParserTest {
     public void tearDown() {
     }
 
+    JAXBContext ctx = 
JAXBContext.newInstance("org.apache.river.container.config");
+    Unmarshaller um = ctx.createUnmarshaller();
+
     @Test
     public void testConfigFileRead() throws Exception {
-        JAXBContext 
ctx=JAXBContext.newInstance("org.apache.river.container.config");
-        Unmarshaller um=ctx.createUnmarshaller();
-        InputStream is=getClass().getResourceAsStream("config-test-doc.xml");
-        ContainerConfig containerConfig=(ContainerConfig) um.unmarshal(is);
+
+        InputStream is = getClass().getResourceAsStream("config-test-doc.xml");
+        ContainerConfig containerConfig = (ContainerConfig) um.unmarshal(is);
 
         assertEquals("lib/abc.jar", containerConfig.getClasspath());
+        assertEquals(3, containerConfig.getElements().size());
     }
+
+    @Test
+    public void testInvalidConfigFileRead() {
+        InputStream is = 
getClass().getResourceAsStream("config-test-bad-doc.xml");
+        try {
+            ContainerConfig containerConfig = (ContainerConfig) 
um.unmarshal(is);
+            fail("Should have gotten a validation error.");
+        } catch (JAXBException ex) {
+            // Got the exception; all is good.
+        }
+   }
 }

Added: 
incubator/river/jtsk/skunk/surrogate/test/org/apache/river/container/config/config-test-bad-doc.xml
URL: 
http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/surrogate/test/org/apache/river/container/config/config-test-bad-doc.xml?rev=1042929&view=auto
==============================================================================
--- 
incubator/river/jtsk/skunk/surrogate/test/org/apache/river/container/config/config-test-bad-doc.xml
 (added)
+++ 
incubator/river/jtsk/skunk/surrogate/test/org/apache/river/container/config/config-test-bad-doc.xml
 Tue Dec  7 07:58:36 2010
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+    Document   : config-test-doc.xml
+    Created on : November 24, 2010, 4:13 PM
+    Author     : trasukg
+    Description:
+        Purpose of the document follows.
+-->
+
+<cfg:container-config  xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
+   xmlns:cfg='http://river.apache.org/xml/ns/container/config/1.0'
+   xsi:schemaLocation='http://river.apache.org/xml/ns/container/config/1.0 
file:/home/trasukg/development/surrogate/schemas/config.xsd'>
+    <cfg:classpath>lib/abc.jar</cfg:classpath>
+
+    <cfg:discovery-context is-default="false" id="">
+        <cfg:locator></cfg:locator>
+        <cfg:group></cfg:group>
+    </cfg:discovery-context>
+
+    <cfg:property name="abc" value="def"/>
+
+    <!-- This ought to cause a validation error. -->
+    <component class="org.apache.SomethingOrOther"/>
+
+</cfg:container-config>

Modified: 
incubator/river/jtsk/skunk/surrogate/test/org/apache/river/container/config/config-test-doc.xml
URL: 
http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/surrogate/test/org/apache/river/container/config/config-test-doc.xml?rev=1042929&r1=1042928&r2=1042929&view=diff
==============================================================================
--- 
incubator/river/jtsk/skunk/surrogate/test/org/apache/river/container/config/config-test-doc.xml
 (original)
+++ 
incubator/river/jtsk/skunk/surrogate/test/org/apache/river/container/config/config-test-doc.xml
 Tue Dec  7 07:58:36 2010
@@ -18,4 +18,8 @@
         <cfg:group></cfg:group>
     </cfg:discovery-context>
 
+    <cfg:property name="abc" value="def"/>
+
+    <cfg:component class="org.apache.SomethingOrOther"/>
+
 </cfg:container-config>


Reply via email to