示例#1
0
  protected void connectWagon(Wagon wagon) throws ConnectionException, AuthenticationException {
    wagon.addTransferListener(checksumObserver);

    wagon.addTransferListener(mockTransferListener);

    wagon.connect(testRepository, getAuthInfo());
  }
示例#2
0
  public void testFailedGetIfNewer() throws Exception {
    if (supportsGetIfNewer()) {
      setupRepositories();
      setupWagonTestingFixtures();
      message("Getting test artifact from test repository " + testRepository);
      Wagon wagon = getWagon();
      wagon.addTransferListener(checksumObserver);
      wagon.connect(testRepository, getAuthInfo());
      destFile = FileTestUtils.createUniqueFile(getName(), getName());
      destFile.deleteOnExit();
      try {
        wagon.getIfNewer("fubar.txt", destFile, 0);
        fail("File was found when it shouldn't have been");
      } catch (ResourceDoesNotExistException e) {
        // expected
        assertTrue(true);
      } finally {
        wagon.removeTransferListener(checksumObserver);

        wagon.disconnect();

        tearDownWagonTestingFixtures();
      }
    }
  }
示例#3
0
  /**
   * Test {@link Wagon#getFileList(String)}.
   *
   * @throws Exception
   * @since 1.0-beta-2
   */
  public void testWagonGetFileList() throws Exception {
    setupRepositories();

    setupWagonTestingFixtures();

    String dirName = "file-list";

    String filenames[] =
        new String[] {
          "test-resource.txt",
          "test-resource.pom",
          "test-resource b.txt",
          "more-resources.dat",
          ".index.txt"
        };

    for (String filename : filenames) {
      putFile(dirName + "/" + filename, dirName + "/" + filename, filename + "\n");
    }

    Wagon wagon = getWagon();

    wagon.connect(testRepository, getAuthInfo());

    List<String> list = wagon.getFileList(dirName);
    assertNotNull("file list should not be null.", list);
    assertTrue(
        "file list should contain more items (actually contains '" + list + "').",
        list.size() >= filenames.length);

    for (String filename : filenames) {
      assertTrue("Filename '" + filename + "' should be in list.", list.contains(filename));
    }

    // WAGON-250
    list = wagon.getFileList("");
    assertNotNull("file list should not be null.", list);
    assertTrue(
        "file list should contain items (actually contains '" + list + "').", !list.isEmpty());
    assertTrue(list.contains("file-list/"));
    assertFalse(list.contains("file-list"));
    assertFalse(list.contains("."));
    assertFalse(list.contains(".."));
    assertFalse(list.contains("./"));
    assertFalse(list.contains("../"));

    wagon.disconnect();

    tearDownWagonTestingFixtures();
  }
示例#4
0
  /**
   * Test for an invalid resource.
   *
   * @throws Exception
   * @since 1.0-beta-2
   */
  public void testWagonResourceNotExists() throws Exception {
    setupRepositories();

    setupWagonTestingFixtures();

    Wagon wagon = getWagon();

    wagon.connect(testRepository, getAuthInfo());

    assertFalse(wagon.resourceExists("a/bad/resource/name/that/should/not/exist.txt"));

    wagon.disconnect();

    tearDownWagonTestingFixtures();
  }
示例#5
0
  /**
   * Test that when putting a directory that already exists new files get also copied
   *
   * @throws Exception
   * @since 1.0-beta-1
   */
  public void testWagonPutDirectoryWhenDirectoryAlreadyExists() throws Exception {

    final String dirName = "directory-copy-existing";

    final String resourceToCreate = "test-resource-1.txt";

    final String[] resources = {
      "a/test-resource-2.txt", "a/b/test-resource-3.txt", "c/test-resource-4.txt"
    };

    setupRepositories();

    setupWagonTestingFixtures();

    Wagon wagon = getWagon();

    if (wagon.supportsDirectoryCopy()) {
      sourceFile = new File(FileTestUtils.getTestOutputDir(), dirName);

      FileUtils.deleteDirectory(sourceFile);

      createDirectory(wagon, resourceToCreate, dirName);

      for (String resource : resources) {
        writeTestFile(resource);
      }

      wagon.connect(testRepository, getAuthInfo());

      wagon.putDirectory(sourceFile, dirName);

      List<String> resourceNames = new ArrayList<String>(resources.length + 1);

      resourceNames.add(dirName + "/" + resourceToCreate);
      for (String resource : resources) {
        resourceNames.add(dirName + "/" + resource);
      }

      assertResourcesAreInRemoteSide(wagon, resourceNames);

      wagon.disconnect();
    }

    tearDownWagonTestingFixtures();
  }
示例#6
0
  /**
   * Test for an existing resource.
   *
   * @throws Exception
   * @since 1.0-beta-2
   */
  public void testWagonResourceExists() throws Exception {
    setupRepositories();

    setupWagonTestingFixtures();

    Wagon wagon = getWagon();

    putFile();

    wagon.connect(testRepository, getAuthInfo());

    assertTrue(
        sourceFile.getName() + " does not exist", wagon.resourceExists(sourceFile.getName()));

    wagon.disconnect();

    tearDownWagonTestingFixtures();
  }
示例#7
0
  /**
   * Test {@link Wagon#getFileList(String)} when the directory does not exist.
   *
   * @throws Exception
   * @since 1.0-beta-2
   */
  public void testWagonGetFileListWhenDirectoryDoesNotExist() throws Exception {
    setupRepositories();

    setupWagonTestingFixtures();

    String dirName = "file-list-unexisting";

    Wagon wagon = getWagon();

    wagon.connect(testRepository, getAuthInfo());

    try {
      wagon.getFileList(dirName);
      fail("getFileList on unexisting directory must throw ResourceDoesNotExistException");
    } catch (ResourceDoesNotExistException e) {
      // expected
    } finally {
      wagon.disconnect();

      tearDownWagonTestingFixtures();
    }
  }
示例#8
0
  /**
   * Test for putting a directory with a destination that multiple directories deep, all of which
   * haven't been created.
   *
   * @throws Exception
   * @since 1.0-beta-2
   */
  public void testWagonPutDirectoryDeepDestination() throws Exception {
    setupRepositories();

    setupWagonTestingFixtures();

    Wagon wagon = getWagon();

    if (wagon.supportsDirectoryCopy()) {
      sourceFile = new File(FileTestUtils.getTestOutputDir(), "deep0/deep1/deep2");

      FileUtils.deleteDirectory(sourceFile);

      writeTestFile("test-resource-1.txt");
      writeTestFile("a/test-resource-2.txt");
      writeTestFile("a/b/test-resource-3.txt");
      writeTestFile("c/test-resource-4.txt");
      writeTestFile("d/e/f/test-resource-5.txt");

      wagon.connect(testRepository, getAuthInfo());

      wagon.putDirectory(sourceFile, "deep0/deep1/deep2");

      destFile = FileTestUtils.createUniqueFile(getName(), getName());

      destFile.deleteOnExit();

      wagon.get("deep0/deep1/deep2/test-resource-1.txt", destFile);
      wagon.get("deep0/deep1/deep2/a/test-resource-2.txt", destFile);
      wagon.get("deep0/deep1/deep2/a/b/test-resource-3.txt", destFile);
      wagon.get("deep0/deep1/deep2/c/test-resource-4.txt", destFile);
      wagon.get("deep0/deep1/deep2/d/e/f/test-resource-5.txt", destFile);

      wagon.disconnect();
    }

    tearDownWagonTestingFixtures();
  }