Search in sources :

Example 1 with RepositoryProperties

use of org.eclipse.winery.repository.backend.filebased.RepositoryProperties in project winery by eclipse.

the class MultiRepositoryManagerTest method testMultiRepositoryCreation.

/**
 * Test whenever the initzialize method reconfigures the RepositoryFactory correctly.
 */
@Test
public void testMultiRepositoryCreation() {
    ArrayList<RepositoryProperties> repositoryList = new ArrayList<>();
    repositoryList.add(new RepositoryProperties("mainTestRepository", "https://github.com/winery/mulit-repo-test", "master"));
    MultiRepositoryManager multiRepositoryManager = new MultiRepositoryManager();
    multiRepositoryManager.initializeRepositoryListForMultiRepositoryAndReconfigureFactory(repositoryList);
    assertTrue(RepositoryFactory.getRepository() instanceof MultiRepository);
}
Also used : ArrayList(java.util.ArrayList) RepositoryProperties(org.eclipse.winery.repository.backend.filebased.RepositoryProperties) Test(org.junit.jupiter.api.Test)

Example 2 with RepositoryProperties

use of org.eclipse.winery.repository.backend.filebased.RepositoryProperties in project winery by eclipse.

the class MultiRepositoryManagerTest method testGetRepositoriesAsList.

/**
 * This test ckecks whenever the repository list is correctly retrieved from the json file.
 */
@Test
public void testGetRepositoriesAsList() {
    writeDependencyFile();
    MultiRepositoryManager multiRepositoryManager = new MultiRepositoryManager();
    List<RepositoryProperties> dependencies = multiRepositoryManager.getRepositoriesAsList();
    assertEquals(1, dependencies.size());
    RepositoryProperties testRepoDependency = dependencies.get(0);
    assertEquals("test", testRepoDependency.getName());
    assertEquals("plain", testRepoDependency.getBranch());
    assertEquals("https://github.com/winery/test-repository", testRepoDependency.getUrl());
}
Also used : RepositoryProperties(org.eclipse.winery.repository.backend.filebased.RepositoryProperties) Test(org.junit.jupiter.api.Test)

Example 3 with RepositoryProperties

use of org.eclipse.winery.repository.backend.filebased.RepositoryProperties in project winery by eclipse.

the class MultiRepositoryManagerTest method testRepositoryListImport.

/**
 * This test checks whenever the repositories of the repositoryList are imported correctly, and whenever the
 * dependencies of those repositories are also correctly imported
 */
@Test
public void testRepositoryListImport() throws UnsupportedEncodingException {
    ArrayList<RepositoryProperties> repositoryList = new ArrayList<>();
    repositoryList.add(new RepositoryProperties("mainTestRepository", "https://github.com/winery/mulit-repo-test", "master"));
    repositoryList.add(new RepositoryProperties("standardTestRepository", "https://github.com/winery/test-repository", "plain"));
    MultiRepositoryManager multiRepositoryManager = new MultiRepositoryManager();
    multiRepositoryManager.addRepositoryToFile(repositoryList);
    try {
        assertTrue(Paths.get(Environments.getInstance().getRepositoryConfig().getRepositoryRoot(), URLEncoder.encode("https://github.com/winery", "UTF-8")).toFile().exists());
        assertTrue(Paths.get(Environments.getInstance().getRepositoryConfig().getRepositoryRoot(), URLEncoder.encode("https://github.com/winery", "UTF-8"), "mulit-repo-test").toFile().exists());
        assertTrue(Paths.get(Environments.getInstance().getRepositoryConfig().getRepositoryRoot(), URLEncoder.encode("https://github.com/winery", "UTF-8"), "multi-repo-dependency").toFile().exists());
        assertTrue(Paths.get(Environments.getInstance().getRepositoryConfig().getRepositoryRoot(), URLEncoder.encode("https://github.com/winery", "UTF-8"), "test-repository").toFile().exists());
    } catch (UnsupportedEncodingException e) {
        LOGGER.error("Error while encoding.");
        throw e;
    }
}
Also used : ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) RepositoryProperties(org.eclipse.winery.repository.backend.filebased.RepositoryProperties) Test(org.junit.jupiter.api.Test)

Example 4 with RepositoryProperties

use of org.eclipse.winery.repository.backend.filebased.RepositoryProperties in project winery by eclipse.

the class RepositoryAdminResource method deleteRepository.

/**
 * Deletes given repository
 *
 * @param name of repository to delete.
 */
@DELETE
@Path("repositories/{repository}")
public Response deleteRepository(@PathParam("repository") String name) {
    String repositoryUrl = "";
    if (RepositoryFactory.getRepository() instanceof MultiRepository) {
        IRepository gitRepo;
        MultiRepositoryManager multiRepositoryManager = new MultiRepositoryManager();
        for (RepositoryProperties repo : multiRepositoryManager.getRepositoriesAsList()) {
            if (repo.getName().equals(name)) {
                repositoryUrl = repo.getUrl();
                break;
            }
        }
        for (IRepository repo : ((MultiRepository) RepositoryFactory.getRepository()).getRepositories()) {
            gitRepo = repo;
            if (gitRepo instanceof GitBasedRepository) {
                if (((GitBasedRepository) gitRepo).getRepositoryUrl() != null) {
                    if (((GitBasedRepository) gitRepo).getRepositoryUrl().equals(repositoryUrl)) {
                        ((GitBasedRepository) gitRepo).forceClear();
                        ((MultiRepository) RepositoryFactory.getRepository()).removeRepository(repositoryUrl);
                        break;
                    }
                }
            }
        }
    }
    return Response.ok().build();
}
Also used : MultiRepositoryManager(org.eclipse.winery.repository.filebased.MultiRepositoryManager) MultiRepository(org.eclipse.winery.repository.filebased.MultiRepository) IRepository(org.eclipse.winery.repository.backend.IRepository) RepositoryProperties(org.eclipse.winery.repository.backend.filebased.RepositoryProperties) GitBasedRepository(org.eclipse.winery.repository.backend.filebased.GitBasedRepository) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE)

Example 5 with RepositoryProperties

use of org.eclipse.winery.repository.backend.filebased.RepositoryProperties in project winery by eclipse.

the class MultiRepositoryManagerTest method testInitializeRepositoryList.

/**
 * Tests whenever a file is created for the repository list in the root folder.
 */
@Test
public void testInitializeRepositoryList() throws IOException {
    ArrayList<RepositoryProperties> repositoryList = new ArrayList<>();
    repositoryList.add(new RepositoryProperties("mainTestRepository", "https://github.com/winery/mulit-repo-test", "master"));
    MultiRepositoryManager multiRepositoryManager = new MultiRepositoryManager();
    multiRepositoryManager.initializeRepositoryListForMultiRepositoryAndReconfigureFactory(repositoryList);
    assertTrue(Paths.get(Environments.getInstance().getRepositoryConfig().getRepositoryRoot(), Filename.FILENAME_JSON_MUTLI_REPOSITORIES).toFile().exists());
    ObjectMapper objectMapper = new ObjectMapper();
    ObjectReader reader = objectMapper.readerFor(new TypeReference<List<RepositoryProperties>>() {
    });
    repositoryList = reader.readValue(Paths.get(Environments.getInstance().getRepositoryConfig().getRepositoryRoot(), Filename.FILENAME_JSON_MUTLI_REPOSITORIES).toFile());
    assertEquals(1, repositoryList.size());
    assertEquals("https://github.com/winery/mulit-repo-test", repositoryList.get(0).getUrl());
    assertEquals("master", repositoryList.get(0).getBranch());
    assertEquals("mainTestRepository", repositoryList.get(0).getName());
}
Also used : ArrayList(java.util.ArrayList) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) ArrayList(java.util.ArrayList) List(java.util.List) RepositoryProperties(org.eclipse.winery.repository.backend.filebased.RepositoryProperties) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test)

Aggregations

RepositoryProperties (org.eclipse.winery.repository.backend.filebased.RepositoryProperties)5 Test (org.junit.jupiter.api.Test)4 ArrayList (java.util.ArrayList)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectReader (com.fasterxml.jackson.databind.ObjectReader)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 List (java.util.List)1 DELETE (javax.ws.rs.DELETE)1 Path (javax.ws.rs.Path)1 IRepository (org.eclipse.winery.repository.backend.IRepository)1 GitBasedRepository (org.eclipse.winery.repository.backend.filebased.GitBasedRepository)1 MultiRepository (org.eclipse.winery.repository.filebased.MultiRepository)1 MultiRepositoryManager (org.eclipse.winery.repository.filebased.MultiRepositoryManager)1