Skip to content
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
wants to merge 11 commits into
base: jabmap
Choose a base branch
from
Open

67 test rest interface #76

wants to merge 11 commits into from

Conversation

vinnyt123
Copy link
Collaborator

@vinnyt123 vinnyt123 commented Sep 29, 2020

  • Tests created for GET /libraries/current/entries
  • Tests created for PUT /libraries/current/map
  • Tests created for GET /libraries/current/map

@vinnyt123 vinnyt123 changed the title [WIP] 67 test rest interface 67 test rest interface Sep 30, 2020
@koppor
Copy link
Collaborator

koppor commented Oct 8, 2020

This fixes #67

Copy link
Collaborator

@koppor koppor left a 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;
Copy link
Collaborator

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;
Copy link
Collaborator

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();
Copy link
Collaborator

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;
Copy link
Collaborator

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\"}}]";
Copy link
Collaborator

@koppor koppor Oct 8, 2020

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();
Copy link
Collaborator

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());
Copy link
Collaborator

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();

(Source: https://www.baeldung.com/rest-assured-response)

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\"}}]";
Copy link
Collaborator

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).

@koppor
Copy link
Collaborator

koppor commented Oct 9, 2020

Please merge upstream/master to get most tests fixed. Please also read on at the failing tests, you'll find

org.jabref.logic.l10n.LocalizationConsistencyTest

  Test findMissingLocalizationKeys() FAILED (1.3s)

  org.opentest4j.AssertionFailedError: DETECTED LANGUAGE KEYS WHICH ARE NOT IN THE ENGLISH LANGUAGE FILE
  PASTE THESE INTO THE ENGLISH LANGUAGE FILE
  
  Launch JabMap=Launch JabMap
  Open JabMap=Open JabMap
   ==> expected: <[]> but was: <[Launch JabMap (src/main/java/org/jabref/gui/keyboard/KeyBinding.java LANG), Open JabMap (src/main/java/org/jabref/gui/keyboard/KeyBinding.java LANG)]>
      at org.jabref.logic.l10n.LocalizationConsistencyTest.findMissingLocalizationKeys(LocalizationConsistencyTest.java:114)

By "ENGLISH LANGUAGE FILE", JabRef_en.properties is meant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants