-
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
base: jabmap
Are you sure you want to change the base?
Conversation
vinnyt123
commented
Sep 29, 2020
•
edited
Loading
edited
- Tests created for GET /libraries/current/entries
- Tests created for PUT /libraries/current/map
- Tests created for GET /libraries/current/map
…test-REST-interface
This fixes #67 |
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.
In general LGTM - some nitpicks
@@ -25,12 +25,9 @@ | |||
import org.jabref.migrations.PreferencesMigrations; | |||
import org.jabref.model.database.BibDatabaseMode; | |||
import org.jabref.preferences.JabRefPreferences; | |||
import org.jabref.rest.resources.RootResource; | |||
import org.jabref.rest.jabmap.JabMapHTTPServer; |
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
// 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the test disabled?
|
||
@BeforeEach | ||
void initMockDatabase() { | ||
RootResource.databaseAccess = new MockDatabaseAccess(); |
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.
Can we work with injection somehow here? @calixtus do you have an idea how to do that?
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import javax.ws.rs.client.Client; |
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.
The test does not use REST-assured as proposed at #67 (comment). An ADR should be added for that.
response = client.target(WEB_SERVICE_URI).path("libraries/current/entries").request().accept(MediaType.APPLICATION_JSON).get(); | ||
assertEquals(200, response.getStatus()); | ||
String responseBody = response.readEntity(String.class); | ||
String expectedJson = "[{\"type\":{\"bibtex_metadata\":\"Article\",\"key\":\"article1\"}},{\"type\":{\"bibtex_metadata\":\"Book\",\"key\":\"book1\"}},{\"type\":{\"bibtex_metadata\":\"MastersThesis\",\"key\":\"MastersThesis1\"}}]"; |
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.
This will be a maintenance hell, because the whitespace and key ordering does not matter for equality.
I think, JSONassert should be used. --> https://github.com/skyscreamer/JSONassert. Then only one line needs to be changed --> assertEquals
--> JSONAssert.assertEquals
.
Maybe try with Jackson or another JSON library for a equality? --> https://www.baeldung.com/jackson-compare-two-json-objects
It does not seem possible with REST-assured to check for the complete json directly.
|
||
assertEquals(expectedJson, responseBody); | ||
} finally { | ||
response.close(); |
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.
This reads like the try-with-resoures (https://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html) should be used
Response response = null; | ||
try { | ||
response = client.target(WEB_SERVICE_URI).path("libraries/current/entries").request().accept(MediaType.APPLICATION_JSON).get(); | ||
assertEquals(200, response.getStatus()); |
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.
This is a call for REST-assured. Maybe, the code can be quickly rewritten to use REST-assured?
String responseString = get(uri + "/movie/" + testMovie.getId()).then()
.assertThat()
.statusCode(HttpStatus.OK.value())
.extract()
.asString();
response = client.target(WEB_SERVICE_URI).path("libraries/current/entries").request().accept(MediaType.APPLICATION_JSON).get(); | ||
assertEquals(200, response.getStatus()); | ||
String responseBody = response.readEntity(String.class); | ||
String expectedJson = "[{\"type\":{\"bibtex_metadata\":\"Article\",\"key\":\"article1\"}},{\"type\":{\"bibtex_metadata\":\"Book\",\"key\":\"book1\"}},{\"type\":{\"bibtex_metadata\":\"MastersThesis\",\"key\":\"MastersThesis1\"}}]"; |
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 change the JSON format to a simpley key/value map as outlined at #73 (comment).
Please merge
By "ENGLISH LANGUAGE FILE", |