Skip to content

Commit

Permalink
Merge 202c5e8 into 1956546
Browse files Browse the repository at this point in the history
  • Loading branch information
Edvard Fonsell committed Jun 26, 2018
2 parents 1956546 + 202c5e8 commit 9c7ab27
Show file tree
Hide file tree
Showing 15 changed files with 117 additions and 85 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
## 5.0.0 (2018-mm-dd)

**Highlights**
- Fix to work with Spring Boot 2.x

**Details**
- nflow-rest-api-jax-rs:
- Change endpoint paths for workflow instance: /v1/workflow-instance/{id} -> /v1/workflow-instance/id/{id}

## 4.2.0 (2017-05-16)

**Highlights**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,13 @@ public class WorkflowDefinitionService {

private static final Logger logger = getLogger(WorkflowDefinitionService.class);

private final AbstractResource nonSpringWorkflowsListing;
private AbstractResource nonSpringWorkflowsListing;
private final Map<String, AbstractWorkflowDefinition<? extends WorkflowState>> workflowDefitions = new LinkedHashMap<>();
private final WorkflowDefinitionDao workflowDefinitionDao;
private final boolean persistWorkflowDefinitions;

@Inject
public WorkflowDefinitionService(@NFlow AbstractResource nflowNonSpringWorkflowsListing,
WorkflowDefinitionDao workflowDefinitionDao, Environment env) {
this.nonSpringWorkflowsListing = nflowNonSpringWorkflowsListing;
public WorkflowDefinitionService(WorkflowDefinitionDao workflowDefinitionDao, Environment env) {
this.workflowDefinitionDao = workflowDefinitionDao;
this.persistWorkflowDefinitions = env.getRequiredProperty("nflow.definition.persist", Boolean.class);
}
Expand All @@ -51,13 +49,18 @@ public WorkflowDefinitionService(@NFlow AbstractResource nflowNonSpringWorkflows
* Add given workflow definitions to the managed definitions.
* @param workflowDefinitions The workflow definitions to be added.
*/
@Autowired(required=false)
@Autowired(required = false)
public void setWorkflowDefinitions(Collection<WorkflowDefinition<? extends WorkflowState>> workflowDefinitions) {
for (AbstractWorkflowDefinition<? extends WorkflowState> wd : workflowDefinitions) {
addWorkflowDefinition(wd);
}
}

@Autowired(required = false)
public void setWorkflowDefinitions(@NFlow AbstractResource nflowNonSpringWorkflowsListing) {
this.nonSpringWorkflowsListing = nflowNonSpringWorkflowsListing;
}

/**
* Return the workflow definition that matches the give workflow type name.
* @param type Workflow definition type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public void setup() throws Exception {
String dummyTestClassname = DummyTestWorkflow.class.getName();
ByteArrayInputStream bis = new ByteArrayInputStream(dummyTestClassname.getBytes(UTF_8));
when(nonSpringWorkflowListing.getInputStream()).thenReturn(bis);
service = new WorkflowDefinitionService(nonSpringWorkflowListing, workflowDefinitionDao, env);
service = new WorkflowDefinitionService(workflowDefinitionDao, env);
service.setWorkflowDefinitions(nonSpringWorkflowListing);
assertThat(service.getWorkflowDefinitions().size(), is(equalTo(0)));
service.postProcessWorkflowDefinitions();
assertThat(service.getWorkflowDefinitions().size(), is(equalTo(1)));
Expand Down Expand Up @@ -80,7 +81,7 @@ public void getWorkflowDefinitionReturnsDefinitionWhenTypeIsFound() {

@Test
public void nonSpringWorkflowsAreOptional() throws Exception {
service = new WorkflowDefinitionService(null, workflowDefinitionDao, env);
service = new WorkflowDefinitionService(workflowDefinitionDao, env);
service.postProcessWorkflowDefinitions();
assertEquals(0, service.getWorkflowDefinitions().size());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@

import org.junit.Test;

import io.nflow.jetty.mapper.BadRequestExceptionMapper;

public class BadRequestExceptionMapperTest {
BadRequestExceptionMapper mapper = new BadRequestExceptionMapper();

@Test
public void badRequestExceptionResultInStatusBadRequest() {
Response response = mapper.toResponse(new BadRequestException());
assertThat(response.getStatus(), is(BAD_REQUEST.getStatusCode()));
try (Response response = mapper.toResponse(new BadRequestException())) {
assertThat(response.getStatus(), is(BAD_REQUEST.getStatusCode()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
import org.junit.runner.RunWith;
import org.mockito.junit.MockitoJUnitRunner;

import io.nflow.jetty.mapper.CustomValidationExceptionMapper;

@RunWith(MockitoJUnitRunner.class)
public class CustomValidationExceptionMapperTest {

Expand All @@ -47,9 +45,10 @@ public void constraintViolationExceptionCausesBadRequest() {

ConstraintViolationException cex = mock(ConstraintViolationException.class);
when(cex.getConstraintViolations()).thenReturn(new LinkedHashSet(asList(violation)));
Response resp = exceptionMapper.toResponse(cex);
assertThat(resp.getStatus(), is(BAD_REQUEST_400));
assertThat(resp.getEntity().toString(), is("violationPath: violationMessage"));
try (Response resp = exceptionMapper.toResponse(cex)) {
assertThat(resp.getStatus(), is(BAD_REQUEST_400));
assertThat(resp.getEntity().toString(), is("violationPath: violationMessage"));
}
}

@SuppressWarnings({ "unchecked", "rawtypes" })
Expand All @@ -65,14 +64,16 @@ public void responseConstraintViolationExceptionCausesInternalServerError() {

ConstraintViolationException cex = mock(ResponseConstraintViolationException.class);
when(cex.getConstraintViolations()).thenReturn(new LinkedHashSet(asList(violation)));
Response resp = exceptionMapper.toResponse(cex);
assertThat(resp.getStatus(), is(INTERNAL_SERVER_ERROR_500));
try (Response resp = exceptionMapper.toResponse(cex)) {
assertThat(resp.getStatus(), is(INTERNAL_SERVER_ERROR_500));
}
}

@Test
public void otherExceptionsCauseInternalServerException() {
ValidationException cex = mock(ValidationException.class);
Response resp = exceptionMapper.toResponse(cex);
assertThat(resp.getStatus(), is(INTERNAL_SERVER_ERROR_500));
try (Response resp = exceptionMapper.toResponse(cex)) {
assertThat(resp.getStatus(), is(INTERNAL_SERVER_ERROR_500));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@

import org.junit.Test;

import io.nflow.jetty.mapper.NotFoundExceptionMapper;

public class NotFoundExceptionMapperTest {
NotFoundExceptionMapper mapper = new NotFoundExceptionMapper();

@Test
public void notFoundExceptionResultInStatusNotFound() {
Response response = mapper.toResponse(new NotFoundException());
assertThat(response.getStatus(), is(NOT_FOUND.getStatusCode()));
try (Response response = mapper.toResponse(new NotFoundException())) {
assertThat(response.getStatus(), is(NOT_FOUND.getStatusCode()));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public Response createWorkflowInstance(
}

@PUT
@Path("/{id}")
@Path("/id/{id}")
@ApiOperation(value = "Update workflow instance", notes = "The service is typically used in manual state "
+ "transition via nFlow Explorer or a business UI.")
@ApiResponses({ @ApiResponse(code = 204, message = "If update was successful"),
Expand All @@ -105,7 +105,7 @@ public Response updateWorkflowInstance(@ApiParam("Internal id for workflow insta
}

@GET
@Path("/{id}")
@Path("/id/{id}")
@ApiOperation(value = "Fetch a workflow instance", notes = "Fetch full state and action history of a single workflow instance.")
public ListWorkflowInstanceResponse fetchWorkflowInstance(
@ApiParam("Internal id for workflow instance") @PathParam("id") int id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
import io.nflow.engine.workflow.instance.WorkflowInstanceFactory;
import io.nflow.rest.v1.converter.CreateWorkflowConverter;
import io.nflow.rest.v1.converter.ListWorkflowInstanceConverter;
import io.nflow.rest.v1.jaxrs.WorkflowInstanceResource;
import io.nflow.rest.v1.msg.CreateWorkflowInstanceRequest;
import io.nflow.rest.v1.msg.ListWorkflowInstanceResponse;
import io.nflow.rest.v1.msg.SetSignalRequest;
Expand Down Expand Up @@ -84,7 +83,7 @@ public void setup() {
resource = new WorkflowInstanceResource(workflowInstances, createWorkflowConverter, listWorkflowConverter,
workflowInstanceFactory);
when(workflowInstanceFactory.newWorkflowInstanceBuilder())
.thenReturn(new WorkflowInstance.Builder(new ObjectStringMapper(new ObjectMapper())));
.thenReturn(new WorkflowInstance.Builder(new ObjectStringMapper(new ObjectMapper())));
}

@Test
Expand All @@ -93,12 +92,13 @@ public void createWorkflowInstanceWorks() {
WorkflowInstance inst = mock(WorkflowInstance.class);
when(createWorkflowConverter.convert(req)).thenReturn(inst);
when(workflowInstances.insertWorkflowInstance(inst)).thenReturn(1);
Response r = resource.createWorkflowInstance(req);
assertThat(r.getStatus(), is(201));
assertThat(r.getHeaderString("Location"), is("1"));
verify(createWorkflowConverter).convert(req);
verify(workflowInstances).insertWorkflowInstance(any(WorkflowInstance.class));
verify(workflowInstances).getWorkflowInstance(1, EnumSet.of(WorkflowInstanceInclude.CURRENT_STATE_VARIABLES), null);
try (Response r = resource.createWorkflowInstance(req)) {
assertThat(r.getStatus(), is(201));
assertThat(r.getHeaderString("Location"), is("1"));
verify(createWorkflowConverter).convert(req);
verify(workflowInstances).insertWorkflowInstance(any(WorkflowInstance.class));
verify(workflowInstances).getWorkflowInstance(1, EnumSet.of(WorkflowInstanceInclude.CURRENT_STATE_VARIABLES), null);
}
}

@Test
Expand All @@ -115,8 +115,8 @@ public void whenUpdatingMessageStateTextIsUpdated() {
resource.updateWorkflowInstance(3, req);

verify(workflowInstances).updateWorkflowInstance(
(WorkflowInstance) argThat(allOf(hasField("state", equalTo(req.state)), hasField("status", equalTo(null)))),
(WorkflowInstanceAction) argThat(hasField("stateText", equalTo("my desc"))));
(WorkflowInstance) argThat(allOf(hasField("state", equalTo(req.state)), hasField("status", equalTo(null)))),
(WorkflowInstanceAction) argThat(hasField("stateText", equalTo("my desc"))));
}

@Test
Expand Down Expand Up @@ -181,20 +181,20 @@ public void listWorkflowInstancesWorks() {
resource.listWorkflowInstances(asList(42), asList("type"), 99, 88, asList("state"),
asList(WorkflowInstanceStatus.created), "businessKey", "externalId", "", null, null);
verify(workflowInstances).listWorkflowInstances((QueryWorkflowInstances) argThat(allOf(
hasField("ids", contains(42)),
hasField("types", contains("type")),
hasField("parentWorkflowId", is(99)),
hasField("parentActionId", is(88)),
hasField("states", contains("state")),
hasField("statuses", contains(WorkflowInstanceStatus.created)),
hasField("businessKey", equalTo("businessKey")),
hasField("externalId", equalTo("externalId")),
hasField("includeActions", equalTo(false)),
hasField("includeCurrentStateVariables", equalTo(false)),
hasField("includeActionStateVariables", equalTo(false)),
hasField("includeChildWorkflows", equalTo(false)),
hasField("maxResults", equalTo(null)),
hasField("maxActions", equalTo(null)))));
hasField("ids", contains(42)),
hasField("types", contains("type")),
hasField("parentWorkflowId", is(99)),
hasField("parentActionId", is(88)),
hasField("states", contains("state")),
hasField("statuses", contains(WorkflowInstanceStatus.created)),
hasField("businessKey", equalTo("businessKey")),
hasField("externalId", equalTo("externalId")),
hasField("includeActions", equalTo(false)),
hasField("includeCurrentStateVariables", equalTo(false)),
hasField("includeActionStateVariables", equalTo(false)),
hasField("includeChildWorkflows", equalTo(false)),
hasField("maxResults", equalTo(null)),
hasField("maxActions", equalTo(null)))));
}

@SuppressWarnings("unchecked")
Expand All @@ -204,27 +204,27 @@ public void listWorkflowInstancesWorksWithAllIncludes() {
asList(WorkflowInstanceStatus.created, WorkflowInstanceStatus.executing),
"businessKey", "externalId", "actions,currentStateVariables,actionStateVariables,childWorkflows", 1L, 1L);
verify(workflowInstances).listWorkflowInstances((QueryWorkflowInstances) argThat(allOf(
hasField("ids", contains(42)),
hasField("types", contains("type")),
hasField("parentWorkflowId", is(99)),
hasField("parentActionId", is(88)),
hasField("states", contains("state")),
hasField("statuses", contains(WorkflowInstanceStatus.created, WorkflowInstanceStatus.executing)),
hasField("businessKey", equalTo("businessKey")),
hasField("externalId", equalTo("externalId")),
hasField("includeActions", equalTo(true)),
hasField("includeCurrentStateVariables", equalTo(true)),
hasField("includeActionStateVariables", equalTo(true)),
hasField("includeChildWorkflows", equalTo(true)),
hasField("maxResults", equalTo(1L)),
hasField("maxActions", equalTo(1L)))));
hasField("ids", contains(42)),
hasField("types", contains("type")),
hasField("parentWorkflowId", is(99)),
hasField("parentActionId", is(88)),
hasField("states", contains("state")),
hasField("statuses", contains(WorkflowInstanceStatus.created, WorkflowInstanceStatus.executing)),
hasField("businessKey", equalTo("businessKey")),
hasField("externalId", equalTo("externalId")),
hasField("includeActions", equalTo(true)),
hasField("includeCurrentStateVariables", equalTo(true)),
hasField("includeActionStateVariables", equalTo(true)),
hasField("includeChildWorkflows", equalTo(true)),
hasField("maxResults", equalTo(1L)),
hasField("maxActions", equalTo(1L)))));
}

@Test
public void fetchingNonExistingWorkflowThrowsNotFoundException() {
thrown.expect(NotFoundException.class);
when(workflowInstances.getWorkflowInstance(42, EnumSet.of(WorkflowInstanceInclude.STARTED), null))
.thenThrow(EmptyResultDataAccessException.class);
.thenThrow(EmptyResultDataAccessException.class);
resource.fetchWorkflowInstance(42, null, null);
}

Expand Down Expand Up @@ -260,11 +260,11 @@ public void setSignalWorks() {
req.reason = "testing";
when(workflowInstances.setSignal(99, Optional.of(42), "testing", WorkflowActionType.externalChange)).thenReturn(true);

Response response = resource.setSignal(99, req);

verify(workflowInstances).setSignal(99, Optional.of(42), "testing", WorkflowActionType.externalChange);
assertThat(response.getStatus(), is(Response.Status.OK.getStatusCode()));
assertThat(response.readEntity(String.class), is("Signal was set successfully"));
try (Response response = resource.setSignal(99, req)) {
verify(workflowInstances).setSignal(99, Optional.of(42), "testing", WorkflowActionType.externalChange);
assertThat(response.getStatus(), is(Response.Status.OK.getStatusCode()));
assertThat(response.readEntity(String.class), is("Signal was set successfully"));
}
}

@Test
Expand All @@ -274,11 +274,11 @@ public void setSignalReturnsOkWhenSignalIsNotUpdated() {
req.reason = "testing";
when(workflowInstances.setSignal(99, Optional.empty(), "testing", WorkflowActionType.externalChange)).thenReturn(false);

Response response = resource.setSignal(99, req);

verify(workflowInstances).setSignal(99, Optional.empty(), "testing", WorkflowActionType.externalChange);
assertThat(response.getStatus(), is(Response.Status.OK.getStatusCode()));
assertThat(response.readEntity(String.class), is("Signal was not set"));
try (Response response = resource.setSignal(99, req)) {
verify(workflowInstances).setSignal(99, Optional.empty(), "testing", WorkflowActionType.externalChange);
assertThat(response.getStatus(), is(Response.Status.OK.getStatusCode()));
assertThat(response.readEntity(String.class), is("Signal was not set"));
}
}

}
16 changes: 14 additions & 2 deletions nflow-tests/src/test/java/io/nflow/tests/AbstractNflowTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
@ContextConfiguration(classes = { RestClientConfiguration.class, PropertiesConfiguration.class })
public abstract class AbstractNflowTest {
protected WebClient workflowInstanceResource;
protected WebClient workflowInstanceIdResource;
protected WebClient workflowDefinitionResource;
protected WebClient statisticsResource;

Expand All @@ -58,6 +59,12 @@ public void setWorkflowInstanceResource(@Named("workflowInstance") WebClient cli
this.workflowInstanceResource = fromClient(client, true).to(newUri, false);
}

@Inject
public void setWorkflowInstanceIdResource(@Named("workflowInstanceId") WebClient client) {
String newUri = UriBuilder.fromUri(client.getCurrentURI()).port(server.getPort()).build().toString();
this.workflowInstanceIdResource = fromClient(client, true).to(newUri, false);
}

@Inject
public void setWorkflowDefinitionResource(@Named("workflowDefinition") WebClient client) {
String newUri = UriBuilder.fromUri(client.getCurrentURI()).port(server.getPort()).build().toString();
Expand All @@ -71,7 +78,7 @@ public void setStatisticsResource(@Named("statistics") WebClient client) {
}

protected ListWorkflowInstanceResponse getWorkflowInstance(int instanceId) {
return getInstanceResource(instanceId).query("include", "currentStateVariables,actions,actionStateVariables").get(
return getInstanceIdResource(instanceId).query("include", "currentStateVariables,actions,actionStateVariables").get(
ListWorkflowInstanceResponse.class);
}

Expand All @@ -87,6 +94,11 @@ private WebClient getInstanceResource(int instanceId) {
return client;
}

private WebClient getInstanceIdResource(int instanceId) {
WebClient client = fromClient(workflowInstanceIdResource, true).path(Integer.toString(instanceId));
return client;
}

protected ListWorkflowDefinitionResponse[] getWorkflowDefinitions() {
WebClient client = fromClient(workflowDefinitionResource, true);
return client.get(ListWorkflowDefinitionResponse[].class);
Expand Down Expand Up @@ -144,7 +156,7 @@ protected ObjectMapper nflowObjectMapper() {
}

protected String updateWorkflowInstance(int instanceId, UpdateWorkflowInstanceRequest request) {
return getInstanceResource(instanceId).put(request, String.class);
return getInstanceIdResource(instanceId).put(request, String.class);
}

private <T> T makeWorkflowInstanceQuery(CreateWorkflowInstanceRequest request, Class<T> responseClass) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void t03_moveToGrantLoanState() {
UpdateWorkflowInstanceRequest ureq = new UpdateWorkflowInstanceRequest();
ureq.nextActivationTime = now();
ureq.state = "grantLoan";
fromClient(workflowInstanceResource, true).path(resp.id).put(ureq);
fromClient(workflowInstanceIdResource, true).path(resp.id).put(ureq);
}

@Test(timeout = 5000)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void t04_queryWorkflowWithActionsReturnsEmptyActions() {

@Test
public void t05_queryWorkflowWithoutActionsReturnsNullActions() {
ListWorkflowInstanceResponse instance = fromClient(workflowInstanceResource, true).path(Integer.toString(resp.id))
ListWorkflowInstanceResponse instance = fromClient(workflowInstanceIdResource, true).path(Integer.toString(resp.id))
.get(ListWorkflowInstanceResponse.class);

assertThat(instance.actions, is(nullValue()));
Expand Down
Loading

0 comments on commit 9c7ab27

Please sign in to comment.