Search in sources :

Example 1 with DefaultManagedRepositoryAdmin

use of org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin in project archiva by apache.

the class CleanupReleasedSnapshotsRepositoryPurgeTest method setUp.

@Before
@Override
public void setUp() throws Exception {
    super.setUp();
    RepositoryContentFactory factory = applicationContext.getBean("repositoryContentFactory#cleanup-released-snapshots", RepositoryContentFactory.class);
    archivaConfiguration = applicationContext.getBean("archivaConfiguration#cleanup-released-snapshots", ArchivaConfiguration.class);
    listenerControl = EasyMock.createControl();
    listener = listenerControl.createMock(RepositoryListener.class);
    List<RepositoryListener> listeners = Collections.singletonList(listener);
    repoPurge = new CleanupReleasedSnapshotsRepositoryPurge(getRepository(), metadataTools, applicationContext.getBean(RepositoryRegistry.class), repositorySession, listeners);
    ((DefaultManagedRepositoryAdmin) applicationContext.getBean(ManagedRepositoryAdmin.class)).setArchivaConfiguration(archivaConfiguration);
}
Also used : RepositoryListener(org.apache.archiva.repository.events.RepositoryListener) ManagedRepositoryAdmin(org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin) DefaultManagedRepositoryAdmin(org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin) RepositoryContentFactory(org.apache.archiva.repository.RepositoryContentFactory) ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration) DefaultManagedRepositoryAdmin(org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin) Before(org.junit.Before)

Example 2 with DefaultManagedRepositoryAdmin

use of org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin in project archiva by apache.

the class HttpProxyTransferTest method setUp.

@Before
public void setUp() throws Exception {
    proxyHandler = applicationContext.getBean("repositoryProxyConnectors#test", RepositoryProxyConnectors.class);
    config = applicationContext.getBean("archivaConfiguration#mock", ArchivaConfiguration.class);
    // clear from previous tests - TODO the spring context should be initialised per test instead, or the config
    // made a complete mock
    config.getConfiguration().getProxyConnectors().clear();
    // Setup source repository (using default layout)
    String repoPath = "target/test-repository/managed/" + getClass().getSimpleName();
    Path destRepoDir = Paths.get(repoPath);
    // Cleanout destination dirs.
    if (Files.exists(destRepoDir)) {
        FileUtils.deleteDirectory(destRepoDir.toFile());
    }
    // Make the destination dir.
    Files.createDirectories(destRepoDir);
    MavenManagedRepository repo = new MavenManagedRepository(MANAGED_ID, "Default Managed Repository", Paths.get(repoPath).getParent());
    repo.setLocation(new URI(repoPath));
    repo.setLayout("default");
    RepositoryContentProvider provider = applicationContext.getBean("repositoryContentProvider#maven", RepositoryContentProvider.class);
    ManagedRepositoryContent repoContent = provider.createManagedContent(repo);
    managedDefaultRepository = repoContent;
    ((DefaultManagedRepositoryAdmin) applicationContext.getBean(ManagedRepositoryAdmin.class)).setArchivaConfiguration(config);
    RepositoryRegistry managedRepositoryAdmin = applicationContext.getBean(RepositoryRegistry.class);
    if (managedRepositoryAdmin.getManagedRepository(repo.getId()) == null) {
        managedRepositoryAdmin.putRepository(repo);
    }
    // config.getConfiguration().addManagedRepository( repo );
    Handler handler = new AbstractHandler() {

        @Override
        public void handle(String s, Request request, HttpServletRequest httpServletRequest, HttpServletResponse response) throws IOException, ServletException {
            response.setContentType("text/plain");
            response.setStatus(HttpServletResponse.SC_OK);
            response.getWriter().print("get-default-layout-1.0.jar\n\n");
            assertNotNull(request.getHeader("Proxy-Connection"));
            ((Request) request).setHandled(true);
        }

        public void handle(String target, HttpServletRequest request, HttpServletResponse response, int dispatch) throws IOException, ServletException {
            response.setContentType("text/plain");
            response.setStatus(HttpServletResponse.SC_OK);
            response.getWriter().print("get-default-layout-1.0.jar\n\n");
            assertNotNull(request.getHeader("Proxy-Connection"));
            ((Request) request).setHandled(true);
        }
    };
    server = new Server();
    ServerConnector serverConnector = new ServerConnector(server, new HttpConnectionFactory());
    server.addConnector(serverConnector);
    server.setHandler(handler);
    server.start();
    int port = serverConnector.getLocalPort();
    NetworkProxyConfiguration proxyConfig = new NetworkProxyConfiguration();
    proxyConfig.setHost("localhost");
    proxyConfig.setPort(port);
    proxyConfig.setProtocol("http");
    proxyConfig.setId(PROXY_ID);
    config.getConfiguration().addNetworkProxy(proxyConfig);
    // Setup target (proxied to) repository.
    RemoteRepositoryConfiguration repoConfig = new RemoteRepositoryConfiguration();
    repoConfig.setId(PROXIED_ID);
    repoConfig.setName("Proxied Repository 1");
    repoConfig.setLayout("default");
    repoConfig.setUrl("http://www.example.com/");
    config.getConfiguration().addRemoteRepository(repoConfig);
}
Also used : Path(java.nio.file.Path) Server(org.eclipse.jetty.server.Server) HttpConnectionFactory(org.eclipse.jetty.server.HttpConnectionFactory) MavenManagedRepository(org.apache.archiva.repository.maven2.MavenManagedRepository) Request(org.eclipse.jetty.server.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) Handler(org.eclipse.jetty.server.Handler) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) HttpServletResponse(javax.servlet.http.HttpServletResponse) RepositoryProxyConnectors(org.apache.archiva.proxy.model.RepositoryProxyConnectors) URI(java.net.URI) ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration) DefaultManagedRepositoryAdmin(org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin) AbstractHandler(org.eclipse.jetty.server.handler.AbstractHandler) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServerConnector(org.eclipse.jetty.server.ServerConnector) RepositoryContentProvider(org.apache.archiva.repository.RepositoryContentProvider) ManagedRepositoryContent(org.apache.archiva.repository.ManagedRepositoryContent) ManagedRepositoryAdmin(org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin) DefaultManagedRepositoryAdmin(org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin) NetworkProxyConfiguration(org.apache.archiva.configuration.NetworkProxyConfiguration) RepositoryRegistry(org.apache.archiva.repository.RepositoryRegistry) RemoteRepositoryConfiguration(org.apache.archiva.configuration.RemoteRepositoryConfiguration) Before(org.junit.Before)

Example 3 with DefaultManagedRepositoryAdmin

use of org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin in project archiva by apache.

the class AbstractMavenRepositorySearch method setUp.

@Before
@Override
public void setUp() throws Exception {
    super.setUp();
    FileUtils.deleteDirectory(Paths.get(org.apache.archiva.common.utils.FileUtils.getBasedir(), "/target/repos/" + TEST_REPO_1 + "/.indexer"));
    assertFalse(Files.exists(Paths.get(org.apache.archiva.common.utils.FileUtils.getBasedir(), "/target/repos/" + TEST_REPO_1 + "/.indexer")));
    FileUtils.deleteDirectory(Paths.get(org.apache.archiva.common.utils.FileUtils.getBasedir(), "/target/repos/" + TEST_REPO_2 + "/.indexer"));
    assertFalse(Files.exists(Paths.get(org.apache.archiva.common.utils.FileUtils.getBasedir(), "/target/repos/" + TEST_REPO_2 + "/.indexer")));
    archivaConfigControl = EasyMock.createControl();
    archivaConfig = archivaConfigControl.createMock(ArchivaConfiguration.class);
    DefaultManagedRepositoryAdmin defaultManagedRepositoryAdmin = new DefaultManagedRepositoryAdmin();
    defaultManagedRepositoryAdmin.setArchivaConfiguration(archivaConfig);
    DefaultProxyConnectorAdmin defaultProxyConnectorAdmin = new DefaultProxyConnectorAdmin();
    defaultProxyConnectorAdmin.setArchivaConfiguration(archivaConfig);
    repositoryRegistry.setArchivaConfiguration(archivaConfig);
    search = new MavenRepositorySearch(indexer, repositoryRegistry, defaultProxyConnectorAdmin, queryCreator);
    assertNotNull(repositoryRegistry);
    defaultManagedRepositoryAdmin.setRepositoryRegistry(repositoryRegistry);
    config = new Configuration();
    config.addManagedRepository(createRepositoryConfig(TEST_REPO_1));
    config.addManagedRepository(createRepositoryConfig(TEST_REPO_2));
    config.addManagedRepository(createRepositoryConfig(REPO_RELEASE));
    archivaConfig.addListener(EasyMock.anyObject(ConfigurationListener.class));
    EasyMock.expect(archivaConfig.getDefaultLocale()).andReturn(Locale.getDefault()).anyTimes();
    EasyMock.expect(archivaConfig.getConfiguration()).andReturn(config).anyTimes();
    archivaConfig.save(EasyMock.anyObject(Configuration.class));
    EasyMock.expectLastCall().anyTimes();
    archivaConfigControl.replay();
    repositoryRegistry.reload();
    archivaConfigControl.reset();
}
Also used : ConfigurationListener(org.apache.archiva.configuration.ConfigurationListener) DefaultProxyConnectorAdmin(org.apache.archiva.admin.repository.proxyconnector.DefaultProxyConnectorAdmin) ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Configuration(org.apache.archiva.configuration.Configuration) ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration) DefaultManagedRepositoryAdmin(org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin) Before(org.junit.Before)

Aggregations

DefaultManagedRepositoryAdmin (org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin)3 ArchivaConfiguration (org.apache.archiva.configuration.ArchivaConfiguration)3 Before (org.junit.Before)3 ManagedRepositoryAdmin (org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin)2 URI (java.net.URI)1 Path (java.nio.file.Path)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 DefaultProxyConnectorAdmin (org.apache.archiva.admin.repository.proxyconnector.DefaultProxyConnectorAdmin)1 Configuration (org.apache.archiva.configuration.Configuration)1 ConfigurationListener (org.apache.archiva.configuration.ConfigurationListener)1 ManagedRepositoryConfiguration (org.apache.archiva.configuration.ManagedRepositoryConfiguration)1 NetworkProxyConfiguration (org.apache.archiva.configuration.NetworkProxyConfiguration)1 RemoteRepositoryConfiguration (org.apache.archiva.configuration.RemoteRepositoryConfiguration)1 RepositoryProxyConnectors (org.apache.archiva.proxy.model.RepositoryProxyConnectors)1 ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)1 RepositoryContentFactory (org.apache.archiva.repository.RepositoryContentFactory)1 RepositoryContentProvider (org.apache.archiva.repository.RepositoryContentProvider)1 RepositoryRegistry (org.apache.archiva.repository.RepositoryRegistry)1 RepositoryListener (org.apache.archiva.repository.events.RepositoryListener)1