@ -4,6 +4,7 @@ import com.atlassian.bitbucket.concurrent.BucketedExecutor;
import com.atlassian.bitbucket.concurrent.ConcurrencyService ;
import com.atlassian.bitbucket.concurrent.ConcurrencyService ;
import com.atlassian.bitbucket.hook.repository.PostRepositoryHookContext ;
import com.atlassian.bitbucket.hook.repository.PostRepositoryHookContext ;
import com.atlassian.bitbucket.hook.repository.RepositoryPushHookRequest ;
import com.atlassian.bitbucket.hook.repository.RepositoryPushHookRequest ;
import com.atlassian.bitbucket.project.Project ;
import com.atlassian.bitbucket.repository.Repository ;
import com.atlassian.bitbucket.repository.Repository ;
import com.atlassian.bitbucket.scm.git.GitScm ;
import com.atlassian.bitbucket.scm.git.GitScm ;
import com.atlassian.bitbucket.scope.Scope ;
import com.atlassian.bitbucket.scope.Scope ;
@ -20,8 +21,10 @@ import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit ;
import org.mockito.junit.MockitoJUnit ;
import org.mockito.junit.MockitoRule ;
import org.mockito.junit.MockitoRule ;
import java.util.Collections ;
import java.util.HashMap ;
import java.util.HashMap ;
import java.util.Map ;
import java.util.Map ;
import java.util.Set ;
import java.util.concurrent.TimeUnit ;
import java.util.concurrent.TimeUnit ;
import static com.atlassian.bitbucket.mockito.MockitoUtils.returnArg ;
import static com.atlassian.bitbucket.mockito.MockitoUtils.returnArg ;
@ -31,7 +34,7 @@ import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.* ;
import static org.mockito.Mockito.* ;
/ * *
/ * *
* Unit tests for { @link MirrorRepositoryHook }
* Unit tests for { @link MirrorRepositoryHook } .
* /
* /
public class MirrorRepositoryHookTest {
public class MirrorRepositoryHookTest {
@ -72,7 +75,7 @@ public class MirrorRepositoryHookTest {
}
}
@Test
@Test
public void testPostReceiv e ( ) {
public void testPostUpdat e ( ) {
when ( passwordEncryptor . decrypt ( anyString ( ) ) ) . thenReturn ( password ) ;
when ( passwordEncryptor . decrypt ( anyString ( ) ) ) . thenReturn ( password ) ;
Repository repo = mock ( Repository . class ) ;
Repository repo = mock ( Repository . class ) ;
@ -89,6 +92,32 @@ public class MirrorRepositoryHookTest {
assertEquals ( 1 , request . getRepositoryId ( ) ) ;
assertEquals ( 1 , request . getRepositoryId ( ) ) ;
}
}
@Test
public void testPostUpdateForHgRepository ( ) {
Repository repo = mock ( Repository . class ) ;
when ( repo . getScmId ( ) ) . thenReturn ( "hg" ) ;
hook . postUpdate ( buildContext ( ) , new RepositoryPushHookRequest . Builder ( repo ) . build ( ) ) ;
verifyZeroInteractions ( bucketedExecutor ) ;
}
@Test
public void testPostUpdateUnconfigured ( ) {
Repository repo = mock ( Repository . class ) ;
when ( repo . getScmId ( ) ) . thenReturn ( GitScm . ID ) ;
Settings settings = mock ( Settings . class ) ;
when ( settings . asMap ( ) ) . thenReturn ( Collections . emptyMap ( ) ) ;
PostRepositoryHookContext context = mock ( PostRepositoryHookContext . class ) ;
when ( context . getSettings ( ) ) . thenReturn ( settings ) ;
hook . postUpdate ( context , new RepositoryPushHookRequest . Builder ( repo ) . build ( ) ) ;
verifyZeroInteractions ( bucketedExecutor ) ;
}
@Test
@Test
public void testValidate ( ) {
public void testValidate ( ) {
Settings settings = mock ( Settings . class ) ;
Settings settings = mock ( Settings . class ) ;
@ -178,7 +207,27 @@ public class MirrorRepositoryHookTest {
hook . validate ( settings , errors , scope ) ;
hook . validate ( settings , errors , scope ) ;
verify ( errors , never ( ) ) . addFormError ( anyString ( ) ) ;
verify ( errors , never ( ) ) . addFormError ( anyString ( ) ) ;
verify ( errors , never ( ) ) . addFieldError ( anyString ( ) , anyString ( ) ) ;
verify ( errors , never ( ) ) . addFieldError ( anyString ( ) , anyString ( ) ) ;
}
@Test
public void testValidateForGlobal ( ) {
SettingsValidationErrors errors = mock ( SettingsValidationErrors . class ) ;
Settings settings = mock ( Settings . class ) ;
hook . validate ( settings , errors , Scopes . global ( ) ) ;
verifyZeroInteractions ( bucketedExecutor , errors , settings ) ;
}
@Test
public void testValidateForProject ( ) {
SettingsValidationErrors errors = mock ( SettingsValidationErrors . class ) ;
Project project = mock ( Project . class ) ;
Settings settings = mock ( Settings . class ) ;
hook . validate ( settings , errors , Scopes . project ( project ) ) ;
verifyZeroInteractions ( bucketedExecutor , errors , settings ) ;
}
}
private PostRepositoryHookContext buildContext ( ) {
private PostRepositoryHookContext buildContext ( ) {