Javaslang Fetched Upstream and Updated (#1368)

* javaslang updates

* groovy

* update and clean from upstream

* upate from upstream and clean

* update

* cleanup

* clean
This commit is contained in:
Andrew Evans 2017-03-12 04:24:32 -06:00 committed by adamd1985
parent dc142e8423
commit b2b5349438
8 changed files with 367 additions and 0 deletions

5
spring-data-javaslang/.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
/target/
/project/
.idea
.classpath
.eclipse

View File

@ -0,0 +1,133 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>spring-data-javaslangb</groupId>
<artifactId>spring-data-javaslangb</artifactId>
<version>0.0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
<maven-compiler-plugin.version>3.1</maven-compiler-plugin.version>
<groovy-eclipse-compiler.version>2.9.1-01</groovy-eclipse-compiler.version>
<groovy-eclipse-batch.version>2.3.7-01</groovy-eclipse-batch.version>
<org.codehouse.groovy.version>2.4.8</org.codehouse.groovy.version>
<javaslang.version>2.0.5</javaslang.version>
<junit.version>4.12</junit.version>
<spring-boot.version>1.5.1.RELEASE</spring-boot.version>
<spring-context.version>4.3.6.RELEASE</spring-context.version>
<spring-core.version>4.3.6.RELEASE</spring-core.version>
<spring-test.version>4.3.6.RELEASE</spring-test.version>
<project.build.testSourceDirectory>${basedir}/src/test/java</project.build.testSourceDirectory>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.1.RELEASE</version>
</parent>
<profiles>
<profile>
<id>test-app</id>
<build>
<defaultGoal>verify</defaultGoal>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>spring-boot-run</id>
<phase>verify</phase>
<goals>
<goal>run</goal>
</goals>
<inherited>false</inherited>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<testSourceDirectory>${project.build.testSourceDirectory}</testSourceDirectory>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<!-- https://mvnrepository.com/artifact/com.h2database/h2 -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.193</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.javaslang/javaslang -->
<dependency>
<groupId>io.javaslang</groupId>
<artifactId>javaslang</artifactId>
<version>${javaslang.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-jpa -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>1.11.0.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-jpa -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${spring-boot.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring-context.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-core -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring-core.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,45 @@
package com.baeldung.spring_data.model;
import javaslang.collection.Seq;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.CollectionTable;
import javax.persistence.Column;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
@Entity
@Table(name = "book")
public class Book {
@GeneratedValue
@Id
private Long id;
private String title;
private Seq<String> authors;
public void setTitle(String title){
this.title = title;
}
public String getTitle(){
return this.title;
}
public Long getId(){
return this.id;
}
public void setAuthors(Seq authors){
this.authors = authors;
}
public Seq getAuthors(){
return this.authors;
}
}

View File

@ -0,0 +1,41 @@
package com.baeldung.spring_data.model;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.List;
@Entity
@Table(name = "java_book")
public class JavaBook {
@GeneratedValue
@Id
private Long id;
private String title;
@ElementCollection
private List<String> authors;
public void setAuthors(List<String> authors){
this.authors = authors;
}
public void setTitle(String title){
this.title = title;
}
public String getTitle(){
return this.title;
}
public Long getId(){
return this.id;
}
}

View File

@ -0,0 +1,19 @@
package com.baeldung.spring_data.repository;
import com.baeldung.spring_data.model.Book;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import javaslang.collection.Seq;
import javaslang.control.Option;
@Repository
public interface BookRepository extends JpaRepository<Book,Long>{
Book save(Book book);
Option<Book> findById(Long id);
Option<Seq<Book>> findByTitleContaining(String title);
}

View File

@ -0,0 +1,17 @@
package com.baeldung.spring_data.repository;
import com.baeldung.spring_data.model.JavaBook;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface JavaBookRepository extends JpaRepository<JavaBook,Long>{
JavaBook save(JavaBook book);
JavaBook findById(Long id);
List<JavaBook> findByTitleContaining(String title);
}

View File

@ -0,0 +1,21 @@
package com.baeldung.spring_data_app;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.transaction.annotation.EnableTransactionManagement;
@Configuration
@EnableJpaRepositories("com.baeldung.spring_data.repository")
@EnableTransactionManagement
@EntityScan("com.baeldung.spring_data.model")
@SpringBootApplication
public class MainApp {
public static void main(String[] args){
SpringApplication.run(MainApp.class, args);
}
}

View File

@ -0,0 +1,86 @@
package com.baeldung.spring_data_tests;
import org.junit.Test;
import org.junit.runner.RunWith;
import com.baeldung.spring_data_app.MainApp;
import com.baeldung.spring_data.model.Book;
import com.baeldung.spring_data.model.JavaBook;
import com.baeldung.spring_data.repository.BookRepository;
import com.baeldung.spring_data.repository.JavaBookRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.test.context.junit4.SpringRunner;
import javaslang.collection.Seq;
import javaslang.collection.List;
import javaslang.control.Option;
import java.util.ArrayList;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = MainApp.class,webEnvironment = WebEnvironment.NONE)
public class SpringTests {
@Autowired
JavaBookRepository javaRepository;
@Autowired
BookRepository repository;
@Test
public void should_return_seq(){
Seq authors = List.of("author1","author2");
Book testBook = new Book();
testBook.setTitle("Javaslang in Spring Data Seq Test Return");
testBook.setAuthors(authors);
Book book = repository.save(testBook);
Option<Seq<Book>> books = repository.findByTitleContaining("Seq Test");
assert(!books.isEmpty());
}
@Test
public void should_return_option_with_book(){
Seq authors = List.of("author1","author2");
Book testBook = new Book();
testBook.setTitle("Javaslang in Spring Data");
testBook.setAuthors(authors);
Book book = repository.save(testBook);
Option<Book> retBook = repository.findById(1L);
assert(retBook.isDefined() && !retBook.isEmpty());
assert(retBook.get() != null);
}
@Test
public void should_return_list(){
ArrayList<String> authors = new ArrayList<String>();
authors.add("author1");
authors.add("author2");
JavaBook testBook = new JavaBook();
testBook.setTitle("Javaslang in Spring Data Seq Return");
testBook.setAuthors(authors);
JavaBook book = javaRepository.save(testBook);
java.util.List<JavaBook> books = javaRepository.findByTitleContaining("Seq");
assert(!books.isEmpty());
assert(books.size() == 1);
assert(books.get(0).getTitle().equals("Javaslang in Spring Data Seq Return"));
}
@Test
public void should_return_book(){
ArrayList<String> authors = new ArrayList<String>();
authors.add("author1");
authors.add("author2");
JavaBook testBook = new JavaBook();
testBook.setTitle("Javaslang in Spring Data");
testBook.setAuthors(authors);
JavaBook book = javaRepository.save(testBook);
JavaBook retBook = javaRepository.findById(1L);
assert(retBook != null);
assert(retBook.getId() == 1L);
assert(retBook.getTitle().contains("Data"));
}
}