Search in sources :

Example 1 with MethodTrackingData

use of org.pentaho.test.platform.MethodTrackingData in project pentaho-platform by pentaho.

the class BackingRepositoryLifecycleManagerAuthenticationSuccessListenerTest method testOnApplicationEvent.

public void testOnApplicationEvent() throws Exception {
    final BackingRepositoryLifecycleManagerAuthenticationSuccessListener listener = new BackingRepositoryLifecycleManagerAuthenticationSuccessListener();
    // Test the getters and setters
    final int order = listener.getOrder() + 1;
    listener.setOrder(order);
    assertEquals(order, listener.getOrder());
    assertEquals(SecurityHelper.getInstance(), listener.getSecurityHelper());
    final MockSecurityHelper mockSecurityHelper = new MockSecurityHelper();
    listener.setSecurityHelper(mockSecurityHelper);
    assertEquals(mockSecurityHelper, listener.getSecurityHelper());
    final MockBackingRepositoryLifecycleManager mockLifecycleManager = new MockBackingRepositoryLifecycleManager(mockSecurityHelper);
    mockLifecycleManager.setThrowException(false);
    listener.setLifecycleManager(mockLifecycleManager);
    assertEquals(mockLifecycleManager, listener.getLifecycleManager());
    // Test that the "newTenant() method is executed as the system currentUser and the
    String principleName = usernamePrincipleUtils.getPrincipleId(new Tenant(CURRENT_TENANT, true), CURRENT_USER);
    listener.onApplicationEvent(new MockAbstractAuthenticationEvent(new MockAuthentication(principleName)));
    final List<MethodTrackingData> methodTrackerHistory1 = mockLifecycleManager.getMethodTrackerHistory();
    assertEquals(4, methodTrackerHistory1.size());
    assertEquals("newTenant", methodTrackerHistory1.get(0).getMethodName());
    assertEquals(2, methodTrackerHistory1.get(0).getParameters().size());
    assertEquals(principleName, methodTrackerHistory1.get(3).getParameters().get(USER_PARAMETER));
    assertEquals(CURRENT_TENANT, usernamePrincipleUtils.getTenant((String) methodTrackerHistory1.get(3).getParameters().get(USER_PARAMETER)).getId());
    assertEquals("newUser", methodTrackerHistory1.get(1).getMethodName());
    assertEquals(3, methodTrackerHistory1.get(1).getParameters().size());
    // Make sure both methods get called when exceptions are thrown
    mockLifecycleManager.resetCallHistory();
    mockLifecycleManager.setThrowException(true);
    listener.onApplicationEvent(new MockAbstractAuthenticationEvent(new MockAuthentication(principleName)));
}
Also used : MockSecurityHelper(org.pentaho.test.platform.engine.security.MockSecurityHelper) MethodTrackingData(org.pentaho.test.platform.MethodTrackingData) Tenant(org.pentaho.platform.core.mt.Tenant) ITenant(org.pentaho.platform.api.mt.ITenant)

Aggregations

ITenant (org.pentaho.platform.api.mt.ITenant)1 Tenant (org.pentaho.platform.core.mt.Tenant)1 MethodTrackingData (org.pentaho.test.platform.MethodTrackingData)1 MockSecurityHelper (org.pentaho.test.platform.engine.security.MockSecurityHelper)1