Skip to content

Commit

Permalink
[MNG-6401] IT for proxy port interpolation
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Jul 3, 2023
1 parent e7f977b commit 9785249
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public TestSuiteOrdering() {
* 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);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project>
<modelVersion>4.0.0</modelVersion>

<groupId>org.apache.maven.its.mng6401</groupId>
<artifactId>test</artifactId>
<version>0.1</version>
<packaging>pom</packaging>

<name>Maven Integration Test :: MNG-6401</name>
<description>Verify that the proxy/port in settings.xml can be interpolated using environment variables and system properties.</description>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.its.plugins</groupId>
<artifactId>maven-it-plugin-expression</artifactId>
<version>2.1-SNAPSHOT</version>
<executions>
<execution>
<id>test</id>
<goals>
<goal>eval</goal>
</goals>
<phase>validate</phase>
<configuration>
<expressions>
<expression>settings/proxies/0/active</expression>
<expression>settings/proxies/0/host</expression>
<expression>settings/proxies/0/port</expression>
</expressions>
<outputFile>target/settings.properties</outputFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
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.
-->

<settings>
<proxies>
<proxy>
<id>my_proxy</id>
<active>${env.MAVEN_PROXY_ACTIVE_BOOLEAN}</active>
<protocol>http</protocol>
<host>${env.MAVEN_PROXY_HOST_STRING}</host>
<port>${env.MAVEN_PROXY_PORT_INT}</port>
<nonProxyHosts>local.net|some.host.com</nonProxyHosts>
</proxy>
</proxies>
</settings>

0 comments on commit 9785249

Please sign in to comment.