|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | +package org.apache.maven.it; |
| 20 | + |
| 21 | +import java.io.IOException; |
| 22 | +import java.nio.file.Files; |
| 23 | +import java.nio.file.Path; |
| 24 | +import java.nio.file.Paths; |
| 25 | + |
| 26 | +import org.junit.jupiter.api.Test; |
| 27 | +import org.junit.jupiter.api.io.TempDir; |
| 28 | + |
| 29 | +import static org.junit.jupiter.api.Assertions.*; |
| 30 | + |
| 31 | +/** |
| 32 | + * Test to verify that the NIO2 migration of integration test infrastructure works correctly. |
| 33 | + * This simulates the patterns used in actual integration tests. |
| 34 | + */ |
| 35 | +public class NIO2MigrationVerificationTest extends AbstractMavenIntegrationTestCase { |
| 36 | + |
| 37 | + @TempDir |
| 38 | + Path tempDir; |
| 39 | + |
| 40 | + @Test |
| 41 | + void testExtractResourcesAsPathPattern() throws IOException { |
| 42 | + // Simulate the pattern: Path testDir = extractResourcesAsPath("/some-test") |
| 43 | + Path testDir = extractResourcesAsPath("test-resource"); |
| 44 | + |
| 45 | + assertNotNull(testDir); |
| 46 | + assertTrue(testDir.isAbsolute()); |
| 47 | + assertTrue(testDir.toString().endsWith("test-resource")); |
| 48 | + } |
| 49 | + |
| 50 | + @Test |
| 51 | + void testPathResolvePattern() throws IOException { |
| 52 | + // Simulate the pattern: Path subDir = testDir.resolve("subdir") |
| 53 | + Path testDir = extractResourcesAsPath("test-resource"); |
| 54 | + Path subDir = testDir.resolve("subdir"); |
| 55 | + Path fileInSubDir = testDir.resolve("subdir/file.txt"); |
| 56 | + |
| 57 | + assertNotNull(subDir); |
| 58 | + assertNotNull(fileInSubDir); |
| 59 | + assertTrue(subDir.toString().endsWith("subdir")); |
| 60 | + assertTrue(fileInSubDir.toString().endsWith("file.txt")); |
| 61 | + } |
| 62 | + |
| 63 | + @Test |
| 64 | + void testPathToStringPattern() throws IOException { |
| 65 | + // Simulate the pattern: newVerifier(testDir.toString()) |
| 66 | + Path testDir = extractResourcesAsPath("test-resource"); |
| 67 | + String testDirString = testDir.toString(); |
| 68 | + |
| 69 | + assertNotNull(testDirString); |
| 70 | + assertTrue(testDirString.endsWith("test-resource")); |
| 71 | + |
| 72 | + // This would be used like: newVerifier(testDirString) |
| 73 | + // We can't actually create a verifier without Maven distribution, |
| 74 | + // but we can verify the string is correct |
| 75 | + assertTrue(Paths.get(testDirString).isAbsolute()); |
| 76 | + } |
| 77 | + |
| 78 | + @Test |
| 79 | + void testBackwardCompatibilityWithFileAPI() throws IOException { |
| 80 | + // Verify that the old File-based method still works |
| 81 | + java.io.File testDir = extractResources("test-resource"); |
| 82 | + |
| 83 | + assertNotNull(testDir); |
| 84 | + assertTrue(testDir.isAbsolute()); |
| 85 | + assertTrue(testDir.getPath().endsWith("test-resource")); |
| 86 | + |
| 87 | + // Verify both methods return equivalent paths |
| 88 | + Path pathResult = extractResourcesAsPath("test-resource"); |
| 89 | + assertEquals(pathResult.toFile(), testDir); |
| 90 | + } |
| 91 | + |
| 92 | + @Test |
| 93 | + void testNewVerifierWithPathString() throws IOException { |
| 94 | + // Test the common pattern of creating a verifier with Path.toString() |
| 95 | + Path testDir = extractResourcesAsPath("test-resource"); |
| 96 | + |
| 97 | + // This simulates: Verifier verifier = newVerifier(testDir.toString()); |
| 98 | + String basedir = testDir.toString(); |
| 99 | + assertNotNull(basedir); |
| 100 | + assertTrue(Paths.get(basedir).isAbsolute()); |
| 101 | + |
| 102 | + // We can't actually create a verifier without the Maven distribution, |
| 103 | + // but we can verify the path string is valid |
| 104 | + Path reconstructed = Paths.get(basedir); |
| 105 | + assertEquals(testDir, reconstructed); |
| 106 | + } |
| 107 | + |
| 108 | + @Test |
| 109 | + void testComplexPathOperations() throws IOException { |
| 110 | + // Test more complex path operations that might be used in integration tests |
| 111 | + Path testDir = extractResourcesAsPath("test-resource"); |
| 112 | + Path projectDir = testDir.resolve("project"); |
| 113 | + Path pomFile = projectDir.resolve("pom.xml"); |
| 114 | + Path targetDir = projectDir.resolve("target"); |
| 115 | + Path classesDir = targetDir.resolve("classes"); |
| 116 | + |
| 117 | + // Verify all paths are constructed correctly |
| 118 | + assertTrue(projectDir.toString().contains("project")); |
| 119 | + assertTrue(pomFile.toString().endsWith("pom.xml")); |
| 120 | + assertTrue(targetDir.toString().contains("target")); |
| 121 | + assertTrue(classesDir.toString().contains("classes")); |
| 122 | + |
| 123 | + // Verify parent-child relationships |
| 124 | + assertEquals(testDir, projectDir.getParent()); |
| 125 | + assertEquals(projectDir, pomFile.getParent()); |
| 126 | + assertEquals(projectDir, targetDir.getParent()); |
| 127 | + assertEquals(targetDir, classesDir.getParent()); |
| 128 | + } |
| 129 | +} |
0 commit comments