forked from JabRef/jabref
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
67 test rest interface #76
Open
vinnyt123
wants to merge
11
commits into
jabmap
Choose a base branch
from
67-test-REST-interface
base: jabmap
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
98565a3
Add test setup for RootResource
vinnyt123 cc977df
Finish tests for save mind map
vinnyt123 dcd0b96
GET test: Get MindMap consisting of single node
tia365 36e907e
GET test: Get MindMap consisting of multiple nodes and edges
tia365 5562106
Refactor DatabaseAccess and add JabMapHTTPServer
vinnyt123 3d3a279
Finish getEntries tests
vinnyt123 0c76e30
GET test: No mindmaps in databae
tia365 84187c4
Merge remote-tracking branch 'origin/67-test-REST-interface' into 67-…
tia365 45a3cb0
GET tests: Only reference bib entries and both reference and mindmap …
tia365 4133ea0
Refactoring
tia365 e0d4988
Clean up test code and refactor rest classes into better package stru…
vinnyt123 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/main/java/org/jabref/rest/jabmap/JabMapHTTPServer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.jabref.rest.jabmap; | ||
|
||
import org.jabref.gui.JabRefMain; | ||
import org.jabref.rest.jabmap.resources.RootResource; | ||
|
||
import org.eclipse.jetty.server.Server; | ||
import org.eclipse.jetty.servlet.ServletContextHandler; | ||
import org.eclipse.jetty.servlet.ServletHolder; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class JabMapHTTPServer { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(JabRefMain.class); | ||
|
||
public static void startHttpEndPoint() { | ||
Server server = createHttpServer(); | ||
|
||
try { | ||
// Starts server to http://localhost:9898/ | ||
server.start(); | ||
} catch (Exception e) { | ||
LOGGER.error("Problem starting HTTP Server", e); | ||
} | ||
} | ||
|
||
private static Server createHttpServer() { | ||
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); | ||
context.setContextPath("/"); | ||
|
||
Server server = new Server(9898); | ||
server.setHandler(context); | ||
addServlet(context); | ||
return server; | ||
} | ||
|
||
private static void addServlet(ServletContextHandler context) { | ||
// this mirrors a webapp/WEB-INF/web.xml | ||
ServletHolder jerseyServlet = context.addServlet( | ||
org.glassfish.jersey.servlet.ServletContainer.class, "/*"); | ||
jerseyServlet.setInitOrder(0); | ||
|
||
// Tells the Jersey Servlet which REST service/class to load. | ||
jerseyServlet.setInitParameter( | ||
"jersey.config.server.provider.classnames", | ||
RootResource.class.getCanonicalName()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/main/java/org/jabref/rest/jabmap/utils/DatabaseAccess.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.jabref.rest.jabmap.utils; | ||
|
||
import java.util.List; | ||
|
||
import javax.ws.rs.WebApplicationException; | ||
import javax.ws.rs.core.Response; | ||
|
||
import javafx.application.Platform; | ||
|
||
import org.jabref.gui.Globals; | ||
import org.jabref.gui.StateManager; | ||
import org.jabref.model.database.BibDatabase; | ||
import org.jabref.model.entry.BibEntry; | ||
|
||
public class DatabaseAccess { | ||
public BibDatabase getActiveDatabase() { | ||
StateManager stateManager = Globals.stateManager; | ||
if (stateManager.getActiveDatabase().isPresent()) { | ||
return stateManager.getActiveDatabase().get().getDatabase(); | ||
} else { | ||
throw new WebApplicationException(Response.Status.INTERNAL_SERVER_ERROR); | ||
} | ||
} | ||
|
||
public void replaceEntries(List<BibEntry> newEntries, List<BibEntry> oldMapEntries, BibDatabase bibDatabase) { | ||
Platform.runLater(() -> { | ||
// Need to run this on the JavaFX thread | ||
// We opted to remove the old entries and insert the updated entries returned by JabMap rather than updating them as the code | ||
// to do so is complicated | ||
bibDatabase.removeEntries(oldMapEntries); | ||
bibDatabase.insertEntries(newEntries); | ||
} | ||
); | ||
} | ||
} |
104 changes: 52 additions & 52 deletions
104
src/test/java/org/jabref/logic/jabmap/BibtexMindMapAdapterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,52 @@ | ||
package org.jabref.logic.jabmap; | ||
|
||
import java.util.List; | ||
|
||
import org.jabref.model.entry.BibEntry; | ||
import org.jabref.model.jabmap.EdgeDirection; | ||
import org.jabref.model.jabmap.MindMap; | ||
import org.jabref.model.jabmap.MindMapEdge; | ||
import org.jabref.model.jabmap.MindMapNode; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
class BibtexMindMapAdapterTest { | ||
|
||
@Test | ||
void mindMap2Bibtex() { | ||
MindMap testMap = new MindMap(); | ||
MindMapNode node1 = new MindMapNode(1L, "node1", "citation_key", 0, 0); | ||
MindMapNode node2 = new MindMapNode(2L, "node2", "citation_key", 0, 10); | ||
MindMapEdge edge1 = new MindMapEdge(1L, 2L, "label", EdgeDirection.DEFAULT); | ||
testMap.addNode(node1); | ||
testMap.addNode(node2); | ||
testMap.addEdge(edge1); | ||
|
||
BibtexMindMapAdapter adapter = new BibtexMindMapAdapter(); | ||
List<BibEntry> entries = adapter.mindMap2Bibtex(testMap); | ||
|
||
// BibEntry node1Entry = new BibEntry(StandardEntryType.MindMapNode).withField(new UnknownField(MAP_NODE_ID), "1"); | ||
// BibEntry node2Entry = new BibEntry(StandardEntryType.MindMapNode).withField(new UnknownField(MAP_NODE_ID), "2"); | ||
// BibEntry edgeEntry = new BibEntry(StandardEntryType.MindMapEdge).withField(new UnknownField(MAP_EDGE_NODE1_ID), "1"); | ||
// assertEquals(List.of(node1Entry, node2Entry, edgeEntry), entries); | ||
} | ||
|
||
@Test | ||
void mindMap2BibtexEdge() { | ||
MindMap testMap = new MindMap(); | ||
MindMapNode node1 = new MindMapNode(1L, "node1", "citation_key", 0, 0); | ||
MindMapNode node2 = new MindMapNode(2L, "node2", "citation_key", 0, 10); | ||
MindMapEdge edge1 = new MindMapEdge(1L, 2L, "label", EdgeDirection.DEFAULT); | ||
testMap.addNode(node1); | ||
testMap.addNode(node2); | ||
testMap.addEdge(edge1); | ||
|
||
BibtexMindMapAdapter adapter = new BibtexMindMapAdapter(); | ||
List<BibEntry> entries = adapter.mindMap2Bibtex(testMap); | ||
|
||
// BibEntry node1Entry = new BibEntry(StandardEntryType.MindMapNode).withField(new UnknownField(MAP_NODE_ID), "1"); | ||
// BibEntry node2Entry = new BibEntry(StandardEntryType.MindMapNode).withField(new UnknownField(MAP_NODE_ID), "2"); | ||
// BibEntry edgeEntry = new BibEntry(StandardEntryType.MindMapEdge).withField(new UnknownField(MAP_EDGE_NODE1_ID), "1"); | ||
// assertEquals(List.of(node1Entry, node2Entry, edgeEntry), entries); | ||
} | ||
} | ||
//package org.jabref.logic.jabmap; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is the test disabled? |
||
// | ||
//import java.util.List; | ||
// | ||
//import org.jabref.model.entry.BibEntry; | ||
//import org.jabref.model.jabmap.EdgeDirection; | ||
//import org.jabref.model.jabmap.MindMap; | ||
//import org.jabref.model.jabmap.MindMapEdge; | ||
//import org.jabref.model.jabmap.MindMapNode; | ||
// | ||
//import org.junit.jupiter.api.Test; | ||
// | ||
//class BibtexMindMapAdapterTest { | ||
// | ||
// @Test | ||
// void mindMap2Bibtex() { | ||
// MindMap testMap = new MindMap(); | ||
// MindMapNode node1 = new MindMapNode(1L, "node1", "citation_key", 0, 0); | ||
// MindMapNode node2 = new MindMapNode(2L, "node2", "citation_key", 0, 10); | ||
// MindMapEdge edge1 = new MindMapEdge(1L, 2L, "label", EdgeDirection.DEFAULT); | ||
// testMap.addNode(node1); | ||
// testMap.addNode(node2); | ||
// testMap.addEdge(edge1); | ||
// | ||
// BibtexMindMapAdapter adapter = new BibtexMindMapAdapter(); | ||
// List<BibEntry> entries = adapter.mindMap2Bibtex(testMap); | ||
// | ||
// // BibEntry node1Entry = new BibEntry(StandardEntryType.MindMapNode).withField(new UnknownField(MAP_NODE_ID), "1"); | ||
// // BibEntry node2Entry = new BibEntry(StandardEntryType.MindMapNode).withField(new UnknownField(MAP_NODE_ID), "2"); | ||
// // BibEntry edgeEntry = new BibEntry(StandardEntryType.MindMapEdge).withField(new UnknownField(MAP_EDGE_NODE1_ID), "1"); | ||
// // assertEquals(List.of(node1Entry, node2Entry, edgeEntry), entries); | ||
// } | ||
// | ||
// @Test | ||
// void mindMap2BibtexEdge() { | ||
// MindMap testMap = new MindMap(); | ||
// MindMapNode node1 = new MindMapNode(1L, "node1", "citation_key", 0, 0); | ||
// MindMapNode node2 = new MindMapNode(2L, "node2", "citation_key", 0, 10); | ||
// MindMapEdge edge1 = new MindMapEdge(1L, 2L, "label", EdgeDirection.DEFAULT); | ||
// testMap.addNode(node1); | ||
// testMap.addNode(node2); | ||
// testMap.addEdge(edge1); | ||
// | ||
// BibtexMindMapAdapter adapter = new BibtexMindMapAdapter(); | ||
// List<BibEntry> entries = adapter.mindMap2Bibtex(testMap); | ||
// | ||
// // BibEntry node1Entry = new BibEntry(StandardEntryType.MindMapNode).withField(new UnknownField(MAP_NODE_ID), "1"); | ||
// // BibEntry node2Entry = new BibEntry(StandardEntryType.MindMapNode).withField(new UnknownField(MAP_NODE_ID), "2"); | ||
// // BibEntry edgeEntry = new BibEntry(StandardEntryType.MindMapEdge).withField(new UnknownField(MAP_EDGE_NODE1_ID), "1"); | ||
// // assertEquals(List.of(node1Entry, node2Entry, edgeEntry), entries); | ||
// } | ||
//} |
22 changes: 22 additions & 0 deletions
22
src/test/java/org/jabref/rest/jabmap/resources/MockDatabaseAccess.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.jabref.rest.jabmap.resources; | ||
|
||
import java.util.List; | ||
|
||
import org.jabref.model.database.BibDatabase; | ||
import org.jabref.model.entry.BibEntry; | ||
import org.jabref.rest.jabmap.utils.DatabaseAccess; | ||
|
||
public class MockDatabaseAccess extends DatabaseAccess { | ||
private BibDatabase bibDatabase = new BibDatabase(); | ||
|
||
@Override | ||
public BibDatabase getActiveDatabase() { | ||
return bibDatabase; | ||
} | ||
|
||
@Override | ||
public void replaceEntries(List<BibEntry> newEntries, List<BibEntry> oldMapEntries, BibDatabase bibDatabase) { | ||
bibDatabase.removeEntries(oldMapEntries); | ||
bibDatabase.insertEntries(newEntries); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please name the calss
JabMapHttpServer
. JabRef tries to follow https://google.github.io/styleguide/javaguide.html#s5.3-camel-case