1 package org.eclipse.aether.spi.connector.layout;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.net.URI;
23
24 import org.eclipse.aether.spi.connector.checksum.ChecksumAlgorithm;
25 import org.eclipse.aether.spi.connector.checksum.ChecksumAlgorithmFactory;
26 import org.eclipse.aether.spi.connector.checksum.ChecksumAlgorithmFactorySupport;
27 import org.junit.Test;
28
29 import org.eclipse.aether.spi.connector.layout.RepositoryLayout.ChecksumLocation;
30
31 import static org.junit.Assert.assertEquals;
32
33 public class ChecksumLocationTest
34 {
35 private ChecksumAlgorithmFactory SHA512 = new ChecksumAlgorithmFactorySupport("SHA-512", "sha512") {
36 @Override
37 public ChecksumAlgorithm getAlgorithm() {
38 throw new RuntimeException("this should not happen");
39 }
40 };
41
42 private ChecksumAlgorithmFactory SHA256 = new ChecksumAlgorithmFactorySupport("SHA-256", "sha256") {
43 @Override
44 public ChecksumAlgorithm getAlgorithm() {
45 throw new RuntimeException("this should not happen");
46 }
47 };
48
49 private ChecksumAlgorithmFactory SHA1 = new ChecksumAlgorithmFactorySupport("SHA-1", "sha1") {
50 @Override
51 public ChecksumAlgorithm getAlgorithm() {
52 throw new RuntimeException("this should not happen");
53 }
54 };
55
56 private ChecksumAlgorithmFactory MD5 = new ChecksumAlgorithmFactorySupport("MD5", "md5") {
57 @Override
58 public ChecksumAlgorithm getAlgorithm() {
59 throw new RuntimeException("this should not happen");
60 }
61 };
62
63 @Test
64 public void testForLocation()
65 {
66 ChecksumLocation cs = ChecksumLocation.forLocation( URI.create( "dir/sub%20dir/file.txt" ), SHA512 );
67 assertEquals( SHA512, cs.getChecksumAlgorithmFactory() );
68 assertEquals( "dir/sub%20dir/file.txt.sha512", cs.getLocation().toString() );
69
70 cs = ChecksumLocation.forLocation( URI.create( "dir/sub%20dir/file.txt" ), SHA256 );
71 assertEquals( SHA256, cs.getChecksumAlgorithmFactory() );
72 assertEquals( "dir/sub%20dir/file.txt.sha256", cs.getLocation().toString() );
73
74 cs = ChecksumLocation.forLocation( URI.create( "dir/sub%20dir/file.txt" ), SHA1 );
75 assertEquals( SHA1, cs.getChecksumAlgorithmFactory() );
76 assertEquals( "dir/sub%20dir/file.txt.sha1", cs.getLocation().toString() );
77
78 cs = ChecksumLocation.forLocation( URI.create( "dir/sub%20dir/file.txt" ), MD5 );
79 assertEquals( MD5, cs.getChecksumAlgorithmFactory() );
80 assertEquals( "dir/sub%20dir/file.txt.md5", cs.getLocation().toString() );
81 }
82
83 @Test( expected = IllegalArgumentException.class )
84 public void testForLocation_WithQueryParams()
85 {
86 ChecksumLocation.forLocation( URI.create( "file.php?param=1" ), SHA1 );
87 }
88
89 @Test( expected = IllegalArgumentException.class )
90 public void testForLocation_WithFragment()
91 {
92 ChecksumLocation.forLocation( URI.create( "file.html#fragment" ), SHA1 );
93 }
94
95 }