Example usage for org.eclipse.jgit.api.errors TransportException TransportException

List of usage examples for org.eclipse.jgit.api.errors TransportException TransportException

Introduction

In this page you can find the example usage for org.eclipse.jgit.api.errors TransportException TransportException.

Prototype

public TransportException(String msg) 

Source Link

Document

Constructor for TransportException

Usage

From source file:com.sap.dirigible.ide.jgit.connector.JGitConnector.java

License:Open Source License

/**
 * /*from  w w  w  .j  a va2  s.  c o  m*/
 * Clones secured git remote repository to the file system.
 * 
 * @param gitDirectory
 *            where the remote repository will be cloned
 * @param repositoryURI
 *            repository's URI example: https://qwerty.com/xyz/abc.git
 * @param username
 *            the username used for authentication
 * @param password
 *            the password used for authentication
 * 
 * @throws InvalidRemoteException
 * @throws TransportException
 * @throws GitAPIException
 */
public static void cloneRepository(File gitDirectory, String repositoryURI, String username, String password)
        throws InvalidRemoteException, TransportException, GitAPIException {
    try {
        CloneCommand cloneCommand = Git.cloneRepository();
        cloneCommand.setURI(repositoryURI);
        if (!StringUtils.isEmptyOrNull(username) && !StringUtils.isEmptyOrNull(password)) {
            cloneCommand.setCredentialsProvider(new UsernamePasswordCredentialsProvider(username, password));
        }
        cloneCommand.setRemote(Constants.DEFAULT_REMOTE_NAME);
        cloneCommand.setDirectory(gitDirectory);
        cloneCommand.call();
    } catch (NullPointerException e) {
        throw new TransportException(INVALID_USERNAME_AND_PASSWORD);
    }
}

From source file:org.commonwl.view.workflow.WorkflowControllerTest.java

License:Apache License

/**
 * Endpoint for main form submission//from  w  w  w .j  av  a 2  s  .  c om
 */
@Test
public void newWorkflowFromGithubURL() throws Exception {

    // Validator pass or fail
    WorkflowFormValidator mockValidator = Mockito.mock(WorkflowFormValidator.class);
    when(mockValidator.validateAndParse(anyObject(), anyObject())).thenReturn(null)
            .thenReturn(new GitDetails("https://github.com/owner/repoName.git", "branch", "path/within"))
            .thenReturn(new GitDetails("https://github.com/owner/repoName.git", "branch", "path/workflow.cwl"));

    // The eventual accepted valid workflow
    Workflow mockWorkflow = Mockito.mock(Workflow.class);
    when(mockWorkflow.getRetrievedFrom())
            .thenReturn(new GitDetails("https://github.com/owner/repoName.git", "branch", "path/workflow.cwl"));
    QueuedWorkflow mockQueuedWorkflow = Mockito.mock(QueuedWorkflow.class);
    when(mockQueuedWorkflow.getTempRepresentation()).thenReturn(mockWorkflow);

    // Mock workflow service returning valid workflow
    WorkflowService mockWorkflowService = Mockito.mock(WorkflowService.class);
    when(mockWorkflowService.createQueuedWorkflow(anyObject())).thenThrow(new WorkflowNotFoundException())
            .thenThrow(new WrongRepositoryStateException("Some Error"))
            .thenThrow(new TransportException("No SSH Key")).thenThrow(new IOException())
            .thenReturn(mockQueuedWorkflow);

    // Mock controller/MVC
    WorkflowController workflowController = new WorkflowController(mockValidator, mockWorkflowService,
            Mockito.mock(GraphVizService.class));
    MockMvc mockMvc = MockMvcBuilders.standaloneSetup(workflowController).build();

    // Error in validation, go to index to show error
    mockMvc.perform(post("/workflows").param("url", "invalidurl")).andExpect(status().isOk())
            .andExpect(view().name("index"));

    // Valid directory URL redirect
    mockMvc.perform(
            post("/workflows").param("url", "https://github.com/owner/repoName/blob/branch/path/within"))
            .andExpect(status().isFound())
            .andExpect(redirectedUrl("/workflows/github.com/owner/repoName/blob/branch/path/within"));

    // Invalid workflow URL, go to index to show error
    mockMvc.perform(post("/workflows").param("url",
            "https://github.com/owner/repoName/blob/branch/path/nonexistant.cwl")).andExpect(status().isOk())
            .andExpect(view().name("index")).andExpect(model().attributeHasFieldErrors("workflowForm", "url"));

    // Git API error
    mockMvc.perform(post("/workflows").param("url",
            "https://github.com/owner/repoName/blob/branch/path/cantbecloned.cwl")).andExpect(status().isOk())
            .andExpect(view().name("index")).andExpect(model().attributeHasFieldErrors("workflowForm", "url"));

    // Unsupported SSH URL
    mockMvc.perform(
            post("/workflows").param("url", "ssh://github.com/owner/repoName/blob/branch/path/workflow.cwl"))
            .andExpect(status().isOk()).andExpect(view().name("index"))
            .andExpect(model().attributeHasFieldErrors("workflowForm", "url"));

    // Unexpected error
    mockMvc.perform(
            post("/workflows").param("url", "ssh://github.com/owner/repoName/blob/branch/path/unexpected.cwl"))
            .andExpect(status().isOk()).andExpect(view().name("index"))
            .andExpect(model().attributeHasFieldErrors("workflowForm", "url"));

    // Valid workflow URL redirect
    mockMvc.perform(
            post("/workflows").param("url", "https://github.com/owner/repoName/blob/branch/path/workflow.cwl"))
            .andExpect(status().isFound())
            .andExpect(redirectedUrl("/workflows/github.com/owner/repoName/blob/branch/path/workflow.cwl"));

}

From source file:org.commonwl.view.workflow.WorkflowControllerTest.java

License:Apache License

/**
 * Displaying workflows//w  w w .  j  a v  a  2s. c  o  m
 */
@Test
public void directWorkflowURL() throws Exception {

    Workflow mockWorkflow = Mockito.mock(Workflow.class);
    QueuedWorkflow mockQueuedWorkflow = Mockito.mock(QueuedWorkflow.class);
    when(mockQueuedWorkflow.getWorkflowList()).thenReturn(null);

    // Mock service
    WorkflowService mockWorkflowService = Mockito.mock(WorkflowService.class);
    when(mockWorkflowService.getWorkflow(Matchers.<GitDetails>anyObject())).thenReturn(mockWorkflow)
            .thenReturn(null);
    when(mockWorkflowService.createQueuedWorkflow(anyObject())).thenReturn(mockQueuedWorkflow)
            .thenThrow(new WorkflowNotFoundException())
            .thenThrow(new WrongRepositoryStateException("Some Error"))
            .thenThrow(new TransportException("No SSH Key")).thenThrow(new IOException());
    List<WorkflowOverview> listOfTwoOverviews = new ArrayList<>();
    listOfTwoOverviews.add(new WorkflowOverview("/workflow1.cwl", "label", "doc"));
    listOfTwoOverviews.add(new WorkflowOverview("/workflow2.cwl", "label2", "doc2"));
    when(mockWorkflowService.getWorkflowsFromDirectory(anyObject())).thenReturn(listOfTwoOverviews)
            .thenReturn(Collections.singletonList(new WorkflowOverview("/workflow1.cwl", "label", "doc")));

    // Mock controller/MVC
    WorkflowController workflowController = new WorkflowController(Mockito.mock(WorkflowFormValidator.class),
            mockWorkflowService, Mockito.mock(GraphVizService.class));
    MockMvc mockMvc = MockMvcBuilders.standaloneSetup(workflowController).build();

    // Workflow already exists in the database
    mockMvc.perform(get("/workflows/github.com/owner/reponame/tree/branch/path/within/workflow.cwl"))
            .andExpect(status().isOk()).andExpect(view().name("workflow"))
            .andExpect(model().attribute("workflow", is(mockWorkflow)));

    // Workflow needs to be created, loading page
    mockMvc.perform(get("/workflows/github.com/owner/reponame/tree/branch/path/within/workflow.cwl"))
            .andExpect(status().isOk()).andExpect(view().name("loading"))
            .andExpect(model().attribute("queued", is(mockQueuedWorkflow)));

    // Directory URL, select between
    mockMvc.perform(get("/workflows/github.com/owner/reponame/tree/branch/path/within"))
            .andExpect(status().isOk()).andExpect(view().name("selectworkflow"))
            .andExpect(model().attributeExists("gitDetails"))
            .andExpect(model().attributeExists("workflowOverviews"));

    // Directory URL with only one workflow redirects
    mockMvc.perform(get("/workflows/github.com/owner/reponame/tree/branch/path/within"))
            .andExpect(status().isFound()).andExpect(redirectedUrl(
                    "/workflows/github.com/owner/reponame/blob/branch/path/within/workflow1.cwl"));

    // Workflow not found
    mockMvc.perform(get("/workflows/github.com/owner/reponame/tree/branch/path/within/nonexistant.cwl"))
            .andExpect(status().isFound()).andExpect(MockMvcResultMatchers.flash().attributeExists("errors"));

    // Git API error
    mockMvc.perform(get("/workflows/github.com/owner/reponame/tree/branch/path/within/cantbecloned.cwl"))
            .andExpect(status().isFound()).andExpect(MockMvcResultMatchers.flash().attributeExists("errors"));

    // Submodules with SSH Url
    mockMvc.perform(get("/workflows/github.com/owner/reponame/tree/branch/path/within/submodulewithssh.cwl"))
            .andExpect(status().isFound()).andExpect(MockMvcResultMatchers.flash().attributeExists("errors"));

    // Unexpected error
    mockMvc.perform(get("/workflows/github.com/owner/reponame/tree/branch/path/within/badworkflow.cwl"))
            .andExpect(status().isFound()).andExpect(MockMvcResultMatchers.flash().attributeExists("errors"));
}

From source file:org.eclipse.dirigible.repository.ext.git.JGitConnector.java

License:Open Source License

/**
 * Clones secured git remote repository to the file system.
 *
 * @param gitDirectory//  ww  w .j  a va2s .  co  m
 *            where the remote repository will be cloned
 * @param repositoryURI
 *            repository's URI example: https://qwerty.com/xyz/abc.git
 * @param username
 *            the username used for authentication
 * @param password
 *            the password used for authentication
 * @param branch
 *            the branch where sources will be cloned from
 * @throws InvalidRemoteException
 * @throws TransportException
 * @throws GitAPIException
 */
public static void cloneRepository(File gitDirectory, String repositoryURI, String username, String password,
        String branch) throws InvalidRemoteException, TransportException, GitAPIException {
    try {
        CloneCommand cloneCommand = Git.cloneRepository();
        cloneCommand.setURI(repositoryURI);
        if (!StringUtils.isEmptyOrNull(username) && !StringUtils.isEmptyOrNull(password)) {
            cloneCommand.setCredentialsProvider(new UsernamePasswordCredentialsProvider(username, password));
        }
        cloneCommand.setBranch(branch);
        cloneCommand.setDirectory(gitDirectory);
        cloneCommand.call();
    } catch (Exception e) {
        throw new TransportException(e.getMessage());
    }
}

From source file:org.springframework.cloud.config.server.environment.JGitEnvironmentRepositoryTests.java

License:Apache License

@Test
public void shouldDeleteBaseDirWhenCloneFails() throws Exception {
    Git mockGit = mock(Git.class);
    CloneCommand mockCloneCommand = mock(CloneCommand.class);

    when(mockCloneCommand.setURI(anyString())).thenReturn(mockCloneCommand);
    when(mockCloneCommand.setDirectory(any(File.class))).thenReturn(mockCloneCommand);
    when(mockCloneCommand.call()).thenThrow(new TransportException("failed to clone"));

    JGitEnvironmentRepository envRepository = new JGitEnvironmentRepository(this.environment);
    envRepository.setGitFactory(new MockGitFactory(mockGit, mockCloneCommand));
    envRepository.setUri("http://somegitserver/somegitrepo");
    envRepository.setBasedir(this.basedir);

    try {// w  w  w  .ja v a2s. c  o m
        envRepository.findOne("bar", "staging", "master");
    } catch (Exception ex) {
        // expected - ignore
    }

    assertFalse("baseDir should be deleted when clone fails", this.basedir.exists());
}