Merge branch 'master' of https://github.com/eugenp/tutorials
This commit is contained in:
@@ -0,0 +1,23 @@
|
|||||||
|
package com.baeldung.stream;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
|
class PrimitiveStreams {
|
||||||
|
|
||||||
|
int min(int[] integers) {
|
||||||
|
return Arrays.stream(integers).min().getAsInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
int max(int... integers) {
|
||||||
|
return IntStream.of(integers).max().getAsInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
int sum(int... integers) {
|
||||||
|
return IntStream.of(integers).sum();
|
||||||
|
}
|
||||||
|
|
||||||
|
double avg(int... integers) {
|
||||||
|
return IntStream.of(integers).average().getAsDouble();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -38,23 +38,14 @@ public class CounterUtil {
|
|||||||
|
|
||||||
public static void counterWithMutableInteger(Map<String, MutableInteger> counterMap) {
|
public static void counterWithMutableInteger(Map<String, MutableInteger> counterMap) {
|
||||||
for (String country : COUNTRY_NAMES) {
|
for (String country : COUNTRY_NAMES) {
|
||||||
MutableInteger oldValue = counterMap.get(country);
|
counterMap.compute(country, (k, v) -> v == null ? new MutableInteger(0) : v)
|
||||||
if (oldValue != null) {
|
.increment();
|
||||||
oldValue.increment();
|
|
||||||
} else {
|
|
||||||
counterMap.put(country, new MutableInteger(1));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void counterWithPrimitiveArray(Map<String, int[]> counterMap) {
|
public static void counterWithPrimitiveArray(Map<String, int[]> counterMap) {
|
||||||
for (String country : COUNTRY_NAMES) {
|
for (String country : COUNTRY_NAMES) {
|
||||||
int[] oldCounter = counterMap.get(country);
|
counterMap.compute(country, (k, v) -> v == null ? new int[] { 0 } : v)[0]++;
|
||||||
if (oldCounter != null) {
|
|
||||||
oldCounter[0] += 1;
|
|
||||||
} else {
|
|
||||||
counterMap.put(country, new int[] { 1 });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,97 @@
|
|||||||
|
package com.baeldung.stream;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
public class PrimitiveStreamsUnitTest {
|
||||||
|
|
||||||
|
private PrimitiveStreams streams = new PrimitiveStreams();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenAnArrayOfIntegersWhenMinIsCalledThenCorrectMinIsReturned() {
|
||||||
|
int[] integers = new int[] {20, 98, 12, 7, 35};
|
||||||
|
int min = streams.min(integers); // returns 7
|
||||||
|
|
||||||
|
assertEquals(7, min);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenAnArrayOfIntegersWhenMaxIsCalledThenCorrectMaxIsReturned() {
|
||||||
|
int max = streams.max(20, 98, 12, 7, 35);
|
||||||
|
|
||||||
|
assertEquals(98, max);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenAnArrayOfIntegersWhenSumIsCalledThenCorrectSumIsReturned() {
|
||||||
|
int sum = streams.sum(20, 98, 12, 7, 35);
|
||||||
|
|
||||||
|
assertEquals(172, sum);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenAnArrayOfIntegersWhenAvgIsCalledThenCorrectAvgIsReturned() {
|
||||||
|
double avg = streams.avg(20, 98, 12, 7, 35);
|
||||||
|
|
||||||
|
assertTrue(34.4 == avg);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenARangeOfIntegersWhenIntStreamSumIsCalledThenCorrectSumIsReturned() {
|
||||||
|
int sum = IntStream.range(1, 10).sum();
|
||||||
|
|
||||||
|
assertEquals(45, sum);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenARangeClosedOfIntegersWhenIntStreamSumIsCalledThenCorrectSumIsReturned() {
|
||||||
|
int sum = IntStream.rangeClosed(1, 10).sum();
|
||||||
|
|
||||||
|
assertEquals(55, sum);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenARangeWhenForEachIsCalledThenTheIndicesWillBePrinted() {
|
||||||
|
IntStream.rangeClosed(1, 5).parallel().forEach(System.out::println);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenAnArrayWhenSumIsCalledThenTheCorrectSumIsReturned() {
|
||||||
|
|
||||||
|
int sum = Arrays.asList(33,45).stream().mapToInt(a -> a).sum();
|
||||||
|
|
||||||
|
assertEquals(78, sum);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenAnIntStreamThenGetTheEvenIntegers() {
|
||||||
|
List<Integer> evenInts = IntStream.rangeClosed(1, 10)
|
||||||
|
.filter(i -> i % 2 == 0)
|
||||||
|
.boxed()
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
List<Integer> expected = IntStream.of(2, 4, 6, 8, 10).boxed().collect(Collectors.toList());
|
||||||
|
|
||||||
|
assertEquals(expected, evenInts);
|
||||||
|
}
|
||||||
|
|
||||||
|
class Person {
|
||||||
|
private int age;
|
||||||
|
|
||||||
|
Person(int age) {
|
||||||
|
this.age = age;
|
||||||
|
}
|
||||||
|
|
||||||
|
int getAge() {
|
||||||
|
return age;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
-64
@@ -10,9 +10,9 @@ import java.util.concurrent.*;
|
|||||||
|
|
||||||
import static junit.framework.TestCase.assertTrue;
|
import static junit.framework.TestCase.assertTrue;
|
||||||
|
|
||||||
public class WaitingForThreadsToFinishTest {
|
public class WaitingForThreadsToFinishManualTest {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(WaitingForThreadsToFinishTest.class);
|
private static final Logger LOG = LoggerFactory.getLogger(WaitingForThreadsToFinishManualTest.class);
|
||||||
private final static ExecutorService WORKER_THREAD_POOL = Executors.newFixedThreadPool(10);
|
private final static ExecutorService WORKER_THREAD_POOL = Executors.newFixedThreadPool(10);
|
||||||
|
|
||||||
public void awaitTerminationAfterShutdown(ExecutorService threadPool) {
|
public void awaitTerminationAfterShutdown(ExecutorService threadPool) {
|
||||||
@@ -142,66 +142,4 @@ public class WaitingForThreadsToFinishTest {
|
|||||||
awaitTerminationAfterShutdown(WORKER_THREAD_POOL);
|
awaitTerminationAfterShutdown(WORKER_THREAD_POOL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void givenMultipleThreads_whenUsingCompletableFutures_thenMainThreadShouldWaitForAllToFinish() {
|
|
||||||
|
|
||||||
CompletableFuture<String> future1 = CompletableFuture.supplyAsync(() -> {
|
|
||||||
|
|
||||||
try {
|
|
||||||
Thread.sleep(1000);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return "Hello";
|
|
||||||
});
|
|
||||||
|
|
||||||
CompletableFuture<String> future2 = CompletableFuture.supplyAsync(() -> {
|
|
||||||
|
|
||||||
try {
|
|
||||||
Thread.sleep(5000);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return "Beautiful";
|
|
||||||
});
|
|
||||||
|
|
||||||
CompletableFuture<String> future3 = CompletableFuture.supplyAsync(() -> {
|
|
||||||
|
|
||||||
try {
|
|
||||||
Thread.sleep(3000);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
return "World";
|
|
||||||
});
|
|
||||||
|
|
||||||
long startProcessingTime = System.currentTimeMillis();
|
|
||||||
CompletableFuture<Void> combinedFuture = CompletableFuture.allOf(future1, future2, future3);
|
|
||||||
combinedFuture.join();
|
|
||||||
|
|
||||||
long totalProcessingTime = System.currentTimeMillis() - startProcessingTime;
|
|
||||||
assertTrue(totalProcessingTime >= 5000 && totalProcessingTime < 6000);
|
|
||||||
|
|
||||||
LOG.debug("Responses from all threads are available after " + totalProcessingTime + " milliseconds");
|
|
||||||
|
|
||||||
try {
|
|
||||||
String thread1Response = future1.get();
|
|
||||||
assertTrue(thread1Response.equals("Hello"));
|
|
||||||
|
|
||||||
String thread2Response = future2.get();
|
|
||||||
assertTrue(thread2Response.equals("Beautiful"));
|
|
||||||
|
|
||||||
String thread3Response = future3.get();
|
|
||||||
assertTrue(thread3Response.equals("World"));
|
|
||||||
|
|
||||||
} catch (InterruptedException | ExecutionException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
awaitTerminationAfterShutdown(WORKER_THREAD_POOL);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -54,7 +54,7 @@ public class GenericFile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getFileInfo() {
|
public String getFileInfo() {
|
||||||
return String.format("File Name: %s\n" + " Extension: %s\n" + " Date Created: %s\n" + " Version: %s\n", this.getName(), this.getExtension(), this.getDateCreated(), this.getVersion());
|
return "Generic File Impl";
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object read() {
|
public Object read() {
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ public class ImageFile extends GenericFile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getFileInfo() {
|
public String getFileInfo() {
|
||||||
return String.format(" %s Height: %d\n Width: %d", super.getFileInfo(), this.getHeight(), this.getWidth());
|
return "Image File Impl";
|
||||||
}
|
}
|
||||||
|
|
||||||
public String read() {
|
public String read() {
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ public class TextFile extends GenericFile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getFileInfo() {
|
public String getFileInfo() {
|
||||||
return String.format(" %s Word Count: %d", super.getFileInfo(), wordCount);
|
return "Text File Impl";
|
||||||
}
|
}
|
||||||
|
|
||||||
public String read() {
|
public String read() {
|
||||||
|
|||||||
@@ -1,52 +0,0 @@
|
|||||||
<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>
|
|
||||||
<artifactId>flyway</artifactId>
|
|
||||||
<version>1.0</version>
|
|
||||||
<name>flyway</name>
|
|
||||||
<packaging>pom</packaging>
|
|
||||||
<description>A sample project to demonstrate Flyway migrations</description>
|
|
||||||
|
|
||||||
<parent>
|
|
||||||
<groupId>com.baeldung</groupId>
|
|
||||||
<artifactId>parent-modules</artifactId>
|
|
||||||
<version>1.0.0-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<modules>
|
|
||||||
<module>spring-flyway</module>
|
|
||||||
</modules>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>mysql</groupId>
|
|
||||||
<artifactId>mysql-connector-java</artifactId>
|
|
||||||
<version>${mysql.version}</version>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
<dependencyManagement>
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-dependencies</artifactId>
|
|
||||||
<version>${spring.boot.version}</version>
|
|
||||||
<type>pom</type>
|
|
||||||
<scope>import</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
</dependencyManagement>
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.flywaydb</groupId>
|
|
||||||
<artifactId>flyway-maven-plugin</artifactId>
|
|
||||||
<version>${flyway-maven-plugin.version}</version>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
<properties>
|
|
||||||
<mysql.version>6.0.5</mysql.version>
|
|
||||||
<flyway-maven-plugin.version>4.0.3</flyway-maven-plugin.version>
|
|
||||||
<spring.boot.version>1.5.8.RELEASE</spring.boot.version>
|
|
||||||
</properties>
|
|
||||||
</project>
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
<?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>
|
|
||||||
|
|
||||||
<artifactId>spring-flyway</artifactId>
|
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
|
||||||
<packaging>jar</packaging>
|
|
||||||
|
|
||||||
<name>spring-flyway</name>
|
|
||||||
<description>Spring Boot Test Flyway Migrations</description>
|
|
||||||
|
|
||||||
<parent>
|
|
||||||
<artifactId>flyway</artifactId>
|
|
||||||
<groupId>com.baeldung</groupId>
|
|
||||||
<version>1.0</version>
|
|
||||||
<relativePath>../../flyway</relativePath>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<properties>
|
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
|
||||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
|
||||||
<java.version>1.8</java.version>
|
|
||||||
</properties>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.flywaydb</groupId>
|
|
||||||
<artifactId>flyway-core</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.projectlombok</groupId>
|
|
||||||
<artifactId>lombok</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.h2database</groupId>
|
|
||||||
<artifactId>h2</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
</project>
|
|
||||||
-12
@@ -1,12 +0,0 @@
|
|||||||
package com.baeldung.springflyway;
|
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
||||||
|
|
||||||
@SpringBootApplication
|
|
||||||
public class SpringFlywayApplication {
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
SpringApplication.run(SpringFlywayApplication.class, args);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
package com.baeldung.springflyway.entities;
|
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Builder;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.GeneratedValue;
|
|
||||||
import javax.persistence.Id;
|
|
||||||
|
|
||||||
@Entity
|
|
||||||
@Data
|
|
||||||
@AllArgsConstructor
|
|
||||||
@NoArgsConstructor
|
|
||||||
@Builder
|
|
||||||
public class Customer {
|
|
||||||
|
|
||||||
@Id
|
|
||||||
@GeneratedValue
|
|
||||||
private Long id;
|
|
||||||
|
|
||||||
private String firstName;
|
|
||||||
private String lastName;
|
|
||||||
|
|
||||||
private String email;
|
|
||||||
|
|
||||||
}
|
|
||||||
-14
@@ -1,14 +0,0 @@
|
|||||||
package com.baeldung.springflyway.migration;
|
|
||||||
|
|
||||||
import org.flywaydb.core.api.migration.spring.SpringJdbcMigration;
|
|
||||||
import org.springframework.jdbc.core.JdbcTemplate;
|
|
||||||
|
|
||||||
public class V2__uk_lastname_customer implements SpringJdbcMigration {
|
|
||||||
|
|
||||||
final String CUSTOMER_LASTNAME_UK = "ALTER TABLE customer ADD CONSTRAINT uk_customer_lastname UNIQUE(last_name);";
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void migrate(final JdbcTemplate jdbcTemplate) throws Exception {
|
|
||||||
jdbcTemplate.execute(CUSTOMER_LASTNAME_UK);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-11
@@ -1,11 +0,0 @@
|
|||||||
package com.baeldung.springflyway.repositories;
|
|
||||||
|
|
||||||
import com.baeldung.springflyway.entities.Customer;
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public interface CustomerRepository extends JpaRepository<Customer, Long> {
|
|
||||||
|
|
||||||
Optional<Customer> findByEmail(String email);
|
|
||||||
}
|
|
||||||
-28
@@ -1,28 +0,0 @@
|
|||||||
package com.baeldung.springflyway;
|
|
||||||
|
|
||||||
import com.baeldung.springflyway.entities.Customer;
|
|
||||||
import com.baeldung.springflyway.repositories.CustomerRepository;
|
|
||||||
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.test.context.junit4.SpringRunner;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
|
||||||
@SpringBootTest
|
|
||||||
public class CustomerRepositoryInitialMigrationIntegrationTest {
|
|
||||||
|
|
||||||
@Autowired CustomerRepository customerRepository;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void givenSchemaCreationMigration_whenTryingToCreateACustomer_thenSuccess() {
|
|
||||||
Customer customer = customerRepository.save(Customer
|
|
||||||
.builder()
|
|
||||||
.email("[email protected]")
|
|
||||||
.build());
|
|
||||||
assertNotNull(customer.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
-35
@@ -1,35 +0,0 @@
|
|||||||
package com.baeldung.springflyway;
|
|
||||||
|
|
||||||
import com.baeldung.springflyway.entities.Customer;
|
|
||||||
import com.baeldung.springflyway.repositories.CustomerRepository;
|
|
||||||
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.test.context.junit4.SpringRunner;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
|
||||||
@SpringBootTest
|
|
||||||
public class CustomerRepositoryInsertDataIntegrationTest {
|
|
||||||
|
|
||||||
@Autowired CustomerRepository customerRepository;
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void givenASetInsertData_whenRunningMigrationsWithSuccess_thenASpecificCustomerIsFound() {
|
|
||||||
Optional<Customer> customerOptional = customerRepository.findByEmail("[email protected]");
|
|
||||||
assertTrue(customerOptional.isPresent());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void givenASetInsertData_whenRunningMigrationsWithSuccess_thenASetOfCustomersIsFound() {
|
|
||||||
List<Customer> customers = customerRepository.findAll();
|
|
||||||
assertNotNull(customers);
|
|
||||||
assertEquals(customers.size(), 6);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
-25
@@ -1,25 +0,0 @@
|
|||||||
package com.baeldung.springflyway;
|
|
||||||
|
|
||||||
import com.baeldung.springflyway.entities.Customer;
|
|
||||||
import com.baeldung.springflyway.repositories.CustomerRepository;
|
|
||||||
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.dao.DataIntegrityViolationException;
|
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
|
||||||
@SpringBootTest
|
|
||||||
public class CustomerRepositoryNotNullConstraintMigrationIntegrationTest {
|
|
||||||
|
|
||||||
@Autowired CustomerRepository customerRepository;
|
|
||||||
|
|
||||||
@Test(expected = DataIntegrityViolationException.class)
|
|
||||||
public void givenTheNotNullConstraintMigrations_whenInsertingACustomerWithNullEmail_thenThrowException() {
|
|
||||||
customerRepository.save(Customer
|
|
||||||
.builder()
|
|
||||||
.build());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
-29
@@ -1,29 +0,0 @@
|
|||||||
package com.baeldung.springflyway;
|
|
||||||
|
|
||||||
import com.baeldung.springflyway.entities.Customer;
|
|
||||||
import com.baeldung.springflyway.repositories.CustomerRepository;
|
|
||||||
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.dao.DataIntegrityViolationException;
|
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
|
||||||
@SpringBootTest(properties = {
|
|
||||||
"flyway.locations[0]=db/migration", "flyway.locations[1]=com/baeldung/springflyway/migration"
|
|
||||||
})
|
|
||||||
public class CustomerRepositoryUniqueConstraintJavaMigrationIntegrationTest {
|
|
||||||
|
|
||||||
@Autowired CustomerRepository customerRepository;
|
|
||||||
|
|
||||||
@Test(expected = DataIntegrityViolationException.class)
|
|
||||||
public void givenTheUniqueConstraintMigrations_whenInsertingAnExistingLastNameCustomer_thenThrowException() {
|
|
||||||
customerRepository.save(Customer
|
|
||||||
.builder()
|
|
||||||
.lastName("LastName")
|
|
||||||
.build());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
-27
@@ -1,27 +0,0 @@
|
|||||||
package com.baeldung.springflyway;
|
|
||||||
|
|
||||||
import com.baeldung.springflyway.entities.Customer;
|
|
||||||
import com.baeldung.springflyway.repositories.CustomerRepository;
|
|
||||||
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.dao.DataIntegrityViolationException;
|
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
|
||||||
@SpringBootTest
|
|
||||||
public class CustomerRepositoryUniqueConstraintMigrationIntegrationTest {
|
|
||||||
|
|
||||||
@Autowired CustomerRepository customerRepository;
|
|
||||||
|
|
||||||
@Test(expected = DataIntegrityViolationException.class)
|
|
||||||
public void givenTheUniqueConstraintMigrations_whenInsertingAnExistingEmailCustomer_thenThrowException() {
|
|
||||||
customerRepository.save(Customer
|
|
||||||
.builder()
|
|
||||||
.email("[email protected]")
|
|
||||||
.build());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
spring.jpa.hibernate.ddl-auto=validate
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
create table if not exists customer (
|
|
||||||
id bigint AUTO_INCREMENT not null primary key,
|
|
||||||
first_name varchar(255) ,
|
|
||||||
last_name varchar(255) ,
|
|
||||||
email varchar(255)
|
|
||||||
);
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
insert into customer (first_name, last_name, email) values ('FirstName', 'LastName', '[email protected]');
|
|
||||||
insert into customer (first_name, last_name, email) values ('FirstName1', 'LastName1', '[email protected]');
|
|
||||||
insert into customer (first_name, last_name, email) values ('FirstName2', 'LastName2', '[email protected]');
|
|
||||||
insert into customer (first_name, last_name, email) values ('FirstName3', 'LastName3', '[email protected]');
|
|
||||||
insert into customer (first_name, last_name, email) values ('FirstName4', 'LastName4', '[email protected]');
|
|
||||||
insert into customer (first_name, last_name, email) values ('FirstName5', 'LastName5', '[email protected]');
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
ALTER TABLE customer ALTER email SET NOT NULL;
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
ALTER TABLE customer ADD CONSTRAINT uk_customer_email UNIQUE(email);
|
|
||||||
Vendored
@@ -1,20 +1,7 @@
|
|||||||
BASIC CRUD API with Spring Boot
|
BASIC CRUD API with Spring Boot
|
||||||
================================
|
================================
|
||||||
|
|
||||||
This is the code of a simple API for some CRUD operations realised for a seminar at [FGI](www.fgi-ud.org) using Spring Boot.
|
This is the code of a simple API for some CRUD operations build using Spring Boot.
|
||||||
|
|
||||||
### Demo
|
|
||||||
* API: The online version **is**/**will be** hosted here: https://fgi-tcheck.herokuapp.com
|
|
||||||
* Mobile version is also opensource and located here: https://github.com/valdesekamdem/tcheck-mobile
|
|
||||||
|
|
||||||
### Features
|
|
||||||
#### Currently Implemented
|
|
||||||
* CRUD
|
|
||||||
* Student
|
|
||||||
|
|
||||||
#### To DO
|
|
||||||
* Validations of input with: [Spring Data Rest Validators](http://docs.spring.io/spring-data/rest/docs/2.1.0.RELEASE/reference/html/validation-chapter.html)
|
|
||||||
|
|
||||||
|
|
||||||
### Requirements
|
### Requirements
|
||||||
|
|
||||||
@@ -49,7 +36,6 @@ Or create a new one via a POST:
|
|||||||
$ curl -X POST -H "Content-Type:application/json" -d '{ "firstName" : "Dassi", "lastName" : "Orleando", "phoneNumber": "+237 545454545", "email": "[email protected]" }' localhost:8080/students
|
$ curl -X POST -H "Content-Type:application/json" -d '{ "firstName" : "Dassi", "lastName" : "Orleando", "phoneNumber": "+237 545454545", "email": "[email protected]" }' localhost:8080/students
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
Now with default configurations it will be available at: [http://localhost:8080](http://localhost:8080)
|
Now with default configurations it will be available at: [http://localhost:8080](http://localhost:8080)
|
||||||
|
|
||||||
Enjoy it :)
|
Enjoy it :)
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
2017-12-13 04:50:16,291 INFO o.a.j.u.JMeterUtils: Setting Locale to en_US
|
||||||
|
2017-12-13 04:50:16,319 INFO o.a.j.JMeter: Loading user properties from: /Users/dassiorleando/projects/biz/baeldung/jmeter/apache-jmeter-3.3/bin/user.properties
|
||||||
|
2017-12-13 04:50:16,392 INFO o.a.j.JMeter: Loading system properties from: /Users/dassiorleando/projects/biz/baeldung/jmeter/apache-jmeter-3.3/bin/system.properties
|
||||||
|
2017-12-13 04:50:16,406 INFO o.a.j.JMeter: Setting JMeter property: jmeter.save.saveservice.output_format=xml
|
||||||
|
2017-12-13 04:50:16,451 INFO o.a.j.JMeter: Copyright (c) 1998-2017 The Apache Software Foundation
|
||||||
|
2017-12-13 04:50:16,451 INFO o.a.j.JMeter: Version 3.3 r1808647
|
||||||
|
2017-12-13 04:50:16,451 INFO o.a.j.JMeter: java.version=1.8.0_152
|
||||||
|
2017-12-13 04:50:16,451 INFO o.a.j.JMeter: java.vm.name=Java HotSpot(TM) 64-Bit Server VM
|
||||||
|
2017-12-13 04:50:16,451 INFO o.a.j.JMeter: os.name=Mac OS X
|
||||||
|
2017-12-13 04:50:16,451 INFO o.a.j.JMeter: os.arch=x86_64
|
||||||
|
2017-12-13 04:50:16,452 INFO o.a.j.JMeter: os.version=10.12.6
|
||||||
|
2017-12-13 04:50:16,452 INFO o.a.j.JMeter: file.encoding=UTF-8
|
||||||
|
2017-12-13 04:50:16,452 INFO o.a.j.JMeter: Max memory =536870912
|
||||||
|
2017-12-13 04:50:16,452 INFO o.a.j.JMeter: Available Processors =4
|
||||||
|
2017-12-13 04:50:16,461 INFO o.a.j.JMeter: Default Locale=English (United States)
|
||||||
|
2017-12-13 04:50:16,462 INFO o.a.j.JMeter: JMeter Locale=English (United States)
|
||||||
|
2017-12-13 04:50:16,462 INFO o.a.j.JMeter: JMeterHome=/Users/dassiorleando/projects/biz/baeldung/jmeter/apache-jmeter-3.3
|
||||||
|
2017-12-13 04:50:16,462 INFO o.a.j.JMeter: user.dir =/Users/dassiorleando/projects/biz/baeldung/tutorials/jmeter
|
||||||
|
2017-12-13 04:50:16,462 INFO o.a.j.JMeter: PWD =/Users/dassiorleando/projects/biz/baeldung/tutorials/jmeter
|
||||||
|
2017-12-13 04:50:16,466 INFO o.a.j.JMeter: IP: 192.168.10.100 Name: MBP FullName: 192.168.10.100
|
||||||
|
2017-12-13 04:50:16,472 INFO o.a.j.s.FileServer: Default base='/Users/dassiorleando/projects/biz/baeldung/tutorials/jmeter'
|
||||||
|
2017-12-13 04:50:16,473 INFO o.a.j.s.FileServer: Set new base='/Users/dassiorleando/projects/biz/baeldung/tutorials/jmeter/src/main/resources'
|
||||||
|
2017-12-13 04:50:17,022 INFO o.a.j.s.SaveService: Testplan (JMX) version: 2.2. Testlog (JTL) version: 2.2
|
||||||
|
2017-12-13 04:50:17,134 INFO o.a.j.s.SaveService: Using SaveService properties file encoding UTF-8
|
||||||
|
2017-12-13 04:50:17,142 INFO o.a.j.s.SaveService: Using SaveService properties version 3.2
|
||||||
|
2017-12-13 04:50:17,168 INFO o.a.j.s.SaveService: Loading file: src/main/resources/JMeter.jmx
|
||||||
|
2017-12-13 04:50:17,340 INFO o.a.j.p.h.s.HTTPSamplerBase: Parser for text/html is org.apache.jmeter.protocol.http.parser.LagartoBasedHtmlParser
|
||||||
|
2017-12-13 04:50:17,351 INFO o.a.j.p.h.s.HTTPSamplerBase: Parser for application/xhtml+xml is org.apache.jmeter.protocol.http.parser.LagartoBasedHtmlParser
|
||||||
|
2017-12-13 04:50:17,352 INFO o.a.j.p.h.s.HTTPSamplerBase: Parser for application/xml is org.apache.jmeter.protocol.http.parser.LagartoBasedHtmlParser
|
||||||
|
2017-12-13 04:50:17,352 INFO o.a.j.p.h.s.HTTPSamplerBase: Parser for text/xml is org.apache.jmeter.protocol.http.parser.LagartoBasedHtmlParser
|
||||||
|
2017-12-13 04:50:17,353 INFO o.a.j.p.h.s.HTTPSamplerBase: Parser for text/vnd.wap.wml is org.apache.jmeter.protocol.http.parser.RegexpHTMLParser
|
||||||
|
2017-12-13 04:50:17,353 INFO o.a.j.p.h.s.HTTPSamplerBase: Parser for text/css is org.apache.jmeter.protocol.http.parser.CssParser
|
||||||
|
2017-12-13 04:50:17,552 INFO o.a.j.JMeter: Creating summariser <summary>
|
||||||
|
2017-12-13 04:50:17,580 INFO o.a.j.e.StandardJMeterEngine: Running the test!
|
||||||
|
2017-12-13 04:50:17,581 INFO o.a.j.s.SampleEvent: List of sample_variables: []
|
||||||
|
2017-12-13 04:50:17,582 INFO o.a.j.s.SampleEvent: List of sample_variables: []
|
||||||
|
2017-12-13 04:50:17,590 INFO o.a.j.e.u.CompoundVariable: Note: Function class names must contain the string: '.functions.'
|
||||||
|
2017-12-13 04:50:17,590 INFO o.a.j.e.u.CompoundVariable: Note: Function class names must not contain the string: '.gui.'
|
||||||
|
2017-12-13 04:50:18,640 INFO o.a.j.JMeter: Running test (1513137018640)
|
||||||
|
2017-12-13 04:50:18,728 INFO o.a.j.e.StandardJMeterEngine: Starting ThreadGroup: 1 : Thread Group
|
||||||
|
2017-12-13 04:50:18,737 INFO o.a.j.e.StandardJMeterEngine: Starting 5 threads for group Thread Group.
|
||||||
|
2017-12-13 04:50:18,737 INFO o.a.j.e.StandardJMeterEngine: Thread will continue on error
|
||||||
|
2017-12-13 04:50:18,738 INFO o.a.j.t.ThreadGroup: Starting thread group... number=1 threads=5 ramp-up=1 perThread=200.0 delayedStart=false
|
||||||
|
2017-12-13 04:50:18,751 INFO o.a.j.t.JMeterThread: Thread started: Thread Group 1-1
|
||||||
|
2017-12-13 04:50:18,753 INFO o.a.j.t.ThreadGroup: Started thread group number 1
|
||||||
|
2017-12-13 04:50:18,753 INFO o.a.j.e.StandardJMeterEngine: All thread groups have been started
|
||||||
|
2017-12-13 04:50:18,786 INFO o.a.j.p.h.s.HTTPHCAbstractImpl: Local host = MBP
|
||||||
|
2017-12-13 04:50:18,797 INFO o.a.j.p.h.s.HTTPHC4Impl: HTTP request retry count = 0
|
||||||
|
2017-12-13 04:50:18,812 INFO o.a.j.s.SampleResult: Note: Sample TimeStamps are START times
|
||||||
|
2017-12-13 04:50:18,812 INFO o.a.j.s.SampleResult: sampleresult.default.encoding is set to ISO-8859-1
|
||||||
|
2017-12-13 04:50:18,812 INFO o.a.j.s.SampleResult: sampleresult.useNanoTime=true
|
||||||
|
2017-12-13 04:50:18,812 INFO o.a.j.s.SampleResult: sampleresult.nanoThreadSleep=5000
|
||||||
|
2017-12-13 04:50:18,954 INFO o.a.j.t.JMeterThread: Thread started: Thread Group 1-2
|
||||||
|
2017-12-13 04:50:19,152 INFO o.a.j.t.JMeterThread: Thread started: Thread Group 1-3
|
||||||
|
2017-12-13 04:50:19,257 INFO o.a.j.t.JMeterThread: Thread is done: Thread Group 1-3
|
||||||
|
2017-12-13 04:50:19,257 INFO o.a.j.t.JMeterThread: Thread finished: Thread Group 1-3
|
||||||
|
2017-12-13 04:50:19,264 INFO o.a.j.t.JMeterThread: Thread is done: Thread Group 1-2
|
||||||
|
2017-12-13 04:50:19,264 INFO o.a.j.t.JMeterThread: Thread is done: Thread Group 1-1
|
||||||
|
2017-12-13 04:50:19,264 INFO o.a.j.t.JMeterThread: Thread finished: Thread Group 1-2
|
||||||
|
2017-12-13 04:50:19,265 INFO o.a.j.t.JMeterThread: Thread finished: Thread Group 1-1
|
||||||
|
2017-12-13 04:50:19,353 INFO o.a.j.t.JMeterThread: Thread started: Thread Group 1-4
|
||||||
|
2017-12-13 04:50:19,365 INFO o.a.j.t.JMeterThread: Thread is done: Thread Group 1-4
|
||||||
|
2017-12-13 04:50:19,365 INFO o.a.j.t.JMeterThread: Thread finished: Thread Group 1-4
|
||||||
|
2017-12-13 04:50:19,557 INFO o.a.j.t.JMeterThread: Thread started: Thread Group 1-5
|
||||||
|
2017-12-13 04:50:19,573 INFO o.a.j.t.JMeterThread: Thread is done: Thread Group 1-5
|
||||||
|
2017-12-13 04:50:19,573 INFO o.a.j.t.JMeterThread: Thread finished: Thread Group 1-5
|
||||||
|
2017-12-13 04:50:19,573 INFO o.a.j.e.StandardJMeterEngine: Notifying test listeners of end of test
|
||||||
|
2017-12-13 04:50:19,575 INFO o.a.j.r.Summariser: summary = 5 in 00:00:01 = 5.4/s Avg: 155 Min: 10 Max: 388 Err: 4 (80.00%)
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user