package org.openur.module.service.security;

import javax.inject.Inject;

import org.apache.shiro.realm.Realm;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.openur.module.domain.security.authentication.UsernamePasswordToken;
import org.openur.module.service.config.SecurityTestSpringConfig;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@ActiveProfiles("testSecurityServices")
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {SecurityTestSpringConfig.class})
public class AuthenticationServicesTest
{
	private static final String USER_NAME = "testUser";
	private static final String PASSWORD = "secret";
	
	@Inject
	private IAuthenticationServices authenticationServices;
	
	@Inject
	private Realm realm;
	
	@Test
	public void testAuthenticate()
	{
		UsernamePasswordToken openUrToken = new UsernamePasswordToken(USER_NAME, PASSWORD);
		authenticationServices.authenticate(openUrToken);
	}
	
	@Test(expected=org.openur.module.util.exception.AuthenticationException.class)
	public void testAuthenticate_Failure()
	{
		UsernamePasswordToken openUrToken = new UsernamePasswordToken(USER_NAME, "someWrongPw");
		Mockito.when(realm.getAuthenticationInfo(openUrToken.getDelegate())).thenThrow(
				new org.apache.shiro.authc.AuthenticationException("wrong credentials"));
		authenticationServices.authenticate(openUrToken);		
	}
}

@@ -188,16 +188,86 @@
 ockito;%0A
+import org.openur.domain.testfixture.testobjects.TestObjectContainer;%0A
 import o
@@ -337,16 +337,16 @@
 dToken;%0A
-
 import o
@@ -786,113 +786,8 @@
 t%0A%7B%0A
-%09private static final String USER_NAME = %22testUser%22;%0A%09private static final String PASSWORD = %22secret%22;%0A%09%0A
 %09@In
@@ -929,94 +929,8 @@
 %0A%09%7B%0A
-%09%09UsernamePasswordToken openUrToken = new UsernamePasswordToken(USER_NAME, PASSWORD);%0A
 %09%09au
@@ -963,27 +963,53 @@
 nticate(
-openUrToken
+TestObjectContainer.USERNAME_PW_TOKEN
 );%0A%09%7D%0A%09%0A
@@ -1131,16 +1131,16 @@
 re()%0A%09%7B%0A
-
 %09%09Userna
@@ -1195,16 +1195,36 @@
 rdToken(
+TestObjectContainer.
 USER_NAM

use Objects from TestObjectContainer.