Skip to content

Commit 9bf7f9d

Browse files
authored
Merge pull request #16077 from tchlyah/fix/couchbase-tests
Fix and enable back Couchbase tests
2 parents 02af22c + dc2aa94 commit 9bf7f9d

File tree

8 files changed

+38
-47
lines changed

8 files changed

+38
-47
lines changed

.github/workflows/angular.yml

+14-14
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ jobs:
7070
- ngx-mariadb-oauth2-infinispan
7171
- ngx-mongodb-kafka-cucumber
7272
- ngx-h2mem-ws-nol2
73-
#- ngx-couchbase
74-
#- ngx-gradle-couchbase-search
73+
- ngx-couchbase
74+
- ngx-gradle-couchbase-search
7575
- ngx-gradle-fr
7676
- ngx-gradle-mysql-es-noi18n-mapsid
7777
- ngx-gradle-mariadb-oauth2-infinispan
@@ -117,18 +117,18 @@ jobs:
117117
war: 0
118118
e2e: 1
119119
testcontainers: 0
120-
#- app-sample: ngx-couchbase
121-
# entity: couchbase
122-
# environment: prod
123-
# war: 0
124-
# e2e: 1
125-
# testcontainers: 1
126-
#- app-sample: ngx-gradle-couchbase-search
127-
# entity: couchbase
128-
# environment: prod
129-
# war: 0
130-
# e2e: 1
131-
# testcontainers: 1
120+
- app-sample: ngx-couchbase
121+
entity: couchbase
122+
environment: prod
123+
war: 0
124+
e2e: 1
125+
testcontainers: 1
126+
- app-sample: ngx-gradle-couchbase-search
127+
entity: couchbase
128+
environment: prod
129+
war: 0
130+
e2e: 1
131+
testcontainers: 1
132132
- app-sample: ngx-gradle-fr
133133
entity: sql
134134
environment: prod

generators/server/templates/src/main/java/package/config/DatabaseConfiguration_couchbase.java.ejs

+13-7
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import tech.jhipster.config.JHipsterProperties;
2424

2525
import com.couchbase.client.java.Bucket;
2626
import com.couchbase.client.java.Cluster;
27+
import com.fasterxml.jackson.databind.ObjectMapper;
2728
import com.github.couchmove.Couchmove;
2829
<%_ if (searchEngineCouchbase) { _%>
2930
import <%= packageName %>.repository.Custom<% if (reactive) { %>Reactive<% } %>CouchbaseRepository;
@@ -39,13 +40,7 @@ import org.slf4j.Logger;
3940
import org.slf4j.LoggerFactory;
4041
import org.springframework.boot.autoconfigure.couchbase.CouchbaseProperties;
4142
import org.springframework.boot.context.properties.EnableConfigurationProperties;
42-
import org.springframework.context.annotation.Bean;
43-
import org.springframework.context.annotation.Configuration;
44-
<%_ if (searchEngineElasticsearch) { _%>
45-
import org.springframework.context.annotation.ComponentScan.Filter;
46-
import org.springframework.context.annotation.FilterType;
47-
<%_ } _%>
48-
import org.springframework.context.annotation.Profile;
43+
import org.springframework.context.annotation.*;
4944
import org.springframework.core.convert.TypeDescriptor;
5045
import org.springframework.core.convert.converter.Converter;
5146
import org.springframework.core.convert.converter.GenericConverter;
@@ -65,6 +60,7 @@ import org.springframework.data.couchbase.core.mapping.event.ValidatingCouchbase
6560
import org.springframework.data.couchbase.repository.auditing.EnableCouchbaseAuditing;
6661
<%_ } _%>
6762
import org.springframework.data.couchbase.repository.config.Enable<%_ if (reactive) { _%>Reactive<% } %>CouchbaseRepositories;
63+
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
6864
import org.springframework.util.StringUtils;
6965
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
7066

@@ -175,12 +171,22 @@ public class DatabaseConfiguration extends AbstractCouchbaseConfiguration {
175171
return mappingCouchbaseConverter;
176172
}
177173
174+
/**
175+
* Workaround for Couchbase overriding SB default jackson mapper: https://github.com/spring-projects/spring-data-couchbase/issues/1209
176+
*/
177+
@Bean
178+
@Primary
179+
ObjectMapper jacksonObjectMapper(Jackson2ObjectMapperBuilder builder) {
180+
return builder.createXmlMapper(false).build();
181+
}
182+
178183
@Bean
179184
public Couchmove couchmove(Cluster cluster) {
180185
log.debug("Configuring Couchmove");
181186
Bucket bucket = cluster.bucket(getBucketName());
182187
Couchmove couchmove = new Couchmove(bucket, cluster, "config/couchmove/changelog");
183188
couchmove.migrate();
189+
couchmove.buildN1qlDeferredIndexes();
184190
return couchmove;
185191
}
186192

generators/server/templates/src/main/java/package/repository/AuthorityRepository.java.ejs

+1-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import org.springframework.data.r2dbc.repository.R2dbcRepository;
3434
import org.springframework.data.mongodb.repository.<% if (reactive) { %>Reactive<% } %>MongoRepository;
3535
<%_ } _%>
3636
<%_ if (databaseTypeCouchbase) { _%>
37-
import org.springframework.data.couchbase.repository.<% if (reactive) { %>Reactive<% } %>CouchbaseRepository;
3837
import org.springframework.data.couchbase.repository.Query;
3938
import com.couchbase.client.java.query.QueryScanConsistency;
4039
import org.springframework.data.couchbase.repository.ScanConsistency;
@@ -68,7 +67,7 @@ import org.springframework.data.neo4j.repository.<% if (reactive) { %>Reactive<%
6867
<%_ if (databaseTypeCouchbase) { _%>
6968
@Repository
7069
<%_ } _%>
71-
public interface AuthorityRepository extends <% if (databaseTypeSql) { %><% if (reactive) { %>R2dbc<% } else { %>Jpa<% } %>Repository<% } else { %><% if (reactive) { %>Reactive<% } %><% if (databaseTypeMongodb) { %>MongoRepository<% } %><% if (databaseTypeNeo4j) { %>Neo4jRepository<% } %><% if (databaseTypeCouchbase) { %>CouchbaseRepository<% } %><% } %><Authority, String> {
70+
public interface AuthorityRepository extends <% if (databaseTypeSql) { %><% if (reactive) { %>R2dbc<% } else { %>Jpa<% } %>Repository<% } else { %><% if (reactive) { %>Reactive<% } %><% if (databaseTypeMongodb) { %>MongoRepository<% } %><% if (databaseTypeNeo4j) { %>Neo4jRepository<% } %><% if (databaseTypeCouchbase) { %>N1qlCouchbaseRepository<% } %><% } %><Authority, String> {
7271
<%_ if (databaseTypeNeo4j) { _%>
7372
<% if (!reactive) { %>// See https://github.com/neo4j/sdn-rx/issues/51<%_ } _%>
7473
<% if (reactive) { %>Flux<% } else { %>List<% } %><<%= asEntity('Authority') %>> findAll();

generators/server/templates/src/main/java/package/repository/N1qlCouchbaseRepository.java.ejs

+7
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ import static java.lang.String.format;
4141
@NoRepositoryBean
4242
public interface N1qlCouchbaseRepository<T, ID> extends CouchbaseRepository<T, ID><% if (searchEngineCouchbase) { %>, SearchCouchbaseRepository<T, ID><% } %> {
4343

44+
static String pageableStatement(Pageable pageable) {
45+
return pageableStatement(pageable, "");
46+
}
47+
4448
static String pageableStatement(Pageable pageable, String prefix) {
4549
Sort sort = Sort.by(
4650
pageable.getSort().stream()
@@ -67,4 +71,7 @@ public interface N1qlCouchbaseRepository<T, ID> extends CouchbaseRepository<T, I
6771

6872
@ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS)
6973
Page<T> findAll(Pageable pageable);
74+
75+
@ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS)
76+
void deleteAll();
7077
}

generators/server/templates/src/main/java/package/repository/UserRepository.java.ejs

+2-16
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,9 @@ import org.springframework.data.mongodb.repository.<% if (reactive) { %>Reactive
9696
import org.springframework.data.neo4j.repository.<% if (reactive) { %>Reactive<% } %>Neo4jRepository;
9797
<%_ } _%>
9898
<%_ if (databaseTypeCouchbase) { _%>
99-
import org.springframework.data.domain.Sort;
10099
import com.couchbase.client.java.query.QueryScanConsistency;
101100
import org.springframework.data.couchbase.repository.Query;
102101
import org.springframework.data.couchbase.repository.ScanConsistency;
103-
import org.springframework.data.couchbase.repository.<% if (reactive) { %>Reactive<% } %>CouchbaseRepository;
104102
import org.springframework.data.domain.PageImpl;
105103
<%_ } _%>
106104
<%_ if (reactive && databaseTypeCassandra) { _%>
@@ -172,7 +170,7 @@ import static <%= packageName %>.config.Constants.ID_DELIMITER;
172170
_%>
173171
<%_ if ((databaseTypeSql && !reactive) || databaseTypeMongodb || databaseTypeNeo4j || databaseTypeCouchbase) { _%>
174172
@Repository
175-
public interface UserRepository extends <% if (databaseTypeSql) { %>JpaRepository<<%= asEntity('User') %>, <%= user.primaryKey.type %>><% } %><% if (reactive) { %>Reactive<% } %><% if (databaseTypeMongodb) { %>MongoRepository<<%= asEntity('User') %>, String><% } %><% if (databaseTypeNeo4j) { %>Neo4jRepository<<%= asEntity('User') %>, String><% } %><% if (databaseTypeCouchbase) { %>CouchbaseRepository<<%= asEntity('User') %>, String><%if (searchEngineCouchbase) { %>, SearchCouchbaseRepository<<%= asEntity('User') %>, String><% } } %> {
173+
public interface UserRepository extends <% if (databaseTypeSql) { %>JpaRepository<<%= asEntity('User') %>, <%= user.primaryKey.type %>><% } %><% if (reactive) { %>Reactive<% } %><% if (databaseTypeMongodb) { %>MongoRepository<<%= asEntity('User') %>, String><% } %><% if (databaseTypeNeo4j) { %>Neo4jRepository<<%= asEntity('User') %>, String><% } %><% if (databaseTypeCouchbase) { %>N1qlCouchbaseRepository<<%= asEntity('User') %>, String><%if (searchEngineCouchbase) { %>, SearchCouchbaseRepository<<%= asEntity('User') %>, String><% } } %> {
176174
<%_ if (cacheManagerIsAvailable) { _%>
177175
178176
String USERS_BY_LOGIN_CACHE = "usersByLogin";
@@ -241,18 +239,6 @@ public interface UserRepository extends <% if (databaseTypeSql) { %>JpaRepositor
241239
<% if (!reactive) { %>// See https://github.com/neo4j/sdn-rx/issues/51<% } %>
242240
<%= listOrFlux %><<%= asEntity('User') %>> findAll();
243241
244-
<%_ } _%>
245-
<%_ if (databaseTypeCouchbase) { _%>
246-
@Override
247-
@ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS)
248-
<%= listOrFlux %><<%= asEntity('User') %>> findAll();
249-
250-
<%_ } _%>
251-
<%_ if (databaseTypeCouchbase) { _%>
252-
@Override
253-
@ScanConsistency(query = QueryScanConsistency.REQUEST_PLUS)
254-
<%= listOrFlux %><<%= asEntity('User') %>> findAll(Sort sort);
255-
256242
<%_ } _%>
257243
<%_ if (databaseTypeSql) { _%>
258244
@EntityGraph(attributePaths = "authorities")
@@ -287,7 +273,7 @@ public interface UserRepository extends <% if (databaseTypeSql) { %>JpaRepositor
287273
<% } else { %>
288274
<%_ if (databaseTypeCouchbase) { _%>
289275
default Page<<%= asEntity('User') %>> findAllActivatedIsTrue(Pageable pageable) {
290-
return new PageImpl<>(findAllActivatedIsTrue(new org.springframework.data.couchbase.core.query.Query().with(pageable).export()), pageable, countAllActivatedIsTrue());
276+
return new PageImpl<>(findAllActivatedIsTrue(N1qlCouchbaseRepository.pageableStatement(pageable)), pageable, countAllActivatedIsTrue());
291277
}
292278
<%_ } else { _%>
293279
Page<<%= asEntity('User') %>> findAllByIdNotNullAndActivatedIsTrue(Pageable pageable);

generators/server/templates/src/main/resources/config/couchmove/changelog/V0__create_indexes.n1ql.ejs

-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
-- create indexes
21
CREATE INDEX type ON `${bucket}`(`_class`)
32
WITH { "defer_build" : true };
43
<%_ if (!skipUserManagement) { _%>
@@ -18,6 +17,3 @@ CREATE INDEX token_date ON `${bucket}`(tokenDate)
1817
WITH { "defer_build" : true };
1918
<%_ } _%>
2019
<%_ } _%>
21-
22-
-- build indexes asynchronously
23-
BUILD INDEX ON `${bucket}`(type<% if (!skipUserManagement) { %>, user_mail<% if (authenticationTypeSession) { %>, token_login, token_date<% } %><% } %>);

generators/server/templates/src/test/java/package/web/rest/PublicUserResourceIT.java.ejs

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ class PublicUserResourceIT <% if (databaseTypeCassandra) { %>extends AbstractCas
208208
<% } _%>
209209
}
210210

211-
<%_ if ((databaseTypeSql || databaseTypeMongodb || databaseTypeNeo4j)
211+
<%_ if ((databaseTypeSql || databaseTypeMongodb || databaseTypeNeo4j || databaseTypeCouchbase)
212212
&& (!(authenticationTypeOauth2 && applicationTypeMicroservice))) { _%>
213213
@Test
214214
<%_ if (databaseTypeSql && !reactive) { _%>

generators/server/templates/src/test/java/package/web/rest/UserResourceIT.java.ejs

-3
Original file line numberDiff line numberDiff line change
@@ -482,9 +482,6 @@ class UserResourceIT <% if (databaseTypeCassandra) { %>extends AbstractCassandra
482482
}
483483
<%_ } _%>
484484

485-
<%_ if (databaseTypeCouchbase) { _%>
486-
@org.junit.Ignore
487-
<%_ } _%>
488485
@Test
489486
<%_ if (databaseTypeSql && !reactive) { _%>
490487
@Transactional

0 commit comments

Comments
 (0)