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());
}
Aggregations