package io.apicurio.registry.content.refs;

import io.apicurio.registry.asyncapi.content.refs.AsyncApiReferenceFinder;
import io.apicurio.registry.content.TypedContent;
import io.apicurio.registry.json.content.refs.JsonSchemaReferenceFinder;
import io.apicurio.registry.rules.validity.ArtifactUtilProviderTestBase;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.Set;

public class JsonSchemaReferenceFinderTest extends ArtifactUtilProviderTestBase {

    /**
     * Test method for
     * {@link AsyncApiReferenceFinder#findExternalReferences(io.apicurio.registry.content.ContentHandle)}.
     */
    @Test
    public void testFindExternalReferences() {
        TypedContent content = resourceToTypedContentHandle("json-schema-with-refs.json");
        JsonSchemaReferenceFinder finder = new JsonSchemaReferenceFinder();
        Set<ExternalReference> foundReferences = finder.findExternalReferences(content);
        Assertions.assertNotNull(foundReferences);
        Assertions.assertEquals(2, foundReferences.size());
        Assertions.assertEquals(Set.of(new JsonPointerExternalReference("./address.json"),
                new JsonPointerExternalReference("./ssn.json")), foundReferences);
    }

}
