#562 - Polishing.

Reformat code. Remove superfluous @Repository annotation.

Original pull request: #564.
This commit is contained in:
Mark Paluch
2020-05-14 09:40:14 +02:00
parent fd52cea0e4
commit 005aa56d5d
17 changed files with 77 additions and 181 deletions

View File

@@ -15,19 +15,18 @@
*/
package example.springdata.couchbase;
import com.couchbase.client.java.Cluster;
import com.couchbase.client.java.manager.query.CreatePrimaryQueryIndexOptions;
import example.springdata.couchbase.model.Airline;
import lombok.RequiredArgsConstructor;
import java.util.List;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.couchbase.core.CouchbaseTemplate;
import com.couchbase.client.java.Cluster;
import com.couchbase.client.java.manager.query.CreatePrimaryQueryIndexOptions;
/**
* Main Class of the module
*
@@ -37,12 +36,9 @@ import org.springframework.data.couchbase.core.CouchbaseTemplate;
@RequiredArgsConstructor
public class CouchbaseMain {
@Autowired
private final CouchbaseTemplate couchbaseTemplate;
@Autowired
private Cluster cluster;
@Autowired CouchbaseTemplate couchbaseTemplate;
@Autowired Cluster cluster;
@PostConstruct
private void postConstruct() {
@@ -51,7 +47,7 @@ public class CouchbaseMain {
CreatePrimaryQueryIndexOptions.createPrimaryQueryIndexOptions().ignoreIfExists(true));
// Need to post-process travel data to add _class attribute
cluster.query("update `travel-sample` set _class='"+Airline.class.getName()+"' where type = 'airline'");
cluster.query("update `travel-sample` set _class='" + Airline.class.getName() + "' where type = 'airline'");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017-2018 the original author or authors.
* Copyright 2017-2020 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.
@@ -19,8 +19,6 @@ import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.couchbase.core.mapping.Document;
import org.springframework.data.couchbase.core.mapping.Field;
/**
* A domain object representing an Airline
@@ -35,15 +33,15 @@ public class Airline {
@Id private String id;
@Field private String type;
private String type;
@Field private String name;
private String name;
@Field private String iata;
private String iata;
@Field private String icao;
private String icao;
@Field private String callsign;
private String callsign;
@Field private String country;
private String country;
}

View File

@@ -1,55 +0,0 @@
/*
* Copyright 2020 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package example.springdata.couchbase.repository;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.couchbase.config.AbstractCouchbaseConfiguration;
/**
* @author Denis Rosa
* Configuration class to connnect with couchbase
*/
@Configuration
public class CouchbaseConfig extends AbstractCouchbaseConfiguration {
@Override
public String getConnectionString() {
return "couchbase://127.0.0.1";
}
@Override
public String getUserName() {
return "Administrator";
}
@Override
public String getPassword() {
return "password";
}
@Override
public String getBucketName() {
return "travel-sample";
}
@Override
protected boolean autoIndexCreation() {
return true;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017-2018 the original author or authors.
* Copyright 2017-2020 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.

View File

@@ -1,3 +1,8 @@
# Increased timeout to fit slower environments like TravisCI
spring.couchbase.env.timeouts.view=15000
spring.couchbase.env.timeouts.query=15000
spring.couchbase.connection-string=couchbase://127.0.0.1
spring.couchbase.username=Administrator
spring.couchbase.password=password
spring.data.couchbase.bucket-name=travel-sample
spring.data.couchbase.auto-index=true

View File

@@ -60,9 +60,11 @@ public class ReactiveAirlineRepositoryIntegrationTests {
@Test
public void shouldFindAirlineN1ql() {
StepVerifier.create(airlineRepository.findByIata("TQ")).assertNext(it -> {
assertThat(it.getCallsign()).isEqualTo("TXW");
}).verifyComplete();
airlineRepository.findByIata("TQ") //
.as(StepVerifier::create) //
.assertNext(it -> {
assertThat(it.getCallsign()).isEqualTo("TXW");
}).verifyComplete();
}
/**
@@ -77,10 +79,11 @@ public class ReactiveAirlineRepositoryIntegrationTests {
.map(Airline::getId) //
.flatMap(airlineRepository::findById);
StepVerifier.create(airline).assertNext(it -> {
airline.as(StepVerifier::create) //
.assertNext(it -> {
assertThat(it.getCallsign()).isEqualTo("TXW");
}).verifyComplete();
assertThat(it.getCallsign()).isEqualTo("TXW");
}).verifyComplete();
}
@@ -89,7 +92,12 @@ public class ReactiveAirlineRepositoryIntegrationTests {
*/
@Test
public void shouldFindAll() {
StepVerifier.create(airlineRepository.findAllBy()).expectNextCount(374).verifyComplete();
airlineRepository.findAllBy().count() //
.as(StepVerifier::create) //
.assertNext(count -> {
assertThat(count).isGreaterThan(100);
}).verifyComplete();
}
/**
@@ -112,6 +120,8 @@ public class ReactiveAirlineRepositoryIntegrationTests {
.map(Airline::getId) //
.flatMap(airlineRepository::findById);
StepVerifier.create(airlineMono).expectNext(airline).verifyComplete();
airlineMono.as(StepVerifier::create) //
.expectNext(airline) //
.verifyComplete();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2017-2018 the original author or authors.
* Copyright 2017-2020 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.
@@ -19,20 +19,18 @@ import static org.assertj.core.api.Assertions.*;
import example.springdata.couchbase.model.Airline;
import example.springdata.couchbase.util.CouchbaseAvailableRule;
import org.springframework.data.couchbase.core.CouchbaseOperations;
import org.springframework.data.couchbase.core.ReactiveCouchbaseOperations;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
import rx.Observable;
import rx.observers.AssertableSubscriber;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.couchbase.core.CouchbaseOperations;
import org.springframework.data.couchbase.core.ReactiveCouchbaseOperations;
import org.springframework.test.context.junit4.SpringRunner;
/**
@@ -67,7 +65,14 @@ public class ReactiveJavaCouchbaseOperationsIntegrationTests {
*/
@Test
public void shouldFindByAll() {
StepVerifier.create( operations.findByQuery( Airline.class).all()).expectNextCount(374).verifyComplete();
operations.findByQuery(Airline.class).all() //
.count() //
.as(StepVerifier::create) //
.assertNext(count -> {
assertThat(count).isGreaterThan(100);
}) //
.verifyComplete();
}
/**
@@ -89,6 +94,7 @@ public class ReactiveJavaCouchbaseOperationsIntegrationTests {
.map(Airline::getId) //
.flatMap(id -> operations.findById(Airline.class).one(id));
StepVerifier.create(airlineMono).expectNext(airline).verifyComplete();
airlineMono.as(StepVerifier::create) //
.expectNext(airline).verifyComplete();
}
}