Skip to content

Commit

Permalink
Spring Boot docs + cleaning up Spring Boot integration. Example can b…
Browse files Browse the repository at this point in the history
  • Loading branch information
jbarrez committed Dec 17, 2014
1 parent 9dddf9c commit 295f566
Show file tree
Hide file tree
Showing 20 changed files with 763 additions and 101 deletions.
13 changes: 13 additions & 0 deletions modules/activiti-spring-boot/spring-boot-samples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,17 @@
<artifactId>h2</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,18 @@
<artifactId>spring-boot-starter-actuator</artifactId>
<version>5.17.0</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>


Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package org.activiti.spring.boot;
package org.activiti.test.spring.boot;


import java.util.Map;

import org.activiti.engine.ProcessEngine;
import org.activiti.spring.boot.DataSourceProcessEngineAutoConfiguration;
import org.activiti.spring.boot.EndpointAutoConfiguration;
import org.activiti.spring.boot.actuate.endpoint.ProcessEngineEndpoint;
import org.junit.Test;
import org.springframework.boot.actuate.autoconfigure.EndpointWebMvcAutoConfiguration;
Expand All @@ -22,6 +25,7 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.http.ResponseEntity;
import org.springframework.orm.jpa.EntityManagerFactoryAccessor;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

Expand All @@ -45,7 +49,8 @@ public static class EmbeddedContainerConfiguration {
MetricFilterAutoConfiguration.class, EndpointWebMvcAutoConfiguration.class,
ManagementServerPropertiesAutoConfiguration.class,
MetricRepositoryAutoConfiguration.class,
DataSourceProcessEngineAutoConfiguration.DataSourceConfiguration.class, EndpointAutoConfiguration.class})
DataSourceProcessEngineAutoConfiguration.DataSourceProcessEngineConfiguration.class,
EndpointAutoConfiguration.class})
public static class EndpointConfiguration {

@Bean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,45 +1,33 @@
package org.activiti.spring.boot;
package org.activiti.test.spring.boot;


import java.util.List;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.spring.SpringProcessEngineConfiguration;
import org.activiti.spring.boot.DataSourceProcessEngineAutoConfiguration;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import javax.persistence.EntityManagerFactory;
import java.util.List;

/**
* @author Josh Long
*/
public class ProcessEngineAutoConfigurationTest {

@Test
public void processEngineWithJpaEntityManager() throws Exception {
AnnotationConfigApplicationContext context = this.context(DataSourceAutoConfiguration.class,
HibernateJpaAutoConfiguration.class, JpaProcessEngineAutoConfiguration.JpaConfiguration.class);
Assert.assertNotNull("entityManagerFactory should not be null", context.getBean(EntityManagerFactory.class));
Assert.assertNotNull("the processEngine should not be null!", context.getBean(ProcessEngine.class));
SpringProcessEngineConfiguration configuration = context.getBean(SpringProcessEngineConfiguration.class);
Assert.assertNotNull("the " + SpringProcessEngineConfiguration.class.getName() + " should not be null", configuration);
Assert.assertNotNull(configuration.getJpaEntityManagerFactory());
}

@Test
public void processEngineWithBasicDataSource() throws Exception {
AnnotationConfigApplicationContext context = this.context(
DataSourceAutoConfiguration.class, DataSourceProcessEngineAutoConfiguration.DataSourceConfiguration.class);
DataSourceAutoConfiguration.class, DataSourceProcessEngineAutoConfiguration.DataSourceProcessEngineConfiguration.class);
Assert.assertNotNull("the processEngine should not be null!", context.getBean(ProcessEngine.class));
}

@Test
public void launchProcessDefinition() throws Exception {
AnnotationConfigApplicationContext applicationContext = this.context(
DataSourceAutoConfiguration.class, DataSourceProcessEngineAutoConfiguration.DataSourceConfiguration.class);
DataSourceAutoConfiguration.class, DataSourceProcessEngineAutoConfiguration.DataSourceProcessEngineConfiguration.class);
RepositoryService repositoryService = applicationContext.getBean(RepositoryService.class);
Assert.assertNotNull("we should have a default repositoryService included", repositoryService);
List<ProcessDefinition> processDefinitionList = repositoryService.createProcessDefinitionQuery()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
<artifactId>spring-boot-starter-integration</artifactId>
<version>5.17.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package org.activiti.spring.boot;
package org.activiti.test.spring.boot;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.impl.pvm.delegate.ActivityExecution;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.spring.boot.DataSourceProcessEngineAutoConfiguration;
import org.activiti.spring.integration.ActivitiInboundGateway;
import org.activiti.spring.integration.IntegrationActivityBehavior;
import org.junit.Assert;
Expand All @@ -24,17 +30,64 @@
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;

/**
* Test the Spring Integration inbound inboundGateway support.
*
* @author Josh Long
*/
public class IntegrationAutoConfigurationTest {

@Configuration
@Import(BaseConfiguration.class)
public static class InboundGatewayConfiguration {
@Bean
public IntegrationActivityBehavior activitiDelegate(ActivitiInboundGateway activitiInboundGateway) {
return new IntegrationActivityBehavior(activitiInboundGateway);
}

@Bean
public ActivitiInboundGateway inboundGateway(ProcessEngine processEngine) {
return new ActivitiInboundGateway(processEngine, "customerId", "projectId", "orderId");
}

@Bean
public IntegrationFlow inboundProcess(ActivitiInboundGateway inboundGateway) {
return IntegrationFlows
.from(inboundGateway)
.handle(new GenericHandler<ActivityExecution>() {
@Override
public Object handle(ActivityExecution execution, Map<String, Object> headers) {
return MessageBuilder.withPayload(execution)
.setHeader("projectId", projectId)
.setHeader("orderId", "246")
.copyHeaders(headers).build();
}
})
.get();
}


@Bean(name="analysingService")
public AnalysingService service() {
return new AnalysingService();
}

public static class AnalysingService {
private final AtomicReference<String> stringAtomicReference
= new AtomicReference<String>();

public void dump(String projectId) {
this.stringAtomicReference.set(projectId);
}

public AtomicReference<String> getStringAtomicReference() {
return stringAtomicReference;
}
}
}


public static final String projectId = "2143243";

private AnnotationConfigApplicationContext context(Class<?>... clzz) {
AnnotationConfigApplicationContext annotationConfigApplicationContext
Expand All @@ -48,7 +101,7 @@ private AnnotationConfigApplicationContext context(Class<?>... clzz) {
@Test
public void testLaunchingGatewayProcessDefinition() throws Exception {
AnnotationConfigApplicationContext applicationContext = this.context(InboundGatewayConfiguration.class);

RepositoryService repositoryService = applicationContext.getBean(RepositoryService.class);
RuntimeService runtimeService = applicationContext.getBean(RuntimeService.class);
ProcessEngine processEngine = applicationContext.getBean(ProcessEngine.class);
Expand All @@ -72,7 +125,7 @@ public void testLaunchingGatewayProcessDefinition() throws Exception {

@Configuration
@Import({DataSourceAutoConfiguration.class,
DataSourceProcessEngineAutoConfiguration.DataSourceConfiguration.class,
DataSourceProcessEngineAutoConfiguration.DataSourceProcessEngineConfiguration.class,
IntegrationAutoConfiguration.class})
public static class BaseConfiguration {

Expand All @@ -88,55 +141,5 @@ public TaskExecutor taskExecutor() {
}


@Configuration
@Import(BaseConfiguration.class)
public static class InboundGatewayConfiguration {
@Bean
public IntegrationActivityBehavior activitiDelegate(ActivitiInboundGateway activitiInboundGateway) {
return new IntegrationActivityBehavior(activitiInboundGateway);
}

@Bean
public ActivitiInboundGateway inboundGateway(ProcessEngine processEngine) {
return new ActivitiInboundGateway(processEngine, "customerId", "projectId", "orderId");
}

@Bean
public IntegrationFlow inboundProcess(ActivitiInboundGateway inboundGateway) {
return IntegrationFlows
.from(inboundGateway)
.handle(new GenericHandler<ActivityExecution>() {
@Override
public Object handle(ActivityExecution execution, Map<String, Object> headers) {
return MessageBuilder.withPayload(execution)
.setHeader("projectId", projectId)
.setHeader("orderId", "246")
.copyHeaders(headers).build();
}
})
.get();
}


@Bean
public AnalysingService service() {
return new AnalysingService();
}

public static class AnalysingService {
private final AtomicReference<String> stringAtomicReference
= new AtomicReference<String>();

public void dump(String projectId) {
this.stringAtomicReference.set(projectId);
}

public AtomicReference<String> getStringAtomicReference() {
return stringAtomicReference;
}
}
}


public static final String projectId = "2143243";

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
<artifactId>spring-boot-starter-jpa</artifactId>
<version>5.17.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.activiti.test.spring.boot;


import javax.persistence.EntityManagerFactory;

import org.activiti.engine.ProcessEngine;
import org.activiti.spring.SpringProcessEngineConfiguration;
import org.activiti.spring.boot.JpaProcessEngineAutoConfiguration;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
* @author Josh Long
*/
public class ProcessEngineAutoConfigurationTest {

@Test
public void processEngineWithJpaEntityManager() throws Exception {
AnnotationConfigApplicationContext context = this.context(DataSourceAutoConfiguration.class,
HibernateJpaAutoConfiguration.class, JpaProcessEngineAutoConfiguration.JpaConfiguration.class);
Assert.assertNotNull("entityManagerFactory should not be null", context.getBean(EntityManagerFactory.class));
Assert.assertNotNull("the processEngine should not be null!", context.getBean(ProcessEngine.class));
SpringProcessEngineConfiguration configuration = context.getBean(SpringProcessEngineConfiguration.class);
Assert.assertNotNull("the " + SpringProcessEngineConfiguration.class.getName() + " should not be null", configuration);
Assert.assertNotNull(configuration.getJpaEntityManagerFactory());
}


private AnnotationConfigApplicationContext context(Class<?>... clzz) {
AnnotationConfigApplicationContext annotationConfigApplicationContext
= new AnnotationConfigApplicationContext();
annotationConfigApplicationContext.register(clzz);
annotationConfigApplicationContext.refresh();
return annotationConfigApplicationContext;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
<artifactId>spring-boot-starter-security</artifactId>
<version>5.17.0</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>


Expand Down
Loading

0 comments on commit 295f566

Please sign in to comment.