Search in sources :

Example 6 with MockMessageLogger

use of org.apache.ivy.util.MockMessageLogger in project ant-ivy by apache.

the class ResolveTest method testExtraAttributes3.

/**
 * Test case for IVY-745.
 *
 * @throws Exception if something goes wrong
 * @see <a href="https://issues.apache.org/jira/browse/IVY-745">IVY-745</a>
 */
@Test
public void testExtraAttributes3() throws Exception {
    MockMessageLogger mockLogger = new MockMessageLogger();
    Ivy ivy = new Ivy();
    ivy.getLoggerEngine().setDefaultLogger(mockLogger);
    ivy.configure(new File("test/repositories/extra-attributes/ivysettings.xml"));
    ivy.getSettings().setDefaultCache(cache);
    ivy.getSettings().validate();
    ResolveReport report = ivy.resolve(ResolveTest.class.getResource("ivy-extra-att3.xml"), getResolveOptions(ivy.getSettings(), new String[] { "*" }).setValidate(false));
    assertTrue(report.hasError());
    // should report error about missing extra attribute in dependency module descriptor
    mockLogger.assertLogContains("expected='task2' found='null'");
}
Also used : ConfigurationResolveReport(org.apache.ivy.core.report.ConfigurationResolveReport) ResolveReport(org.apache.ivy.core.report.ResolveReport) MockMessageLogger(org.apache.ivy.util.MockMessageLogger) Ivy(org.apache.ivy.Ivy) JarFile(java.util.jar.JarFile) File(java.io.File) Test(org.junit.Test)

Example 7 with MockMessageLogger

use of org.apache.ivy.util.MockMessageLogger in project ant-ivy by apache.

the class RetrieveTest method testRetrieveDifferentArtifactsOfSameModuleToSameFile.

@Test(expected = RuntimeException.class)
public void testRetrieveDifferentArtifactsOfSameModuleToSameFile() throws Exception {
    ResolveReport report = ivy.resolve(new File("test/repositories/1/org2/mod2.2/ivys/ivy-0.5.xml").toURI().toURL(), getResolveOptions(new String[] { "*" }));
    assertNotNull(report);
    ModuleDescriptor md = report.getModuleDescriptor();
    assertNotNull(md);
    String pattern = "build/test/retrieve/[module]/[module].[ext]";
    MockMessageLogger mockLogger = new MockMessageLogger();
    Message.setDefaultLogger(mockLogger);
    try {
        ivy.retrieve(md.getModuleRevisionId(), getRetrieveOptions().setDestArtifactPattern(pattern));
    } finally {
        mockLogger.assertLogDoesntContain("multiple artifacts");
    }
}
Also used : ModuleDescriptor(org.apache.ivy.core.module.descriptor.ModuleDescriptor) ResolveReport(org.apache.ivy.core.report.ResolveReport) MockMessageLogger(org.apache.ivy.util.MockMessageLogger) File(java.io.File) Test(org.junit.Test)

Example 8 with MockMessageLogger

use of org.apache.ivy.util.MockMessageLogger in project ant-ivy by apache.

the class IgnoreCircularDependencyStrategyTest method setUp.

@Before
public void setUp() {
    strategy = IgnoreCircularDependencyStrategy.getInstance();
    mockMessageImpl = new MockMessageLogger();
    messageLoggerEngine = setupMockLogger(mockMessageImpl);
}
Also used : MockMessageLogger(org.apache.ivy.util.MockMessageLogger) Before(org.junit.Before)

Example 9 with MockMessageLogger

use of org.apache.ivy.util.MockMessageLogger in project ant-ivy by apache.

the class IvyTest method testMultipleInstances.

@Test
public void testMultipleInstances() throws Exception {
    // this test checks that IvyContext is properly set and unset when using multiple instances
    // of Ivy. We also check logging, because it heavily relies on IvyContext.
    // we start by loading one ivy instance and using it to resolve some dependencies
    MockMessageLogger mockLogger = new MockMessageLogger();
    Ivy ivy = Ivy.newInstance();
    ivy.getLoggerEngine().setDefaultLogger(mockLogger);
    ivy.configure(new File("test/repositories/ivysettings.xml"));
    assertNotSame("IvyContext should be cleared and return a default Ivy instance", IvyContext.getContext().getIvy(), ivy);
    ResolveReport report = ivy.resolve(new File("test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml"), getResolveOptions(ivy, new String[] { "*" }));
    assertNotNull(report);
    assertFalse(report.hasError());
    mockLogger.assertLogContains("mod1.1");
    assertNotSame("IvyContext should be cleared and return a default Ivy instance", IvyContext.getContext().getIvy(), ivy);
    // then we load another instance, and use it for another resolution
    MockMessageLogger mockLogger2 = new MockMessageLogger();
    Ivy ivy2 = new Ivy();
    ivy2.getLoggerEngine().setDefaultLogger(mockLogger2);
    ivy2.configure(new File("test/repositories/norev/ivysettings.xml").toURI().toURL());
    report = ivy2.resolve(new File("test/repositories/norev/ivy.xml"), getResolveOptions(ivy2, new String[] { "*" }));
    assertNotNull(report);
    assertFalse(report.hasError());
    mockLogger2.assertLogContains("norev/ivysettings.xml");
    assertNotSame("IvyContext should be cleared and return a default Ivy instance", IvyContext.getContext().getIvy(), ivy2);
    // finally we reuse the first instance to make another resolution
    report = ivy.resolve(new File("test/repositories/1/org6/mod6.1/ivys/ivy-0.3.xml"), getResolveOptions(ivy, new String[] { "extension" }));
    assertNotNull(report);
    assertFalse(report.hasError());
    mockLogger.assertLogContains("mod6.1");
    assertNotSame("IvyContext should be cleared and return a default Ivy instance", IvyContext.getContext().getIvy(), ivy);
}
Also used : ResolveReport(org.apache.ivy.core.report.ResolveReport) MockMessageLogger(org.apache.ivy.util.MockMessageLogger) File(java.io.File) Test(org.junit.Test)

Example 10 with MockMessageLogger

use of org.apache.ivy.util.MockMessageLogger in project ant-ivy by apache.

the class LogTriggerTest method testMessage.

@Test
public void testMessage() {
    trigger.setMessage("msg: ${organisation} ${module} ${revision}");
    MockMessageLogger mockLogger = new MockMessageLogger();
    Message.setDefaultLogger(mockLogger);
    trigger.progress(ev);
    mockLogger.assertLogInfoContains("msg: o A 1");
}
Also used : MockMessageLogger(org.apache.ivy.util.MockMessageLogger) Test(org.junit.Test)

Aggregations

MockMessageLogger (org.apache.ivy.util.MockMessageLogger)10 Test (org.junit.Test)8 File (java.io.File)4 ResolveReport (org.apache.ivy.core.report.ResolveReport)4 DefaultDependencyDescriptor (org.apache.ivy.core.module.descriptor.DefaultDependencyDescriptor)2 ModuleDescriptor (org.apache.ivy.core.module.descriptor.ModuleDescriptor)2 ModuleRevisionId (org.apache.ivy.core.module.id.ModuleRevisionId)2 ResolvedModuleRevision (org.apache.ivy.core.resolve.ResolvedModuleRevision)2 Before (org.junit.Before)2 Date (java.util.Date)1 JarFile (java.util.jar.JarFile)1 Ivy (org.apache.ivy.Ivy)1 DefaultArtifact (org.apache.ivy.core.module.descriptor.DefaultArtifact)1 ConfigurationResolveReport (org.apache.ivy.core.report.ConfigurationResolveReport)1 DownloadReport (org.apache.ivy.core.report.DownloadReport)1 DownloadOptions (org.apache.ivy.core.resolve.DownloadOptions)1