Skip to content

Commit

Permalink
Fix deprecations in MongoDB and WebFlux modules
Browse files Browse the repository at this point in the history
  • Loading branch information
artembilan committed Jul 9, 2018
1 parent a1f016a commit d4b7cef
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2017 the original author or authors.
* Copyright 2013-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -51,14 +51,15 @@
* @author Amol Nayak
* @author Artem Bilan
* @author Gary Russell
*
* @since 3.0
*/
public class ConfigurableMongoDbMessageStore extends AbstractConfigurableMongoDbMessageStore
implements MessageStore {

public final static String DEFAULT_COLLECTION_NAME = "configurableStoreMessages";

private final Collection<MessageGroupCallback> expiryCallbacks = new LinkedHashSet<MessageGroupCallback>();
private final Collection<MessageGroupCallback> expiryCallbacks = new LinkedHashSet<>();

private volatile boolean timeoutOnIdle;

Expand Down Expand Up @@ -133,7 +134,7 @@ public Message<?> removeMessage(UUID id) {
public long getMessageCount() {
Query query = Query.query(Criteria.where(MessageDocumentFields.MESSAGE_ID).exists(true)
.and(MessageDocumentFields.GROUP_ID).exists(false));
return this.mongoTemplate.getCollection(this.collectionName).count(query.getQueryObject());
return this.mongoTemplate.getCollection(this.collectionName).countDocuments(query.getQueryObject());
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -248,7 +248,7 @@ public MessageMetadata getMessageMetadata(UUID id) {
@Override
@ManagedAttribute
public long getMessageCount() {
return this.template.getCollection(this.collectionName).count();
return this.template.getCollection(this.collectionName).countDocuments();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -40,6 +40,8 @@
*
* @author Oleg Zhurakousky
* @author Xavier Padró
* @author Artem Bilan
*
* @since 2.1
*/
public abstract class MongoDbAvailableTests {
Expand All @@ -48,7 +50,7 @@ public abstract class MongoDbAvailableTests {
public MongoDbAvailableRule redisAvailableRule = new MongoDbAvailableRule();


protected MongoDbFactory prepareMongoFactory(String... additionalCollectionsToDrop) throws Exception {
protected MongoDbFactory prepareMongoFactory(String... additionalCollectionsToDrop) {
MongoDbFactory mongoDbFactory = new SimpleMongoDbFactory(new MongoClient(), "test");
cleanupCollections(mongoDbFactory, additionalCollectionsToDrop);
return mongoDbFactory;
Expand Down Expand Up @@ -151,6 +153,7 @@ public static class TestMongoConverter extends MappingMongoConverter {
public TestMongoConverter(
MongoDbFactory mongoDbFactory,
MappingContext<? extends MongoPersistentEntity<?>, MongoPersistentProperty> mappingContext) {

super(new DefaultDbRefResolver(mongoDbFactory), mappingContext);
}

Expand All @@ -170,7 +173,7 @@ public static class TestCollectionCallback implements CollectionCallback<Long> {

@Override
public Long doInCollection(MongoCollection<Document> collection) throws MongoException, DataAccessException {
return collection.count();
return collection.countDocuments();
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.httpBasic;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.web.reactive.function.client.ExchangeFilterFunctions.Credentials.basicAuthenticationCredentials;
import static org.springframework.web.reactive.function.client.ExchangeFilterFunctions.basicAuthentication;

import java.security.Principal;
import java.util.Collections;
Expand Down Expand Up @@ -139,7 +137,6 @@ public void setup() {
WebTestClient.bindToApplicationContext(this.wac)
.apply(SecurityMockServerConfigurers.springSecurity())
.configureClient()
.filter(basicAuthentication())
.build();
}

Expand Down Expand Up @@ -217,7 +214,7 @@ public void testHttpReactiveProxyFlow() throws Exception {
@SuppressWarnings("unchecked")
public void testHttpReactivePost() {
this.webTestClient.post().uri("/reactivePost")
.attributes(basicAuthenticationCredentials("guest", "guest"))
.headers(headers -> headers.setBasicAuth("guest", "guest"))
.body(Mono.just("foo\nbar\nbaz"), String.class)
.exchange()
.expectStatus().isAccepted();
Expand All @@ -239,7 +236,7 @@ public void testHttpReactivePost() {
public void testSse() {
Flux<String> responseBody =
this.webTestClient.get().uri("/sse")
.attributes(basicAuthenticationCredentials("guest", "guest"))
.headers(headers -> headers.setBasicAuth("guest", "guest"))
.exchange()
.returnResult(String.class)
.getResponseBody();
Expand All @@ -263,15 +260,15 @@ public void testDynamicHttpEndpoint() throws Exception {
this.integrationFlowContext.registration(flow).register();

this.webTestClient.get().uri("/dynamic?name=BAR")
.attributes(basicAuthenticationCredentials("guest", "guest"))
.headers(headers -> headers.setBasicAuth("guest", "guest"))
.exchange()
.expectBody(String.class)
.isEqualTo("bar");

flowRegistration.destroy();

this.webTestClient.get().uri("/dynamic?name=BAZ")
.attributes(basicAuthenticationCredentials("guest", "guest"))
.headers(headers -> headers.setBasicAuth("guest", "guest"))
.exchange()
.expectStatus()
.isNotFound();
Expand Down

0 comments on commit d4b7cef

Please sign in to comment.