Files
spring-data-examples/jpa/javaslang/src/test/java/example/PersonRepositoryIntegrationTests.java
Oliver Gierke cd36f6f0da #231 - Added example for Javaslang support on repositories.
Added an example that shows how Javaslang's collection types and Option can be used as repository query methods starting with Spring Data Ingalls RC1.
2016-12-14 14:05:38 +01:00

75 lines
2.1 KiB
Java

/*
* Copyright 2016 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;
import static org.assertj.core.api.Assertions.*;
import javaslang.collection.Seq;
import javaslang.control.Option;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.transaction.annotation.Transactional;
/**
* Integration tests for {@link PersonRepository} showing Javaslang support at repsoitory query methods.
*
* @author Oliver Gierke
*/
@RunWith(SpringRunner.class)
@Transactional
@SpringBootTest
public class PersonRepositoryIntegrationTests {
@Autowired PersonRepository people;
@SpringBootApplication
static class Configuration {}
/**
* @see #231
*/
@Test
public void readsPersonIntoJavaslangOptionById() {
Person dave = people.save(new Person("Dave", "Matthews"));
Option<Person> result = people.findById(dave.getId());
assertThat(result.isEmpty()).isFalse();
assertThat(result.get()).isEqualTo(dave);
}
/**
* @see #231
*/
@Test
public void readsPeopleIntoJavaslangSeq() {
Person dave = people.save(new Person("Dave", "Matthews"));
Person carter = people.save(new Person("Carter", "Beauford"));
Seq<Person> result = people.findByFirstnameContaining("art");
assertThat(result.contains(carter)).isTrue();
assertThat(result.contains(dave)).isFalse();
}
}