generator-jhipster: Couchbase tests are failing

Overview of the issue

Failure seems to be caused by EJS issues.

WARNING! Copying template /home/runner/generator-jhipster/generators/entity-server/templates/src/main/java/package/domain/Entity.java.ejs failed. [TypeError: /home/runner/generator-jhipster/generators/entity-server/templates/src/main/java/package/domain/Entity.java.ejs:680
    678|         this.set<%= relationshipNameCapitalized %>(<%= otherEntityName %>);
    679| <%_ if ((databaseType === 'couchbase' && !otherEntityIsEmbedded) || reactiveRelationshipWithId) { _%>
 >> 680|         this.<%= relationshipFieldName %>Id = <%= otherEntityName %> != null ? <%= otherEntityName %>.get<%= primaryKey.nameCapitalized %>() : null;
    681| <%_ } _%>
    682|         return this;
    683|     }

Cannot read property 'nameCapitalized' of undefined]
ERROR! /home/runner/generator-jhipster/generators/entity-server/templates/src/main/java/package/domain/Entity.java.ejs:680
    678|         this.set<%= relationshipNameCapitalized %>(<%= otherEntityName %>);
    679| <%_ if ((databaseType === 'couchbase' && !otherEntityIsEmbedded) || reactiveRelationshipWithId) { _%>
 >> 680|         this.<%= relationshipFieldName %>Id = <%= otherEntityName %> != null ? <%= otherEntityName %>.get<%= primaryKey.nameCapitalized %>() : null;
    681| <%_ } _%>
    682|         return this;
    683|     }

Cannot read property 'nameCapitalized' of undefined
TypeError: /home/runner/generator-jhipster/generators/entity-server/templates/src/main/java/package/domain/Entity.java.ejs:680
    678|         this.set<%= relationshipNameCapitalized %>(<%= otherEntityName %>);
    679| <%_ if ((databaseType === 'couchbase' && !otherEntityIsEmbedded) || reactiveRelationshipWithId) { _%>
 >> 680|         this.<%= relationshipFieldName %>Id = <%= otherEntityName %> != null ? <%= otherEntityName %>.get<%= primaryKey.nameCapitalized %>() : null;
    681| <%_ } _%>
    682|         return this;
    683|     }

Cannot read property 'nameCapitalized' of undefined
    at module.exports.eval (/home/runner/generator-jhipster/generators/entity-server/templates/src/main/java/package/domain/Entity.java.ejs:1460:37)
    at Entity.java (/home/runner/generator-jhipster/node_modules/ejs/lib/ejs.js:691:17)
    at tryHandleCache (/home/runner/generator-jhipster/node_modules/ejs/lib/ejs.js:272:36)
    at Object.exports.renderFile (/home/runner/generator-jhipster/node_modules/ejs/lib/ejs.js:489:10)
    at Object.renderContent (/home/runner/generator-jhipster/generators/utils.js:250:9)
    at module.exports.template (/home/runner/generator-jhipster/generators/generator-base-private.js:755:23)
    at /home/runner/generator-jhipster/generators/generator-base.js:2233:42
    at Array.forEach (<anonymous>)
    at /home/runner/generator-jhipster/generators/generator-base.js:2149:45
    at Array.forEach (<anonymous>) {
  path: '/home/runner/generator-jhipster/generators/entity-server/templates/src/main/java/package/domain/Entity.java.ejs'
}
Error: Process completed with exit code 1.
Motivation for or Use Case

All our nightly builds on https://github.com/hipster-labs/jhipster-daily-builds should pass.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 21 (12 by maintainers)

Commits related to this issue

Most upvoted comments

Hi @mraible, thanks for the repos! TLDR; all tests passed… 😃

I mainly worked on a fork of https://github.com/mraible/ngx-couchbase and focus again on the failing integration tests. I found the root cause of the issue I mentioned earlier (the one with spring data generating the wrong query for fields with @Field annotations).

The fix seems to be pretty simple in Spring Data (N1qlQueryCreator.java).

In that converter of using getName() on source we need to change that to getFieldName() which has the logic to check for @Field annotation and obtain the value from it in case it is present or fallback to getName() through fieldNameStrategy if not.

I extended the Spring Data Couchbase Repository infrastructure to test this, and fixed a couple more tests of the 6 remaining. I am planning on creating a PR in your repo so you can take a look and give it a try. I will also try to look into Spring Data project to see if that issue is already reported and if not try to contribute that fix.

Now, there were a couple more Integration tests that failed after my fix and are related with other “new issues” that I discovered. One is related with how Spring Data generates the query for this respository method:

@ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS)
List<User> findAllByIdNotNullAndActivatedIsTrue();

This method generates:

SELECT META(`testBucket`).id AS __id, META(`testBucket`).cas AS __cas, `testBucket`.* FROM `testBucket` WHERE `_class` = "tech.jhipster.sample.domain.User" AND id is not null and `activated`

which seems OK and straightforward for any DB but in Couchbase, IDs are treated in a different way and they need to be accessed through the metadata object. So the query that method should generate, should be something like:

SELECT META(`testBucket`).id AS __id, META(`testBucket`).cas AS __cas, `testBucket`.* FROM `testBucket` WHERE `_class` = "tech.jhipster.sample.domain.User" AND meta(`testBucket`).id is not null and `activated`

I did succeed fixing this in Spring Data N1qlQueryCreator (in the same Converter lambda mentioned earlier) but the fix is more involved since we also need to tweak the QueryCriteria class (there is some escaping with backticks in that class that needs to be handled). I will try to report this to the Spring Data team as well, although I am thinking that the meta().id not being supported in derived query methods is by design.

This is because they provide the @Query annotation and we can just annotate that method and add the behavior we want. Of course this needs to be changed in the JHipster Generator. Anyways, It would be nice to double check with them.

The other test that fails is:

@Test
void assertThatUserCanBeFoundByEmailIgnoreCase() {
    UserDetails userDetails = domainUserDetailsService.loadUserByUsername(USER_TWO_EMAIL.toUpperCase(Locale.ENGLISH));
    assertThat(userDetails).isNotNull();
    assertThat(userDetails.getUsername()).isEqualTo(USER_TWO_LOGIN);
}

and this one is also related with a repository method, but in this case I believe that is because the Couchbase implementation does not support the “IgnoreCase” in:

@ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS)
Optional<User> findOneByEmailIgnoreCase(String email);

This method generates the follow query:

SELECT META(`testBucket`).id AS __id, META(`testBucket`).cas AS __cas, `testBucket`.* FROM `testBucket` WHERE `_class` = "tech.jhipster.sample.domain.User" AND `email` = $1

and in Couchbase we should have something like:

SELECT META(`testBucket`).id AS __id, META(`testBucket`).cas AS __cas, `testBucket`.* FROM `testBucket` WHERE `_class` = "tech.jhipster.sample.domain.User" AND lower(`email`) = lower($1)

I think that we can probably solve this test changing the JHipster Generator and change the method name if the database is couchbase or just use a @Query annotation directly in the method. I actually fixed it in my fork with @Query:

@Query("#{#n1ql.selectEntity} WHERE LOWER(email) = LOWER($1) AND #{#n1ql.filter}")

With all these changes in ngx-couchbase, all tests passed and we should pretty good to retry the build. Anyways, I still need to check if these fixes are valid also for the reactive version. Will try to look into during this week.

@mmonti I created a couple of repos from my branch so you can see the test failures.

If you run ./mvnw verify after cloning them, you’ll see the integration test failures.

You can also run them and see that e2e tests pass.

npm install
docker-compose -f src/main/docker/couchbase.yml up -d
./mvnw
# open a new terminal after it finishes starting
npm run e2e

Thanks for that @mshima! I integrated @murdos’ changes into https://github.com/jhipster/generator-jhipster/pull/13770. I’m able to create the ngx-couchbase app with entities and all e2e tests pass. Tests are failing, not sure why.