// Path: src/test/java/com/asolutions/MockTestCase.java
// public class MockTestCase {
// 
// 	protected Mockery context = new JUnit4Mockery();
// 
// 	@Before
// 	public void setupMockery() {
// 		context.setImposteriser(ClassImposteriser.INSTANCE);
// 	}
// 	
// 	@After
// 	public void mockeryAssertIsSatisfied(){
// 		context.assertIsSatisfied();
// 	}
// 
// 	protected void checking(Expectations expectations) {
// 		context.checking(expectations);
// 	}
// 
// }
// 
// Path: src/main/java/com/asolutions/scmsshd/authorizors/AuthorizationLevel.java
// public enum AuthorizationLevel {
// 	AUTH_LEVEL_READ_ONLY, 
// 	AUTH_LEVEL_READ_WRITE;
// }
// 
// Path: src/main/java/com/asolutions/scmsshd/commands/FilteredCommand.java
// public class FilteredCommand {
// 	
// 	private String command;
// 	private String argument;
// 
// 	public FilteredCommand() {
// 	}
// 	
// 	public FilteredCommand(String command, String argument) {
// 		this.command = command;
// 		this.argument = argument;
// 	}
// 
// 	public void setArgument(String argument) {
// 		this.argument = argument;
// 	}
// 	
// 	public void setCommand(String command) {
// 		this.command = command;
// 	}
// 
// 	public String getCommand() {
// 		return this.command;
// 	}
// 
// 	public String getArgument() {
// 		return this.argument;
// 	}
// 	
// 	@Override
// 	public String toString()
// 	{
// 		return "Filtered Command: " + getCommand() + ", " + getArgument();
// 	}
// 
// }
// 
// Path: src/main/java/com/asolutions/scmsshd/commands/factories/GitSCMCommandFactory.java
// public class GitSCMCommandFactory implements ISCMCommandFactory {
// 
// 	public static final String REPOSITORY_BASE = "repositoryBase";
// 
// 	public Command create(FilteredCommand filteredCommand,
// 			IProjectAuthorizer projectAuthorizer,
// 			IPathToProjectNameConverter pathToProjectNameConverter,
// 			Properties configuration) {
// 		SCMCommand retVal = new SCMCommand(filteredCommand, projectAuthorizer, new GitSCMCommandHandler(), pathToProjectNameConverter, configuration);
// 		return retVal;
// 	}
// 
// }
// 
// Path: src/main/java/com/asolutions/scmsshd/exceptions/Failure.java
// public class Failure extends RuntimeException {
// 
// 	private static final long serialVersionUID = 5704607166844629700L;
// 	private int resultCode;
// 	private final String genericError;
// 	private final String specifics;
// 
// 	public Failure(int i, String genericError, String specifics) {
// 		this.resultCode = i;
// 		this.genericError = genericError;
// 		this.specifics = specifics;
// 	}
// 	
// 	public int getResultCode() {
// 		return resultCode;
// 	}
// 	
// 	public String toFormattedErrorMessage(){
// 		StringBuilder builder = new StringBuilder();
// 		builder.append("**********************************\n");
// 		builder.append("\n");
// 		builder.append(genericError);
// 		builder.append("\n");
// 		builder.append("\n");
// 		builder.append("Specifics:\n");
// 		builder.append("  ").append(specifics).append("\n");
// 		builder.append("\n");
// 		builder.append("**********************************\n");
// 		return builder.toString();
// 	}
// 
// }
// 
// Path: src/main/java/com/asolutions/scmsshd/exceptions/MustHaveWritePrivilagesToPushFailure.java
// public class MustHaveWritePrivilagesToPushFailure extends Failure{
// 
// 	private static final long serialVersionUID = 7650486977318806435L;
// 
// 	public MustHaveWritePrivilagesToPushFailure(String specifics) {
// 		super(0, "You must have write privilages to be able to push", specifics);
// 	}
// 	
// }


import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Properties;
import org.apache.sshd.server.CommandFactory.ExitCallback;
import org.jmock.Expectations;
import org.junit.Test;
import static org.junit.Assert.*;
import org.spearce.jgit.lib.Repository;
import org.spearce.jgit.transport.ReceivePack;
import com.asolutions.MockTestCase;
import com.asolutions.scmsshd.authorizors.AuthorizationLevel;
import com.asolutions.scmsshd.commands.FilteredCommand;
import com.asolutions.scmsshd.commands.factories.GitSCMCommandFactory;
import com.asolutions.scmsshd.exceptions.Failure;
import com.asolutions.scmsshd.exceptions.MustHaveWritePrivilagesToPushFailure;
		checking(new Expectations() {
			{
				one(mockRepoProvider).provide(base,
						filteredCommand.getArgument());
				will(returnValue(mockRepoistory));
				one(mockReceivePackProvider).provide(mockRepoistory);
				will(returnValue(mockUploadPack));
				one(mockUploadPack).receive(mockInputStream, mockOutputStream,
						mockErrorStream);
//				one(mockExitCallback).onExit(0);
//				one(mockOutputStream).flush();
//				one(mockErrorStream).flush();

				one(mockConfig).getProperty(
						GitSCMCommandFactory.REPOSITORY_BASE);
				will(returnValue(pathtobasedir));
			}
		});

		GitSCMCommandImpl handler = new GitReceivePackSCMCommandHandler(
				mockRepoProvider, mockReceivePackProvider);
		handler.runCommand(filteredCommand, mockInputStream, mockOutputStream,
				mockErrorStream, mockExitCallback, mockConfig,
				AuthorizationLevel.AUTH_LEVEL_READ_WRITE);
	}

	@Test
	public void testThrowsExceptionIfWrongAccessLevel() throws Exception {

		final String pathtobasedir = "pathtobasedir";
// Path: src/test/java/com/asolutions/MockTestCase.java
// public class MockTestCase {
// 
// 	protected Mockery context = new JUnit4Mockery();
// 
// 	@Before
// 	public void setupMockery() {
// 		context.setImposteriser(ClassImposteriser.INSTANCE);
// 	}
// 	
// 	@After
// 	public void mockeryAssertIsSatisfied(){
// 		context.assertIsSatisfied();
// 	}
// 
// 	protected void checking(Expectations expectations) {
// 		context.checking(expectations);
// 	}
// 
// }
// 
// Path: src/main/java/com/asolutions/scmsshd/authorizors/AuthorizationLevel.java
// public enum AuthorizationLevel {
// 	AUTH_LEVEL_READ_ONLY, 
// 	AUTH_LEVEL_READ_WRITE;
// }
// 
// Path: src/main/java/com/asolutions/scmsshd/commands/FilteredCommand.java
// public class FilteredCommand {
// 	
// 	private String command;
// 	private String argument;
// 
// 	public FilteredCommand() {
// 	}
// 	
// 	public FilteredCommand(String command, String argument) {
// 		this.command = command;
// 		this.argument = argument;
// 	}
// 
// 	public void setArgument(String argument) {
// 		this.argument = argument;
// 	}
// 	
// 	public void setCommand(String command) {
// 		this.command = command;
// 	}
// 
// 	public String getCommand() {
// 		return this.command;
// 	}
// 
// 	public String getArgument() {
// 		return this.argument;
// 	}
// 	
// 	@Override
// 	public String toString()
// 	{
// 		return "Filtered Command: " + getCommand() + ", " + getArgument();
// 	}
// 
// }
// 
// Path: src/main/java/com/asolutions/scmsshd/commands/factories/GitSCMCommandFactory.java
// public class GitSCMCommandFactory implements ISCMCommandFactory {
// 
// 	public static final String REPOSITORY_BASE = "repositoryBase";
// 
// 	public Command create(FilteredCommand filteredCommand,
// 			IProjectAuthorizer projectAuthorizer,
// 			IPathToProjectNameConverter pathToProjectNameConverter,
// 			Properties configuration) {
// 		SCMCommand retVal = new SCMCommand(filteredCommand, projectAuthorizer, new GitSCMCommandHandler(), pathToProjectNameConverter, configuration);
// 		return retVal;
// 	}
// 
// }
// 
// Path: src/main/java/com/asolutions/scmsshd/exceptions/Failure.java
// public class Failure extends RuntimeException {
// 
// 	private static final long serialVersionUID = 5704607166844629700L;
// 	private int resultCode;
// 	private final String genericError;
// 	private final String specifics;
// 
// 	public Failure(int i, String genericError, String specifics) {
// 		this.resultCode = i;
// 		this.genericError = genericError;
// 		this.specifics = specifics;
// 	}
// 	
// 	public int getResultCode() {
// 		return resultCode;
// 	}
// 	
// 	public String toFormattedErrorMessage(){
// 		StringBuilder builder = new StringBuilder();
// 		builder.append("**********************************\n");
// 		builder.append("\n");
// 		builder.append(genericError);
// 		builder.append("\n");
// 		builder.append("\n");
// 		builder.append("Specifics:\n");
// 		builder.append("  ").append(specifics).append("\n");
// 		builder.append("\n");
// 		builder.append("**********************************\n");
// 		return builder.toString();
// 	}
// 
// }
// 
// Path: src/main/java/com/asolutions/scmsshd/exceptions/MustHaveWritePrivilagesToPushFailure.java
// public class MustHaveWritePrivilagesToPushFailure extends Failure{
// 
// 	private static final long serialVersionUID = 7650486977318806435L;
// 
// 	public MustHaveWritePrivilagesToPushFailure(String specifics) {
// 		super(0, "You must have write privilages to be able to push", specifics);
// 	}
// 	
// }


// Path: src/test/java/com/asolutions/scmsshd/commands/git/GitReceivePackSCMCommandHandlerTest.java
import java.io.File;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Properties;
import org.apache.sshd.server.CommandFactory.ExitCallback;
import org.jmock.Expectations;
import org.junit.Test;
import static org.junit.Assert.*;
import org.spearce.jgit.lib.Repository;
import org.spearce.jgit.transport.ReceivePack;
import com.asolutions.MockTestCase;
import com.asolutions.scmsshd.authorizors.AuthorizationLevel;
import com.asolutions.scmsshd.commands.FilteredCommand;
import com.asolutions.scmsshd.commands.factories.GitSCMCommandFactory;
import com.asolutions.scmsshd.exceptions.Failure;
import com.asolutions.scmsshd.exceptions.MustHaveWritePrivilagesToPushFailure;

		checking(new Expectations() {
			{
				one(mockRepoProvider).provide(base,
						filteredCommand.getArgument());
				will(returnValue(mockRepoistory));
				one(mockReceivePackProvider).provide(mockRepoistory);
				will(returnValue(mockUploadPack));
				one(mockUploadPack).receive(mockInputStream, mockOutputStream,
						mockErrorStream);
//				one(mockExitCallback).onExit(0);
//				one(mockOutputStream).flush();
//				one(mockErrorStream).flush();

				one(mockConfig).getProperty(
						GitSCMCommandFactory.REPOSITORY_BASE);
				will(returnValue(pathtobasedir));
			}
		});

		GitSCMCommandImpl handler = new GitReceivePackSCMCommandHandler(
				mockRepoProvider, mockReceivePackProvider);
		handler.runCommand(filteredCommand, mockInputStream, mockOutputStream,
				mockErrorStream, mockExitCallback, mockConfig,
				AuthorizationLevel.AUTH_LEVEL_READ_WRITE);
	}

	@Test
	public void testThrowsExceptionIfWrongAccessLevel() throws Exception {

		final String pathtobasedir = "pathtobasedir";
		final FilteredCommand filteredCommand = new FilteredCommand(