Search in sources :

Example 1 with RepositoryRequest

use of org.apache.archiva.repository.content.maven2.RepositoryRequest in project archiva by apache.

the class ArchivaDavResourceFactoryTest method testRequestArtifactMetadataThreePartsRepoHasDefaultLayout.

// MRM-1239
@Test
public void testRequestArtifactMetadataThreePartsRepoHasDefaultLayout() throws Exception {
    // should fetch metadata
    DavResourceLocator locator = new ArchivaDavResourceLocator("", "/repository/" + INTERNAL_REPO + "/eclipse/jdtcore/maven-metadata.xml", INTERNAL_REPO, new ArchivaDavLocatorFactory());
    ManagedRepositoryContent internalRepo = createManagedRepositoryContent(INTERNAL_REPO);
    // use actual object (this performs the isMetadata, isDefault and isSupportFile check!)
    RepositoryRequest repoRequest = new RepositoryRequest();
    resourceFactory.setRepositoryRequest(repoRequest);
    try {
        archivaConfigurationControl.reset();
        expect(archivaConfiguration.getConfiguration()).andReturn(config).times(1);
        expect(request.getMethod()).andReturn("GET").times(4);
        expect(request.getRemoteAddr()).andReturn("http://localhost:8080").times(3);
        expect(request.getContextPath()).andReturn("").times(1);
        expect(request.getDavSession()).andReturn(new ArchivaDavSession()).times(2);
        expect(request.getRequestURI()).andReturn("http://localhost:8080/archiva/repository/" + INTERNAL_REPO + "/eclipse/jdtcore/maven-metadata.xml");
        response.setHeader("Pragma", "no-cache");
        expectLastCall();
        response.setHeader("Cache-Control", "no-cache");
        expectLastCall();
        response.setDateHeader(eq("Last-Modified"), anyLong());
        expectLastCall();
        archivaConfigurationControl.replay();
        repoContentFactoryControl.replay();
        requestControl.replay();
        responseControl.replay();
        resourceFactory.createResource(locator, request, response);
        archivaConfigurationControl.verify();
        repoContentFactoryControl.verify();
        requestControl.verify();
        responseControl.verify();
    } catch (DavException e) {
        fail("A DavException should not have been thrown!");
    }
}
Also used : DavException(org.apache.jackrabbit.webdav.DavException) ManagedRepositoryContent(org.apache.archiva.repository.ManagedRepositoryContent) RepositoryRequest(org.apache.archiva.repository.content.maven2.RepositoryRequest) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator) Test(org.junit.Test)

Example 2 with RepositoryRequest

use of org.apache.archiva.repository.content.maven2.RepositoryRequest in project archiva by apache.

the class ArchivaDavResourceFactoryTest method testRequestMetadataRepoIsLegacy.

@Test
public void testRequestMetadataRepoIsLegacy() throws Exception {
    ManagedRepositoryContent legacyRepo = createManagedRepositoryContent(LEGACY_REPO);
    ConfigurableListableBeanFactory beanFactory = ((ConfigurableApplicationContext) applicationContext).getBeanFactory();
    RepositoryContentProvider provider = createRepositoryContentProvider(legacyRepo);
    beanFactory.registerSingleton("repositoryContentProvider#legacy", provider);
    RepositoryContentFactory repoContentFactory = applicationContext.getBean("repositoryContentFactory#default", RepositoryContentFactory.class);
    repoContentFactory.getRepositoryContentProviders().add(provider);
    defaultManagedRepositoryAdmin.addManagedRepository(createManagedRepository(LEGACY_REPO, Paths.get("target/test-classes/" + LEGACY_REPO).toString(), "legacy"), false, null);
    DavResourceLocator locator = new ArchivaDavResourceLocator("", "/repository/" + LEGACY_REPO + "/eclipse/maven-metadata.xml", LEGACY_REPO, new ArchivaDavLocatorFactory());
    // use actual object (this performs the isMetadata, isDefault and isSupportFile check!)
    RepositoryRequest repoRequest = new RepositoryRequest();
    resourceFactory.setRepositoryRequest(repoRequest);
    try {
        archivaConfigurationControl.reset();
        expect(archivaConfiguration.getConfiguration()).andReturn(config).times(2);
        expect(repoFactory.getManagedRepositoryContent(LEGACY_REPO)).andReturn(legacyRepo);
        expect(request.getMethod()).andReturn("GET").times(3);
        expect(request.getRemoteAddr()).andReturn("http://localhost:8080").times(3);
        expect(request.getDavSession()).andReturn(new ArchivaDavSession()).times(2);
        expect(request.getContextPath()).andReturn("").times(2);
        archivaConfigurationControl.replay();
        repoContentFactoryControl.replay();
        requestControl.replay();
        resourceFactory.createResource(locator, request, response);
        archivaConfigurationControl.verify();
        repoContentFactoryControl.verify();
        requestControl.verify();
        fail("A 404 error should have been thrown!");
    } catch (DavException e) {
        assertEquals(404, e.getErrorCode());
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) RepositoryContentProvider(org.apache.archiva.repository.RepositoryContentProvider) DavException(org.apache.jackrabbit.webdav.DavException) ManagedRepositoryContent(org.apache.archiva.repository.ManagedRepositoryContent) RepositoryRequest(org.apache.archiva.repository.content.maven2.RepositoryRequest) ConfigurableListableBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) RepositoryContentFactory(org.apache.archiva.repository.RepositoryContentFactory) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator) Test(org.junit.Test)

Example 3 with RepositoryRequest

use of org.apache.archiva.repository.content.maven2.RepositoryRequest in project archiva by apache.

the class ArchivaDavResourceFactoryTest method testRequestArtifactMetadataTwoPartsRepoHasDefaultLayout.

@Test
public void testRequestArtifactMetadataTwoPartsRepoHasDefaultLayout() throws Exception {
    // should not fetch metadata
    DavResourceLocator locator = new ArchivaDavResourceLocator("", "/repository/" + INTERNAL_REPO + "/eclipse/maven-metadata.xml", INTERNAL_REPO, new ArchivaDavLocatorFactory());
    ManagedRepositoryContent internalRepo = createManagedRepositoryContent(INTERNAL_REPO);
    // use actual object (this performs the isMetadata, isDefault and isSupportFile check!)
    RepositoryRequest repoRequest = new RepositoryRequest();
    resourceFactory.setRepositoryRequest(repoRequest);
    try {
        archivaConfigurationControl.reset();
        expect(archivaConfiguration.getConfiguration()).andReturn(config).times(2);
        expect(repoFactory.getManagedRepositoryContent(INTERNAL_REPO)).andReturn(internalRepo);
        expect(request.getMethod()).andReturn("GET").times(3);
        expect(request.getRemoteAddr()).andReturn("http://localhost:8080").times(3);
        expect(request.getDavSession()).andReturn(new ArchivaDavSession()).times(2);
        expect(request.getContextPath()).andReturn("").times(2);
        archivaConfigurationControl.replay();
        repoContentFactoryControl.replay();
        requestControl.replay();
        resourceFactory.createResource(locator, request, response);
        archivaConfigurationControl.verify();
        repoContentFactoryControl.verify();
        requestControl.verify();
        fail("A 404 error should have been thrown!");
    } catch (DavException e) {
        assertEquals(404, e.getErrorCode());
    }
}
Also used : DavException(org.apache.jackrabbit.webdav.DavException) ManagedRepositoryContent(org.apache.archiva.repository.ManagedRepositoryContent) RepositoryRequest(org.apache.archiva.repository.content.maven2.RepositoryRequest) DavResourceLocator(org.apache.jackrabbit.webdav.DavResourceLocator) Test(org.junit.Test)

Aggregations

ManagedRepositoryContent (org.apache.archiva.repository.ManagedRepositoryContent)3 RepositoryRequest (org.apache.archiva.repository.content.maven2.RepositoryRequest)3 DavException (org.apache.jackrabbit.webdav.DavException)3 DavResourceLocator (org.apache.jackrabbit.webdav.DavResourceLocator)3 Test (org.junit.Test)3 RepositoryContentFactory (org.apache.archiva.repository.RepositoryContentFactory)1 RepositoryContentProvider (org.apache.archiva.repository.RepositoryContentProvider)1 ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)1 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)1