#297 - Upgraded samples for Spring Data for Cassandra to Kay.

Adapt to changed API. Migrate tests to use AssertJ. Re-enable Cassandra examples. Adapt Cassandra examples to relocated packages. Adapt reactive Cassandra examples to removed insert(Publisher) method.

Exclude the reporter-config3 library from cassandra-all as it pulls in an outdated hibernate-validator version 4.3.0 that conflicts with Spring Boot's Hibernate Validator baseline and it's not required during tests because we don't publish any metrics.
This commit is contained in:
Mark Paluch
2017-05-05 11:40:49 +02:00
committed by Oliver Gierke
parent 5d34f0a00d
commit d319758bef
27 changed files with 132 additions and 171 deletions

View File

@@ -17,8 +17,8 @@ package example.springdata.cassandra.java8;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.cassandra.config.AbstractCassandraConfiguration;
import org.springframework.data.cassandra.config.SchemaAction;
import org.springframework.data.cassandra.config.java.AbstractCassandraConfiguration;
import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories;
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016 the original author or authors.
* Copyright 2016-2017 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.
@@ -23,7 +23,7 @@ import java.time.LocalDate;
import java.time.ZoneId;
import org.springframework.data.annotation.Id;
import org.springframework.data.cassandra.mapping.Table;
import org.springframework.data.cassandra.core.mapping.Table;
/**
* @author Mark Paluch

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016 the original author or authors.
* Copyright 2016-2017 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.
@@ -18,13 +18,13 @@ package example.springdata.cassandra.java8;
import java.time.LocalDate;
import java.time.ZoneId;
import org.springframework.data.cassandra.mapping.CassandraType;
import org.springframework.data.cassandra.core.mapping.CassandraType;
import org.springframework.data.cassandra.repository.Query;
import org.springframework.data.repository.Repository;
/**
* Repository to manage {@link Order} instances.
*
*
* @author Mark Paluch
*/
public interface OrderRepository extends Repository<Order, String> {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016 the original author or authors.
* Copyright 2016-2017 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.
@@ -16,13 +16,13 @@
package example.springdata.cassandra.java8;
import org.springframework.data.annotation.Id;
import org.springframework.data.cassandra.mapping.Table;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.cassandra.core.mapping.Table;
/**
* @author Mark Paluch
*/

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016 the original author or authors.
* Copyright 2016-2017 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,43 +19,36 @@ import java.util.Optional;
import java.util.stream.Stream;
import org.springframework.data.cassandra.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.Repository;
/**
* Repository to manage {@link Person} instances.
*
*
* @author Mark Paluch
*/
public interface PersonRepository extends Repository<Person, String> {
/**
* Special customization of {@link CrudRepository#findOne(java.io.Serializable)} to return a JDK 8 {@link Optional}.
*
* @param id
* @return
*/
Optional<Person> findOne(String id);
Optional<Person> findById(String id);
Stream<Person> findAll();
/**
* Sample method to derive a query from using JDK 8's {@link Optional} as return type.
*
*
* @param id
* @return
*/
@Query("select * from person where id = ?0")
Optional<Person> findById(String id);
Optional<Person> findPersonById(String id);
/**
* Sample default method to show JDK 8 feature support.
*
*
* @param person
* @return
*/
default Optional<Person> findByPerson(Person person) {
return findById(person == null ? null : person.id);
return findPersonById(person == null ? null : person.id);
}
void deleteAll();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016 the original author or authors.
* Copyright 2016-2017 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.
@@ -15,8 +15,7 @@
*/
package example.springdata.cassandra.java8;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import example.springdata.cassandra.util.CassandraKeyspace;
@@ -35,7 +34,7 @@ import org.springframework.test.context.junit4.SpringRunner;
/**
* Integration test to show the usage of Java 8 features with Spring Data Cassandra.
*
*
* @author Mark Paluch
*/
@RunWith(SpringRunner.class)
@@ -57,8 +56,8 @@ public class Java8IntegrationTests {
Person homer = repository.save(new Person("1", "Homer", "Simpson"));
assertThat(repository.findOne(homer.id).isPresent(), is(true));
assertThat(repository.findOne(homer.id + 1), is(Optional.<Person> empty()));
assertThat(repository.findById(homer.id).isPresent()).isTrue();
assertThat(repository.findById(homer.id + 1)).isEqualTo(Optional.<Person> empty());
}
@Test
@@ -67,8 +66,8 @@ public class Java8IntegrationTests {
Person homer = repository.save(new Person("1", "Homer", "Simpson"));
Optional<Person> result = repository.findByPerson(homer);
assertThat(result.isPresent(), is(true));
assertThat(result.get(), is(homer));
assertThat(result.isPresent()).isTrue();
assertThat(result.get()).isEqualTo(homer);
}
/**
@@ -82,7 +81,7 @@ public class Java8IntegrationTests {
Person bart = repository.save(new Person("2", "Bart", "Simpson"));
try (Stream<Person> stream = repository.findAll()) {
assertThat(stream.collect(Collectors.toList()), hasItems(homer, bart));
assertThat(stream.collect(Collectors.toList())).contains(homer, bart);
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016 the original author or authors.
* Copyright 2016-2017 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.
@@ -15,8 +15,7 @@
*/
package example.springdata.cassandra.java8;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.assertj.core.api.Assertions.*;
import example.springdata.cassandra.util.CassandraKeyspace;
@@ -34,7 +33,7 @@ import org.springframework.test.context.junit4.SpringRunner;
/**
* Integration test to show the usage of JSR-310 date/time types with Spring Data Cassandra.
*
*
* @author Mark Paluch
*/
@RunWith(SpringRunner.class)
@@ -58,7 +57,7 @@ public class Jsr310IntegrationTests {
repository.save(order);
assertThat(repository.findOrderByOrderDateAndZoneId(order.getOrderDate(), order.getZoneId()), is(equalTo(order)));
assertThat(repository.findOrderByOrderDateAndZoneId(order.getOrderDate(), order.getZoneId())).isEqualTo(order);
}
@Test
@@ -71,6 +70,6 @@ public class Jsr310IntegrationTests {
com.datastax.driver.core.LocalDate date = com.datastax.driver.core.LocalDate.fromYearMonthDay(2010, 1, 2);
String zoneId = order.getZoneId().getId();
assertThat(repository.findOrderByDate(date, zoneId), is(equalTo(order)));
assertThat(repository.findOrderByDate(date, zoneId)).isEqualTo(order);
}
}