hivemind-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From k...@apache.org
Subject cvs commit: jakarta-hivemind/framework/src/test/org/apache/hivemind/impl TestSchemaProcessor.java
Date Wed, 27 Apr 2005 10:49:41 GMT
knut        2005/04/27 03:49:40

  Modified:    .        status.xml
               framework/src/java/org/apache/hivemind/impl
                        SchemaElement.java
               framework/src/test/org/apache/hivemind/impl
                        TestSchemaProcessor.java
  Log:
  translate unique attribute values before checking uniqueness (see HIVEMIND-100)
  
  Revision  Changes    Path
  1.124     +1 -0      jakarta-hivemind/status.xml
  
  Index: status.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/status.xml,v
  retrieving revision 1.123
  retrieving revision 1.124
  diff -u -r1.123 -r1.124
  --- status.xml	16 Apr 2005 15:46:07 -0000	1.123
  +++ status.xml	27 Apr 2005 10:49:40 -0000	1.124
  @@ -41,6 +41,7 @@
         <action type="add" dev="HLS"> Added newLocation() method to HiveMindTestCase.
</action>
         <action type="add" dev="HLS" due-to="Achim Hügen" fixes-bug="HIVEMIND-97">
Apply Achim Hügen's JMX patch. </action>
         <action type="updated" dev="HLS"> Update to Javassist 3.0. </action>
  +      <action type="fix" dev="KW" due-to="Michael Frericks" fixes-bug="HIVEMIND-100">
Translate unique attribute values before checking uniqueness. </action>
       </release>
       <release version="1.1-alpha-3" date="Mar 22 2005">
         <action type="fix" dev="JC" fixes-bug="HIVEMIND-96" >Interceptors can now be
ordered by name rather than interceptor factory id.</action>
  
  
  
  1.8       +12 -3     jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/SchemaElement.java
  
  Index: SchemaElement.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/SchemaElement.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- SchemaElement.java	6 Jan 2005 01:45:12 -0000	1.7
  +++ SchemaElement.java	27 Apr 2005 10:49:40 -0000	1.8
  @@ -194,17 +194,26 @@
           if (valuesMap == null)
               return;
   
  -        Location prior = (Location) valuesMap.get(value);
  +        Object translatedValue = getAttributeTranslator(name).translate(
  +                _processor.getContributingModule(),
  +                Object.class,
  +                value,
  +                location);
  +
  +        Location prior = (Location) valuesMap.get(translatedValue);
   
           if (prior == null)
           {
  -            valuesMap.put(value, location);
  +            valuesMap.put(translatedValue, location);
               return;
           }
   
           // A conflict.
   
  -        errors.add(ImplMessages.uniqueAttributeConstraintBroken(name, value, prior));
  +        errors.add(ImplMessages.uniqueAttributeConstraintBroken(
  +                name,
  +                translatedValue.toString(),
  +                prior));
       }
   
       void fireBegin(Element element)
  
  
  
  1.13      +130 -0    jakarta-hivemind/framework/src/test/org/apache/hivemind/impl/TestSchemaProcessor.java
  
  Index: TestSchemaProcessor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-hivemind/framework/src/test/org/apache/hivemind/impl/TestSchemaProcessor.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- TestSchemaProcessor.java	10 Feb 2005 01:04:32 -0000	1.12
  +++ TestSchemaProcessor.java	27 Apr 2005 10:49:40 -0000	1.13
  @@ -18,9 +18,13 @@
   import hivemind.test.services.impl.StringHolderImpl;
   
   import java.util.Collections;
  +import java.util.Iterator;
   import java.util.List;
   import java.util.Map;
  +import java.util.Set;
  +import java.util.TreeSet;
   
  +import org.apache.hivemind.Location;
   import org.apache.hivemind.internal.Module;
   import org.apache.hivemind.schema.SchemaProcessor;
   import org.apache.hivemind.schema.Translator;
  @@ -279,6 +283,9 @@
   
           List elements = Collections.singletonList(element);
   
  +        m.getTranslator("cartoon");
  +        control.setReturnValue(new NullTranslator());
  +
           m.resolveType("StringHolderImpl");
           control.setReturnValue(StringHolderImpl.class);
   
  @@ -312,4 +319,127 @@
           verifyControls();
       }
   
  +    /**
  +     * Test contributing 2 elements from 2 modules to a configuration-point with an attribute
that
  +     * is marked unique and is translated by translator 'qualified-id'. Both contributed
elements
  +     * use same untranslated value in the unique attribute. Fixes HIVEMIND-100.
  +     */
  +    public void testUniqueElement()
  +    {
  +        ElementModelImpl em = new ElementModelImpl();
  +
  +        em.setElementName("cartoon");
  +
  +        AttributeModelImpl am = new AttributeModelImpl();
  +        am.setName("name");
  +        am.setTranslator("qualified-id");
  +        am.setUnique(true);
  +
  +        em.addAttributeModel(am);
  +
  +        em.addRule(new CreateObjectRule("StringHolderImpl"));
  +
  +        ReadAttributeRule rule = new ReadAttributeRule();
  +        rule.setAttributeName("name");
  +        rule.setPropertyName("value");
  +
  +        em.addRule(rule);
  +
  +        em.addRule(new InvokeParentRule("addElement"));
  +
  +        SchemaImpl schema = new SchemaImpl();
  +        schema.addElementModel(em);
  +
  +        MockControl control1 = newControl(Module.class);
  +        Module m1 = (Module) control1.getMock();
  +
  +        MockControl control2 = newControl(Module.class);
  +        Module m2 = (Module) control2.getMock();
  +
  +        schema.setModule(m1);
  +
  +        SchemaProcessorImpl p = new SchemaProcessorImpl(null, schema);
  +
  +        Location location1 = newLocation();
  +        ElementImpl element1 = new ElementImpl();
  +        element1.setElementName("cartoon");
  +        element1.addAttribute(new AttributeImpl("name", "flintstone"));
  +        element1.setLocation(location1);
  +
  +        List elements1 = Collections.singletonList(element1);
  +
  +        Location location2 = newLocation();
  +        ElementImpl element2 = new ElementImpl();
  +        element2.setElementName("cartoon");
  +        element2.addAttribute(new AttributeImpl("name", "flintstone"));
  +        element2.setLocation(location2);
  +
  +        List elements2 = Collections.singletonList(element2);
  +
  +        MockControl tControl1 = newControl(Translator.class);
  +        Translator t1 = (Translator) tControl1.getMock();
  +
  +        m1.getTranslator("qualified-id");
  +        control1.setReturnValue(t1);
  +
  +        String flintstoneKeyModule1 = "m1.flintstone";
  +        t1.translate(m1, Object.class, "flintstone", element1.getLocation());
  +        tControl1.setReturnValue(flintstoneKeyModule1);
  +
  +        m1.resolveType("StringHolderImpl");
  +        control1.setReturnValue(StringHolderImpl.class);
  +
  +        m1.expandSymbols("flintstone", location1);
  +        control1.setReturnValue("flintstone");
  +
  +        m1.getTranslator("qualified-id");
  +        control1.setReturnValue(t1);
  +
  +        t1.translate(m1, String.class, "flintstone", element1.getLocation());
  +        tControl1.setReturnValue(flintstoneKeyModule1);
  +
  +        m1.resolveType("StringHolderImpl");
  +        control1.setReturnValue(StringHolderImpl.class);
  +
  +        MockControl tControl2 = newControl(Translator.class);
  +        Translator t2 = (Translator) tControl2.getMock();
  +
  +        m2.getTranslator("qualified-id");
  +        control2.setReturnValue(t2);
  +
  +        String flintstoneKeyModule2 = "m2.flintstone";
  +        t2.translate(m2, Object.class, "flintstone", element2.getLocation());
  +        tControl2.setReturnValue(flintstoneKeyModule2);
  +
  +        m2.expandSymbols("flintstone", location2);
  +        control2.setReturnValue("flintstone");
  +
  +        m2.getTranslator("qualified-id");
  +        control2.setReturnValue(t2);
  +
  +        t2.translate(m2, String.class, "flintstone", element2.getLocation());
  +        tControl2.setReturnValue(flintstoneKeyModule2);
  +
  +        replayControls();
  +
  +        p.process(elements1, m1);
  +        p.process(elements2, m2);
  +
  +        List list = p.getElements();
  +
  +        assertEquals(2, list.size());
  +
  +        Set keys = new TreeSet();
  +        for (Iterator iter = list.iterator(); iter.hasNext();)
  +        {
  +            StringHolderImpl element = (StringHolderImpl) iter.next();
  +            keys.add(element.getValue());
  +        }
  +
  +        assertTrue(keys.contains(flintstoneKeyModule1));
  +        assertTrue(keys.contains(flintstoneKeyModule2));
  +
  +        verifyControls();
  +    }
  +
   }
  \ No newline at end of file
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-cvs-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-cvs-help@jakarta.apache.org


Mime
View raw message