You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by kw...@apache.org on 2016/05/25 08:11:25 UTC

svn commit: r1745450 - /qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/singleton/AbstractConfiguredObjectTest.java

Author: kwall
Date: Wed May 25 08:11:25 2016
New Revision: 1745450

URL: http://svn.apache.org/viewvc?rev=1745450&view=rev
Log:
QPID-7203: [Java Broker] Strengthen unit tests

Modified:
    qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/singleton/AbstractConfiguredObjectTest.java

Modified: qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/singleton/AbstractConfiguredObjectTest.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/singleton/AbstractConfiguredObjectTest.java?rev=1745450&r1=1745449&r2=1745450&view=diff
==============================================================================
--- qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/singleton/AbstractConfiguredObjectTest.java (original)
+++ qpid/java/trunk/broker-core/src/test/java/org/apache/qpid/server/model/testmodels/singleton/AbstractConfiguredObjectTest.java Wed May 25 08:11:25 2016
@@ -892,7 +892,7 @@ public class AbstractConfiguredObjectTes
         final Date originalCreatedTime = object.getCreatedTime();
         final Date originalLastUpdatedTime = object.getLastUpdatedTime();
         assertTrue("Unexpected created time", originalCreatedTime.after(now));
-        assertEquals("Unexpected created and updated time", object.getCreatedTime(), originalLastUpdatedTime);
+        assertEquals("Unexpected created and updated time", originalCreatedTime, originalLastUpdatedTime);
 
         Thread.sleep(5);  // Let a small amount of time pass
 
@@ -914,6 +914,68 @@ public class AbstractConfiguredObjectTes
         assertTrue("Last updated time by should be changed by update", originalLastUpdatedTime.before(object.getLastUpdatedTime()));
     }
 
+    public void testAuditInformationIgnoresUserSuppliedAttributes() throws Exception
+    {
+        final String user = "user";
+        final Subject userSubject = createTestAuthenticatedSubject(user);
+
+        final Map<String, Object> attributes = new HashMap<>();
+        attributes.put(TestSingleton.NAME, "myName");
+        attributes.put(TestSingleton.CREATED_BY, "bogusCreator");
+        attributes.put(TestSingleton.CREATED_TIME, new Date(0));
+        attributes.put(TestSingleton.LAST_UPDATED_BY, "bogusUpdater");
+        attributes.put(TestSingleton.LAST_UPDATED_TIME, new Date(0));
+
+        final Date now = new Date();
+        Thread.sleep(5);  // Let a small amount of time pass
+
+        final TestSingleton object = Subject.doAs(userSubject,
+                                                  new PrivilegedAction<TestSingleton>()
+                                                  {
+                                                      @Override
+                                                      public TestSingleton run()
+                                                      {
+                                                          return _model.getObjectFactory().create(TestSingleton.class, attributes);
+                                                      }
+                                                  });
+
+        assertEquals("Unexpected creating user after object creation", user,  object.getCreatedBy());
+        assertEquals("Unexpected last updating user after object creation", user, object.getLastUpdatedBy());
+
+        final Date originalCreatedTime = object.getCreatedTime();
+        assertTrue("Unexpected created time", originalCreatedTime.after(now));
+        final Date originalLastUpdatedTime = object.getLastUpdatedTime();
+        assertEquals("Unexpected created and updated time", originalCreatedTime, originalLastUpdatedTime);
+
+
+        Subject.doAs(userSubject,
+                     new PrivilegedAction<Void>()
+                     {
+                         @Override
+                         public Void run()
+                         {
+                             final Map<String, Object> updateMap = new HashMap<>();
+                             updateMap.put(TestSingleton.INT_VALUE, 5);
+                             updateMap.put(TestSingleton.CREATED_BY, "bogusCreator");
+                             updateMap.put(TestSingleton.CREATED_TIME, new Date(0));
+                             updateMap.put(TestSingleton.LAST_UPDATED_BY, "bogusUpdater");
+                             updateMap.put(TestSingleton.LAST_UPDATED_TIME, new Date(0));
+
+                             object.setAttributes(updateMap);
+                             return null;
+                         }
+                     });
+
+        Thread.sleep(5);  // Let a small amount of time pass
+
+        assertEquals("Creating user should not be changed by update", user, object.getCreatedBy());
+        assertEquals("Created time should not be changed by update", originalCreatedTime, object.getCreatedTime());
+
+        assertEquals("Last updated by should be changed by update", user, object.getLastUpdatedBy());
+        assertTrue("Last updated time by should be changed by update", originalLastUpdatedTime.before(object.getLastUpdatedTime()));
+    }
+
+
     public void testAuditInformationPersistenceAndRecovery() throws Exception
     {
         final String creatingUser = "creatingUser";



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org