@Test
public void testRewritePlan() throws Exception {

    final File testOutDir = new File(testOutBaseDir, "testRewritePlan");
    FileUtils.deleteDirectory(testOutDir);
    testOutDir.mkdirs();
    final File copyTarget = new File(testOutDir, "copied");
    copyTarget.mkdirs();
    final String expectFilename = "sample-plan.json";
    final URL samplePlanUrl = new File(srcDir, expectFilename).toURI().toURL();
    final Result<OakpalPlan> simplePlanResult = OakpalPlan.fromJson(samplePlanUrl);
    assertTrue("plan is successful", simplePlanResult.isSuccess());
    final OakpalPlan simplePlan = simplePlanResult.getOrDefault(null);
    final String preInstallFilename = "tmp_foo_bar.zip";
    final File preInstallPackage = TestPackageUtil.prepareTestPackage(preInstallFilename);
    final URL preInstallUrl = new URL("oakpaltest:/target/test-packages/" + preInstallPackage.getName());
    final URL repoInitUrl1 = new URL("oakpaltest:/target/test-classes/OpearPackageMojoTest/repoinit1.txt");
    final URL repoInitUrl2 = new URL("oakpaltest:/target/test-classes/OpearPackageMojoTest/repoinit2.txt");
    final String rewrittenName = "my-plan.json";
    final String rewrittenPreInstallName = "my_preinstall.zip";
    final String rewrittenRepoInitName1 = "repoinit1.txt";
    final String rewrittenRepoInitName2 = "repoinit2.txt";
    final List<String> rewrittenRepoInitNames = Arrays.asList(rewrittenRepoInitName1, rewrittenRepoInitName2);
    final Map<URL, String> rewrites = new HashMap<>();
    rewrites.put(preInstallUrl, rewrittenPreInstallName);
    rewrites.put(repoInitUrl1, rewrittenRepoInitName1);
    rewrites.put(repoInitUrl2, rewrittenRepoInitName2);
    OakpalPlan rewritten = OpearPackageMojo.rewritePlan(copyTarget, rewrites, simplePlan, rewrittenName);
    assertEquals("expect new preinstall url",
            new File(copyTarget, rewrittenPreInstallName).getAbsoluteFile().toURI().toURL(),
            rewritten.getPreInstallUrls().get(0));
    assertEquals("expect relativized preinstall url", rewrittenPreInstallName,
            rewritten.toJson().getJsonArray("preInstallUrls").getString(0));
    assertEquals("expect new repoInitUrl1",
            new File(copyTarget, rewrittenRepoInitName1).getAbsoluteFile().toURI().toURL(),
            rewritten.getRepoInitUrls().get(0));
    assertEquals("expect new repoInitUrl2",
            new File(copyTarget, rewrittenRepoInitName2).getAbsoluteFile().toURI().toURL(),
            rewritten.getRepoInitUrls().get(1));
    assertEquals("expect relativized repoInitUrls", rewrittenRepoInitNames,
            JavaxJson.unwrapArray(rewritten.toJson().getJsonArray("repoInitUrls")));
}