Merge remote-tracking branch 'eugenp/master'
This commit is contained in:
commit
c4141abaec
|
@ -0,0 +1,11 @@
|
|||
log:
|
||||
level: warn
|
||||
appenders:
|
||||
- type: file
|
||||
logFormat: '%c{20}: %m%n'
|
||||
file: /home/logger.log
|
||||
|
||||
jetty:
|
||||
context: /hello
|
||||
connector:
|
||||
port: 10001
|
|
@ -0,0 +1,50 @@
|
|||
<?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/maven-v4_0_0.xsd">
|
||||
<parent>
|
||||
<artifactId>bootique-parent</artifactId>
|
||||
<groupId>io.bootique.parent</groupId>
|
||||
<version>0.12</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung.bootique</groupId>
|
||||
<artifactId>bootique</artifactId>
|
||||
<name>bootique</name>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<url>http://maven.apache.org</url>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.bootique</groupId>
|
||||
<artifactId>bootique-test</artifactId>
|
||||
<version>0.23</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.bootique.bom</groupId>
|
||||
<artifactId>bootique-bom</artifactId>
|
||||
<version>0.23</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
<properties>
|
||||
<main.class>com.baeldung.bootique.App</main.class>
|
||||
</properties>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,66 @@
|
|||
<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/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung.bootique</groupId>
|
||||
<artifactId>bootique</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>bootique</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<main.class>com.baeldung.bootique.App</main.class>
|
||||
</properties>
|
||||
|
||||
<parent>
|
||||
<groupId>io.bootique.parent</groupId>
|
||||
<artifactId>bootique-parent</artifactId>
|
||||
<version>0.12</version>
|
||||
</parent>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.bootique.bom</groupId>
|
||||
<artifactId>bootique-bom</artifactId>
|
||||
<version>0.23</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.bootique.jersey</groupId>
|
||||
<artifactId>bootique-jersey</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.bootique.logback</groupId>
|
||||
<artifactId>bootique-logback</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.bootique</groupId>
|
||||
<artifactId>bootique-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,41 @@
|
|||
package com.baeldung.bootique;
|
||||
|
||||
import com.baeldung.bootique.module.ModuleBinder;
|
||||
import com.baeldung.bootique.router.IndexController;
|
||||
import com.baeldung.bootique.router.SaveController;
|
||||
import com.google.inject.Module;
|
||||
import io.bootique.Bootique;
|
||||
import io.bootique.jersey.JerseyModule;
|
||||
import io.bootique.log.BootLogger;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class App {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Module module = binder -> JerseyModule.extend(binder).addResource(IndexController.class)
|
||||
.addResource(SaveController.class);
|
||||
Bootique.app(args).module(module).module(ModuleBinder.class).bootLogger(new BootLogger() {
|
||||
@Override
|
||||
public void trace(Supplier<String> arg0) {
|
||||
// ...
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stdout(String arg0) {
|
||||
// ...
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stderr(String arg0, Throwable arg1) {
|
||||
// ...
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stderr(String arg0) {
|
||||
// ...
|
||||
}
|
||||
}).autoLoadModules().exec();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.baeldung.bootique.module;
|
||||
|
||||
import com.baeldung.bootique.service.HelloService;
|
||||
import com.baeldung.bootique.service.impl.HelloServiceImpl;
|
||||
import com.google.inject.Binder;
|
||||
import com.google.inject.Module;
|
||||
|
||||
public class ModuleBinder implements Module {
|
||||
|
||||
@Override
|
||||
public void configure(Binder binder) {
|
||||
binder.bind(HelloService.class).to(HelloServiceImpl.class);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package com.baeldung.bootique.module;
|
||||
|
||||
import com.google.inject.Module;
|
||||
import io.bootique.BQModuleProvider;
|
||||
|
||||
public class ModuleProvider implements BQModuleProvider {
|
||||
|
||||
@Override
|
||||
public Module module() {
|
||||
return new ModuleBinder();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.baeldung.bootique.router;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.Path;
|
||||
|
||||
@Path("/")
|
||||
public class IndexController {
|
||||
|
||||
@GET
|
||||
public String index() {
|
||||
return "Hello, baeldung!";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.baeldung.bootique.router;
|
||||
|
||||
import com.baeldung.bootique.service.HelloService;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
|
||||
@Path("/save")
|
||||
public class SaveController {
|
||||
|
||||
@Inject
|
||||
HelloService helloService;
|
||||
|
||||
@POST
|
||||
public String save() {
|
||||
return "Data Saved!";
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package com.baeldung.bootique.service;
|
||||
|
||||
public interface HelloService {
|
||||
|
||||
boolean save();
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package com.baeldung.bootique.service.impl;
|
||||
|
||||
import com.baeldung.bootique.service.HelloService;
|
||||
|
||||
public class HelloServiceImpl implements HelloService {
|
||||
|
||||
@Override
|
||||
public boolean save() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
com.baeldung.bootique.module.ModuleProvider
|
|
@ -0,0 +1,27 @@
|
|||
package com.baeldung.bootique;
|
||||
|
||||
import com.baeldung.bootique.service.HelloService;
|
||||
import io.bootique.BQRuntime;
|
||||
import io.bootique.test.junit.BQDaemonTestFactory;
|
||||
import io.bootique.test.junit.BQTestFactory;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class AppTest {
|
||||
|
||||
@Rule
|
||||
public BQTestFactory bqTestFactory = new BQTestFactory();
|
||||
|
||||
@Rule
|
||||
public BQDaemonTestFactory bqDaemonTestFactory = new BQDaemonTestFactory();
|
||||
|
||||
@Test
|
||||
public void givenService_expectBoolen() {
|
||||
BQRuntime runtime = bqTestFactory.app("--server").autoLoadModules().createRuntime();
|
||||
HelloService service = runtime.getInstance(HelloService.class);
|
||||
assertEquals(true, service.save());
|
||||
}
|
||||
|
||||
}
|
|
@ -1,39 +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>
|
||||
<groupId>com.baeldung.hashcode</groupId>
|
||||
<artifactId>hashcode</artifactId>
|
||||
<version>1.0</version>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>1.7.25</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-simple</artifactId>
|
||||
<version>1.7.25</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
|
@ -1,23 +0,0 @@
|
|||
package com.baeldung.application;
|
||||
|
||||
import com.baeldung.entities.User;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Map<User, User> users = new HashMap<>();
|
||||
User user1 = new User(1L, "John", "john@domain.com");
|
||||
User user2 = new User(2L, "Jennifer", "jennifer@domain.com");
|
||||
User user3 = new User(3L, "Mary", "mary@domain.com");
|
||||
|
||||
users.put(user1, user1);
|
||||
users.put(user2, user2);
|
||||
users.put(user3, user3);
|
||||
|
||||
if (users.containsKey(user1)) {
|
||||
System.out.print("User found in the collection");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
package com.baeldung.entities;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class User {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(User.class);
|
||||
private long id;
|
||||
private String name;
|
||||
private String email;
|
||||
|
||||
public User(long id, String name, String email) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null) return false;
|
||||
if (this.getClass() != o.getClass()) return false;
|
||||
User user = (User) o;
|
||||
return id != user.id && (!name.equals(user.name) && !email.equals(user.email));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 7;
|
||||
hash = 31 * hash + (int) id;
|
||||
hash = 31 * hash + (name == null ? 0 : name.hashCode());
|
||||
hash = 31 * hash + (email == null ? 0 : email.hashCode());
|
||||
logger.info("hashCode() method called - Computed hash: " + hash);
|
||||
return hash;
|
||||
}
|
||||
// getters and setters here
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
package com.baeldung.application;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.PrintStream;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class ApplicationTest {
|
||||
|
||||
private ByteArrayOutputStream outContent;
|
||||
|
||||
@Before
|
||||
public void setUpPrintStreamInstance() throws Exception {
|
||||
this.outContent = new ByteArrayOutputStream();
|
||||
System.setOut(new PrintStream(outContent));
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDownByteArrayOutputStream() throws Exception {
|
||||
outContent = null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void main_NoInputState_TextPrintedToConsole() throws Exception {
|
||||
Application.main(new String[]{});
|
||||
assertEquals("User found in the collection", outContent.toString());
|
||||
}
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
package com.baeldung.entities;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class UserTest {
|
||||
|
||||
private User user;
|
||||
private User comparisonUser;
|
||||
|
||||
@Before
|
||||
public void setUpUserInstances() {
|
||||
this.user = new User(1L, "test", "test@domain.com");
|
||||
this.comparisonUser = this.user;
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDownUserInstances() {
|
||||
user = null;
|
||||
comparisonUser = null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equals_EqualUserInstance_TrueAssertion(){
|
||||
Assert.assertTrue(user.equals(comparisonUser));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hashCode_UserHash_TrueAssertion() {
|
||||
Assert.assertEquals(1792276941, user.hashCode());
|
||||
}
|
||||
}
|
|
@ -15,14 +15,12 @@ public class CyclicBarrierDemo {
|
|||
private int NUM_PARTIAL_RESULTS;
|
||||
private int NUM_WORKERS;
|
||||
|
||||
|
||||
private void runSimulation(int numWorkers, int numberOfPartialResults) {
|
||||
NUM_PARTIAL_RESULTS = numberOfPartialResults;
|
||||
NUM_WORKERS = numWorkers;
|
||||
|
||||
cyclicBarrier = new CyclicBarrier(NUM_WORKERS, new AggregatorThread());
|
||||
System.out.println("Spawning " + NUM_WORKERS + " worker threads to compute "
|
||||
+ NUM_PARTIAL_RESULTS + " partial results each");
|
||||
System.out.println("Spawning " + NUM_WORKERS + " worker threads to compute " + NUM_PARTIAL_RESULTS + " partial results each");
|
||||
for (int i = 0; i < NUM_WORKERS; i++) {
|
||||
Thread worker = new Thread(new NumberCruncherThread());
|
||||
worker.setName("Thread " + i);
|
||||
|
@ -38,8 +36,7 @@ public class CyclicBarrierDemo {
|
|||
List<Integer> partialResult = new ArrayList<>();
|
||||
for (int i = 0; i < NUM_PARTIAL_RESULTS; i++) {
|
||||
Integer num = random.nextInt(10);
|
||||
System.out.println(thisThreadName
|
||||
+ ": Crunching some numbers! Final result - " + num);
|
||||
System.out.println(thisThreadName + ": Crunching some numbers! Final result - " + num);
|
||||
partialResult.add(num);
|
||||
}
|
||||
partialResults.add(partialResult);
|
||||
|
@ -57,13 +54,12 @@ public class CyclicBarrierDemo {
|
|||
@Override
|
||||
public void run() {
|
||||
String thisThreadName = Thread.currentThread().getName();
|
||||
System.out.println(thisThreadName + ": Computing final sum of " + NUM_WORKERS
|
||||
+ " workers, having " + NUM_PARTIAL_RESULTS + " results each.");
|
||||
System.out.println(thisThreadName + ": Computing final sum of " + NUM_WORKERS + " workers, having " + NUM_PARTIAL_RESULTS + " results each.");
|
||||
int sum = 0;
|
||||
for (List<Integer> threadResult : partialResults) {
|
||||
System.out.print("Adding ");
|
||||
for (Integer partialResult : threadResult) {
|
||||
System.out.print(partialResult+" ");
|
||||
System.out.print(partialResult + " ");
|
||||
sum += partialResult;
|
||||
}
|
||||
System.out.println();
|
||||
|
|
|
@ -15,7 +15,8 @@ public class Philosopher implements Runnable {
|
|||
Thread.sleep(((int) (Math.random() * 100)));
|
||||
}
|
||||
|
||||
@Override public void run() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
while (true) {
|
||||
doAction(System.nanoTime() + ": Thinking"); // thinking
|
||||
|
|
|
@ -6,22 +6,22 @@ import java.util.concurrent.TimeUnit;
|
|||
|
||||
public class ExecutorServiceDemo {
|
||||
|
||||
ExecutorService executor = Executors.newFixedThreadPool(10);
|
||||
ExecutorService executor = Executors.newFixedThreadPool(10);
|
||||
|
||||
public void execute() {
|
||||
public void execute() {
|
||||
|
||||
executor.submit(() -> {
|
||||
new Task();
|
||||
});
|
||||
executor.submit(() -> {
|
||||
new Task();
|
||||
});
|
||||
|
||||
executor.shutdown();
|
||||
executor.shutdownNow();
|
||||
try {
|
||||
executor.awaitTermination(20l, TimeUnit.NANOSECONDS);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
executor.shutdown();
|
||||
executor.shutdownNow();
|
||||
try {
|
||||
executor.awaitTermination(20l, TimeUnit.NANOSECONDS);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,36 +9,36 @@ import java.util.concurrent.TimeoutException;
|
|||
|
||||
public class FutureDemo {
|
||||
|
||||
public String invoke() {
|
||||
public String invoke() {
|
||||
|
||||
String str = null;
|
||||
String str = null;
|
||||
|
||||
ExecutorService executorService = Executors.newFixedThreadPool(10);
|
||||
ExecutorService executorService = Executors.newFixedThreadPool(10);
|
||||
|
||||
Future<String> future = executorService.submit(() -> {
|
||||
// Task
|
||||
Thread.sleep(10000l);
|
||||
return "Hellow world";
|
||||
});
|
||||
Future<String> future = executorService.submit(() -> {
|
||||
// Task
|
||||
Thread.sleep(10000l);
|
||||
return "Hellow world";
|
||||
});
|
||||
|
||||
future.cancel(false);
|
||||
future.cancel(false);
|
||||
|
||||
try {
|
||||
future.get(20, TimeUnit.SECONDS);
|
||||
} catch (InterruptedException | ExecutionException | TimeoutException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
try {
|
||||
future.get(20, TimeUnit.SECONDS);
|
||||
} catch (InterruptedException | ExecutionException | TimeoutException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
if (future.isDone() && !future.isCancelled()) {
|
||||
try {
|
||||
str = future.get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (future.isDone() && !future.isCancelled()) {
|
||||
try {
|
||||
str = future.get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return str;
|
||||
return str;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,20 +4,20 @@ import java.util.concurrent.ThreadFactory;
|
|||
|
||||
public class BaeldungThreadFactory implements ThreadFactory {
|
||||
|
||||
private int threadId;
|
||||
private String name;
|
||||
private int threadId;
|
||||
private String name;
|
||||
|
||||
public BaeldungThreadFactory(String name) {
|
||||
threadId = 1;
|
||||
this.name = name;
|
||||
}
|
||||
public BaeldungThreadFactory(String name) {
|
||||
threadId = 1;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Thread newThread(Runnable r) {
|
||||
Thread t = new Thread(r, name + "-Thread_" + threadId);
|
||||
System.out.println("created new thread with id : " + threadId + " and name : " + t.getName());
|
||||
threadId++;
|
||||
return t;
|
||||
}
|
||||
@Override
|
||||
public Thread newThread(Runnable r) {
|
||||
Thread t = new Thread(r, name + "-Thread_" + threadId);
|
||||
System.out.println("created new thread with id : " + threadId + " and name : " + t.getName());
|
||||
threadId++;
|
||||
return t;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,9 +2,9 @@ package com.baeldung.concurrent.threadfactory;
|
|||
|
||||
public class Task implements Runnable {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// task details
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
// task details
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -14,26 +14,25 @@ public class LookupFSJNDI {
|
|||
super();
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
private void init() throws NamingException {
|
||||
Hashtable<String, String> env = new Hashtable<String, String>();
|
||||
|
||||
env.put (Context.INITIAL_CONTEXT_FACTORY,
|
||||
"com.sun.jndi.fscontext.RefFSContextFactory");
|
||||
|
||||
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");
|
||||
// URI to namespace (actual directory)
|
||||
env.put(Context.PROVIDER_URL, "file:./src/test/resources");
|
||||
|
||||
|
||||
ctx = new InitialContext(env);
|
||||
}
|
||||
|
||||
public InitialContext getCtx() {
|
||||
return ctx;
|
||||
}
|
||||
|
||||
|
||||
public File getFile(String fileName) {
|
||||
File file;
|
||||
try {
|
||||
file = (File)getCtx().lookup(fileName);
|
||||
file = (File) getCtx().lookup(fileName);
|
||||
} catch (NamingException e) {
|
||||
file = null;
|
||||
}
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
package com.baeldung.application;
|
||||
|
||||
import com.baeldung.entities.User;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Map<User, User> users = new HashMap<>();
|
||||
User user1 = new User(1L, "John", "john@domain.com");
|
||||
User user2 = new User(2L, "Jennifer", "jennifer@domain.com");
|
||||
User user3 = new User(3L, "Mary", "mary@domain.com");
|
||||
|
||||
users.put(user1, user1);
|
||||
users.put(user2, user2);
|
||||
users.put(user3, user3);
|
||||
|
||||
if (users.containsKey(user1)) {
|
||||
System.out.print("User found in the collection");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.entities;
|
||||
package com.baeldung.hashcode.entities;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
@ -18,13 +18,16 @@ public class User {
|
|||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null) return false;
|
||||
if (this.getClass() != o.getClass()) return false;
|
||||
if (this == o)
|
||||
return true;
|
||||
if (o == null)
|
||||
return false;
|
||||
if (this.getClass() != o.getClass())
|
||||
return false;
|
||||
User user = (User) o;
|
||||
return id != user.id && (!name.equals(user.name) && !email.equals(user.email));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 7;
|
||||
|
|
|
@ -10,7 +10,6 @@ public class JMXTutorialMainlauncher {
|
|||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(JMXTutorialMainlauncher.class);
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
|
|
@ -8,9 +8,8 @@ import java.net.*;
|
|||
|
||||
public class EchoClient {
|
||||
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(EchoClient.class);
|
||||
|
||||
|
||||
private Socket clientSocket;
|
||||
private PrintWriter out;
|
||||
private BufferedReader in;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package com.baeldung.stream;
|
||||
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
|
|
@ -12,15 +12,10 @@ class StringHelper {
|
|||
}
|
||||
|
||||
static String removeLastCharOptional(String s) {
|
||||
return Optional.ofNullable(s)
|
||||
.filter(str -> str.length() != 0)
|
||||
.map(str -> str.substring(0, str.length() - 1))
|
||||
.orElse(s);
|
||||
return Optional.ofNullable(s).filter(str -> str.length() != 0).map(str -> str.substring(0, str.length() - 1)).orElse(s);
|
||||
}
|
||||
|
||||
static String removeLastCharRegexOptional(String s) {
|
||||
return Optional.ofNullable(s)
|
||||
.map(str -> str.replaceAll(".$", ""))
|
||||
.orElse(s);
|
||||
return Optional.ofNullable(s).map(str -> str.replaceAll(".$", "")).orElse(s);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,11 +25,7 @@ public class MyTokenizer {
|
|||
}
|
||||
|
||||
public List<String> getTokensWithCollection(String str) {
|
||||
return Collections
|
||||
.list(new StringTokenizer(str, ","))
|
||||
.stream()
|
||||
.map(token -> (String) token)
|
||||
.collect(Collectors.toList());
|
||||
return Collections.list(new StringTokenizer(str, ",")).stream().map(token -> (String) token).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<String> getTokensFromFile(String path, String delim) {
|
||||
|
|
|
@ -11,12 +11,12 @@ public class CustomTemporalAdjuster implements TemporalAdjuster {
|
|||
@Override
|
||||
public Temporal adjustInto(Temporal temporal) {
|
||||
switch (DayOfWeek.of(temporal.get(ChronoField.DAY_OF_WEEK))) {
|
||||
case FRIDAY:
|
||||
return temporal.plus(3, ChronoUnit.DAYS);
|
||||
case SATURDAY:
|
||||
return temporal.plus(2, ChronoUnit.DAYS);
|
||||
default:
|
||||
return temporal.plus(1, ChronoUnit.DAYS);
|
||||
case FRIDAY:
|
||||
return temporal.plus(3, ChronoUnit.DAYS);
|
||||
case SATURDAY:
|
||||
return temporal.plus(2, ChronoUnit.DAYS);
|
||||
default:
|
||||
return temporal.plus(1, ChronoUnit.DAYS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||
public class Consumer implements Runnable {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(Consumer.class);
|
||||
|
||||
|
||||
private final TransferQueue<String> transferQueue;
|
||||
private final String name;
|
||||
private final int numberOfMessagesToConsume;
|
||||
|
|
|
@ -15,28 +15,24 @@ public class LongAccumulatorUnitTest {
|
|||
|
||||
@Test
|
||||
public void givenLongAccumulator_whenApplyActionOnItFromMultipleThrads_thenShouldProduceProperResult() throws InterruptedException {
|
||||
//given
|
||||
// given
|
||||
ExecutorService executorService = Executors.newFixedThreadPool(8);
|
||||
LongBinaryOperator sum = Long::sum;
|
||||
LongAccumulator accumulator = new LongAccumulator(sum, 0L);
|
||||
int numberOfThreads = 4;
|
||||
int numberOfIncrements = 100;
|
||||
|
||||
//when
|
||||
Runnable accumulateAction = () -> IntStream
|
||||
.rangeClosed(0, numberOfIncrements)
|
||||
.forEach(accumulator::accumulate);
|
||||
// when
|
||||
Runnable accumulateAction = () -> IntStream.rangeClosed(0, numberOfIncrements).forEach(accumulator::accumulate);
|
||||
|
||||
for (int i = 0; i < numberOfThreads; i++) {
|
||||
executorService.execute(accumulateAction);
|
||||
}
|
||||
|
||||
|
||||
//then
|
||||
// then
|
||||
executorService.awaitTermination(500, TimeUnit.MILLISECONDS);
|
||||
executorService.shutdown();
|
||||
assertEquals(accumulator.get(), 20200);
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,30 +1,26 @@
|
|||
package com.baeldung.application;
|
||||
package com.baeldung.hashcode.application;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import com.baeldung.hashcode.entities.User;
|
||||
import org.junit.Test;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.PrintStream;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class ApplicationTest {
|
||||
|
||||
private ByteArrayOutputStream outContent;
|
||||
|
||||
@Before
|
||||
public void setUpPrintStreamInstance() throws Exception {
|
||||
this.outContent = new ByteArrayOutputStream();
|
||||
System.setOut(new PrintStream(outContent));
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDownByteArrayOutputStream() throws Exception {
|
||||
outContent = null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void main_NoInputState_TextPrintedToConsole() throws Exception {
|
||||
Application.main(new String[]{});
|
||||
assertEquals("User found in the collection", outContent.toString());
|
||||
Map<User, User> users = new HashMap<>();
|
||||
User user1 = new User(1L, "John", "john@domain.com");
|
||||
User user2 = new User(2L, "Jennifer", "jennifer@domain.com");
|
||||
User user3 = new User(3L, "Mary", "mary@domain.com");
|
||||
|
||||
users.put(user1, user1);
|
||||
users.put(user2, user2);
|
||||
users.put(user3, user3);
|
||||
|
||||
assertTrue(users.containsKey(user1));
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung.entities;
|
||||
package com.baeldung.hashcode.entities;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
|
@ -23,7 +23,7 @@ public class UserTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void equals_EqualUserInstance_TrueAssertion(){
|
||||
public void equals_EqualUserInstance_TrueAssertion() {
|
||||
Assert.assertTrue(user.equals(comparisonUser));
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@ public class LambdaExceptionWrappersUnitTest {
|
|||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(LambdaExceptionWrappersUnitTest.class);
|
||||
|
||||
|
||||
private List<Integer> integers;
|
||||
|
||||
@Before
|
||||
|
|
|
@ -29,12 +29,9 @@ public class ListOfListsUnitTest {
|
|||
|
||||
@Test
|
||||
public void givenListOfLists_thenCheckNames() {
|
||||
assertEquals("Pen 1", ((Pen) listOfLists.get(0)
|
||||
.get(0)).getName());
|
||||
assertEquals("Pencil 1", ((Pencil) listOfLists.get(1)
|
||||
.get(0)).getName());
|
||||
assertEquals("Rubber 1", ((Rubber) listOfLists.get(2)
|
||||
.get(0)).getName());
|
||||
assertEquals("Pen 1", ((Pen) listOfLists.get(0).get(0)).getName());
|
||||
assertEquals("Pencil 1", ((Pencil) listOfLists.get(1).get(0)).getName());
|
||||
assertEquals("Rubber 1", ((Rubber) listOfLists.get(2).get(0)).getName());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@ -43,11 +40,9 @@ public class ListOfListsUnitTest {
|
|||
|
||||
((ArrayList<Pencil>) listOfLists.get(1)).remove(0);
|
||||
listOfLists.remove(1);
|
||||
assertEquals("Rubber 1", ((Rubber) listOfLists.get(1)
|
||||
.get(0)).getName());
|
||||
assertEquals("Rubber 1", ((Rubber) listOfLists.get(1).get(0)).getName());
|
||||
listOfLists.remove(0);
|
||||
assertEquals("Rubber 1", ((Rubber) listOfLists.get(0)
|
||||
.get(0)).getName());
|
||||
assertEquals("Rubber 1", ((Rubber) listOfLists.get(0).get(0)).getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -67,11 +62,8 @@ public class ListOfListsUnitTest {
|
|||
list.add(pencils);
|
||||
list.add(rubbers);
|
||||
|
||||
assertEquals("Pen 1", ((Pen) list.get(0)
|
||||
.get(0)).getName());
|
||||
assertEquals("Pencil 1", ((Pencil) list.get(1)
|
||||
.get(0)).getName());
|
||||
assertEquals("Rubber 1", ((Rubber) list.get(2)
|
||||
.get(0)).getName());
|
||||
assertEquals("Pen 1", ((Pen) list.get(0).get(0)).getName());
|
||||
assertEquals("Pencil 1", ((Pencil) list.get(1).get(0)).getName());
|
||||
assertEquals("Rubber 1", ((Rubber) list.get(2).get(0)).getName());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@ public class CoreThreadPoolIntegrationTest {
|
|||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(CoreThreadPoolIntegrationTest.class);
|
||||
|
||||
|
||||
@Test(timeout = 1000)
|
||||
public void whenCallingExecuteWithRunnable_thenRunnableIsExecuted() throws InterruptedException {
|
||||
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
### Relevant articles
|
||||
|
||||
- [Introduction to jOOL](http://www.baeldung.com/jool)
|
25
jooq/pom.xml
25
jooq/pom.xml
|
@ -1,25 +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">
|
||||
<parent>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>jooq</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.jooq</groupId>
|
||||
<artifactId>jool</artifactId>
|
||||
<version>${jool.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<jool.version>0.9.12</jool.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -181,6 +181,11 @@
|
|||
<artifactId>jetty-servlet</artifactId>
|
||||
<version>${jetty.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>rome</groupId>
|
||||
<artifactId>rome</artifactId>
|
||||
<version>${rome.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.specto</groupId>
|
||||
<artifactId>hoverfly-java</artifactId>
|
||||
|
@ -497,5 +502,6 @@
|
|||
<hll.version>1.6.0</hll.version>
|
||||
<bytebuddy.version>1.7.1</bytebuddy.version>
|
||||
<pcollections.version>2.1.2</pcollections.version>
|
||||
<rome.version>1.0</rome.version>
|
||||
</properties>
|
||||
</project>
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
package com.baeldung.rome;
|
||||
|
||||
import com.sun.syndication.feed.synd.*;
|
||||
import com.sun.syndication.io.FeedException;
|
||||
import com.sun.syndication.io.SyndFeedInput;
|
||||
import com.sun.syndication.io.SyndFeedOutput;
|
||||
import com.sun.syndication.io.XmlReader;
|
||||
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class RSSRomeExample {
|
||||
|
||||
public static void main(String[] args) throws IOException, FeedException {
|
||||
SyndFeed feed = createFeed();
|
||||
addEntryToFeed(feed);
|
||||
publishFeed(feed);
|
||||
readFeed();
|
||||
}
|
||||
|
||||
private static SyndFeed createFeed() {
|
||||
SyndFeed feed = new SyndFeedImpl();
|
||||
feed.setFeedType("rss_1.0");
|
||||
feed.setTitle("Test title");
|
||||
feed.setLink("http://www.somelink.com");
|
||||
feed.setDescription("Basic description");
|
||||
|
||||
return feed;
|
||||
}
|
||||
|
||||
private static void addEntryToFeed(SyndFeed feed) {
|
||||
SyndEntry entry = new SyndEntryImpl();
|
||||
entry.setTitle("Entry title");
|
||||
entry.setLink("http://www.somelink.com/entry1");
|
||||
|
||||
addDescriptionToEntry(entry);
|
||||
addCategoryToEntry(entry);
|
||||
|
||||
feed.setEntries(Arrays.asList(entry));
|
||||
}
|
||||
|
||||
private static void addDescriptionToEntry(SyndEntry entry) {
|
||||
SyndContent description = new SyndContentImpl();
|
||||
description.setType("text/html");
|
||||
description.setValue("First entry");
|
||||
|
||||
entry.setDescription(description);
|
||||
}
|
||||
|
||||
private static void addCategoryToEntry(SyndEntry entry) {
|
||||
List<SyndCategory> categories = new ArrayList<>();
|
||||
SyndCategory category = new SyndCategoryImpl();
|
||||
category.setName("Sophisticated category");
|
||||
categories.add(category);
|
||||
|
||||
entry.setCategories(categories);
|
||||
}
|
||||
|
||||
private static void publishFeed(SyndFeed feed) throws IOException, FeedException {
|
||||
Writer writer = new FileWriter("xyz.txt");
|
||||
SyndFeedOutput syndFeedOutput = new SyndFeedOutput();
|
||||
syndFeedOutput.output(feed, writer);
|
||||
writer.close();
|
||||
}
|
||||
|
||||
private static SyndFeed readFeed() throws IOException, FeedException {
|
||||
URL feedSource = new URL("http://rssblog.whatisrss.com/feed/");
|
||||
SyndFeedInput input = new SyndFeedInput();
|
||||
return input.build(new XmlReader(feedSource));
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.baeldung;
|
||||
package com.baeldung.jool;
|
||||
|
||||
import org.jooq.lambda.Seq;
|
||||
import org.jooq.lambda.Unchecked;
|
||||
|
@ -13,6 +13,7 @@ import java.util.Arrays;
|
|||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
@ -20,7 +21,7 @@ import static junit.framework.Assert.assertTrue;
|
|||
import static junit.framework.TestCase.assertEquals;
|
||||
import static org.jooq.lambda.tuple.Tuple.tuple;
|
||||
|
||||
public class JOOLUnitTest {
|
||||
public class JOOLTest {
|
||||
@Test
|
||||
public void givenSeq_whenCheckContains_shouldReturnTrue() {
|
||||
List<Integer> concat = Seq.of(1, 2, 3).concat(Seq.of(4, 5, 6)).toList();
|
||||
|
@ -54,58 +55,58 @@ public class JOOLUnitTest {
|
|||
@Test
|
||||
public void givenSeq_whenJoin_shouldHaveElementsFromBothSeq() {
|
||||
assertEquals(
|
||||
Seq.of(1, 2, 4).innerJoin(Seq.of(1, 2, 3), (a, b) -> a == b).toList(),
|
||||
Arrays.asList(tuple(1, 1), tuple(2, 2))
|
||||
Seq.of(1, 2, 4).innerJoin(Seq.of(1, 2, 3), Objects::equals).toList(),
|
||||
Arrays.asList(tuple(1, 1), tuple(2, 2))
|
||||
);
|
||||
|
||||
|
||||
assertEquals(
|
||||
Seq.of(1, 2, 4).leftOuterJoin(Seq.of(1, 2, 3), (a, b) -> a == b).toList(),
|
||||
Arrays.asList(tuple(1, 1), tuple(2, 2), tuple(4, null))
|
||||
Seq.of(1, 2, 4).leftOuterJoin(Seq.of(1, 2, 3), Objects::equals).toList(),
|
||||
Arrays.asList(tuple(1, 1), tuple(2, 2), tuple(4, null))
|
||||
);
|
||||
|
||||
assertEquals(
|
||||
Seq.of(1, 2, 4).rightOuterJoin(Seq.of(1, 2, 3), (a, b) -> a == b).toList(),
|
||||
Arrays.asList(tuple(1, 1), tuple(2, 2), tuple(null, 3))
|
||||
Seq.of(1, 2, 4).rightOuterJoin(Seq.of(1, 2, 3), Objects::equals).toList(),
|
||||
Arrays.asList(tuple(1, 1), tuple(2, 2), tuple(null, 3))
|
||||
);
|
||||
|
||||
assertEquals(
|
||||
Seq.of(1, 2).crossJoin(Seq.of("A", "B")).toList(),
|
||||
Arrays.asList(tuple(1, "A"), tuple(1, "B"), tuple(2, "A"), tuple(2, "B"))
|
||||
Seq.of(1, 2).crossJoin(Seq.of("A", "B")).toList(),
|
||||
Arrays.asList(tuple(1, "A"), tuple(1, "B"), tuple(2, "A"), tuple(2, "B"))
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenSeq_whenManipulateSeq_seqShouldHaveNewElementsInIt() {
|
||||
assertEquals(
|
||||
Seq.of(1, 2, 3).cycle().limit(9).toList(),
|
||||
Arrays.asList(1, 2, 3, 1, 2, 3, 1, 2, 3)
|
||||
Seq.of(1, 2, 3).cycle().limit(9).toList(),
|
||||
Arrays.asList(1, 2, 3, 1, 2, 3, 1, 2, 3)
|
||||
);
|
||||
|
||||
assertEquals(
|
||||
Seq.of(1, 2, 3).duplicate().map((first, second) -> tuple(first.toList(), second.toList())),
|
||||
tuple(Arrays.asList(1, 2, 3), Arrays.asList(1, 2, 3))
|
||||
Seq.of(1, 2, 3).duplicate().map((first, second) -> tuple(first.toList(), second.toList())),
|
||||
tuple(Arrays.asList(1, 2, 3), Arrays.asList(1, 2, 3))
|
||||
);
|
||||
|
||||
assertEquals(
|
||||
Seq.of(1, 2, 3, 4).intersperse(0).toList(),
|
||||
Arrays.asList(1, 0, 2, 0, 3, 0, 4)
|
||||
Seq.of(1, 2, 3, 4).intersperse(0).toList(),
|
||||
Arrays.asList(1, 0, 2, 0, 3, 0, 4)
|
||||
);
|
||||
|
||||
assertEquals(
|
||||
Seq.of(1, 2, 3, 4, 5).shuffle().toList().size(),
|
||||
5
|
||||
Seq.of(1, 2, 3, 4, 5).shuffle().toList().size(),
|
||||
5
|
||||
);
|
||||
|
||||
assertEquals(
|
||||
Seq.of(1, 2, 3, 4).partition(i -> i > 2).map((first, second) -> tuple(first.toList(), second.toList())),
|
||||
tuple(Arrays.asList(3, 4), Arrays.asList(1, 2))
|
||||
Seq.of(1, 2, 3, 4).partition(i -> i > 2).map((first, second) -> tuple(first.toList(), second.toList())),
|
||||
tuple(Arrays.asList(3, 4), Arrays.asList(1, 2))
|
||||
|
||||
);
|
||||
|
||||
assertEquals(
|
||||
Seq.of(1, 2, 3, 4).reverse().toList(),
|
||||
Arrays.asList(4, 3, 2, 1)
|
||||
Seq.of(1, 2, 3, 4).reverse().toList(),
|
||||
Arrays.asList(4, 3, 2, 1)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -117,20 +118,20 @@ public class JOOLUnitTest {
|
|||
expectedAfterGroupBy.put(0, Arrays.asList(2, 4));
|
||||
|
||||
assertEquals(
|
||||
Seq.of(1, 2, 3, 4).groupBy(i -> i % 2),
|
||||
expectedAfterGroupBy
|
||||
Seq.of(1, 2, 3, 4).groupBy(i -> i % 2),
|
||||
expectedAfterGroupBy
|
||||
);
|
||||
|
||||
|
||||
assertEquals(
|
||||
Seq.of("a", "b", "c").foldLeft("!", (u, t) -> u + t),
|
||||
"!abc"
|
||||
Seq.of("a", "b", "c").foldLeft("!", (u, t) -> u + t),
|
||||
"!abc"
|
||||
);
|
||||
|
||||
|
||||
assertEquals(
|
||||
Seq.of("a", "b", "c").foldRight("!", (t, u) -> t + u),
|
||||
"abc!"
|
||||
Seq.of("a", "b", "c").foldRight("!", (t, u) -> t + u),
|
||||
"abc!"
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -138,13 +139,13 @@ public class JOOLUnitTest {
|
|||
public void givenSeq_whenUsingSeqWhile_shouldBehaveAsWhileLoop() {
|
||||
|
||||
assertEquals(
|
||||
Seq.of(1, 2, 3, 4, 5).skipWhile(i -> i < 3).toList(),
|
||||
Arrays.asList(3, 4, 5)
|
||||
Seq.of(1, 2, 3, 4, 5).skipWhile(i -> i < 3).toList(),
|
||||
Arrays.asList(3, 4, 5)
|
||||
);
|
||||
|
||||
assertEquals(
|
||||
Seq.of(1, 2, 3, 4, 5).skipUntil(i -> i == 3).toList(),
|
||||
Arrays.asList(3, 4, 5)
|
||||
Seq.of(1, 2, 3, 4, 5).skipUntil(i -> i == 3).toList(),
|
||||
Arrays.asList(3, 4, 5)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -152,19 +153,19 @@ public class JOOLUnitTest {
|
|||
public void givenSeq_whenZip_shouldHaveZippedSeq() {
|
||||
|
||||
assertEquals(
|
||||
Seq.of(1, 2, 3).zip(Seq.of("a", "b", "c")).toList(),
|
||||
Arrays.asList(tuple(1, "a"), tuple(2, "b"), tuple(3, "c"))
|
||||
Seq.of(1, 2, 3).zip(Seq.of("a", "b", "c")).toList(),
|
||||
Arrays.asList(tuple(1, "a"), tuple(2, "b"), tuple(3, "c"))
|
||||
);
|
||||
|
||||
assertEquals(
|
||||
Seq.of(1, 2, 3).zip(Seq.of("a", "b", "c"), (x, y) -> x + ":" + y).toList(),
|
||||
Arrays.asList("1:a", "2:b", "3:c")
|
||||
Seq.of(1, 2, 3).zip(Seq.of("a", "b", "c"), (x, y) -> x + ":" + y).toList(),
|
||||
Arrays.asList("1:a", "2:b", "3:c")
|
||||
);
|
||||
|
||||
|
||||
assertEquals(
|
||||
Seq.of("a", "b", "c").zipWithIndex().toList(),
|
||||
Arrays.asList(tuple("a", 0L), tuple("b", 1L), tuple("c", 2L))
|
||||
Seq.of("a", "b", "c").zipWithIndex().toList(),
|
||||
Arrays.asList(tuple("a", 0L), tuple("b", 1L), tuple("c", 2L))
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -187,8 +188,8 @@ public class JOOLUnitTest {
|
|||
|
||||
//then
|
||||
assertEquals(
|
||||
collect,
|
||||
Arrays.asList(1, 1, 1)
|
||||
collect,
|
||||
Arrays.asList(1, 1, 1)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -197,13 +198,13 @@ public class JOOLUnitTest {
|
|||
public void givenOperationThatThrowsCheckedException_whenExecuteUsingUncheckedFuction_shouldPass() {
|
||||
//when
|
||||
List<Integer> collect = Stream.of("a", "b", "c")
|
||||
.map(Unchecked.function(elem -> methodThatThrowsChecked(elem)))
|
||||
.collect(Collectors.toList());
|
||||
.map(Unchecked.function(this::methodThatThrowsChecked))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
//then
|
||||
assertEquals(
|
||||
collect,
|
||||
Arrays.asList(1, 1, 1)
|
||||
collect,
|
||||
Arrays.asList(1, 1, 1)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -236,5 +237,4 @@ public class JOOLUnitTest {
|
|||
Arrays.asList(tuple("michael", "similar", "winter", "summer"), tuple("jodie", "variable", "winter", "summer"))
|
||||
);
|
||||
}
|
||||
|
||||
}
|
4
pom.xml
4
pom.xml
|
@ -38,6 +38,7 @@
|
|||
<module>apache-thrift</module>
|
||||
<module>autovalue</module>
|
||||
<module>axon</module>
|
||||
<module>bootique</module>
|
||||
|
||||
<module>cdi</module>
|
||||
<!-- <module>core-java-9</module> -->
|
||||
|
@ -80,10 +81,9 @@
|
|||
<module>javax-servlets</module>
|
||||
<module>javaxval</module>
|
||||
<module>jaxb</module>
|
||||
<!--<module>jee7</module>-->
|
||||
<module>jee7</module>
|
||||
<!-- <module>jhipster/jhipster-monolithic</module> -->
|
||||
<module>jjwt</module>
|
||||
<module>jooq</module>
|
||||
<module>jpa-storedprocedure</module>
|
||||
<module>jsf</module>
|
||||
<module>json-path</module>
|
||||
|
|
|
@ -42,16 +42,11 @@ public class ActivitiController {
|
|||
}
|
||||
|
||||
@GetMapping("/complete-task-A/{processInstanceId}")
|
||||
public TaskRepresentation completeTaskA(@PathVariable String processInstanceId) {
|
||||
public void completeTaskA(@PathVariable String processInstanceId) {
|
||||
Task task = taskService.createTaskQuery()
|
||||
.processInstanceId(processInstanceId)
|
||||
.singleResult();
|
||||
taskService.complete(task.getId());
|
||||
logger.info("Task completed");
|
||||
task = taskService.createTaskQuery()
|
||||
.processInstanceId(processInstanceId)
|
||||
.singleResult();
|
||||
|
||||
return new TaskRepresentation(task.getId(), task.getName(), task.getProcessInstanceId());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
package com.example.activitiwithspring.servicetasks;
|
||||
|
||||
import org.activiti.engine.delegate.DelegateExecution;
|
||||
import org.activiti.engine.delegate.JavaDelegate;
|
||||
|
||||
public class SendEmailServiceTask implements JavaDelegate {
|
||||
|
||||
public void execute(DelegateExecution execution) {
|
||||
//logic to sent email confirmation
|
||||
}
|
||||
|
||||
}
|
|
@ -1,66 +1,35 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||
xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI"
|
||||
xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI"
|
||||
typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath"
|
||||
targetNamespace="http://www.activiti.org/processdef" xmlns:modeler="http://activiti.com/modeler"
|
||||
modeler:version="1.0ev" modeler:exportDateTime="20170619132653"
|
||||
modeler:modelId="1005315" modeler:modelVersion="1"
|
||||
modeler:modelLastUpdated="1497875208422">
|
||||
<process id="my-process" name="my-process"
|
||||
isExecutable="true">
|
||||
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/processdef" xmlns:modeler="http://activiti.com/modeler" modeler:version="1.0ev" modeler:exportDateTime="20170726123124" modeler:modelId="1005315" modeler:modelVersion="1" modeler:modelLastUpdated="1501068675875">
|
||||
<process id="my-process" name="say-hello-process" isExecutable="true">
|
||||
<startEvent id="startEvent" name="startEvent">
|
||||
</startEvent>
|
||||
<sequenceFlow id="sid-1A81F784-4743-4CD6-B81D-A6F61DFBDAF4"
|
||||
sourceRef="startEvent" targetRef="sid-293091EF-68C4-4A5C-B747-B1C46809CB69">
|
||||
</sequenceFlow>
|
||||
<userTask id="sid-293091EF-68C4-4A5C-B747-B1C46809CB69" name="A"
|
||||
activiti:assignee="$INITIATOR">
|
||||
<sequenceFlow id="sequence-flow-1" sourceRef="startEvent" targetRef="A">
|
||||
</sequenceFlow>
|
||||
<userTask id="A" name="A" activiti:assignee="$INITIATOR">
|
||||
</userTask>
|
||||
<sequenceFlow id="sid-EA5C6B84-3FF8-4B39-8961-92F1E230F3FB"
|
||||
sourceRef="sid-293091EF-68C4-4A5C-B747-B1C46809CB69" targetRef="sid-7EAE076A-BCD0-416E-98E2-23A7E37C4010">
|
||||
</sequenceFlow>
|
||||
<userTask id="sid-7EAE076A-BCD0-416E-98E2-23A7E37C4010" name="B"
|
||||
activiti:assignee="$INITIATOR">
|
||||
</userTask>
|
||||
<sequenceFlow id="sid-CB9C412E-AD0B-4EFA-B160-E1DA2507A3D9"
|
||||
sourceRef="sid-7EAE076A-BCD0-416E-98E2-23A7E37C4010" targetRef="endEvent">
|
||||
<sequenceFlow id="sequence-flow-2" sourceRef="A" targetRef="endEvent">
|
||||
</sequenceFlow>
|
||||
<endEvent id="endEvent" name="endEvent">
|
||||
</endEvent>
|
||||
</process>
|
||||
<bpmndi:BPMNDiagram id="BPMNDiagram_say-hello-process">
|
||||
<bpmndi:BPMNPlane bpmnElement="say-hello-process"
|
||||
id="BPMNPlane_say-hello-process">
|
||||
<bpmndi:BPMNPlane bpmnElement="say-hello-process" id="BPMNPlane_say-hello-process">
|
||||
<bpmndi:BPMNShape bpmnElement="startEvent" id="BPMNShape_startEvent">
|
||||
<omgdc:Bounds height="30.0" width="30.0" x="120.0" y="163.0" />
|
||||
<omgdc:Bounds height="30.0" width="30.0" x="120.0" y="163.0"/>
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape bpmnElement="endEvent" id="BPMNShape_endEvent">
|
||||
<omgdc:Bounds height="28.0" width="28.0" x="525.0" y="164.0" />
|
||||
<omgdc:Bounds height="28.0" width="28.0" x="365.0" y="164.0"/>
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape bpmnElement="sid-293091EF-68C4-4A5C-B747-B1C46809CB69"
|
||||
id="BPMNShape_sid-293091EF-68C4-4A5C-B747-B1C46809CB69">
|
||||
<omgdc:Bounds height="80.0" width="100.0" x="210.0" y="138.0" />
|
||||
<bpmndi:BPMNShape bpmnElement="A" id="BPMNShape_A">
|
||||
<omgdc:Bounds height="80.0" width="100.0" x="210.0" y="138.0"/>
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape bpmnElement="sid-7EAE076A-BCD0-416E-98E2-23A7E37C4010"
|
||||
id="BPMNShape_sid-7EAE076A-BCD0-416E-98E2-23A7E37C4010">
|
||||
<omgdc:Bounds height="80.0" width="100.0" x="360.0" y="138.0" />
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNEdge bpmnElement="sid-CB9C412E-AD0B-4EFA-B160-E1DA2507A3D9"
|
||||
id="BPMNEdge_sid-CB9C412E-AD0B-4EFA-B160-E1DA2507A3D9">
|
||||
<omgdi:waypoint x="460.0" y="178.0" />
|
||||
<omgdi:waypoint x="525.0" y="178.0" />
|
||||
<bpmndi:BPMNEdge bpmnElement="sequence-flow-1" id="BPMNEdge_sequence-flow-1">
|
||||
<omgdi:waypoint x="150.0" y="178.0"/>
|
||||
<omgdi:waypoint x="210.0" y="178.0"/>
|
||||
</bpmndi:BPMNEdge>
|
||||
<bpmndi:BPMNEdge bpmnElement="sid-EA5C6B84-3FF8-4B39-8961-92F1E230F3FB"
|
||||
id="BPMNEdge_sid-EA5C6B84-3FF8-4B39-8961-92F1E230F3FB">
|
||||
<omgdi:waypoint x="310.0" y="178.0" />
|
||||
<omgdi:waypoint x="360.0" y="178.0" />
|
||||
</bpmndi:BPMNEdge>
|
||||
<bpmndi:BPMNEdge bpmnElement="sid-1A81F784-4743-4CD6-B81D-A6F61DFBDAF4"
|
||||
id="BPMNEdge_sid-1A81F784-4743-4CD6-B81D-A6F61DFBDAF4">
|
||||
<omgdi:waypoint x="150.0" y="178.0" />
|
||||
<omgdi:waypoint x="210.0" y="178.0" />
|
||||
<bpmndi:BPMNEdge bpmnElement="sequence-flow-2" id="BPMNEdge_sequence-flow-2">
|
||||
<omgdi:waypoint x="310.0" y="178.0"/>
|
||||
<omgdi:waypoint x="365.0" y="178.0"/>
|
||||
</bpmndi:BPMNEdge>
|
||||
</bpmndi:BPMNPlane>
|
||||
</bpmndi:BPMNDiagram>
|
||||
|
|
|
@ -106,14 +106,12 @@ public class ActivitiControllerIntegrationTest {
|
|||
.get(0);
|
||||
|
||||
logger.info("process instance = " + pi.getId());
|
||||
String responseBody = this.mockMvc.perform(MockMvcRequestBuilders.get("/complete-task-A/" + pi.getId()))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
TaskRepresentation task = mapper.readValue(responseBody, TaskRepresentation.class);
|
||||
assertEquals("B", task.getName());
|
||||
this.mockMvc.perform(MockMvcRequestBuilders.get("/complete-task-A/" + pi.getId()))
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
|
||||
List<ProcessInstance> list = runtimeService.createProcessInstanceQuery().list();
|
||||
assertEquals(0, list.size());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
package com.example.activitiwithspring;
|
||||
|
||||
import org.activiti.engine.ProcessEngine;
|
||||
import org.activiti.engine.ProcessEngineConfiguration;
|
||||
import org.activiti.engine.ProcessEngines;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ProcessEngineCreationTests {
|
||||
|
||||
@Test
|
||||
public void givenXMLConfig_whenGetDefault_thenGotProcessEngine() {
|
||||
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
|
||||
assertNotNull(processEngine);
|
||||
assertEquals("root", processEngine.getProcessEngineConfiguration().getJdbcUsername());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenXMLConfig_whenCreateDefaultConfiguration_thenGotProcessEngine() {
|
||||
ProcessEngineConfiguration processEngineConfiguration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResourceDefault();
|
||||
ProcessEngine processEngine = processEngineConfiguration.buildProcessEngine();
|
||||
assertNotNull(processEngine);
|
||||
assertEquals("root", processEngine.getProcessEngineConfiguration().getJdbcUsername());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenDifferentNameXMLConfig_whenGetProcessEngineConfig_thenGotResult() {
|
||||
ProcessEngineConfiguration processEngineConfiguration = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("my.activiti.cfg.xml");
|
||||
ProcessEngine processEngine = processEngineConfiguration.buildProcessEngine();
|
||||
assertNotNull(processEngine);
|
||||
assertEquals("baeldung", processEngine.getProcessEngineConfiguration().getJdbcUsername());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenDifferentBeanNameInXMLConfig_whenGetProcessEngineConfig_thenGotResult() {
|
||||
ProcessEngineConfiguration processEngineConfiguration = ProcessEngineConfiguration
|
||||
.createProcessEngineConfigurationFromResource("my.activiti.cfg.xml", "myProcessEngineConfiguration");
|
||||
ProcessEngine processEngine = processEngineConfiguration.buildProcessEngine();
|
||||
assertNotNull(processEngine);
|
||||
assertEquals("baeldung", processEngine.getProcessEngineConfiguration().getJdbcUsername());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenNoXMLConfig_whenCreateInMemProcessEngineConfig_thenCreated() {
|
||||
ProcessEngineConfiguration processEngineConfiguration = ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration();
|
||||
ProcessEngine processEngine = processEngineConfiguration
|
||||
.setJdbcUrl("jdbc:h2:mem:my-own-in-mem-db;DB_CLOSE_DELAY=1000")
|
||||
.buildProcessEngine();
|
||||
assertNotNull(processEngine);
|
||||
assertEquals("sa", processEngine.getProcessEngineConfiguration().getJdbcUsername());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenNoXMLConfig_whenCreateProcessEngineConfig_thenCreated() {
|
||||
ProcessEngineConfiguration processEngineConfiguration = ProcessEngineConfiguration.createStandaloneProcessEngineConfiguration();
|
||||
ProcessEngine processEngine = processEngineConfiguration
|
||||
.setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE)
|
||||
.setJdbcUrl("jdbc:h2:mem:my-own-db;DB_CLOSE_DELAY=1000")
|
||||
.buildProcessEngine();
|
||||
assertNotNull(processEngine);
|
||||
assertEquals("sa", processEngine.getProcessEngineConfiguration().getJdbcUsername());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
package com.example.activitiwithspring;
|
||||
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.activiti.engine.ActivitiException;
|
||||
import org.activiti.engine.ProcessEngine;
|
||||
import org.activiti.engine.ProcessEngines;
|
||||
import org.activiti.engine.RepositoryService;
|
||||
import org.activiti.engine.RuntimeService;
|
||||
import org.activiti.engine.TaskService;
|
||||
import org.activiti.engine.runtime.ProcessInstance;
|
||||
import org.activiti.engine.task.Task;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ProcessExecutionTests {
|
||||
|
||||
@Test
|
||||
public void givenBPMN_whenDeployProcess_thenDeployed() {
|
||||
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
|
||||
RepositoryService repositoryService = processEngine.getRepositoryService();
|
||||
repositoryService.createDeployment()
|
||||
.addClasspathResource("org/activiti/test/vacationRequest.bpmn20.xml")
|
||||
.deploy();
|
||||
Long count = repositoryService.createProcessDefinitionQuery().count();
|
||||
assertTrue(count >= 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenProcessDefinition_whenStartProcessInstance_thenProcessRunning() {
|
||||
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
|
||||
RepositoryService repositoryService = processEngine.getRepositoryService();
|
||||
repositoryService.createDeployment()
|
||||
.addClasspathResource("org/activiti/test/vacationRequest.bpmn20.xml")
|
||||
.deploy();
|
||||
|
||||
Map<String, Object> variables = new HashMap<String, Object>();
|
||||
variables.put("employeeName", "Kermit");
|
||||
variables.put("numberOfDays", new Integer(4));
|
||||
variables.put("vacationMotivation", "I'm really tired!");
|
||||
|
||||
RuntimeService runtimeService = processEngine.getRuntimeService();
|
||||
ProcessInstance processInstance = runtimeService
|
||||
.startProcessInstanceByKey("vacationRequest", variables);
|
||||
|
||||
Long count = runtimeService.createProcessInstanceQuery().count();
|
||||
assertTrue(count >= 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenProcessInstance_whenCompleteTask_thenProcessExecutionContinues() {
|
||||
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
|
||||
RepositoryService repositoryService = processEngine.getRepositoryService();
|
||||
repositoryService.createDeployment()
|
||||
.addClasspathResource("org/activiti/test/vacationRequest.bpmn20.xml")
|
||||
.deploy();
|
||||
|
||||
Map<String, Object> variables = new HashMap<String, Object>();
|
||||
variables.put("employeeName", "Kermit");
|
||||
variables.put("numberOfDays", new Integer(4));
|
||||
variables.put("vacationMotivation", "I'm really tired!");
|
||||
|
||||
RuntimeService runtimeService = processEngine.getRuntimeService();
|
||||
ProcessInstance processInstance = runtimeService
|
||||
.startProcessInstanceByKey("vacationRequest", variables);
|
||||
|
||||
TaskService taskService = processEngine.getTaskService();
|
||||
List<Task> tasks = taskService.createTaskQuery().taskCandidateGroup("management").list();
|
||||
|
||||
Task task = tasks.get(0);
|
||||
|
||||
Map<String, Object> taskVariables = new HashMap<String, Object>();
|
||||
taskVariables.put("vacationApproved", "false");
|
||||
taskVariables.put("comments", "We have a tight deadline!");
|
||||
taskService.complete(task.getId(), taskVariables);
|
||||
|
||||
Task currentTask = taskService.createTaskQuery().taskName("Modify vacation request").singleResult();
|
||||
assertNotNull(currentTask);
|
||||
}
|
||||
|
||||
@Test(expected = ActivitiException.class)
|
||||
public void givenProcessDefinition_whenSuspend_thenNoProcessInstanceCreated() {
|
||||
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
|
||||
RepositoryService repositoryService = processEngine.getRepositoryService();
|
||||
repositoryService.createDeployment()
|
||||
.addClasspathResource("org/activiti/test/vacationRequest.bpmn20.xml")
|
||||
.deploy();
|
||||
|
||||
RuntimeService runtimeService = processEngine.getRuntimeService();
|
||||
repositoryService.suspendProcessDefinitionByKey("vacationRequest");
|
||||
runtimeService.startProcessInstanceByKey("vacationRequest");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration">
|
||||
|
||||
<property name="jdbcUrl" value="jdbc:h2:mem:activiti;DB_CLOSE_DELAY=1000" />
|
||||
<property name="jdbcDriver" value="org.h2.Driver" />
|
||||
<property name="jdbcUsername" value="root" />
|
||||
<property name="jdbcPassword" value="" />
|
||||
|
||||
<property name="databaseSchemaUpdate" value="true" />
|
||||
</bean>
|
||||
|
||||
</beans>
|
|
@ -0,0 +1,26 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
|
||||
|
||||
<property name="jdbcUrl" value="jdbc:h2:mem:baeldung;DB_CLOSE_DELAY=1000" />
|
||||
<property name="jdbcDriver" value="org.h2.Driver" />
|
||||
<property name="jdbcUsername" value="baeldung" />
|
||||
<property name="jdbcPassword" value="" />
|
||||
|
||||
<property name="databaseSchemaUpdate" value="true" />
|
||||
</bean>
|
||||
|
||||
<bean id="myProcessEngineConfiguration" class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
|
||||
|
||||
<property name="jdbcUrl" value="jdbc:h2:mem:baeldung;DB_CLOSE_DELAY=1000" />
|
||||
<property name="jdbcDriver" value="org.h2.Driver" />
|
||||
<property name="jdbcUsername" value="baeldung" />
|
||||
<property name="jdbcPassword" value="" />
|
||||
|
||||
<property name="databaseSchemaUpdate" value="true" />
|
||||
</bean>
|
||||
|
||||
</beans>
|
|
@ -0,0 +1,149 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/processdef" xmlns:modeler="http://activiti.com/modeler" modeler:version="1.0ev" modeler:exportDateTime="20170708124328" modeler:modelId="1005826" modeler:modelVersion="1" modeler:modelLastUpdated="1499514116825">
|
||||
<process id="vacationRequest" name="vacationRequest" isExecutable="true">
|
||||
<startEvent id="startEvent" name="request" activiti:initiator="employeeName">
|
||||
<extensionElements>
|
||||
<activiti:formProperty id="numberOfDays" name="Number of days" type="long" required="true"/>
|
||||
<activiti:formProperty id="startDate" name="Vacation start date (MM-dd-yyyy)" type="date" datePattern="MM-dd-yyyy hh:mm" required="true"/>
|
||||
<activiti:formProperty id="reason" name="Reason for leave" type="string"/>
|
||||
<modeler:editor-resource-id><![CDATA[startEvent1]]></modeler:editor-resource-id>
|
||||
</extensionElements>
|
||||
</startEvent>
|
||||
<userTask id="handle_vacation_request" name="Handle Request for Vacation">
|
||||
<documentation>${employeeName} would like to take ${numberOfDays} day(s) of vacation (Motivation: ${reason}).</documentation>
|
||||
<extensionElements>
|
||||
<activiti:formProperty id="vacationApproval" name="Do you approve this vacation request?" type="enum" required="true"/>
|
||||
<activiti:formProperty id="comments" name="Comments from Manager" type="string"/>
|
||||
<modeler:allow-send-email><![CDATA[true]]></modeler:allow-send-email>
|
||||
<modeler:activiti-idm-initiator><![CDATA[true]]></modeler:activiti-idm-initiator>
|
||||
<modeler:editor-resource-id><![CDATA[sid-B9AA8E66-2F11-45D0-A270-B052E1A9248E]]></modeler:editor-resource-id>
|
||||
</extensionElements>
|
||||
<potentialOwner>
|
||||
<resourceAssignmentExpression>
|
||||
<formalExpression>management</formalExpression>
|
||||
</resourceAssignmentExpression>
|
||||
</potentialOwner>
|
||||
</userTask>
|
||||
<exclusiveGateway id="sid-12A577AE-5227-4918-8DE1-DC077D70967C">
|
||||
<extensionElements>
|
||||
<modeler:editor-resource-id><![CDATA[sid-12A577AE-5227-4918-8DE1-DC077D70967C]]></modeler:editor-resource-id>
|
||||
</extensionElements>
|
||||
</exclusiveGateway>
|
||||
<userTask id="modify_vacation_request" name="Modify vacation request" activiti:assignee="$INITIATOR">
|
||||
<documentation>Your manager has disapproved your vacation request for ${numberOfDays} days.
|
||||
Reason: ${comments}</documentation>
|
||||
<extensionElements>
|
||||
<activiti:formProperty id="numberOfDays" name="Number of days" type="long" expression="${numberOfDays}" required="true"/>
|
||||
<activiti:formProperty id="startDate" name="First day of vacation(MM-dd-yyyy)" type="date" expression="${startDate}" datePattern="MM-dd-yyyy hh:mm" required="true"/>
|
||||
<activiti:formProperty id="reason" name="Reason for leave" type="string" expression="${reason}"/>
|
||||
<activiti:formProperty id="resendRequest" name="Resend vacation request to manager?" type="enum" required="true"/>
|
||||
<modeler:allow-send-email><![CDATA[true]]></modeler:allow-send-email>
|
||||
<modeler:activiti-idm-initiator><![CDATA[true]]></modeler:activiti-idm-initiator>
|
||||
<modeler:initiator-can-complete><![CDATA[false]]></modeler:initiator-can-complete>
|
||||
<modeler:editor-resource-id><![CDATA[sid-47240E94-C0C1-4886-B856-BC8E757746C9]]></modeler:editor-resource-id>
|
||||
</extensionElements>
|
||||
</userTask>
|
||||
<serviceTask id="send-email-confirmation" name="Send email confirmation" activiti:class="com.example.activitiwithspring.servicetasks.SendEmailServiceTask.java">
|
||||
<extensionElements>
|
||||
<modeler:editor-resource-id><![CDATA[sid-2C5E1831-9101-4F70-9AEF-4BA72B704205]]></modeler:editor-resource-id>
|
||||
</extensionElements>
|
||||
</serviceTask>
|
||||
<sequenceFlow id="flow1" name="flow1" sourceRef="startEvent" targetRef="handle_vacation_request">
|
||||
<extensionElements>
|
||||
<modeler:editor-resource-id><![CDATA[sid-638FA42C-E698-4BC9-9EB3-265968CA4E93]]></modeler:editor-resource-id>
|
||||
</extensionElements>
|
||||
</sequenceFlow>
|
||||
<sequenceFlow id="flow2" name="flow2" sourceRef="handle_vacation_request" targetRef="sid-12A577AE-5227-4918-8DE1-DC077D70967C">
|
||||
<extensionElements>
|
||||
<modeler:editor-resource-id><![CDATA[sid-6F2DDE04-7618-4EEA-B7DC-5BD5E0036BE3]]></modeler:editor-resource-id>
|
||||
</extensionElements>
|
||||
</sequenceFlow>
|
||||
<endEvent id="EndEvent" name="End Event">
|
||||
<extensionElements>
|
||||
<modeler:editor-resource-id><![CDATA[sid-381E38DD-C43B-4D36-8BB1-4C96F4E90A5C]]></modeler:editor-resource-id>
|
||||
</extensionElements>
|
||||
</endEvent>
|
||||
<sequenceFlow id="flow7" name="flow7" sourceRef="send-email-confirmation" targetRef="EndEvent">
|
||||
<extensionElements>
|
||||
<modeler:editor-resource-id><![CDATA[sid-F059DECE-ADF0-4BFC-BCB5-1F670ECA2C1D]]></modeler:editor-resource-id>
|
||||
</extensionElements>
|
||||
</sequenceFlow>
|
||||
<sequenceFlow id="flow3" name="approved" sourceRef="sid-12A577AE-5227-4918-8DE1-DC077D70967C" targetRef="send-email-confirmation">
|
||||
<extensionElements>
|
||||
<modeler:editor-resource-id><![CDATA[sid-609BEB69-E833-4D2F-BD14-FC8F7FD3E9C7]]></modeler:editor-resource-id>
|
||||
</extensionElements>
|
||||
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${vacationApproved == 'true'}]]></conditionExpression>
|
||||
</sequenceFlow>
|
||||
<sequenceFlow id="flow4" name="rejected" sourceRef="sid-12A577AE-5227-4918-8DE1-DC077D70967C" targetRef="modify_vacation_request">
|
||||
<extensionElements>
|
||||
<modeler:editor-resource-id><![CDATA[sid-C5D24BF7-A499-4B44-8670-F4D674475623]]></modeler:editor-resource-id>
|
||||
</extensionElements>
|
||||
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${vacationApproved == 'false'}]]></conditionExpression>
|
||||
</sequenceFlow>
|
||||
<sequenceFlow id="flow6" name="Don't Resend" sourceRef="modify_vacation_request" targetRef="EndEvent">
|
||||
<extensionElements>
|
||||
<modeler:editor-resource-id><![CDATA[sid-5E626939-310D-4A58-947E-B3AE0DCDEE58]]></modeler:editor-resource-id>
|
||||
</extensionElements>
|
||||
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${resendRequest == 'false'}]]></conditionExpression>
|
||||
</sequenceFlow>
|
||||
<sequenceFlow id="flow5" name="Resend Request" sourceRef="modify_vacation_request" targetRef="handle_vacation_request">
|
||||
<extensionElements>
|
||||
<modeler:editor-resource-id><![CDATA[sid-F0B813CA-C242-4C33-861A-5EFDDAE0C66D]]></modeler:editor-resource-id>
|
||||
</extensionElements>
|
||||
<conditionExpression xsi:type="tFormalExpression"><![CDATA[${resendRequest == 'true'}]]></conditionExpression>
|
||||
</sequenceFlow>
|
||||
</process>
|
||||
<bpmndi:BPMNDiagram id="BPMNDiagram_vacationRequest">
|
||||
<bpmndi:BPMNPlane bpmnElement="vacationRequest" id="BPMNPlane_vacationRequest">
|
||||
<bpmndi:BPMNShape bpmnElement="startEvent" id="BPMNShape_startEvent">
|
||||
<omgdc:Bounds height="30.0" width="30.0" x="100.0" y="163.0"/>
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape bpmnElement="handle_vacation_request" id="BPMNShape_handle_vacation_request">
|
||||
<omgdc:Bounds height="80.0" width="100.0" x="210.0" y="138.0"/>
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape bpmnElement="sid-12A577AE-5227-4918-8DE1-DC077D70967C" id="BPMNShape_sid-12A577AE-5227-4918-8DE1-DC077D70967C">
|
||||
<omgdc:Bounds height="40.0" width="40.0" x="375.0" y="158.0"/>
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape bpmnElement="modify_vacation_request" id="BPMNShape_modify_vacation_request">
|
||||
<omgdc:Bounds height="80.0" width="100.0" x="465.0" y="225.0"/>
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape bpmnElement="send-email-confirmation" id="BPMNShape_send-email-confirmation">
|
||||
<omgdc:Bounds height="80.0" width="100.0" x="465.0" y="105.0"/>
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNShape bpmnElement="EndEvent" id="BPMNShape_EndEvent">
|
||||
<omgdc:Bounds height="28.0" width="28.0" x="660.0" y="180.0"/>
|
||||
</bpmndi:BPMNShape>
|
||||
<bpmndi:BPMNEdge bpmnElement="flow1" id="BPMNEdge_flow1">
|
||||
<omgdi:waypoint x="130.0" y="178.0"/>
|
||||
<omgdi:waypoint x="210.0" y="178.0"/>
|
||||
</bpmndi:BPMNEdge>
|
||||
<bpmndi:BPMNEdge bpmnElement="flow2" id="BPMNEdge_flow2">
|
||||
<omgdi:waypoint x="310.0" y="178.18450184501845"/>
|
||||
<omgdi:waypoint x="375.4259259259259" y="178.42592592592592"/>
|
||||
</bpmndi:BPMNEdge>
|
||||
<bpmndi:BPMNEdge bpmnElement="flow3" id="BPMNEdge_flow3">
|
||||
<omgdi:waypoint x="411.12091503267976" y="174.12091503267973"/>
|
||||
<omgdi:waypoint x="465.0" y="159.01673640167365"/>
|
||||
</bpmndi:BPMNEdge>
|
||||
<bpmndi:BPMNEdge bpmnElement="flow4" id="BPMNEdge_flow4">
|
||||
<omgdi:waypoint x="395.5" y="197.5"/>
|
||||
<omgdi:waypoint x="395.5" y="265.0"/>
|
||||
<omgdi:waypoint x="465.0" y="265.0"/>
|
||||
</bpmndi:BPMNEdge>
|
||||
<bpmndi:BPMNEdge bpmnElement="flow5" id="BPMNEdge_flow5">
|
||||
<omgdi:waypoint x="465.0" y="285.0"/>
|
||||
<omgdi:waypoint x="259.75" y="285.0"/>
|
||||
<omgdi:waypoint x="259.99632352941177" y="218.0"/>
|
||||
</bpmndi:BPMNEdge>
|
||||
<bpmndi:BPMNEdge bpmnElement="flow6" id="BPMNEdge_flow6">
|
||||
<omgdi:waypoint x="565.0" y="242.67295597484278"/>
|
||||
<omgdi:waypoint x="661.2166041257227" y="199.70830884952008"/>
|
||||
</bpmndi:BPMNEdge>
|
||||
<bpmndi:BPMNEdge bpmnElement="flow7" id="BPMNEdge_flow7">
|
||||
<omgdi:waypoint x="565.0" y="145.0"/>
|
||||
<omgdi:waypoint x="674.0" y="145.0"/>
|
||||
<omgdi:waypoint x="674.0" y="180.0"/>
|
||||
</bpmndi:BPMNEdge>
|
||||
</bpmndi:BPMNPlane>
|
||||
</bpmndi:BPMNDiagram>
|
||||
</definitions>
|
|
@ -0,0 +1,75 @@
|
|||
package com.baeldung.valuewithdefaults;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.PropertySource;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.primitives.Ints;
|
||||
|
||||
/**
|
||||
* Demonstrates setting defaults for @Value annotation. Note that there are no properties
|
||||
* defined in the specified property source. We also assume that the user here
|
||||
* does not have a system property named some.key.
|
||||
*
|
||||
*/
|
||||
@Configuration
|
||||
@PropertySource(name = "myProperties", value = "valueswithdefaults.properties")
|
||||
public class ValuesWithDefaultsApp {
|
||||
|
||||
@Value("${some.key:my default value}")
|
||||
private String stringWithDefaultValue;
|
||||
|
||||
@Value("${some.key:}")
|
||||
private String stringWithBlankDefaultValue;
|
||||
|
||||
@Value("${some.key:true}")
|
||||
private boolean booleanWithDefaultValue;
|
||||
|
||||
@Value("${some.key:42}")
|
||||
private int intWithDefaultValue;
|
||||
|
||||
@Value("${some.key:one,two,three}")
|
||||
private String[] stringArrayWithDefaults;
|
||||
|
||||
@Value("${some.key:1,2,3}")
|
||||
private int[] intArrayWithDefaults;
|
||||
|
||||
@Value("#{systemProperties['some.key'] ?: 'my default system property value'}")
|
||||
private String spelWithDefaultValue;
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
ApplicationContext applicationContext = new AnnotationConfigApplicationContext(ValuesWithDefaultsApp.class);
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void afterInitialize() {
|
||||
// strings
|
||||
Assert.isTrue(stringWithDefaultValue.equals("my default value"));
|
||||
Assert.isTrue(stringWithBlankDefaultValue.equals(""));
|
||||
|
||||
// other primitives
|
||||
Assert.isTrue(booleanWithDefaultValue);
|
||||
Assert.isTrue(intWithDefaultValue == 42);
|
||||
|
||||
// arrays
|
||||
List<String> stringListValues = Lists.newArrayList("one", "two", "three");
|
||||
Assert.isTrue(Arrays.asList(stringArrayWithDefaults).containsAll(stringListValues));
|
||||
|
||||
List<Integer> intListValues = Lists.newArrayList(1, 2, 3);
|
||||
Assert.isTrue(Ints.asList(intArrayWithDefaults).containsAll(intListValues));
|
||||
|
||||
// SpEL
|
||||
Assert.isTrue(spelWithDefaultValue.equals("my default system property value"));
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue