Package org.pentaho.platform.engine.security

Source Code of org.pentaho.platform.engine.security.PentahoSecurityContextHolderStrategyTest

package org.pentaho.platform.engine.security;

import org.junit.Test;
import org.springframework.security.Authentication;
import org.springframework.security.context.SecurityContext;

import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;

public class PentahoSecurityContextHolderStrategyTest {

  @Test
  public void testGetContext() throws Exception {
    final PentahoSecurityContextHolderStrategy strategy = new PentahoSecurityContextHolderStrategy();
    SecurityContext context = strategy.getContext();
    assertNotNull( context );
    final Authentication authentication = mock( Authentication.class );
    context.setAuthentication( authentication );

    assertSame( authentication, strategy.getContext().getAuthentication() );
    Thread thread = new Thread( new Runnable() {
      @Override public void run() {
        assertSame( authentication, strategy.getContext().getAuthentication() );
        Authentication authentication2 = mock( Authentication.class );
        strategy.getContext().setAuthentication( authentication2 );
        assertSame( authentication2, strategy.getContext().getAuthentication() );
        synchronized ( this ) {
          notify();
        }
      }
    });
    thread.start();
    synchronized ( thread ) {
      thread.wait();
    }
    assertSame( authentication, strategy.getContext().getAuthentication() );
  }
}
TOP

Related Classes of org.pentaho.platform.engine.security.PentahoSecurityContextHolderStrategyTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.