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