コード例 #1
0
  @Test
  public void testResolveAndRethrowFailureWithNoMissingDependenciesShouldDoNothing()
      throws IOException, ParseException {
    ModuleDescriptor moduleDescriptor = createAnonymousModuleDescriptor();
    prepareTestsThatRetrieveDependencies(moduleDescriptor);
    prepareResolveReport();
    ResolvedConfiguration configuration = ivyDependencyResolver.resolve(configurationStub);

    assertFalse(configuration.hasError());
    configuration.rethrowFailure();
  }
コード例 #2
0
  @Test
  public void testResolveAndRethrowFailureWithMissingDependenciesShouldThrowResolveException()
      throws IOException, ParseException {
    ModuleDescriptor moduleDescriptor = createAnonymousModuleDescriptor();
    prepareTestsThatRetrieveDependencies(moduleDescriptor);
    Exception failure = new Exception("broken");
    prepareResolveReportWithError(failure);
    ResolvedConfiguration configuration = ivyDependencyResolver.resolve(configurationStub);

    assertTrue(configuration.hasError());
    try {
      configuration.rethrowFailure();
      fail();
    } catch (ResolveException e) {
      assertThat(
          e.getMessage(), startsWith("Could not resolve all dependencies for <configuration>"));
      assertThat(e.getCause(), sameInstance((Throwable) failure));
    }
  }
コード例 #3
0
 @Test
 public void testResolveAndGetFilesWithMissingDependenciesShouldThrowResolveException()
     throws IOException, ParseException {
   ModuleDescriptor moduleDescriptor = createAnonymousModuleDescriptor();
   prepareTestsThatRetrieveDependencies(moduleDescriptor);
   Exception failure = new Exception("broken");
   prepareResolveReportWithError(failure);
   ResolvedConfiguration configuration = ivyDependencyResolver.resolve(configurationStub);
   context.checking(
       new Expectations() {
         {
           allowing(configurationStub).getAllDependencies();
         }
       });
   try {
     configuration.getFiles(Specs.SATISFIES_ALL);
     fail();
   } catch (ResolveException e) {
     assertThat(
         e.getMessage(), startsWith("Could not resolve all dependencies for <configuration>"));
     assertThat(e.getCause(), sameInstance((Throwable) failure));
   }
 }
コード例 #4
0
  @Test
  public void testResolveAndGetFilesWithDependencySubset() throws IOException, ParseException {
    prepareResolveReport();
    final ModuleDependency moduleDependencyDummy1 = context.mock(ModuleDependency.class, "dep1");
    final ModuleDependency moduleDependencyDummy2 = context.mock(ModuleDependency.class, "dep2");
    final SelfResolvingDependency selfResolvingDependencyDummy =
        context.mock(SelfResolvingDependency.class);
    final ResolvedDependency root = context.mock(ResolvedDependency.class, "root");
    final ResolvedDependency resolvedDependency1 =
        context.mock(ResolvedDependency.class, "resolved1");
    final ResolvedDependency resolvedDependency2 =
        context.mock(ResolvedDependency.class, "resolved2");
    ResolvedDependency resolvedDependency3 = context.mock(ResolvedDependency.class, "resolved3");
    final DependencySet dependencies = context.mock(DependencySet.class);
    final Map<Dependency, Set<ResolvedDependency>> firstLevelResolvedDependencies =
        new LinkedHashMap<Dependency, Set<ResolvedDependency>>();
    firstLevelResolvedDependencies.put(
        moduleDependencyDummy1, toSet(resolvedDependency1, resolvedDependency2));
    firstLevelResolvedDependencies.put(moduleDependencyDummy2, toSet(resolvedDependency3));

    context.checking(
        new Expectations() {
          {
            allowing(resolvedDependency1).getParentArtifacts(root);
            will(
                returnValue(
                    toSet(
                        createResolvedArtifact(
                            context,
                            "dep1parent",
                            "someType",
                            "someExtension",
                            new File("dep1parent")))));
            allowing(resolvedDependency1).getChildren();
            will(returnValue(emptySet()));
            allowing(resolvedDependency2).getParentArtifacts(root);
            will(
                returnValue(
                    toSet(
                        createResolvedArtifact(
                            context,
                            "dep2parent",
                            "someType",
                            "someExtension",
                            new File("dep2parent")))));
            allowing(resolvedDependency2).getChildren();
            will(returnValue(emptySet()));
            allowing(configurationStub).getAllDependencies();
            will(returnValue(dependencies));
            allowing(dependencies).withType(ModuleDependency.class);
            will(
                returnValue(
                    toDomainObjectSet(
                        ModuleDependency.class, moduleDependencyDummy1, moduleDependencyDummy2)));
            allowing(conversionResultStub).getFirstLevelResolvedDependencies();
            will(returnValue(firstLevelResolvedDependencies));
            allowing(conversionResultStub).getRoot();
            will(returnValue(root));
          }
        });

    ModuleDescriptor moduleDescriptor = createAnonymousModuleDescriptor();
    prepareTestsThatRetrieveDependencies(moduleDescriptor);

    ResolvedConfiguration resolvedConfig = ivyDependencyResolver.resolve(configurationStub);
    Set<File> actualFiles =
        resolvedConfig.getFiles(
            new Spec<Dependency>() {
              public boolean isSatisfiedBy(Dependency element) {
                return element == moduleDependencyDummy1 || element == selfResolvingDependencyDummy;
              }
            });
    assertThat(actualFiles, equalTo(toSet(new File("dep1parent"), new File("dep2parent"))));

    Set<ResolvedDependency> actualDeps =
        resolvedConfig.getFirstLevelModuleDependencies(
            new Spec<Dependency>() {
              public boolean isSatisfiedBy(Dependency element) {
                return element == moduleDependencyDummy1;
              }
            });
    assertThat(actualDeps, equalTo(toSet(resolvedDependency1, resolvedDependency2)));
  }