KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > jayasoft > ivy > report > XmlReportOutputterTest


1 /*
2  * This file is subject to the licence found in LICENCE.TXT in the root directory of the project.
3  * Copyright Jayasoft 2005 - All rights reserved
4  *
5  * #SNAPSHOT#
6  */

7 package fr.jayasoft.ivy.report;
8
9 import java.io.ByteArrayOutputStream JavaDoc;
10 import java.io.File JavaDoc;
11
12 import junit.framework.TestCase;
13
14 import org.apache.tools.ant.Project;
15 import org.apache.tools.ant.taskdefs.Delete;
16
17 import fr.jayasoft.ivy.Ivy;
18
19 public class XmlReportOutputterTest extends TestCase {
20     private final Ivy _ivy;
21     private File JavaDoc _cache;
22
23     public XmlReportOutputterTest() throws Exception JavaDoc {
24         _ivy = new Ivy();
25         _ivy.configure(new File JavaDoc("test/repositories/ivyconf.xml"));
26     }
27
28     protected void setUp() throws Exception JavaDoc {
29         createCache();
30     }
31
32     private void createCache() {
33         _cache = new File JavaDoc("build/cache");
34         _cache.mkdirs();
35     }
36     
37     protected void tearDown() throws Exception JavaDoc {
38         cleanCache();
39     }
40
41     private void cleanCache() {
42         Delete del = new Delete();
43         del.setProject(new Project());
44         del.setDir(_cache);
45         del.execute();
46     }
47     
48     public void testWriteOrigin() throws Exception JavaDoc {
49         ResolveReport report = _ivy.resolve(new File JavaDoc("test/repositories/1/org1/mod1.1/ivys/ivy-1.0.xml").toURL(),
50                 null, new String JavaDoc[] {"default"}, _cache, null, true);
51         assertNotNull(report);
52         
53         ByteArrayOutputStream JavaDoc buffer = new ByteArrayOutputStream JavaDoc();
54         XmlReportOutputter outputter = new XmlReportOutputter();
55         outputter.output(report.getConfigurationReport("default"), buffer);
56         buffer.flush();
57         String JavaDoc xml = buffer.toString();
58         
59         String JavaDoc expectedLocation = "location=\"" + new File JavaDoc("test/repositories/1/org1/mod1.2/jars/mod1.2-2.0.jar").getAbsolutePath() + "\"";
60         String JavaDoc expectedIsLocal = "is-local=\"true\"";
61
62         assertTrue("XML doesn't contain artifact location attribute", xml.indexOf(expectedLocation) != -1);
63         assertTrue("XML doesn't contain artifact is-local attribute", xml.indexOf(expectedIsLocal) != -1);
64     }
65 }
66
Popular Tags