harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "spark shen (JIRA)" <j...@apache.org>
Subject [jira] Created: (HARMONY-4505) [classlib][beans] Beans module needs a persistence delegate for java.util.Date class
Date Fri, 20 Jul 2007 07:46:06 GMT
[classlib][beans] Beans module needs a persistence delegate for java.util.Date class
------------------------------------------------------------------------------------

                 Key: HARMONY-4505
                 URL: https://issues.apache.org/jira/browse/HARMONY-4505
             Project: Harmony
          Issue Type: Bug
          Components: Classlib
            Reporter: spark shen


The following test case will fail on Harmony, but pass on RI.
public static class DummyBean {

		private String value;

		public DummyBean() {
		}

		public DummyBean(String s) {
			value = s;
		}

		public String getDummyValue() {
			return value;
		}

		public void setDummyValue(String s) {
			value = s;
		}
		
		public boolean equals(Object bean) {
			if (!(bean instanceof DummyBean)) {
	            return false;
	        }
			DummyBean aBean = (DummyBean) bean;
			
			if (aBean.value == null && value != null || value != null
	                && aBean.value == null) {
	            return false;
	        } else if(value != null && aBean.value != null){
	        	return value.equals(aBean.value);
	        }
			return true;
		}
	}
	public void test_writeExpression_writeObject() {
		ByteArrayOutputStream output = new ByteArrayOutputStream();
        XMLEncoder encoder = new XMLEncoder( output );

        Date date = new Date(2007, 06, 26);
        Expression expression = new Expression( date, "toString", null );
        String date_string = null;
        try {
                date_string = (String) expression.getValue();
        } catch (Exception e ) {
                System.out.println("Failed to get the date value.");
                e.printStackTrace();
        }
        DummyBean bean = new DummyBean( date_string );
        // The expression knows about the date object.
        encoder.writeExpression( expression );
        encoder.writeObject( date );
        // The value for the bean is already part of the expression
        // so instead of writing the value we write a reference to
        // the extpression.
        encoder.writeObject( bean );

        encoder.flush();
        encoder.close();
        
        DataInputStream stream = new DataInputStream(new ByteArrayInputStream(
				output.toByteArray()));
		XMLDecoder decoder = new XMLDecoder(stream);
		Date aDate = (Date) decoder.readObject();
		assertEquals(date, aDate);
		
		DummyBean aBean = (DummyBean) decoder.readObject();
		assertEquals(bean, aBean);
	}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message