View Javadoc
1   package io.apicurio.registry.maven;
2   
3   import org.junit.jupiter.api.Test;
4   
5   import static org.junit.jupiter.api.Assertions.assertEquals;
6   import static org.junit.jupiter.api.Assertions.assertFalse;
7   import static org.junit.jupiter.api.Assertions.assertTrue;
8   
9   public class ReferenceUrlUtilTest {
10  
11      @Test
12      void testRegistryReferenceNameRemovesOriginAndPreservesFragment() {
13          String fullReference = "http://localhost:8080/apis/registry/v3/groups/master/artifacts/"
14                  + "kafka-bindings.yml/versions/branch=latest/content#/components/messageTraits/"
15                  + "kafkaKeyString";
16  
17          assertEquals("/apis/registry/v3/groups/master/artifacts/kafka-bindings.yml/versions/"
18                  + "branch=latest/content#/components/messageTraits/kafkaKeyString",
19                  ReferenceUrlUtil.registryReferenceName(fullReference));
20      }
21  
22      @Test
23      void testDecodePathSegmentDecodesEncodedValues() {
24          assertEquals("master group", ReferenceUrlUtil.decodePathSegment("master%20group"));
25          assertEquals("branch=latest", ReferenceUrlUtil.decodePathSegment("branch%3Dlatest"));
26      }
27  
28      @Test
29      void testIsSameApicurioServerNormalizesCaseAndDefaultPort() {
30          assertTrue(ReferenceUrlUtil.isSameApicurioServer(
31                  "http://localhost/apis/registry/v3",
32                  "http://LOCALHOST:80/apis/registry/v3/groups/master/artifacts/test/versions/1"));
33          assertFalse(ReferenceUrlUtil.isSameApicurioServer(
34                  "http://localhost/apis/registry/v3",
35                  "http://otherhost/apis/registry/v3/groups/master/artifacts/test/versions/1"));
36      }
37  
38      @Test
39      void testIsAbsoluteUriRejectsRelativePaths() {
40          assertTrue(ReferenceUrlUtil.isAbsoluteUri("https://example.com/schema.json"));
41          assertFalse(ReferenceUrlUtil.isAbsoluteUri("./avro/shared.avsc"));
42      }
43  }