You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by ar...@apache.org on 2003/01/20 17:13:34 UTC
cvs commit: jakarta-ojb/src/test/org/apache/ojb/broker/metadata CustomAttributesTest.java
arminw 2003/01/20 08:13:34
Modified: src/java/org/apache/ojb/broker/metadata DescriptorBase.java
src/test/org/apache/ojb/broker/metadata
CustomAttributesTest.java
Log:
fix bug,
Attributes for FieldDescriptor are not
serialized and after deserialization
FieldDescriptor.getAttribute always returns null.
thanks Alexey.
Revision Changes Path
1.3 +3 -2 jakarta-ojb/src/java/org/apache/ojb/broker/metadata/DescriptorBase.java
Index: DescriptorBase.java
===================================================================
RCS file: /home/cvs/jakarta-ojb/src/java/org/apache/ojb/broker/metadata/DescriptorBase.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DescriptorBase.java 24 Dec 2002 13:14:33 -0000 1.2
+++ DescriptorBase.java 20 Jan 2003 16:13:33 -0000 1.3
@@ -56,13 +56,14 @@
import java.util.HashMap;
import java.util.Map;
+import java.io.Serializable;
/**
* base class for all Descriptors. It is used to implement the AttributeContainer
* interface which provides mechanics for user defined attributes.
* @author Thomas Mahler
*/
-class DescriptorBase implements AttributeContainer
+class DescriptorBase implements AttributeContainer, Serializable
{
/** holds user defined attributes */
private Map attributeList = null;
@@ -98,7 +99,7 @@
*/
public String getAttribute(String attributeName, String defaultValue)
{
- String result = null;
+ String result = defaultValue;
if (attributeList!=null)
{
result = (String)attributeList.get(attributeName);
1.4 +20 -0 jakarta-ojb/src/test/org/apache/ojb/broker/metadata/CustomAttributesTest.java
Index: CustomAttributesTest.java
===================================================================
RCS file: /home/cvs/jakarta-ojb/src/test/org/apache/ojb/broker/metadata/CustomAttributesTest.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- CustomAttributesTest.java 24 Dec 2002 14:05:36 -0000 1.3
+++ CustomAttributesTest.java 20 Jan 2003 16:13:34 -0000 1.4
@@ -64,4 +64,24 @@
assertTrue("red".equals(ord.getAttribute("color")));
assertTrue("tiny".equals(ord.getAttribute("size")));
}
+
+ /** Test using attributes on serialized/deserialized repository*/
+ public void testSerializedReadCustomAttributes()
+ {
+ DescriptorRepository repository = MetadataManager.getInstance().copyOfGlobalRepository();
+
+ ClassDescriptor cld = repository.getDescriptorFor(Article.class);
+ assertTrue("blue".equals(cld.getAttribute("color")));
+ assertTrue("big".equals(cld.getAttribute("size")));
+
+ FieldDescriptor fld = cld.getFieldDescriptorByName("isSelloutArticle");
+ assertTrue("green".equals(fld.getAttribute("color")));
+ assertTrue("small".equals(fld.getAttribute("size")));
+
+
+ ObjectReferenceDescriptor ord = cld.getObjectReferenceDescriptorByName("productGroup");
+ assertNotNull("did not find ord for 'productGroup'!", ord);
+ assertTrue("red".equals(ord.getAttribute("color")));
+ assertTrue("tiny".equals(ord.getAttribute("size")));
+ }
}