-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from olenagerasimova/14-test
feat: test with plugin from maven-central
- Loading branch information
Showing
8 changed files
with
460 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
166 changes: 166 additions & 0 deletions
166
...http3/src/test/java/com/artipie/aether/transport/http3/ArtipieAndPluginFromCentralIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
package com.artipie.aether.transport.http3; | ||
|
||
import java.io.IOException; | ||
import java.util.function.Consumer; | ||
import org.hamcrest.MatcherAssert; | ||
import org.hamcrest.Matchers; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.testcontainers.containers.BindMode; | ||
import org.testcontainers.containers.Container; | ||
import org.testcontainers.containers.GenericContainer; | ||
import org.testcontainers.containers.Network; | ||
import org.testcontainers.containers.output.OutputFrame; | ||
import org.testcontainers.containers.output.Slf4jLogConsumer; | ||
import org.testcontainers.images.builder.ImageFromDockerfile; | ||
import org.testcontainers.utility.MountableFile; | ||
|
||
/** | ||
* In this test we use this plugin from maven central to build test maven project and obtain | ||
* dependencies from artipie via HTTP/3 protocol. | ||
* Various maven repositories configuration settings are tested. | ||
*/ | ||
public class ArtipieAndPluginFromCentralIT { | ||
|
||
private static final Logger LOGGER = | ||
LoggerFactory.getLogger(ArtipieAndPluginFromCentralIT.class); | ||
|
||
private GenericContainer<?> mavenClient; | ||
|
||
private GenericContainer<?> artipie; | ||
|
||
private final Consumer<OutputFrame> artipieLog = | ||
new Slf4jLogConsumer(LoggerFactory.getLogger("ARTIPIE")); | ||
|
||
private Network net; | ||
|
||
@BeforeEach | ||
void init() throws IOException, InterruptedException { | ||
this.net = Network.newNetwork(); | ||
this.artipie = new GenericContainer<>("artipie/artipie-ubuntu:latest") | ||
.withNetwork(this.net) | ||
.withNetworkAliases("artipie") | ||
.withLogConsumer(this.artipieLog) | ||
.withClasspathResourceMapping( | ||
"artipie.yaml", "/etc/artipie/artipie.yml", BindMode.READ_ONLY | ||
) | ||
.withClasspathResourceMapping( | ||
"my-maven-proxy.yaml", "/var/artipie/repo/my-maven-proxy.yaml", BindMode.READ_ONLY | ||
) | ||
.withWorkingDirectory("/w"); | ||
this.mavenClient = new GenericContainer<>( | ||
new ImageFromDockerfile("maven-client").withFileFromClasspath( | ||
"Dockerfile", "ArtipieAndPluginFromCentralIT/Dockerfile" | ||
) | ||
) | ||
.withNetwork(this.net) | ||
.withCommand("tail", "-f", "/dev/null") | ||
.withWorkingDirectory("/w"); | ||
this.mavenClient.start(); | ||
this.artipie.start(); | ||
this.mavenClient.execInContainer("sleep", "5"); | ||
} | ||
|
||
/** | ||
* Here artipie HTTP/3 repository is specified in maven settings.xml file. Maven client uses this | ||
* repository to download dependencies only (not plugins). Thus, maven client does the following:<p/> | ||
* 1) downloads maven-resolver-transport-http3 and its deps from central directly<p/> | ||
* 2) once downloaded, maven-resolver-transport-http3 plugin is activated and | ||
* project dependencies are downloaded from repository, specified in settings.xml file via HTTP/3<p/> | ||
* 3) maven client needs some other plugins to build the project, and it tries to obtain them | ||
* from central still using maven-resolver-transport-http3, and plugin | ||
* performs requests to central via HTTP/1.1<p/> | ||
*/ | ||
@Test | ||
void buildsWithMavenProfile() throws IOException, InterruptedException { | ||
this.putClasspathResourceToClient("ArtipieAndPluginFromCentralIT/com/example/test-maven-profile/maven-settings.xml", "/w/settings.xml"); | ||
this.putClasspathResourceToClient("ArtipieAndPluginFromCentralIT/com/example/test-maven-profile/pom.xml", "/w/pom.xml"); | ||
final Container.ExecResult exec = this.mavenClient.execInContainer( | ||
"mvn", "install", "-DskipTests", "-s", "settings.xml", "-Daether.connector.https.securityMode=insecure" | ||
); | ||
String res = String.join("\n", exec.getStdout(), exec.getStderr()); | ||
LOGGER.info(res); | ||
MatcherAssert.assertThat("Maven install status is not successful", exec.getExitCode() == 0); | ||
MatcherAssert.assertThat( | ||
res, | ||
Matchers.stringContainsInOrder( | ||
"Downloaded from central: https://repo.maven.apache.org/maven2/com/artipie/maven/resolver/maven-resolver-transport-http3", | ||
"BUILD SUCCESS", | ||
"Request over HTTP/3.0 done, method=GET, resp status=200, url=https://artipie:8091/my-maven-proxy/args4j/args4j/2.33/args4j-2.33.jar", | ||
"Request over HTTP/3.0 done, method=GET, resp status=200, url=https://artipie:8091/my-maven-proxy/org/springframework/spring-web/6.1.0/spring-web-6.1.0.jar", | ||
"Request over HTTP/1.1 done, method=GET, resp status=200, url=https://repo.maven.apache.org/maven2/org/apache/maven/maven-archiver/3.6.0/maven-archiver-3.6.0.pom" | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* Here repository is specified in pom.xml file, maven client work logic is the same as in | ||
* {@link ArtipieAndPluginFromCentralIT#buildsWithMavenProfile()}. | ||
*/ | ||
@Test | ||
void buildsWithPomRepo() throws IOException, InterruptedException { | ||
this.putClasspathResourceToClient("ArtipieAndPluginFromCentralIT/com/example/test-pom-repo/pom.xml", "/w/pom.xml"); | ||
final Container.ExecResult exec = this.mavenClient.execInContainer( | ||
"mvn", "install", "-Daether.connector.https.securityMode=insecure" | ||
); | ||
String res = String.join("\n", exec.getStdout(), exec.getStderr()); | ||
LOGGER.info(res); | ||
MatcherAssert.assertThat("Maven install status is not successful", exec.getExitCode() == 0); | ||
MatcherAssert.assertThat( | ||
res, | ||
Matchers.stringContainsInOrder( | ||
"Downloaded from central: https://repo.maven.apache.org/maven2/com/artipie/maven/resolver/maven-resolver-transport-http3", | ||
"BUILD SUCCESS", | ||
"Request over HTTP/3.0 done, method=GET, resp status=200, url=https://artipie:8091/my-maven-proxy/args4j/args4j/2.33/args4j-2.33.jar", | ||
"Request over HTTP/3.0 done, method=GET, resp status=200, url=https://artipie:8091/my-maven-proxy/org/springframework/spring-web/6.1.0/spring-web-6.1.0.jar", | ||
"Request over HTTP/1.1 done, method=GET, resp status=200, url=https://repo.maven.apache.org/maven2/org/apache/maven/maven-archiver/3.6.0/maven-archiver-3.6.0.pom" | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* In this example project we specify both repositories for plugins and dependencies in pom.xml. | ||
* In the case, when maven client is not able to download plugin from custom repo, it switches | ||
* to central. Thus, maven client does the following:<p/> | ||
* 1) tries to get maven-resolver-transport-http3 plugin from artipie via HTTP/1.1, but fails | ||
* and switches to central<p/> | ||
* 2) once downloaded, maven-resolver-transport-http3 plugin is activated and | ||
* all other dependencies and plugins are downloaded from artipie via HTTP/3 | ||
*/ | ||
@Test | ||
void buildsWithPomPluginRepo() throws IOException, InterruptedException { | ||
this.putClasspathResourceToClient("ArtipieAndPluginFromCentralIT/com/example/test-pom-plugin-repo/pom.xml", "/w/pom.xml"); | ||
final Container.ExecResult exec = this.mavenClient.execInContainer( | ||
"mvn", "install", "-Daether.connector.https.securityMode=insecure" | ||
); | ||
String res = String.join("\n", exec.getStdout(), exec.getStderr()); | ||
LOGGER.info(res); | ||
MatcherAssert.assertThat("Maven install status is not successful", exec.getExitCode() == 0); | ||
MatcherAssert.assertThat( | ||
res, | ||
Matchers.stringContainsInOrder( | ||
"Downloaded from central: https://repo.maven.apache.org/maven2/com/artipie/maven/resolver/maven-resolver-transport-http3", | ||
"BUILD SUCCESS", | ||
"Request over HTTP/3.0 done, method=GET, resp status=200, url=https://artipie:8091/my-maven-proxy/args4j/args4j/2.33/args4j-2.33.jar", | ||
"Request over HTTP/3.0 done, method=GET, resp status=200, url=https://artipie:8091/my-maven-proxy/org/springframework/spring-web/6.1.0/spring-web-6.1.0.jar", | ||
"Request over HTTP/3.0 done, method=GET, resp status=200, url=https://artipie:8091/my-maven-proxy/org/apache/maven/maven-archiver/3.6.0/maven-archiver-3.6.0.pom" | ||
) | ||
); | ||
} | ||
|
||
@AfterEach | ||
void close() { | ||
this.artipie.stop(); | ||
this.mavenClient.stop(); | ||
this.net.close(); | ||
} | ||
|
||
private void putClasspathResourceToClient(final String res, final String path) { | ||
final MountableFile file = MountableFile.forClasspathResource(res); | ||
this.mavenClient.copyFileToContainer(file, path); | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
mvn-resolver-transport-http3/src/test/resources/ArtipieAndPluginFromCentralIT/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Ubuntu 16.04 | ||
# Oracle Java 21 64 bit | ||
# Maven 3.9.5 | ||
|
||
FROM ubuntu:22.04 | ||
|
||
# this is a non-interactive automated build - avoid some warning messages | ||
ENV DEBIAN_FRONTEND noninteractive | ||
|
||
# update dpkg repositories | ||
RUN apt-get update | ||
|
||
# install wget | ||
RUN apt-get install -y wget | ||
|
||
# get maven 3.3.9 | ||
RUN wget --no-verbose -O /tmp/apache-maven-3.9.5.tar.gz https://dlcdn.apache.org/maven/maven-3/3.9.5/binaries/apache-maven-3.9.5-bin.tar.gz | ||
|
||
# install maven | ||
RUN tar xzf /tmp/apache-maven-3.9.5.tar.gz -C /opt/ | ||
RUN ln -s /opt/apache-maven-3.9.5 /opt/maven | ||
RUN ln -s /opt/maven/bin/mvn /usr/local/bin | ||
RUN rm -f /tmp/apache-maven-3.9.5.tar.gz | ||
ENV MAVEN_HOME /opt/maven | ||
|
||
# remove download archive files | ||
RUN apt-get clean | ||
|
||
# set shell variables for java installation | ||
ENV java_version 21 | ||
ENV filename jdk-21_linux-x64_bin.tar.gz | ||
ENV downloadlink https://download.oracle.com/java/21/latest/$filename | ||
|
||
# download java, accepting the license agreement | ||
RUN wget --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" -O /tmp/$filename $downloadlink | ||
|
||
# unpack java | ||
RUN mkdir /opt/java-oracle/ && mkdir /opt/java-oracle/jdk21/ && tar -zxf /tmp/$filename -C /opt/java-oracle/jdk21/ --strip-components 1 | ||
ENV JAVA_HOME /opt/java-oracle/jdk21 | ||
ENV PATH $JAVA_HOME/bin:$PATH | ||
|
||
# configure symbolic links for the java and javac executables | ||
RUN update-alternatives --install /usr/bin/java java $JAVA_HOME/bin/java 20000 && update-alternatives --install /usr/bin/javac javac $JAVA_HOME/bin/javac 20000 | ||
|
||
# check maven | ||
RUN mvn --version | ||
|
||
CMD [""] |
40 changes: 40 additions & 0 deletions
40
...resources/ArtipieAndPluginFromCentralIT/com/example/test-maven-profile/maven-settings.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
The MIT License (MIT) | ||
Copyright (c) 2020 artipie.com | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included | ||
in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
--> | ||
<settings> | ||
<profiles> | ||
<profile> | ||
<id>artipie-proxy</id> | ||
<repositories> | ||
<repository> | ||
<id>my-maven</id> | ||
<url>https://artipie:8091/my-maven-proxy/</url> | ||
</repository> | ||
</repositories> | ||
</profile> | ||
</profiles> | ||
<activeProfiles> | ||
<activeProfile>artipie-proxy</activeProfile> | ||
</activeProfiles> | ||
</settings> |
62 changes: 62 additions & 0 deletions
62
...3/src/test/resources/ArtipieAndPluginFromCentralIT/com/example/test-maven-profile/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
The MIT License (MIT) | ||
Copyright (c) 2020 artipie.com | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included | ||
in all copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>com.example</groupId> | ||
<artifactId>test-maven-profile</artifactId> | ||
<version>0.1</version> | ||
<packaging>jar</packaging> | ||
<name>Pom with dependencies</name> | ||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | ||
</properties> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>args4j</groupId> | ||
<artifactId>args4j</artifactId> | ||
<version>2.33</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-web</artifactId> | ||
<version>6.1.0</version> | ||
</dependency> | ||
|
||
</dependencies> | ||
<build> | ||
<extensions> | ||
<extension> | ||
<groupId>com.artipie.maven.resolver</groupId> | ||
<artifactId>maven-resolver-transport-http3</artifactId> | ||
<version>LATEST</version> | ||
</extension> | ||
</extensions> | ||
</build> | ||
|
||
</project> |
Oops, something went wrong.
fed7eb4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't able to retrieve PDD puzzles from the code base and submit them to github. If you think that it's a bug on our side, please submit it to yegor256/0pdd:
Please, copy and paste this stack trace to GitHub: