Search in sources :

Example 1 with JsonDocumentManager

use of com.reprezen.swagedit.core.json.references.JsonDocumentManager in project KaiZen-OpenAPI-Editor by RepreZen.

the class Mocks method mockHyperlinkDetector.

public static JsonReferenceHyperlinkDetector mockHyperlinkDetector(final URI uri, final JsonNode document) {
    final JsonDocumentManager manager = mock(JsonDocumentManager.class);
    final IFile file = mock(IFile.class);
    when(file.exists()).thenReturn(true);
    when(manager.getDocument(Mockito.any(URI.class))).thenReturn(document);
    when(manager.getFile(Mockito.any(URI.class))).thenReturn(file);
    return new SwaggerReferenceHyperlinkDetector() {

        // allow running tests as non plugin tests
        protected URI getBaseURI() {
            return uri;
        }

        protected JsonReferenceFactory getFactory() {
            return new JsonReferenceFactory() {

                @Override
                public JsonReference createSimpleReference(URI baseURI, AbstractNode valueNode) {
                    JsonReference ref = super.createSimpleReference(baseURI, valueNode);
                    if (ref != null) {
                        ref.setDocumentManager(manager);
                    }
                    return ref;
                }

                @Override
                public JsonReference create(AbstractNode node) {
                    JsonReference ref = super.create(node);
                    ref.setDocumentManager(manager);
                    return ref;
                }

                @Override
                public JsonReference create(JsonNode node) {
                    JsonReference ref = super.create(node);
                    ref.setDocumentManager(manager);
                    return ref;
                }

                ;
            };
        }
    };
}
Also used : JsonReference(com.reprezen.swagedit.core.json.references.JsonReference) IFile(org.eclipse.core.resources.IFile) SwaggerReferenceHyperlinkDetector(com.reprezen.swagedit.editor.hyperlinks.SwaggerReferenceHyperlinkDetector) AbstractNode(com.reprezen.swagedit.core.model.AbstractNode) JsonReferenceFactory(com.reprezen.swagedit.core.json.references.JsonReferenceFactory) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonDocumentManager(com.reprezen.swagedit.core.json.references.JsonDocumentManager) URI(java.net.URI)

Example 2 with JsonDocumentManager

use of com.reprezen.swagedit.core.json.references.JsonDocumentManager in project KaiZen-OpenAPI-Editor by RepreZen.

the class Mocks method mockJsonReferenceFactory.

public static JsonReferenceFactory mockJsonReferenceFactory(final Map<URI, JsonNode> entries) {
    final IFile file = mock(IFile.class);
    when(file.exists()).thenReturn(true);
    return new JsonReferenceFactory() {

        public JsonReference create(AbstractNode node) {
            JsonReference ref = super.create(node);
            ref.setDocumentManager(new JsonDocumentManager() {

                @Override
                public IFile getFile(URI uri) {
                    return file;
                }

                @Override
                public JsonNode getDocument(URI uri) {
                    return entries.get(uri);
                }
            });
            return ref;
        }

        ;
    };
}
Also used : JsonReference(com.reprezen.swagedit.core.json.references.JsonReference) IFile(org.eclipse.core.resources.IFile) AbstractNode(com.reprezen.swagedit.core.model.AbstractNode) JsonReferenceFactory(com.reprezen.swagedit.core.json.references.JsonReferenceFactory) JsonNode(com.fasterxml.jackson.databind.JsonNode) JsonDocumentManager(com.reprezen.swagedit.core.json.references.JsonDocumentManager) URI(java.net.URI)

Aggregations

JsonNode (com.fasterxml.jackson.databind.JsonNode)2 JsonDocumentManager (com.reprezen.swagedit.core.json.references.JsonDocumentManager)2 JsonReference (com.reprezen.swagedit.core.json.references.JsonReference)2 JsonReferenceFactory (com.reprezen.swagedit.core.json.references.JsonReferenceFactory)2 AbstractNode (com.reprezen.swagedit.core.model.AbstractNode)2 URI (java.net.URI)2 IFile (org.eclipse.core.resources.IFile)2 SwaggerReferenceHyperlinkDetector (com.reprezen.swagedit.editor.hyperlinks.SwaggerReferenceHyperlinkDetector)1