db-jdo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c..@apache.org
Subject svn commit: r159284 - in incubator/jdo/trunk/api20: src/java/javax/jdo/Bundle.properties src/java/javax/jdo/listener/InstanceLifecycleEvent.java test/java/javax/jdo/listener/InstanceLifecycleEventTest.java
Date Mon, 28 Mar 2005 19:39:22 GMT
Author: clr
Date: Mon Mar 28 11:39:20 2005
New Revision: 159284

URL: http://svn.apache.org/viewcvs?view=rev&rev=159284
Log:
added InstanceLifecycleEventTest

Added:
    incubator/jdo/trunk/api20/test/java/javax/jdo/listener/InstanceLifecycleEventTest.java
Modified:
    incubator/jdo/trunk/api20/src/java/javax/jdo/Bundle.properties
    incubator/jdo/trunk/api20/src/java/javax/jdo/listener/InstanceLifecycleEvent.java

Modified: incubator/jdo/trunk/api20/src/java/javax/jdo/Bundle.properties
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api20/src/java/javax/jdo/Bundle.properties?view=diff&r1=159283&r2=159284
==============================================================================
--- incubator/jdo/trunk/api20/src/java/javax/jdo/Bundle.properties (original)
+++ incubator/jdo/trunk/api20/src/java/javax/jdo/Bundle.properties Mon Mar 28 11:39:20 2005
@@ -45,3 +45,4 @@
 EXC_NamingException: A NamingException was thrown while obtaining the \
 PersistenceManagerFactory at "{0}" from JNDI.
 EXC_StringWrongLength: There must be exactly one character in the input String for CharIdentity.
+EXC_IllegalEventType:The event type is outside the range of valid event types.

Modified: incubator/jdo/trunk/api20/src/java/javax/jdo/listener/InstanceLifecycleEvent.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api20/src/java/javax/jdo/listener/InstanceLifecycleEvent.java?view=diff&r1=159283&r2=159284
==============================================================================
--- incubator/jdo/trunk/api20/src/java/javax/jdo/listener/InstanceLifecycleEvent.java (original)
+++ incubator/jdo/trunk/api20/src/java/javax/jdo/listener/InstanceLifecycleEvent.java Mon
Mar 28 11:39:20 2005
@@ -21,6 +21,8 @@
 
 package javax.jdo.listener;
 
+import javax.jdo.spi.I18NHelper;
+
 /**
  * This is the event class used in life cycle event notifications.
  * <P>Note that although InstanceLifecycleEvent inherits Serializable interface 
@@ -32,6 +34,7 @@
 public class InstanceLifecycleEvent
     extends java.util.EventObject {
 
+    private static final int FIRST_EVENT_TYPE = 0;
     public static final int CREATE = 0;
     public static final int LOAD = 1;
     public static final int STORE = 2;
@@ -40,6 +43,11 @@
     public static final int DIRTY = 5;
     public static final int DETACH = 6;
     public static final int ATTACH = 7;
+    private static final int LAST_EVENT_TYPE = 7;
+
+    /** The Internationalization message helper.
+     */
+    private final static I18NHelper msg = I18NHelper.getInstance ("javax.jdo.Bundle"); //NOI18N
 
     /**
      * The event type that triggered the construction of this event object.
@@ -59,9 +67,7 @@
      * @since 2.0
      */
     public InstanceLifecycleEvent (Object source, int type) {
-        super (source);
-        eventType = type;
-        target = null;
+        this(source, type, null);
     }
 
     /**
@@ -74,6 +80,9 @@
      */
     public InstanceLifecycleEvent (Object source, int type, Object target) {
         super (source);
+        if (type < FIRST_EVENT_TYPE || type > LAST_EVENT_TYPE) {
+            throw new IllegalArgumentException(msg.msg("EXC_IllegalEventType"));
+        }
         eventType = type;
         this.target = target;
     }

Added: incubator/jdo/trunk/api20/test/java/javax/jdo/listener/InstanceLifecycleEventTest.java
URL: http://svn.apache.org/viewcvs/incubator/jdo/trunk/api20/test/java/javax/jdo/listener/InstanceLifecycleEventTest.java?view=auto&rev=159284
==============================================================================
--- incubator/jdo/trunk/api20/test/java/javax/jdo/listener/InstanceLifecycleEventTest.java
(added)
+++ incubator/jdo/trunk/api20/test/java/javax/jdo/listener/InstanceLifecycleEventTest.java
Mon Mar 28 11:39:20 2005
@@ -0,0 +1,130 @@
+/*
+ * Copyright 2005 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.
+ */
+
+/*
+ * InstanceLifecycleEventTest.java
+ *
+ */
+
+package javax.jdo.listener;
+
+import javax.jdo.util.AbstractTest;
+import javax.jdo.util.BatchTestRunner;
+
+/**
+ * Tests that instances of InstanceLifecycleEvent can be created and
+ * that the source, type, and target instances are correct.
+ */
+public class InstanceLifecycleEventTest extends AbstractTest {
+    
+    Object created = new Object();
+    Object loaded = new Object();
+    Object stored = new Object();
+    Object cleared = new Object();
+    Object deleted = new Object();
+    Object dirtied = new Object();
+    Object attached = new Object();
+    Object attachTarget = new Object();
+    Object detached = new Object();
+    Object detachTarget = new Object();
+    
+    /** Creates a new instance of SingleFieldIdentityTest */
+    public InstanceLifecycleEventTest() {
+    }
+    
+    /**
+     * @param args the command line arguments
+     */
+    public static void main(String[] args) {
+        BatchTestRunner.run(InstanceLifecycleEventTest.class);
+    }
+    
+    public void testConstructorCreateEvent() {
+        InstanceLifecycleEvent e = new InstanceLifecycleEvent 
+                (created, InstanceLifecycleEvent.CREATE);
+        assertSame ("Create source differs.", created, e.getSource());
+        assertEquals ("Create type differs.", InstanceLifecycleEvent.CREATE, e.getEventType());
+    }
+    
+    public void testConstructorLoadEvent() {
+        InstanceLifecycleEvent e = new InstanceLifecycleEvent 
+                (loaded, InstanceLifecycleEvent.LOAD);
+        assertSame ("Load source differs.", loaded, e.getSource());
+        assertEquals ("Load type differs.", InstanceLifecycleEvent.LOAD, e.getEventType());
+    }
+    
+    public void testConstructorStoreEvent() {
+        InstanceLifecycleEvent e = new InstanceLifecycleEvent 
+                (stored, InstanceLifecycleEvent.STORE);
+        assertSame ("Store source differs.", stored, e.getSource());
+        assertEquals ("Store type differs.", InstanceLifecycleEvent.STORE, e.getEventType());
+    }
+    
+    public void testConstructorClearEvent() {
+        InstanceLifecycleEvent e = new InstanceLifecycleEvent 
+                (cleared, InstanceLifecycleEvent.CLEAR);
+        assertSame ("Clear source differs.", cleared, e.getSource());
+        assertEquals ("Clear type differs.", InstanceLifecycleEvent.CLEAR, e.getEventType());
+    }
+    
+    public void testConstructorDeleteEvent() {
+        InstanceLifecycleEvent e = new InstanceLifecycleEvent 
+                (deleted, InstanceLifecycleEvent.DELETE);
+        assertSame ("Delete source differs.", deleted, e.getSource());
+        assertEquals ("Delete type differs.", InstanceLifecycleEvent.DELETE, e.getEventType());
+    }
+    
+    public void testConstructorDirtyEvent() {
+        InstanceLifecycleEvent e = new InstanceLifecycleEvent 
+                (dirtied, InstanceLifecycleEvent.DIRTY);
+        assertSame ("Dirty source differs.", dirtied, e.getSource());
+        assertEquals ("Dirty type differs.", InstanceLifecycleEvent.DIRTY, e.getEventType());
+    }
+    
+    public void testConstructorDetachEvent() {
+        InstanceLifecycleEvent e = new InstanceLifecycleEvent 
+                (detached, InstanceLifecycleEvent.DETACH, detachTarget);
+        assertSame ("Detach source differs.", detached, e.getSource());
+        assertEquals ("Detach type differs.", InstanceLifecycleEvent.DETACH, e.getEventType());
+        assertSame ("Detach target differs.", detachTarget, e.getTarget());
+    }
+    
+    public void testConstructorAttachEvent() {
+        InstanceLifecycleEvent e = new InstanceLifecycleEvent 
+                (attached, InstanceLifecycleEvent.ATTACH, attachTarget);
+        assertSame ("Attach source differs.", attached, e.getSource());
+        assertEquals ("Attach type differs.", InstanceLifecycleEvent.ATTACH, e.getEventType());
+        assertSame ("Attach target differs.", attachTarget, e.getTarget());
+    }
+    
+    public void testIllegalConstructorTooSmall() {
+        try {
+            InstanceLifecycleEvent e = new InstanceLifecycleEvent (new Object(), -1);
+        } catch (IllegalArgumentException e) {
+            return; // good catch
+        } 
+        fail ("Invalid event did not throw IllegalArgumentException.");
+    }
+    
+    public void testIllegalConstructorTooBig() {
+        try {
+            InstanceLifecycleEvent e = new InstanceLifecycleEvent (new Object(), 8);
+        } catch (IllegalArgumentException e) {
+            return; // good catch
+        }
+        fail ("Invalid event did not throw IllegalArgumentException.");
+    }
+}



Mime
View raw message