1 package org.apache.maven.shared.io.location;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.io.IOException;
24
25 import junit.framework.TestCase;
26
27 import org.apache.maven.artifact.Artifact;
28 import org.apache.maven.artifact.DefaultArtifact;
29 import org.apache.maven.artifact.handler.DefaultArtifactHandler;
30 import org.apache.maven.artifact.versioning.VersionRange;
31 import org.apache.maven.shared.io.TestUtils;
32
33 public class ArtifactLocationTest
34 extends TestCase
35 {
36
37 public void testShouldConstructFromTempFileSpecification()
38 throws IOException
39 {
40 File f = File.createTempFile( "artifact-location.", ".test" );
41 f.deleteOnExit();
42
43 Artifact a = new DefaultArtifact( "group", "artifact", VersionRange.createFromVersion( "1" ), null, "jar",
44 null, new DefaultArtifactHandler() );
45
46 a.setFile( f );
47
48 ArtifactLocation location = new ArtifactLocation( a, f.getAbsolutePath() );
49
50 assertSame( f, location.getFile() );
51 }
52
53 public void testShouldRead()
54 throws IOException
55 {
56 File f = File.createTempFile( "url-location.", ".test" );
57 f.deleteOnExit();
58
59 String testStr = "This is a test";
60
61 TestUtils.writeFileWithEncoding( f, testStr, "US-ASCII" );
62
63 Artifact a = new DefaultArtifact( "group", "artifact", VersionRange.createFromVersion( "1" ), null, "jar",
64 null, new DefaultArtifactHandler() );
65
66 a.setFile( f );
67
68 ArtifactLocation location = new ArtifactLocation( a, f.getAbsolutePath() );
69
70 location.open();
71
72 byte[] buffer = new byte[testStr.length()];
73
74 int read = location.read( buffer );
75
76 assertEquals( testStr.length(), read );
77
78 assertEquals( testStr, new String( buffer, "US-ASCII" ) );
79 }
80
81 }