From 65f2d39a401a5d3eed8ee25c965e5b6551b3f1cf Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Wed, 23 Aug 2023 10:54:36 +0200 Subject: [PATCH] [MNG-6401] IT for proxy port interpolation (#275) --- ...enITmng6401ProxyPortInterpolationTest.java | 60 +++++++++++++++++++ .../apache/maven/it/TestSuiteOrdering.java | 1 + .../mng-6401-proxy-port-interpolation/pom.xml | 57 ++++++++++++++++++ .../settings.xml | 33 ++++++++++ 4 files changed, 151 insertions(+) create mode 100644 its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6401ProxyPortInterpolationTest.java create mode 100644 its/core-it-suite/src/test/resources/mng-6401-proxy-port-interpolation/pom.xml create mode 100644 its/core-it-suite/src/test/resources/mng-6401-proxy-port-interpolation/settings.xml diff --git a/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6401ProxyPortInterpolationTest.java b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6401ProxyPortInterpolationTest.java new file mode 100644 index 0000000000..42c2cc6396 --- /dev/null +++ b/its/core-it-suite/src/test/java/org/apache/maven/it/MavenITmng6401ProxyPortInterpolationTest.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.maven.it; + +import java.io.File; +import java.util.Properties; + +import org.apache.maven.settings.Proxy; +import org.apache.maven.shared.verifier.Verifier; +import org.apache.maven.shared.verifier.util.ResourceExtractor; +import org.junit.jupiter.api.Test; + +class MavenITmng6401ProxyPortInterpolationTest extends AbstractMavenIntegrationTestCase { + + private Proxy proxy; + + private int port; + + protected MavenITmng6401ProxyPortInterpolationTest() { + super("(4.0.0-alpha-7,)"); + } + + @Test + public void testitEnvVars() throws Exception { + File testDir = ResourceExtractor.simpleExtractResources(getClass(), "/mng-6401-proxy-port-interpolation"); + + Verifier verifier = newVerifier(testDir.getAbsolutePath()); + verifier.setAutoclean(false); + verifier.deleteDirectory("target"); + verifier.addCliArgument("--settings"); + verifier.addCliArgument("settings.xml"); + verifier.setEnvironmentVariable("MAVEN_PROXY_ACTIVE_BOOLEAN", "true"); + verifier.setEnvironmentVariable("MAVEN_PROXY_HOST_STRING", "myproxy.host.net"); + verifier.setEnvironmentVariable("MAVEN_PROXY_PORT_INT", "18080"); + verifier.addCliArgument("validate"); + verifier.execute(); + verifier.verifyErrorFreeLog(); + + Properties props = verifier.loadProperties("target/settings.properties"); + assertEquals("true", props.getProperty("settings.proxies.0.active")); + assertEquals("myproxy.host.net", props.getProperty("settings.proxies.0.host")); + assertEquals("18080", props.getProperty("settings.proxies.0.port")); + } +} diff --git a/its/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java b/its/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java index 50a6929367..2b8c5e9360 100644 --- a/its/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java +++ b/its/core-it-suite/src/test/java/org/apache/maven/it/TestSuiteOrdering.java @@ -120,6 +120,7 @@ public class TestSuiteOrdering implements ClassOrderer { * the tests are to finishing. Newer tests are also more likely to fail, so this is * a fail fast technique as well. */ + suite.addTestSuite(MavenITmng6401ProxyPortInterpolationTest.class); suite.addTestSuite(MavenITmng7228LeakyModelTest.class); suite.addTestSuite(MavenITmng7819FileLockingWithSnapshotsTest.class); suite.addTestSuite(MavenITmng5600DependencyManagementImportExclusionsTest.class); diff --git a/its/core-it-suite/src/test/resources/mng-6401-proxy-port-interpolation/pom.xml b/its/core-it-suite/src/test/resources/mng-6401-proxy-port-interpolation/pom.xml new file mode 100644 index 0000000000..1e899332ca --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-6401-proxy-port-interpolation/pom.xml @@ -0,0 +1,57 @@ + + + + 4.0.0 + + org.apache.maven.its.mng6401 + test + 0.1 + pom + + Maven Integration Test :: MNG-6401 + Verify that the proxy/port in settings.xml can be interpolated using environment variables and system properties. + + + + + org.apache.maven.its.plugins + maven-it-plugin-expression + 2.1-SNAPSHOT + + + test + + eval + + validate + + + settings/proxies/0/active + settings/proxies/0/host + settings/proxies/0/port + + target/settings.properties + + + + + + + diff --git a/its/core-it-suite/src/test/resources/mng-6401-proxy-port-interpolation/settings.xml b/its/core-it-suite/src/test/resources/mng-6401-proxy-port-interpolation/settings.xml new file mode 100644 index 0000000000..2b2d66640b --- /dev/null +++ b/its/core-it-suite/src/test/resources/mng-6401-proxy-port-interpolation/settings.xml @@ -0,0 +1,33 @@ + + + + + + + + my_proxy + ${env.MAVEN_PROXY_ACTIVE_BOOLEAN} + http + ${env.MAVEN_PROXY_HOST_STRING} + ${env.MAVEN_PROXY_PORT_INT} + local.net|some.host.com + + +