Search in sources :

Example 31 with Repository

use of org.apache.maven.wagon.repository.Repository in project artifact-registry-maven-tools by GoogleCloudPlatform.

the class ArtifactRegistryWagonTest method testAuthenticatedPut.

@Test
public void testAuthenticatedPut() throws Exception {
    MockHttpTransport transport = new MockHttpTransport.Builder().setLowLevelHttpResponse(new MockLowLevelHttpResponse()).build();
    ArtifactRegistryWagon wagon = new ArtifactRegistryWagon();
    wagon.setCredentialProvider(() -> GoogleCredentials.create(new AccessToken("test-access-token", Date.from(Instant.now().plusSeconds(1000)))));
    wagon.setHttpTransportFactory(() -> transport);
    wagon.connect(new Repository("my-repo", REPO_URL));
    File f = FileTestUtils.createUniqueFile("my/artifact/dir", "test");
    Files.asCharSink(f, Charset.defaultCharset()).write("test content");
    wagon.put(f, "my/resource");
    String authHeader = transport.getLowLevelHttpRequest().getFirstHeaderValue("Authorization");
    Assert.assertEquals("Bearer test-access-token", authHeader);
    Assert.assertEquals("test content", transport.getLowLevelHttpRequest().getContentAsString());
    Assert.assertEquals("https://maven.pkg.dev/my-project/my-repo/my/resource", transport.getLowLevelHttpRequest().getUrl());
}
Also used : Repository(org.apache.maven.wagon.repository.Repository) MockHttpTransport(com.google.api.client.testing.http.MockHttpTransport) MockLowLevelHttpResponse(com.google.api.client.testing.http.MockLowLevelHttpResponse) AccessToken(com.google.auth.oauth2.AccessToken) File(java.io.File) Test(org.junit.Test)

Aggregations

Repository (org.apache.maven.wagon.repository.Repository)31 Test (org.junit.Test)13 IOException (java.io.IOException)11 MockHttpTransport (com.google.api.client.testing.http.MockHttpTransport)9 File (java.io.File)9 AuthenticationException (org.apache.maven.wagon.authentication.AuthenticationException)8 Wagon (org.apache.maven.wagon.Wagon)7 ProxyInfo (org.apache.maven.wagon.proxy.ProxyInfo)7 Path (java.nio.file.Path)6 ArtifactRepository (org.apache.maven.artifact.repository.ArtifactRepository)6 ConnectionException (org.apache.maven.wagon.ConnectionException)6 TransferFailedException (org.apache.maven.wagon.TransferFailedException)6 AuthenticationInfo (org.apache.maven.wagon.authentication.AuthenticationInfo)5 AuthorizationException (org.apache.maven.wagon.authorization.AuthorizationException)5 AccessToken (com.google.auth.oauth2.AccessToken)4 ZipEntry (java.util.zip.ZipEntry)4 ZipFile (java.util.zip.ZipFile)4 RoleManagementService (org.apache.archiva.redback.rest.api.services.RoleManagementService)4 RemoteRepository (org.apache.archiva.repository.RemoteRepository)4 UnsupportedProtocolException (org.apache.maven.wagon.UnsupportedProtocolException)4