#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:
committed by
Oliver Gierke
parent
5d34f0a00d
commit
d319758bef
@@ -18,8 +18,8 @@ package example.springdata.cassandra.basic;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
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.core.CassandraTemplate;
|
||||
import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2016 the original author or authors.
|
||||
* Copyright 2013-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,15 +18,16 @@ package example.springdata.cassandra.basic;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import org.springframework.data.cassandra.mapping.Column;
|
||||
import org.springframework.data.cassandra.mapping.PrimaryKey;
|
||||
import org.springframework.data.cassandra.mapping.Table;
|
||||
import org.springframework.data.cassandra.core.mapping.Column;
|
||||
import org.springframework.data.cassandra.core.mapping.PrimaryKey;
|
||||
import org.springframework.data.cassandra.core.mapping.Table;
|
||||
|
||||
/**
|
||||
* Sample user class.
|
||||
*
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Thomas Darimont
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
|
||||
@@ -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,16 +15,16 @@
|
||||
*/
|
||||
package example.springdata.cassandra.convert;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.cassandra.mapping.Table;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.cassandra.core.mapping.Table;
|
||||
|
||||
/**
|
||||
* Sample Addressbook class.
|
||||
*
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@Data
|
||||
|
||||
@@ -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.
|
||||
@@ -21,7 +21,7 @@ import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* Sample Contact class.
|
||||
*
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@Data
|
||||
|
||||
@@ -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.
|
||||
@@ -21,9 +21,9 @@ import java.util.List;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
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.convert.CassandraCustomConversions;
|
||||
import org.springframework.data.cassandra.core.convert.CassandraCustomConversions;
|
||||
import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -32,7 +32,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
/**
|
||||
* {@link Configuration} class to register custom converters.
|
||||
*
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@Configuration
|
||||
|
||||
@@ -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,11 +15,11 @@
|
||||
*/
|
||||
package example.springdata.cassandra.projection;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.cassandra.mapping.Table;
|
||||
|
||||
import lombok.Value;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.cassandra.core.mapping.Table;
|
||||
|
||||
/**
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
|
||||
@@ -16,17 +16,11 @@
|
||||
package example.springdata.cassandra.projection;
|
||||
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
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.core.CassandraTemplate;
|
||||
import org.springframework.data.cassandra.repository.config.EnableCassandraRepositories;
|
||||
|
||||
import com.datastax.driver.core.Session;
|
||||
|
||||
import example.springdata.cassandra.basic.User;
|
||||
|
||||
/**
|
||||
* Basic {@link Configuration} to create the necessary schema for the {@link Customer} table.
|
||||
*
|
||||
|
||||
@@ -18,7 +18,7 @@ package example.springdata.cassandra.udt;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
import org.springframework.data.cassandra.mapping.UserDefinedType;
|
||||
import org.springframework.data.cassandra.core.mapping.UserDefinedType;
|
||||
|
||||
/**
|
||||
* @author Mark Paluch
|
||||
|
||||
@@ -15,15 +15,16 @@
|
||||
*/
|
||||
package example.springdata.cassandra.udt;
|
||||
|
||||
import com.datastax.driver.core.DataType.Name;
|
||||
import com.datastax.driver.core.UDTValue;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.cassandra.mapping.CassandraType;
|
||||
import org.springframework.data.cassandra.mapping.Table;
|
||||
import org.springframework.data.cassandra.core.mapping.CassandraType;
|
||||
import org.springframework.data.cassandra.core.mapping.Table;
|
||||
|
||||
import com.datastax.driver.core.DataType.Name;
|
||||
import com.datastax.driver.core.UDTValue;
|
||||
|
||||
/**
|
||||
* @author Mark Paluch
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
* Copyright 2013-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.basic;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.junit.Assume.*;
|
||||
|
||||
import example.springdata.cassandra.util.CassandraKeyspace;
|
||||
@@ -35,7 +34,7 @@ import com.datastax.driver.core.Session;
|
||||
|
||||
/**
|
||||
* Integration test showing the basic usage of {@link BasicUserRepository}.
|
||||
*
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Thomas Darimont
|
||||
* @author Christoph Strobl
|
||||
@@ -71,7 +70,7 @@ public class BasicUserRepositoryTests {
|
||||
|
||||
user = repository.save(user);
|
||||
|
||||
assertThat(repository.findById(user.getId()), is(user));
|
||||
assertThat(repository.findById(user.getId())).contains(user);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,8 +81,8 @@ public class BasicUserRepositoryTests {
|
||||
|
||||
repository.save(user);
|
||||
|
||||
assertThat(repository.findUserByIdIn(1000), is(nullValue()));
|
||||
assertThat(repository.findUserByIdIn(42), is(equalTo(user)));
|
||||
assertThat(repository.findUserByIdIn(1000)).isNull();
|
||||
assertThat(repository.findUserByIdIn(42)).isEqualTo(user);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -103,7 +102,7 @@ public class BasicUserRepositoryTests {
|
||||
|
||||
repository.save(user);
|
||||
|
||||
assertThat(repository.findUserByUsername(user.getUsername()), is(user));
|
||||
assertThat(repository.findUserByUsername(user.getUsername())).isEqualTo(user);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -123,6 +122,6 @@ public class BasicUserRepositoryTests {
|
||||
|
||||
repository.save(user);
|
||||
|
||||
assertThat(repository.findUsersByLastnameStartsWith("last"), hasItem(user));
|
||||
assertThat(repository.findUsersByLastnameStartsWith("last")).contains(user);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,12 +15,10 @@
|
||||
*/
|
||||
package example.springdata.cassandra.basic;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import example.springdata.cassandra.util.CassandraKeyspace;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
@@ -32,18 +30,20 @@ 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.cassandra.core.AsyncCassandraTemplate;
|
||||
import org.springframework.data.cassandra.core.CassandraOperations;
|
||||
import org.springframework.data.cassandra.core.CassandraTemplate;
|
||||
import org.springframework.data.cassandra.core.WriteListener;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.util.concurrent.ListenableFuture;
|
||||
|
||||
import com.datastax.driver.core.Row;
|
||||
import com.datastax.driver.core.Session;
|
||||
import com.datastax.driver.core.querybuilder.Insert;
|
||||
import com.datastax.driver.core.querybuilder.QueryBuilder;
|
||||
|
||||
/**
|
||||
* Integration test showing the basic usage of {@link CassandraTemplate}.
|
||||
*
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@@ -52,11 +52,12 @@ public class CassandraOperationsIntegrationTests {
|
||||
|
||||
@ClassRule public final static CassandraKeyspace CASSANDRA_KEYSPACE = CassandraKeyspace.onLocalhost();
|
||||
|
||||
@Autowired Session session;
|
||||
@Autowired CassandraOperations template;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
template.truncate("users");
|
||||
template.getCqlOperations().execute("TRUNCATE users");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,14 +73,14 @@ public class CassandraOperationsIntegrationTests {
|
||||
.value("lname", "White") //
|
||||
.ifNotExists(); //
|
||||
|
||||
template.execute(insert);
|
||||
template.getCqlOperations().execute(insert);
|
||||
|
||||
User user = template.selectOneById(User.class, 42L);
|
||||
assertThat(user.getUsername(), is(equalTo("heisenberg")));
|
||||
User user = template.selectOneById(42L, User.class);
|
||||
assertThat(user.getUsername()).isEqualTo("heisenberg");
|
||||
|
||||
List<User> users = template.select(QueryBuilder.select().from("users"), User.class);
|
||||
assertThat(users, hasSize(1));
|
||||
assertThat(users.get(0), is(equalTo(user)));
|
||||
assertThat(users).hasSize(1);
|
||||
assertThat(users.get(0)).isEqualTo(user);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -100,9 +101,9 @@ public class CassandraOperationsIntegrationTests {
|
||||
user.setFirstname(null);
|
||||
template.update(user);
|
||||
|
||||
User loaded = template.selectOneById(User.class, 42L);
|
||||
assertThat(loaded.getUsername(), is(equalTo("heisenberg")));
|
||||
assertThat(loaded.getFirstname(), is(nullValue()));
|
||||
User loaded = template.selectOneById(42L, User.class);
|
||||
assertThat(loaded.getUsername()).isEqualTo("heisenberg");
|
||||
assertThat(loaded.getFirstname()).isNull();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -119,21 +120,16 @@ public class CassandraOperationsIntegrationTests {
|
||||
|
||||
final CountDownLatch countDownLatch = new CountDownLatch(1);
|
||||
|
||||
template.insertAsynchronously(user, new WriteListener<User>() {
|
||||
AsyncCassandraTemplate asyncTemplate = new AsyncCassandraTemplate(session);
|
||||
|
||||
@Override
|
||||
public void onWriteComplete(Collection<User> entities) {
|
||||
countDownLatch.countDown();
|
||||
}
|
||||
ListenableFuture<User> future = asyncTemplate.insert(user);
|
||||
|
||||
@Override
|
||||
public void onException(Exception x) {}
|
||||
});
|
||||
future.addCallback(it -> countDownLatch.countDown(), throwable -> countDownLatch.countDown());
|
||||
|
||||
countDownLatch.await(5, TimeUnit.SECONDS);
|
||||
|
||||
User loaded = template.selectOneById(User.class, user.getId());
|
||||
assertThat(loaded, is(equalTo(user)));
|
||||
User loaded = template.selectOneById(user.getId(), User.class);
|
||||
assertThat(loaded).isEqualTo(user);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,13 +149,13 @@ public class CassandraOperationsIntegrationTests {
|
||||
template.insert(user);
|
||||
|
||||
Long id = template.selectOne(QueryBuilder.select("user_id").from("users"), Long.class);
|
||||
assertThat(id, is(user.getId()));
|
||||
assertThat(id).isEqualTo(user.getId());
|
||||
|
||||
Row row = template.selectOne(QueryBuilder.select("user_id").from("users"), Row.class);
|
||||
assertThat(row.getLong(0), is(user.getId()));
|
||||
assertThat(row.getLong(0)).isEqualTo(user.getId());
|
||||
|
||||
Map<String, Object> map = template.selectOne(QueryBuilder.select().from("users"), Map.class);
|
||||
assertThat(map, hasEntry("user_id", user.getId()));
|
||||
assertThat(map, hasEntry("fname", "Walter"));
|
||||
assertThat(map).containsEntry("user_id", user.getId());
|
||||
assertThat(map).containsEntry("fname", "Walter");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.convert;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import example.springdata.cassandra.util.CassandraKeyspace;
|
||||
|
||||
@@ -47,7 +46,7 @@ public class ConversionIntegrationTests {
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
operations.truncate("addressbook");
|
||||
operations.getCqlOperations().execute("TRUNCATE addressbook");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,11 +66,11 @@ public class ConversionIntegrationTests {
|
||||
|
||||
Row row = operations.selectOne(QueryBuilder.select().from("addressbook"), Row.class);
|
||||
|
||||
assertThat(row, is(notNullValue()));
|
||||
assertThat(row).isNotNull();
|
||||
|
||||
assertThat(row.getString("id"), is(equalTo("private")));
|
||||
assertThat(row.getString("me"), containsString("\"firstname\":\"Walter\""));
|
||||
assertThat(row.getList("friends", String.class), hasSize(2));
|
||||
assertThat(row.getString("id")).isEqualTo("private");
|
||||
assertThat(row.getString("me")).contains("\"firstname\":\"Walter\"");
|
||||
assertThat(row.getList("friends", String.class)).hasSize(2);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,8 +90,8 @@ public class ConversionIntegrationTests {
|
||||
|
||||
Addressbook loaded = operations.selectOne(QueryBuilder.select().from("addressbook"), Addressbook.class);
|
||||
|
||||
assertThat(loaded.getMe(), is(equalTo(addressbook.getMe())));
|
||||
assertThat(loaded.getFriends(), is(equalTo(addressbook.getFriends())));
|
||||
assertThat(loaded.getMe()).isEqualTo(addressbook.getMe());
|
||||
assertThat(loaded.getFriends()).isEqualTo(addressbook.getFriends());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,7 +111,7 @@ public class ConversionIntegrationTests {
|
||||
|
||||
CustomAddressbook loaded = operations.selectOne(QueryBuilder.select().from("addressbook"), CustomAddressbook.class);
|
||||
|
||||
assertThat(loaded.getTheId(), is(equalTo(addressbook.getId())));
|
||||
assertThat(loaded.getMyDetailsAsJson(), containsString("\"firstname\":\"Walter\""));
|
||||
assertThat(loaded.getTheId()).isEqualTo(addressbook.getId());
|
||||
assertThat(loaded.getMyDetailsAsJson()).contains("\"firstname\":\"Walter\"");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.projection;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import example.springdata.cassandra.util.CassandraKeyspace;
|
||||
|
||||
@@ -33,7 +32,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link CustomerRepository} to show projection capabilities.
|
||||
*
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@@ -60,8 +59,8 @@ public class CustomerRepositoryIntegrationTest {
|
||||
|
||||
Collection<CustomerProjection> result = customers.findAllProjectedBy();
|
||||
|
||||
assertThat(result, hasSize(2));
|
||||
assertThat(result.iterator().next().getFirstname(), is("Carter"));
|
||||
assertThat(result).hasSize(2);
|
||||
assertThat(result.iterator().next().getFirstname()).isEqualTo("Carter");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -69,8 +68,8 @@ public class CustomerRepositoryIntegrationTest {
|
||||
|
||||
Collection<CustomerProjection> result = customers.findById("d", CustomerProjection.class);
|
||||
|
||||
assertThat(result, hasSize(1));
|
||||
assertThat(result.iterator().next().getFirstname(), is("Dave"));
|
||||
assertThat(result).hasSize(1);
|
||||
assertThat(result.iterator().next().getFirstname()).isEqualTo("Dave");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -78,11 +77,11 @@ public class CustomerRepositoryIntegrationTest {
|
||||
|
||||
CustomerSummary result = customers.findProjectedById(dave.getId(), CustomerSummary.class);
|
||||
|
||||
assertThat(result, is(notNullValue()));
|
||||
assertThat(result.getFullName(), is("Dave Matthews"));
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getFullName()).isEqualTo("Dave Matthews");
|
||||
|
||||
// Proxy backed by original instance as the projection uses dynamic elements
|
||||
assertThat(((TargetAware) result).getTarget(), is(instanceOf(Customer.class)));
|
||||
assertThat(((TargetAware) result).getTarget()).isInstanceOf(Customer.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -90,9 +89,8 @@ public class CustomerRepositoryIntegrationTest {
|
||||
|
||||
CustomerProjection result = customers.findProjectedById(dave.getId());
|
||||
|
||||
assertThat(result, is(notNullValue()));
|
||||
assertThat(result.getFirstname(), is("Dave"));
|
||||
assertThat(((TargetAware) result).getTarget(), is(instanceOf(Customer.class)));
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.getFirstname()).isEqualTo("Dave");
|
||||
assertThat(((TargetAware) result).getTarget()).isInstanceOf(Customer.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,8 +28,8 @@ import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
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.core.CassandraAdminOperations;
|
||||
import org.springframework.data.cassandra.core.CassandraOperations;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
@@ -40,7 +40,7 @@ import com.datastax.driver.core.UserType;
|
||||
|
||||
/**
|
||||
* Integration test to show User-Defined type support.
|
||||
*
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@@ -74,7 +74,7 @@ public class UserDefinedTypeIntegrationTest {
|
||||
|
||||
@Before
|
||||
public void before() throws Exception {
|
||||
operations.truncate("person");
|
||||
operations.getCqlOperations().execute("TRUNCATE person");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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;
|
||||
|
||||
/**
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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> {
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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();
|
||||
|
||||
17
cassandra/java8/src/test/java/example/springdata/cassandra/java8/Java8IntegrationTests.java
Normal file → Executable file
17
cassandra/java8/src/test/java/example/springdata/cassandra/java8/Java8IntegrationTests.java
Normal file → Executable 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
11
cassandra/java8/src/test/java/example/springdata/cassandra/java8/Jsr310IntegrationTests.java
Normal file → Executable file
11
cassandra/java8/src/test/java/example/springdata/cassandra/java8/Jsr310IntegrationTests.java
Normal file → Executable 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,26 +11,8 @@
|
||||
<artifactId>spring-data-cassandra-reactive</artifactId>
|
||||
<name>Spring Data Cassandra - Reactive features</name>
|
||||
|
||||
<properties>
|
||||
<spring-data-releasetrain.version>Kay-RC2</spring-data-releasetrain.version>
|
||||
<spring.version>5.0.0.RC3</spring.version>
|
||||
<reactor.version>3.1.0.M3</reactor.version>
|
||||
<rxjava.version>2.1.3</rxjava.version>
|
||||
<rxjava-reactive-streams.version>1.2.1</rxjava-reactive-streams.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-commons</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-cassandra</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.projectreactor</groupId>
|
||||
<artifactId>reactor-core</artifactId>
|
||||
@@ -39,13 +21,11 @@
|
||||
<dependency>
|
||||
<groupId>io.reactivex.rxjava2</groupId>
|
||||
<artifactId>rxjava</artifactId>
|
||||
<version>${rxjava.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.reactivex</groupId>
|
||||
<artifactId>rxjava-reactive-streams</artifactId>
|
||||
<version>${rxjava-reactive-streams.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
||||
@@ -73,13 +73,13 @@ public class ReactiveCassandraTemplateIntegrationTest {
|
||||
|
||||
template.count(Person.class) //
|
||||
.doOnNext(System.out::println) //
|
||||
.thenMany(template.insert(Flux.just(new Person("Hank", "Schrader", 43), //
|
||||
new Person("Mike", "Ehrmantraut", 62)))) //
|
||||
.thenMany(Flux.just(new Person("Hank", "Schrader", 43), //
|
||||
new Person("Mike", "Ehrmantraut", 62)))
|
||||
.flatMap(template::insert) //
|
||||
.last() //
|
||||
.flatMap(v -> template.count(Person.class)) //
|
||||
.doOnNext(System.out::println) //
|
||||
.doOnSuccess(it -> countDownLatch.countDown()) //
|
||||
.doOnError(throwable -> countDownLatch.countDown()) //
|
||||
.doOnTerminate((i, t) -> countDownLatch.countDown()) //
|
||||
.subscribe();
|
||||
|
||||
countDownLatch.await();
|
||||
|
||||
@@ -75,8 +75,7 @@ public class ReactivePersonRepositoryIntegrationTest {
|
||||
.last() //
|
||||
.flatMap(v -> repository.count()) //
|
||||
.doOnNext(System.out::println) //
|
||||
.doOnSuccess(it -> countDownLatch.countDown()) //
|
||||
.doOnError(throwable -> countDownLatch.countDown()) //
|
||||
.doOnTerminate((l, t) -> countDownLatch.countDown()) //
|
||||
.subscribe();
|
||||
|
||||
countDownLatch.await();
|
||||
|
||||
@@ -55,7 +55,7 @@ public class RxJava2PersonRepositoryIntegrationTest {
|
||||
|
||||
Completable deleteAll = repository.deleteAll();
|
||||
|
||||
Flowable<Person> save = repository.saveAll(Flowable.just(new Person("Walter", "White", 50), //
|
||||
Observable<Person> save = repository.saveAll(Observable.just(new Person("Walter", "White", 50), //
|
||||
new Person("Skyler", "White", 45), //
|
||||
new Person("Saul", "Goodman", 42), //
|
||||
new Person("Jesse", "Pinkman", 27)));
|
||||
@@ -73,15 +73,14 @@ public class RxJava2PersonRepositoryIntegrationTest {
|
||||
|
||||
repository.count() //
|
||||
.doOnSuccess(System.out::println) //
|
||||
.toFlowable() //
|
||||
.switchMap(count -> repository.saveAll(Flowable.just(new Person("Hank", "Schrader", 43), //
|
||||
.toObservable() //
|
||||
.switchMap(count -> repository.saveAll(Observable.just(new Person("Hank", "Schrader", 43), //
|
||||
new Person("Mike", "Ehrmantraut", 62)))) //
|
||||
.lastElement() //
|
||||
.toSingle() //
|
||||
.flatMap(v -> repository.count()) //
|
||||
.doOnSuccess(System.out::println) //
|
||||
.doAfterTerminate(countDownLatch::countDown) //
|
||||
.doOnError(throwable -> countDownLatch.countDown()) //
|
||||
.subscribe();
|
||||
|
||||
countDownLatch.await();
|
||||
|
||||
@@ -32,6 +32,10 @@
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-all</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.addthis.metrics</groupId>
|
||||
<artifactId>reporter-config3</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user