Provide integration tests for license creation covering start date, end date, status, type and end date semantics

Description

Extend and improve the integration test https://github.com/folio-org/mod-licenses/blob/master/service/src/integration-test/groovy/org/olf/licenses/LicenseLifecycleSpec.groovy with test cases that cover the setting of

  • end-date

  • start-date

  • status

  • type

  • endDateSemantics

  • license links

  • tags

Checklist

hide

TestRail: Results

Activity

Show:

Jag Goraya July 5, 2019 at 12:52 PM

Ian Ibbotson (Use this one) March 28, 2019 at 11:27 AM
Edited

Sorry - one thing to add, because it might not be immediately obvious.

For related items like sets and collections, you won't need to access other URLs - you can just embed the data in the JSON. In particular, to create license links you would cross reference

https://github.com/folio-org/mod-licenses/blob/master/service/grails-app/domain/org/olf/licenses/LicenseLink.groovy

and use something like:

[ "name":"hello", "description":"Description", ...Other "links":[ [ "linkType":"A string Link type", "linkLabel": "A link label", "relation": "A relation", "direction": "In" ], [ "linkType":"A string Link type", "linkLabel": "A second link label", "relation": "A relation", "direction": "In" ] ] ]

So you would not need to call a LicenseLink endpoint directly, but by nesting the structures in the JSON you send to the create license endpoint by POSTing to /licenses/licenses. The reciprocal belongsTo/owner property on LicenseLink is set automatically by the framework - you don't need to touch it

On the back-end there is clever code that matches the properties in the JSON to the properties in the database and does all the mappings for you. If you want to know more about this, your keywords are "Grails Data Binding" - I tend to run away screaming at that point tho, and let steve take over - he knows that stuff inside out - i find it better to just try and deal with the Json level interface and assume the JSON map properties will correspond with the Domain class properties. 99.9% of the time it works out that way

Ian Ibbotson (Use this one) March 28, 2019 at 11:15 AM
Edited

Hey Peter - there might be some terminology fuzz here as there are actually 2 sets of integration tests - ones that run on the back-end (Which complete only by talking to the web service APIs, and have no UI component at all) and some that are executed in the front end environment.

Some general stuff then

Here I think we are only talking about the back-end integration tests. Essentially these tests ensure that the API to the module is working as expected and say nothing about the front end.

The nub of this issue is to make the command

grails test-app

complete and run a sensible set of unit and integration tests.

The integration tests require you to have a postgres database - you can find the appropriate config in grails-app/conf/application.yml and in particular, look under environments: test: dataSource: for details. You'll see that the default is localhost:54321/okapi_modules_test.

There is some reading here: https://docs.grails.org/latest/guide/testing.html

In terms of (1) and (2)

The first thing to do is to be aware that grails is a heavily opinionated framework, and if you can grok the framework, you'll know the answer to these things. So the fundamental answer is to work through the grails tutorials and ask questions about how the framework operates. For some extra info tho.

Grails looks in a very specific place for URL mappings (Although those mappings can contain patterns that map many URLs onto specific controllers) See:

https://github.com/folio-org/mod-licenses/blob/master/service/grails-app/controllers/org/olf/licenses/UrlMappings.groovy

This line :

"/licenses/licenses"(resources:'license') {

Is telling you that the /licenses/licenses is being used to expose GET, PUT, POST and other HTTP verbs.

If you wanted to create an org for example, you would post to /licenses/org.

I think for this issue, /licenses/licenses, /licenses/licenses/UUID-OF-ITEM-TO-UPDATE are all you will need.

(2) By Convention, property names in JSON match their property names in domain classes, so
In https://github.com/folio-org/mod-licenses/blob/master/service/src/integration-test/groovy/org/olf/licenses/LicenseLifecycleSpec.groovy on line 80 you will see

Map license_to_add = [ 'name' : name, 'description' : description, ]

And these two properties map directly to lines 15 and 16 of
https://github.com/folio-org/mod-licenses/blob/master/service/grails-app/domain/org/olf/licenses/License.groovy

Two words of warning however:
1) Sometimes we subtly change the presentaiton of the JSON by overriding the template. For example, how Licenses are actually presented is controlled by https://github.com/folio-org/mod-licenses/blob/master/service/grails-app/views/license/_license.gson In this case, we just accept the defaults, but then we expand some of the linked resources (By default, the framework doesn't expand related objects to prevent deeply nested trees).

2) Sometimes we use trait interfaces like
class License implements CustomProperties,MultiTenant<License> {

to add extra properties into a domain class. In this case - the property customProperties is not in the License domain class itself, but you will see it's data in the JSON - The trait interface is adding that functionality to the class.

Does that help at all? LMK if not.

Ian.

Peter Böhm March 22, 2019 at 2:31 PM

When I try to duplicate an existing (e.g. the existing "set up new licenses" for new test "set end-date"),

  1. how do I find out the URL I need to post the request to (like here in line 86)

  2. how do I find out the correct labels (like 'name' or description' in line 82f. )

I created this test, is the approach correct?

void "Setting end-date"(enddate) { when: Map date_to_add = [ 'end-date': enddate, ] def resp = restBuilder().post("$baseUrl/licenses/licenses") { header 'X-Okapi-Tenant', enddate authHeaders.rehydrate(delegate, owner, thisObject)() contentType 'application/json' accept 'application/json' json date_to_add } then: resp.status == CREATED.value() where: enddate = '2020-12-31' }

maybe could have a look at that?

Peter Böhm March 8, 2019 at 2:25 PM

I'm still not quite sure how to extend and run the integration test and whether I can do this right now with only the front end set up locally. If someone were available maybe for a call about that from next Wednesday on, that would be great

Duplicate

Details

Components

Assignee

Reporter

Labels

Priority

Sprint

Development Team

Bienenvolk

TestRail: Cases

Open TestRail: Cases

TestRail: Runs

Open TestRail: Runs
Created February 12, 2019 at 1:37 PM
Updated July 5, 2019 at 12:52 PM
Resolved July 5, 2019 at 12:52 PM
TestRail: Cases
TestRail: Runs