From 0c953abb36dce1d66547fed39d06b7c979effaf0 Mon Sep 17 00:00:00 2001 From: Jan Galinski Date: Sun, 26 Jul 2020 16:20:26 +0200 Subject: [PATCH 01/23] indent with 2 spaces --- .../bpm/data/example/domain/Order.java | 19 +- .../data/example/domain/OrderPosition.java | 19 +- .../data/example/domain/OrderRepository.java | 43 ++- .../data/example/process/OrderApproval.java | 242 ++++++------ .../process/OrderApprovalInstance.java | 2 + .../process/OrderApprovalInstanceFactory.java | 50 +-- .../example/rest/ApproveTaskCompleteDto.java | 10 +- .../bpm/data/example/rest/ApproveTaskDto.java | 174 ++++----- .../example/process/GuardProcessTest.java | 84 ++-- .../rest/ApproveOrderTaskControllerTest.java | 72 ++-- .../src/test/resources/logback.xml | 2 +- .../src/main/kotlin/domain/Order.kt | 24 +- .../src/main/kotlin/domain/OrderPosition.kt | 24 +- .../src/main/kotlin/domain/OrderRepository.kt | 22 +- .../src/main/kotlin/process/OrderApproval.kt | 106 ++--- .../kotlin/process/OrderApprovalInstance.kt | 2 +- .../process/OrderApprovalInstanceFactory.kt | 18 +- .../KotlinJacksonDataFormatConfigurator.kt | 14 +- .../src/test/kotlin/itest/ActionStage.kt | 362 +++++++++--------- .../src/test/kotlin/itest/AssertStage.kt | 22 +- .../itest/RuntimeServiceAdapterITest.kt | 202 +++++----- .../kotlin/itest/TaskServiceAdapterITest.kt | 278 +++++++------- .../kotlin/itest/VariableMapAdapterITest.kt | 1 + .../KotlinJacksonDataFormatConfigurator.kt | 12 +- example/itest/src/test/resources/logback.xml | 2 +- .../spin/ErasedCollectionTypeDetector.java | 143 ++++--- .../spin/SpinTypeDetectorConfigurator.java | 16 +- .../jackson/JacksonDeserializationTest.java | 20 +- .../bpm/data/jackson/MyComplexType.java | 80 ++-- .../data/jackson/SpinDeserializationTest.java | 36 +- .../camunda/bpm/data/CamundaBpmData.java | 35 +- .../adapter/AbstractReadWriteAdapter.java | 87 ++--- .../camunda/bpm/data/adapter/ReadAdapter.java | 9 +- .../bpm/data/adapter/ValueWrapperUtil.java | 230 ++++++----- .../adapter/VariableNotFoundException.java | 16 +- .../bpm/data/adapter/WriteAdapter.java | 3 +- .../adapter/WrongVariableTypeException.java | 14 +- .../basic/AbstractBasicReadWriteAdapter.java | 67 ++-- .../basic/ReadWriteAdapterRuntimeService.java | 92 ++--- .../basic/ReadWriteAdapterTaskService.java | 92 ++--- .../basic/ReadWriteAdapterVariableMap.java | 86 ++--- .../basic/ReadWriteAdapterVariableScope.java | 86 ++--- .../list/AbstractListReadWriteAdapter.java | 84 ++-- .../list/ListReadWriteAdapterCaseService.java | 92 ++--- .../ListReadWriteAdapterRuntimeService.java | 92 ++--- .../list/ListReadWriteAdapterTaskService.java | 92 ++--- .../list/ListReadWriteAdapterVariableMap.java | 86 ++--- .../ListReadWriteAdapterVariableScope.java | 86 ++--- .../map/AbstractMapReadWriteAdapter.java | 102 +++-- .../map/MapReadWriteAdapterCaseService.java | 82 ++-- .../MapReadWriteAdapterRuntimeService.java | 82 ++-- .../map/MapReadWriteAdapterTaskService.java | 82 ++-- .../map/MapReadWriteAdapterVariableMap.java | 88 ++--- .../map/MapReadWriteAdapterVariableScope.java | 88 ++--- .../set/AbstractSetReadWriteAdapter.java | 85 ++-- .../set/SetReadWriteAdapterCaseService.java | 92 ++--- .../SetReadWriteAdapterRuntimeService.java | 92 ++--- .../set/SetReadWriteAdapterTaskService.java | 92 ++--- .../set/SetReadWriteAdapterVariableMap.java | 86 ++--- .../set/SetReadWriteAdapterVariableScope.java | 86 ++--- .../bpm/data/builder/VariableMapBuilder.java | 12 +- .../data/factory/BasicVariableFactory.java | 18 +- .../bpm/data/factory/SetVariableFactory.java | 12 +- .../reader/CaseServiceVariableReader.java | 3 +- .../reader/RuntimeServiceVariableReader.java | 4 +- .../reader/TaskServiceVariableReader.java | 4 +- .../bpm/data/reader/VariableMapReader.java | 2 + .../bpm/data/reader/VariableReader.java | 20 +- .../bpm/data/reader/VariableScopeReader.java | 4 +- .../bpm/data/writer/GlobalVariableWriter.java | 21 +- .../bpm/data/writer/LocalVariableWriter.java | 21 +- .../src/main/kotlin/CamundaBpmDataKotlin.kt | 172 ++++----- .../main/kotlin/VariableFactoryFluentApi.kt | 18 +- .../main/kotlin/acl/AntiCorruptionLayer.kt | 120 +++--- .../src/main/kotlin/acl/CamundaBpmDataACL.kt | 80 ++-- .../main/kotlin/acl/CamundaBpmDataMapper.kt | 140 +++---- .../acl/apply/GlobalScopeReplaceStrategy.kt | 16 +- .../acl/apply/LocalScopeReplaceStrategy.kt | 16 +- .../acl/apply/ValueApplicationStrategy.kt | 10 +- .../IdentityVariableMapTransformer.kt | 4 +- .../acl/transform/VariableMapTransformer.kt | 14 +- .../main/kotlin/guard/CamundaBpmDataGuards.kt | 148 ++++--- .../src/main/kotlin/guard/GuardViolation.kt | 24 +- .../condition/VariableExistsGuardCondition.kt | 30 +- .../guard/condition/VariableGuardCondition.kt | 118 +++--- .../VariableMatchesGuardCondition.kt | 44 +-- .../VariableNotExistsGuardCondition.kt | 30 +- .../condition/VariableValueGuardCondition.kt | 44 +-- .../VariableValueOneOfGuardCondition.kt | 44 +-- .../DefaultGuardExecutionListener.kt | 44 +-- .../integration/DefaultGuardTaskListener.kt | 54 +-- .../integration/GuardViolationException.kt | 26 +- .../acl/CamundaBpmDataACLFactoryTest.java | 20 +- .../data/adapter/ValueWrapperUtilTest.java | 1 + .../ProcessExecutionVariableReaderTest.java | 2 + .../src/test/kotlin/VariablesGuardTest.kt | 50 +-- extension/core/src/test/kotlin/acl/ACLTest.kt | 268 ++++++------- .../kotlin/acl/AntiCorruptionLayerTest.kt | 171 ++++----- .../test/kotlin/acl/CamundaBpmDataACLTest.kt | 106 ++--- .../kotlin/acl/CamundaBpmDataMapperTest.kt | 180 ++++----- .../apply/GlobalScopeReplaceStrategyTest.kt | 22 +- .../apply/LocalScopeReplaceStrategyTest.kt | 22 +- .../IdentityVariableMapTransformerTest.kt | 16 +- .../kotlin/guard/CamundaBpmDataGuardsTest.kt | 350 ++++++++--------- .../guard/VariableGuardConditionTest.kt | 92 ++--- .../integration/GuardExecutionListenerTest.kt | 66 ++-- .../integration/GuardTaskListenerTest.kt | 66 ++-- .../GuardViolationExceptionTest.kt | 26 +- .../src/main/kotlin/CamundaBpmDataMockito.kt | 136 +++---- .../main/kotlin/CaseServiceMockVerifier.kt | 128 +++---- .../kotlin/CaseServiceVariableMockBuilder.kt | 136 +++---- .../main/kotlin/RuntimeServiceMockVerifier.kt | 130 +++---- .../RuntimeServiceVariableMockBuilder.kt | 146 +++---- .../main/kotlin/TaskServiceMockVerifier.kt | 160 ++++---- .../kotlin/TaskServiceVariableMockBuilder.kt | 146 +++---- .../src/test/kotlin/CaseServiceMockingTest.kt | 76 ++-- .../test/kotlin/RuntimeServiceMockingTest.kt | 78 ++-- .../test/kotlin/RuntimeServiceVerifierTest.kt | 126 +++--- .../src/test/kotlin/TaskServiceMockingTest.kt | 78 ++-- .../test/kotlin/TaskServiceVerifierTest.kt | 164 ++++---- 120 files changed, 4401 insertions(+), 4385 deletions(-) diff --git a/example/example-java/src/main/java/io/holunda/camunda/bpm/data/example/domain/Order.java b/example/example-java/src/main/java/io/holunda/camunda/bpm/data/example/domain/Order.java index 092cdb45..d87f30b9 100644 --- a/example/example-java/src/main/java/io/holunda/camunda/bpm/data/example/domain/Order.java +++ b/example/example-java/src/main/java/io/holunda/camunda/bpm/data/example/domain/Order.java @@ -30,8 +30,9 @@ public Order() { /** * Constructor to pass all member attributes. - * @param orderId order id - * @param created creation date + * + * @param orderId order id + * @param created creation date * @param positions list of positions. */ public Order(String orderId, Date created, List positions) { @@ -42,6 +43,7 @@ public Order(String orderId, Date created, List positions) { /** * Sets the order id. + * * @param orderId order id to set. */ public void setOrderId(String orderId) { @@ -50,6 +52,7 @@ public void setOrderId(String orderId) { /** * Sets the created date. + * * @param created created date to set. */ public void setCreated(Date created) { @@ -58,6 +61,7 @@ public void setCreated(Date created) { /** * Sets the order positions. + * * @param positions list of positions to set. */ public void setPositions(List positions) { @@ -66,6 +70,7 @@ public void setPositions(List positions) { /** * Retrieves the order id. + * * @return order id. */ public String getOrderId() { @@ -74,6 +79,7 @@ public String getOrderId() { /** * Retrieves the created date. + * * @return date of create. */ public Date getCreated() { @@ -82,6 +88,7 @@ public Date getCreated() { /** * Retrieves the list of positions. + * * @return list of positions. */ public List getPositions() { @@ -119,9 +126,9 @@ public int hashCode() { @Override public String toString() { return "Order{" + - "orderId='" + orderId + '\'' + - ", created=" + created + - ", positions=" + positions + - '}'; + "orderId='" + orderId + '\'' + + ", created=" + created + + ", positions=" + positions + + '}'; } } diff --git a/example/example-java/src/main/java/io/holunda/camunda/bpm/data/example/domain/OrderPosition.java b/example/example-java/src/main/java/io/holunda/camunda/bpm/data/example/domain/OrderPosition.java index b9e680e8..26003837 100644 --- a/example/example-java/src/main/java/io/holunda/camunda/bpm/data/example/domain/OrderPosition.java +++ b/example/example-java/src/main/java/io/holunda/camunda/bpm/data/example/domain/OrderPosition.java @@ -28,9 +28,10 @@ public OrderPosition() { /** * Constructor setting fields. - * @param title title of position. + * + * @param title title of position. * @param netCost net cost per unit. - * @param amount amount of units. + * @param amount amount of units. */ public OrderPosition(String title, BigDecimal netCost, Long amount) { this.title = title; @@ -40,6 +41,7 @@ public OrderPosition(String title, BigDecimal netCost, Long amount) { /** * Retrieves title. + * * @return position title. */ public String getTitle() { @@ -48,6 +50,7 @@ public String getTitle() { /** * Retrieves net cost per unit. + * * @return net cost per unit. */ public BigDecimal getNetCost() { @@ -56,6 +59,7 @@ public BigDecimal getNetCost() { /** * Retrieves amount of units. + * * @return amount of units. */ public Long getAmount() { @@ -64,6 +68,7 @@ public Long getAmount() { /** * Sets the title. + * * @param title title to set. */ public void setTitle(String title) { @@ -72,6 +77,7 @@ public void setTitle(String title) { /** * Sets net cost per unit. + * * @param netCost net cost to set. */ public void setNetCost(BigDecimal netCost) { @@ -80,6 +86,7 @@ public void setNetCost(BigDecimal netCost) { /** * Sets amount of units. + * * @param amount amount to set. */ public void setAmount(Long amount) { @@ -117,9 +124,9 @@ public int hashCode() { @Override public String toString() { return "OrderPosition{" + - "title='" + title + '\'' + - ", netCost=" + netCost + - ", amount=" + amount + - '}'; + "title='" + title + '\'' + + ", netCost=" + netCost + + ", amount=" + amount + + '}'; } } diff --git a/example/example-java/src/main/java/io/holunda/camunda/bpm/data/example/domain/OrderRepository.java b/example/example-java/src/main/java/io/holunda/camunda/bpm/data/example/domain/OrderRepository.java index df51c35a..6e85df7f 100644 --- a/example/example-java/src/main/java/io/holunda/camunda/bpm/data/example/domain/OrderRepository.java +++ b/example/example-java/src/main/java/io/holunda/camunda/bpm/data/example/domain/OrderRepository.java @@ -16,26 +16,27 @@ @Component public class OrderRepository { - /** - * Internal representation for storage. - */ - private final Map orders = new HashMap<>(); - - public OrderRepository() { - final List positions = new ArrayList<>(); - positions.add(new OrderPosition("Pencil", BigDecimal.valueOf(1.50), 2L)); - positions.add(new OrderPosition("Pen", BigDecimal.valueOf(2.10), 2L)); - orders.put("1", new Order("1", Date.from(Instant.now()), positions)); - } - - - /** - * Loads order by id. - * @param orderId order id to load the order for. - * @return order or null. - */ - public Order loadOrder(String orderId) { - return orders.get(orderId); - } + /** + * Internal representation for storage. + */ + private final Map orders = new HashMap<>(); + + public OrderRepository() { + final List positions = new ArrayList<>(); + positions.add(new OrderPosition("Pencil", BigDecimal.valueOf(1.50), 2L)); + positions.add(new OrderPosition("Pen", BigDecimal.valueOf(2.10), 2L)); + orders.put("1", new Order("1", Date.from(Instant.now()), positions)); + } + + + /** + * Loads order by id. + * + * @param orderId order id to load the order for. + * @return order or null. + */ + public Order loadOrder(String orderId) { + return orders.get(orderId); + } } diff --git a/example/example-java/src/main/java/io/holunda/camunda/bpm/data/example/process/OrderApproval.java b/example/example-java/src/main/java/io/holunda/camunda/bpm/data/example/process/OrderApproval.java index 76d2ab77..2d288c2b 100644 --- a/example/example-java/src/main/java/io/holunda/camunda/bpm/data/example/process/OrderApproval.java +++ b/example/example-java/src/main/java/io/holunda/camunda/bpm/data/example/process/OrderApproval.java @@ -30,129 +30,129 @@ @Configuration public class OrderApproval { - public static final String KEY = "order-approval"; + public static final String KEY = "order-approval"; - enum Elements { - start_order_created, - user_approve_order, - end_order_approved, - end_order_rejected; + enum Elements { + start_order_created, + user_approve_order, + end_order_approved, + end_order_rejected; - static String element(Elements element) { - return element.name(); - } - } - - public static final VariableFactory ORDER_ID = stringVariable("orderId"); - public static final VariableFactory ORDER = customVariable("order", Order.class); - public static final VariableFactory ORDER_APPROVED = booleanVariable("orderApproved"); - public static final VariableFactory ORDER_POSITION = customVariable("orderPosition", OrderPosition.class); - public static final VariableFactory ORDER_TOTAL = customVariable("orderTotal", BigDecimal.class); - - private static final Logger logger = LoggerFactory.getLogger(OrderApproval.class); - - @Autowired - private OrderRepository orderRepository; - - /** - * Loads a primitive variable by id (string) and store a complex variable (order). - * Used in "Load Order" service task in BPMN ${loadOrder} - * - * @return Java delegate - */ - @Bean - public JavaDelegate loadOrder() { - return execution -> { - String orderId = ORDER_ID.from(execution).get(); - Order order = orderRepository.loadOrder(orderId); - ORDER.on(execution).set(order); - }; - } - - /** - * Load a local order position, write a local variable. - */ - @Bean - public JavaDelegate calculateOrderPositions() { - return execution -> { - OrderPosition orderPosition = ORDER_POSITION.from(execution).get(); - BigDecimal oldTotal = ORDER_TOTAL.from(execution).getOptional().orElse(BigDecimal.ZERO); - BigDecimal newTotal = oldTotal.add(orderPosition.getNetCost().multiply(BigDecimal.valueOf(orderPosition.getAmount()))); - ORDER_TOTAL.on(execution).setLocal(newTotal); - - // alternative - // ORDER_TOTAL.on(execution).updateLocal(amount -> amount.add(orderPosition.getNetCost().multiply(BigDecimal.valueOf(orderPosition.getAmount())))); - }; - } - - - /** - * Read a local variable and store it in global variable. - */ - @Bean - public ExecutionListener writeOrderTotal() { - return execution -> - { - BigDecimal total = ORDER_TOTAL.from(execution).get(); - ORDER_TOTAL.on(execution).set(total); - }; - } - - /** - * Checks that the variable "orderId" exists. - * Used as execution listener on start event in BPMN ${guardExecutionListener} - * - * @return execution listener. - */ - @Bean - public ExecutionListener guardExecutionListener() { - return new DefaultGuardExecutionListener(newArrayList(exists(ORDER_ID)), true); - } - - /** - * Checks that the variable "orderApproved" exists. - * Used as task listener on complete of user task in BPMN ${taskExecutionListener} - * - * @return task listener. - */ - @Bean - public TaskListener guardTaskListener() { - return new DefaultGuardTaskListener( - newArrayList( - exists(ORDER_APPROVED) - ), true - ); - } - - - /** - * Logs the task creation. - * - * @param task task passed by the engine. - */ - @EventListener(condition = "#task != null && #task.eventName == 'create'") - public void taskLogger(DelegateTask task) { - logger.info("TASK LOGGER: Created user task {}", task.getId()); - } - - /** - * Logs process start. - * - * @param execution execution passed by the engine. - */ - @EventListener(condition = "#execution != null && #execution.eventName == 'start' && #execution.currentActivityId == 'start_order_created'") - public void processStartLogger(DelegateExecution execution) { - logger.info("INSTANCE LOGGER: Started process instance {}", execution.getProcessInstanceId()); - } - - /** - * Logs process end. - * - * @param execution execution passed by the engine. - */ - @EventListener(condition = "#execution != null && #execution.eventName == 'end' && #execution.currentActivityId == 'end_order_approved'") - public void processEndLogger(DelegateExecution execution) { - logger.info("INSTANCE LOGGER: Finished process instance {}", execution.getProcessInstanceId()); + static String element(Elements element) { + return element.name(); } + } + + public static final VariableFactory ORDER_ID = stringVariable("orderId"); + public static final VariableFactory ORDER = customVariable("order", Order.class); + public static final VariableFactory ORDER_APPROVED = booleanVariable("orderApproved"); + public static final VariableFactory ORDER_POSITION = customVariable("orderPosition", OrderPosition.class); + public static final VariableFactory ORDER_TOTAL = customVariable("orderTotal", BigDecimal.class); + + private static final Logger logger = LoggerFactory.getLogger(OrderApproval.class); + + @Autowired + private OrderRepository orderRepository; + + /** + * Loads a primitive variable by id (string) and store a complex variable (order). + * Used in "Load Order" service task in BPMN ${loadOrder} + * + * @return Java delegate + */ + @Bean + public JavaDelegate loadOrder() { + return execution -> { + String orderId = ORDER_ID.from(execution).get(); + Order order = orderRepository.loadOrder(orderId); + ORDER.on(execution).set(order); + }; + } + + /** + * Load a local order position, write a local variable. + */ + @Bean + public JavaDelegate calculateOrderPositions() { + return execution -> { + OrderPosition orderPosition = ORDER_POSITION.from(execution).get(); + BigDecimal oldTotal = ORDER_TOTAL.from(execution).getOptional().orElse(BigDecimal.ZERO); + BigDecimal newTotal = oldTotal.add(orderPosition.getNetCost().multiply(BigDecimal.valueOf(orderPosition.getAmount()))); + ORDER_TOTAL.on(execution).setLocal(newTotal); + + // alternative + // ORDER_TOTAL.on(execution).updateLocal(amount -> amount.add(orderPosition.getNetCost().multiply(BigDecimal.valueOf(orderPosition.getAmount())))); + }; + } + + + /** + * Read a local variable and store it in global variable. + */ + @Bean + public ExecutionListener writeOrderTotal() { + return execution -> + { + BigDecimal total = ORDER_TOTAL.from(execution).get(); + ORDER_TOTAL.on(execution).set(total); + }; + } + + /** + * Checks that the variable "orderId" exists. + * Used as execution listener on start event in BPMN ${guardExecutionListener} + * + * @return execution listener. + */ + @Bean + public ExecutionListener guardExecutionListener() { + return new DefaultGuardExecutionListener(newArrayList(exists(ORDER_ID)), true); + } + + /** + * Checks that the variable "orderApproved" exists. + * Used as task listener on complete of user task in BPMN ${taskExecutionListener} + * + * @return task listener. + */ + @Bean + public TaskListener guardTaskListener() { + return new DefaultGuardTaskListener( + newArrayList( + exists(ORDER_APPROVED) + ), true + ); + } + + + /** + * Logs the task creation. + * + * @param task task passed by the engine. + */ + @EventListener(condition = "#task != null && #task.eventName == 'create'") + public void taskLogger(DelegateTask task) { + logger.info("TASK LOGGER: Created user task {}", task.getId()); + } + + /** + * Logs process start. + * + * @param execution execution passed by the engine. + */ + @EventListener(condition = "#execution != null && #execution.eventName == 'start' && #execution.currentActivityId == 'start_order_created'") + public void processStartLogger(DelegateExecution execution) { + logger.info("INSTANCE LOGGER: Started process instance {}", execution.getProcessInstanceId()); + } + + /** + * Logs process end. + * + * @param execution execution passed by the engine. + */ + @EventListener(condition = "#execution != null && #execution.eventName == 'end' && #execution.currentActivityId == 'end_order_approved'") + public void processEndLogger(DelegateExecution execution) { + logger.info("INSTANCE LOGGER: Finished process instance {}", execution.getProcessInstanceId()); + } } diff --git a/example/example-java/src/main/java/io/holunda/camunda/bpm/data/example/process/OrderApprovalInstance.java b/example/example-java/src/main/java/io/holunda/camunda/bpm/data/example/process/OrderApprovalInstance.java index 6ff1aa6f..1014e1cc 100644 --- a/example/example-java/src/main/java/io/holunda/camunda/bpm/data/example/process/OrderApprovalInstance.java +++ b/example/example-java/src/main/java/io/holunda/camunda/bpm/data/example/process/OrderApprovalInstance.java @@ -16,6 +16,7 @@ public class OrderApprovalInstance implements Supplier { /** * Creates the supplier. + * * @param instance instance. */ public OrderApprovalInstance(ProcessInstance instance) { @@ -24,6 +25,7 @@ public OrderApprovalInstance(ProcessInstance instance) { /** * Retrieval of the instance. + * * @return instance. */ public ProcessInstance get() { diff --git a/example/example-java/src/main/java/io/holunda/camunda/bpm/data/example/process/OrderApprovalInstanceFactory.java b/example/example-java/src/main/java/io/holunda/camunda/bpm/data/example/process/OrderApprovalInstanceFactory.java index 90b5b95d..2c779369 100644 --- a/example/example-java/src/main/java/io/holunda/camunda/bpm/data/example/process/OrderApprovalInstanceFactory.java +++ b/example/example-java/src/main/java/io/holunda/camunda/bpm/data/example/process/OrderApprovalInstanceFactory.java @@ -16,29 +16,31 @@ @Component public class OrderApprovalInstanceFactory { - /** - * Runtime service to access Camunda API. - */ - private final RuntimeService runtimeService; - - /** - * Constructs the factory. - * @param runtimeService runtime service to use. - */ - public OrderApprovalInstanceFactory(RuntimeService runtimeService) { - this.runtimeService = runtimeService; - } - - /** - * Start new approval process. - * @param orderId id of an order. - * @return instance supplier. - */ - public OrderApprovalInstance start(String orderId) { - VariableMap vars = createVariables(); - ORDER_ID.on(vars).set(orderId); - ProcessInstance instance = runtimeService.startProcessInstanceByKey(OrderApproval.KEY, "order-" + UUID.randomUUID().toString(), vars); - return new OrderApprovalInstance(instance); - } + /** + * Runtime service to access Camunda API. + */ + private final RuntimeService runtimeService; + + /** + * Constructs the factory. + * + * @param runtimeService runtime service to use. + */ + public OrderApprovalInstanceFactory(RuntimeService runtimeService) { + this.runtimeService = runtimeService; + } + + /** + * Start new approval process. + * + * @param orderId id of an order. + * @return instance supplier. + */ + public OrderApprovalInstance start(String orderId) { + VariableMap vars = createVariables(); + ORDER_ID.on(vars).set(orderId); + ProcessInstance instance = runtimeService.startProcessInstanceByKey(OrderApproval.KEY, "order-" + UUID.randomUUID().toString(), vars); + return new OrderApprovalInstance(instance); + } } diff --git a/example/example-java/src/main/java/io/holunda/camunda/bpm/data/example/rest/ApproveTaskCompleteDto.java b/example/example-java/src/main/java/io/holunda/camunda/bpm/data/example/rest/ApproveTaskCompleteDto.java index 25df939a..cddf2f3f 100644 --- a/example/example-java/src/main/java/io/holunda/camunda/bpm/data/example/rest/ApproveTaskCompleteDto.java +++ b/example/example-java/src/main/java/io/holunda/camunda/bpm/data/example/rest/ApproveTaskCompleteDto.java @@ -12,16 +12,21 @@ public class ApproveTaskCompleteDto { /** * Empty constructor. */ - public ApproveTaskCompleteDto() { } + public ApproveTaskCompleteDto() { + } /** * Constructs DTO with response. + * * @param approved response value. */ - public ApproveTaskCompleteDto(Boolean approved) {this.approved = approved;} + public ApproveTaskCompleteDto(Boolean approved) { + this.approved = approved; + } /** * Retrieves response value. + * * @return response value. */ public Boolean getApproved() { @@ -30,6 +35,7 @@ public Boolean getApproved() { /** * Sets response value. + * * @param approved response value to set. */ public void setApproved(Boolean approved) { diff --git a/example/example-java/src/main/java/io/holunda/camunda/bpm/data/example/rest/ApproveTaskDto.java b/example/example-java/src/main/java/io/holunda/camunda/bpm/data/example/rest/ApproveTaskDto.java index 0034742b..b8226dec 100644 --- a/example/example-java/src/main/java/io/holunda/camunda/bpm/data/example/rest/ApproveTaskDto.java +++ b/example/example-java/src/main/java/io/holunda/camunda/bpm/data/example/rest/ApproveTaskDto.java @@ -9,95 +9,97 @@ */ public class ApproveTaskDto { - /** - * Order to carry. - */ - private Order order; - - /** - * Order total. - */ - private BigDecimal orderTotal; - - /** - * Empty constructor. - */ - public ApproveTaskDto() { } - - /** - * Constructs the DTO with order. - * - * @param order order to store. - */ - public ApproveTaskDto(Order order, BigDecimal orderTotal) { - this.order = order; - this.orderTotal = orderTotal; + /** + * Order to carry. + */ + private Order order; + + /** + * Order total. + */ + private BigDecimal orderTotal; + + /** + * Empty constructor. + */ + public ApproveTaskDto() { + } + + /** + * Constructs the DTO with order. + * + * @param order order to store. + */ + public ApproveTaskDto(Order order, BigDecimal orderTotal) { + this.order = order; + this.orderTotal = orderTotal; + } + + /** + * Sets order. + * + * @param order order to set. + */ + public void setOrder(Order order) { + this.order = order; + } + + /** + * Sets order total. + * + * @param orderTotal order total. + */ + public void setOrderTotal(BigDecimal orderTotal) { + this.orderTotal = orderTotal; + } + + /** + * Get order. + * + * @return order to get. + */ + public Order getOrder() { + return order; + } + + /** + * Retrieves the total. + * + * @return order total. + */ + public BigDecimal getOrderTotal() { + return orderTotal; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; } - - /** - * Sets order. - * - * @param order order to set. - */ - public void setOrder(Order order) { - this.order = order; - } - - /** - * Sets order total. - * @param orderTotal order total. - */ - public void setOrderTotal(BigDecimal orderTotal) { - this.orderTotal = orderTotal; + if (o == null || getClass() != o.getClass()) { + return false; } - /** - * Get order. - * - * @return order to get. - */ - public Order getOrder() { - return order; - } - - /** - * Retrieves the total. - * @return order total. - */ - public BigDecimal getOrderTotal() { - return orderTotal; - } + ApproveTaskDto that = (ApproveTaskDto) o; - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - - ApproveTaskDto that = (ApproveTaskDto) o; - - if (order != null ? !order.equals(that.order) : that.order != null) { - return false; - } - return orderTotal != null ? orderTotal.equals(that.orderTotal) : that.orderTotal == null; - } - - @Override - public int hashCode() { - int result = order != null ? order.hashCode() : 0; - result = 31 * result + (orderTotal != null ? orderTotal.hashCode() : 0); - return result; - } - - @Override - public String toString() { - return "ApproveTaskDto{" + - "order=" + order + - ", orderTotal=" + orderTotal + - '}'; + if (order != null ? !order.equals(that.order) : that.order != null) { + return false; } + return orderTotal != null ? orderTotal.equals(that.orderTotal) : that.orderTotal == null; + } + + @Override + public int hashCode() { + int result = order != null ? order.hashCode() : 0; + result = 31 * result + (orderTotal != null ? orderTotal.hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "ApproveTaskDto{" + + "order=" + order + + ", orderTotal=" + orderTotal + + '}'; + } } - diff --git a/example/example-java/src/test/java/io/holunda/camunda/bpm/data/example/process/GuardProcessTest.java b/example/example-java/src/test/java/io/holunda/camunda/bpm/data/example/process/GuardProcessTest.java index 95eb964e..633f6820 100644 --- a/example/example-java/src/test/java/io/holunda/camunda/bpm/data/example/process/GuardProcessTest.java +++ b/example/example-java/src/test/java/io/holunda/camunda/bpm/data/example/process/GuardProcessTest.java @@ -25,58 +25,58 @@ @Deployment(resources = "order_approval.bpmn") public class GuardProcessTest { - @Rule - public final ProcessEngineRule rule = new StandaloneInMemoryTestConfiguration( - Lists.newArrayList(new SpinProcessEnginePlugin()) - ).rule(); + @Rule + public final ProcessEngineRule rule = new StandaloneInMemoryTestConfiguration( + Lists.newArrayList(new SpinProcessEnginePlugin()) + ).rule(); - @Before - public void register() { - OrderApproval config = new OrderApproval(); - Mocks.register("guardExecutionListener", config.guardExecutionListener()); - Mocks.register("guardTaskListener", config.guardTaskListener()); - Mocks.register("orderApproval", new MockOrderApproval()); - } + @Before + public void register() { + OrderApproval config = new OrderApproval(); + Mocks.register("guardExecutionListener", config.guardExecutionListener()); + Mocks.register("guardTaskListener", config.guardTaskListener()); + Mocks.register("orderApproval", new MockOrderApproval()); + } - static class MockOrderApproval { - public JavaDelegate loadOrder() { - return execution -> { - OrderApproval.ORDER.on(execution).set(new Order("1", Date.from(Instant.now()), new ArrayList<>())); - }; - } + static class MockOrderApproval { + public JavaDelegate loadOrder() { + return execution -> { + OrderApproval.ORDER.on(execution).set(new Order("1", Date.from(Instant.now()), new ArrayList<>())); + }; + } - public JavaDelegate calculateOrderPositions() { - return mock(JavaDelegate.class); - } + public JavaDelegate calculateOrderPositions() { + return mock(JavaDelegate.class); } + } - @Test - public void shouldFireExceptionIfOrderIdIsMissing() { + @Test + public void shouldFireExceptionIfOrderIdIsMissing() { - assertThrows( - GuardViolationException.class, - // manual start by-passing the factory - () -> rule.getRuntimeService().startProcessInstanceByKey(OrderApproval.KEY), - "Guard violated by execution '6' in activity 'Order created'\nExpecting variable 'orderId' to be set, but it was not found.\n"); + assertThrows( + GuardViolationException.class, + // manual start by-passing the factory + () -> rule.getRuntimeService().startProcessInstanceByKey(OrderApproval.KEY), + "Guard violated by execution '6' in activity 'Order created'\nExpecting variable 'orderId' to be set, but it was not found.\n"); - } + } - @Test - public void shouldFireExceptionApproveDecisionIsMissing() { + @Test + public void shouldFireExceptionApproveDecisionIsMissing() { - OrderApprovalInstanceFactory factory = new OrderApprovalInstanceFactory(rule.getRuntimeService()); - factory.start("1"); + OrderApprovalInstanceFactory factory = new OrderApprovalInstanceFactory(rule.getRuntimeService()); + factory.start("1"); - // async after start - Job asyncStart = rule.getManagementService().createJobQuery().singleResult(); - rule.getManagementService().executeJob(asyncStart.getId()); - Task task = rule.getTaskService().createTaskQuery().singleResult(); + // async after start + Job asyncStart = rule.getManagementService().createJobQuery().singleResult(); + rule.getManagementService().executeJob(asyncStart.getId()); + Task task = rule.getTaskService().createTaskQuery().singleResult(); - assertThrows( - ProcessEngineException.class, - () -> rule.getTaskService().complete(task.getId()), - "Guard violated in task 'Approve order' (taskId: '21')\nExpecting variable 'orderApproved' to be set, but it was not found.\n" - ); - } + assertThrows( + ProcessEngineException.class, + () -> rule.getTaskService().complete(task.getId()), + "Guard violated in task 'Approve order' (taskId: '21')\nExpecting variable 'orderApproved' to be set, but it was not found.\n" + ); + } } diff --git a/example/example-java/src/test/java/io/holunda/camunda/bpm/data/example/rest/ApproveOrderTaskControllerTest.java b/example/example-java/src/test/java/io/holunda/camunda/bpm/data/example/rest/ApproveOrderTaskControllerTest.java index a3eac7c9..de27a1fe 100644 --- a/example/example-java/src/test/java/io/holunda/camunda/bpm/data/example/rest/ApproveOrderTaskControllerTest.java +++ b/example/example-java/src/test/java/io/holunda/camunda/bpm/data/example/rest/ApproveOrderTaskControllerTest.java @@ -26,44 +26,44 @@ */ public class ApproveOrderTaskControllerTest { - private final static Order order = new Order("ORDER-ID-1", new Date(), new ArrayList<>()); - private final TaskService taskService = mock(TaskService.class); - private final TaskServiceMockVerifier verifier = taskServiceMockVerifier(taskService); - private final ApproveOrderTaskController controller = new ApproveOrderTaskController(taskService); - private String taskId; + private final static Order order = new Order("ORDER-ID-1", new Date(), new ArrayList<>()); + private final TaskService taskService = mock(TaskService.class); + private final TaskServiceMockVerifier verifier = taskServiceMockVerifier(taskService); + private final ApproveOrderTaskController controller = new ApproveOrderTaskController(taskService); + private String taskId; - @Before - public void prepareTest() { - reset(taskService); - taskId = UUID.randomUUID().toString(); - } + @Before + public void prepareTest() { + reset(taskService); + taskId = UUID.randomUUID().toString(); + } - @Test - public void testLoadTask() { - // given - taskServiceVariableMockBuilder(taskService) - .initial(ORDER, order) - .initial(ORDER_TOTAL, BigDecimal.ZERO) - .build(); - // when - ResponseEntity responseEntity = controller.loadTask(taskId); - // then - assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK); - assertThat(responseEntity.getBody()).isEqualTo(new ApproveTaskDto(order, BigDecimal.ZERO)); - verifier.verifyGet(ORDER, taskId); - verifier.verifyGet(ORDER_TOTAL, taskId); - verifier.verifyNoMoreInteractions(); - } + @Test + public void testLoadTask() { + // given + taskServiceVariableMockBuilder(taskService) + .initial(ORDER, order) + .initial(ORDER_TOTAL, BigDecimal.ZERO) + .build(); + // when + ResponseEntity responseEntity = controller.loadTask(taskId); + // then + assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(responseEntity.getBody()).isEqualTo(new ApproveTaskDto(order, BigDecimal.ZERO)); + verifier.verifyGet(ORDER, taskId); + verifier.verifyGet(ORDER_TOTAL, taskId); + verifier.verifyNoMoreInteractions(); + } - @Test - public void testCompleteTask() { - // when - ApproveTaskCompleteDto response = new ApproveTaskCompleteDto(true); - ResponseEntity responseEntity = controller.completeTask(taskId, response); - // then - assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT); - verifier.verifyComplete(builder().set(ORDER_APPROVED, response.getApproved()).build(), taskId); - verifier.verifyNoMoreInteractions(); - } + @Test + public void testCompleteTask() { + // when + ApproveTaskCompleteDto response = new ApproveTaskCompleteDto(true); + ResponseEntity responseEntity = controller.completeTask(taskId, response); + // then + assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.NO_CONTENT); + verifier.verifyComplete(builder().set(ORDER_APPROVED, response.getApproved()).build(), taskId); + verifier.verifyNoMoreInteractions(); + } } diff --git a/example/example-java/src/test/resources/logback.xml b/example/example-java/src/test/resources/logback.xml index 2651c6ed..95d93801 100644 --- a/example/example-java/src/test/resources/logback.xml +++ b/example/example-java/src/test/resources/logback.xml @@ -9,6 +9,6 @@ - + diff --git a/example/example-kotlin/src/main/kotlin/domain/Order.kt b/example/example-kotlin/src/main/kotlin/domain/Order.kt index 68e6740d..77cf955c 100644 --- a/example/example-kotlin/src/main/kotlin/domain/Order.kt +++ b/example/example-kotlin/src/main/kotlin/domain/Order.kt @@ -6,16 +6,16 @@ import java.util.* * Order business entity. */ data class Order( - /** - * Order id. - */ - val orderId: String, - /** - * Order create date. - */ - val created: Date, - /** - * List of order positions. - */ - val positions: List = listOf() + /** + * Order id. + */ + val orderId: String, + /** + * Order create date. + */ + val created: Date, + /** + * List of order positions. + */ + val positions: List = listOf() ) diff --git a/example/example-kotlin/src/main/kotlin/domain/OrderPosition.kt b/example/example-kotlin/src/main/kotlin/domain/OrderPosition.kt index d4e8d74d..62b1394b 100644 --- a/example/example-kotlin/src/main/kotlin/domain/OrderPosition.kt +++ b/example/example-kotlin/src/main/kotlin/domain/OrderPosition.kt @@ -6,16 +6,16 @@ import java.math.BigDecimal * Order position business entity. */ data class OrderPosition( - /** - * Title. - */ - val title: String, - /** - * Net cost per unit. - */ - val netCost: BigDecimal, - /** - * Amount (number of units). - */ - val amount: Long + /** + * Title. + */ + val title: String, + /** + * Net cost per unit. + */ + val netCost: BigDecimal, + /** + * Amount (number of units). + */ + val amount: Long ) diff --git a/example/example-kotlin/src/main/kotlin/domain/OrderRepository.kt b/example/example-kotlin/src/main/kotlin/domain/OrderRepository.kt index 5bd92d5a..d53ec13e 100644 --- a/example/example-kotlin/src/main/kotlin/domain/OrderRepository.kt +++ b/example/example-kotlin/src/main/kotlin/domain/OrderRepository.kt @@ -11,17 +11,17 @@ import java.time.Instant @Component class OrderRepository { - val orders = mapOf("1" to Order( - orderId = "1", - created = Date.from(Instant.now()), - positions = listOf( - OrderPosition(title = "Pencil", netCost = BigDecimal.valueOf(1.50), amount = 2), - OrderPosition(title = "Pen", netCost = BigDecimal.valueOf(2.10), amount = 2) - ) - )) + val orders = mapOf("1" to Order( + orderId = "1", + created = Date.from(Instant.now()), + positions = listOf( + OrderPosition(title = "Pencil", netCost = BigDecimal.valueOf(1.50), amount = 2), + OrderPosition(title = "Pen", netCost = BigDecimal.valueOf(2.10), amount = 2) + ) + )) - fun loadOrder(orderId: String): Order { - return orders.getValue(orderId) - } + fun loadOrder(orderId: String): Order { + return orders.getValue(orderId) + } } diff --git a/example/example-kotlin/src/main/kotlin/process/OrderApproval.kt b/example/example-kotlin/src/main/kotlin/process/OrderApproval.kt index 00fbf173..5797c4eb 100644 --- a/example/example-kotlin/src/main/kotlin/process/OrderApproval.kt +++ b/example/example-kotlin/src/main/kotlin/process/OrderApproval.kt @@ -28,67 +28,67 @@ import java.math.BigDecimal @Configuration class OrderApproval { - @Autowired - lateinit var orderRepository: OrderRepository + @Autowired + lateinit var orderRepository: OrderRepository - companion object : KLogging() { - const val KEY = "order-approval" - } + companion object : KLogging() { + const val KEY = "order-approval" + } - object Variables { - val ORDER_ID = stringVariable("orderId") - val ORDER: VariableFactory = customVariable("order") - val ORDER_APPROVED = booleanVariable("orderApproved") - val ORDER_POSITION: VariableFactory = customVariable("orderPosition") - val ORDER_TOTAL: VariableFactory = customVariable("orderTotal") - } + object Variables { + val ORDER_ID = stringVariable("orderId") + val ORDER: VariableFactory = customVariable("order") + val ORDER_APPROVED = booleanVariable("orderApproved") + val ORDER_POSITION: VariableFactory = customVariable("orderPosition") + val ORDER_TOTAL: VariableFactory = customVariable("orderTotal") + } - /** - * Load a primitive variable by id (string) and store a complex variable (order). - */ - @Bean - fun loadOrder() = JavaDelegate { execution -> - val orderId = ORDER_ID.from(execution).get() - val order = orderRepository.loadOrder(orderId) - ORDER.on(execution).set(order) - ORDER_TOTAL.on(execution).set(BigDecimal.ZERO) - } + /** + * Load a primitive variable by id (string) and store a complex variable (order). + */ + @Bean + fun loadOrder() = JavaDelegate { execution -> + val orderId = ORDER_ID.from(execution).get() + val order = orderRepository.loadOrder(orderId) + ORDER.on(execution).set(order) + ORDER_TOTAL.on(execution).set(BigDecimal.ZERO) + } - /** - * Load a local order position, write a local variable. - */ - @Bean - fun calculateOrderPositions() = JavaDelegate { execution -> - val orderPosition = ORDER_POSITION.from(execution).get() + /** + * Load a local order position, write a local variable. + */ + @Bean + fun calculateOrderPositions() = JavaDelegate { execution -> + val orderPosition = ORDER_POSITION.from(execution).get() - ORDER_TOTAL.on(execution).update { it.plus(orderPosition.netCost.times(BigDecimal.valueOf(orderPosition.amount))) } - } + ORDER_TOTAL.on(execution).update { it.plus(orderPosition.netCost.times(BigDecimal.valueOf(orderPosition.amount))) } + } - /** - * Read a local variable and store it in global variable. - */ - @Bean - fun writeOrderTotal() = ExecutionListener { execution -> - val total = ORDER_TOTAL.from(execution).get() - ORDER_TOTAL.on(execution).set(total) - } + /** + * Read a local variable and store it in global variable. + */ + @Bean + fun writeOrderTotal() = ExecutionListener { execution -> + val total = ORDER_TOTAL.from(execution).get() + ORDER_TOTAL.on(execution).set(total) + } - /** - * Log the task id. - */ - @EventListener(condition = "#task != null && #task.eventName == 'create'") - fun taskLogger(task: DelegateTask) { - logger.info("TASK LOGGER: Created user task ${task.id}") - } + /** + * Log the task id. + */ + @EventListener(condition = "#task != null && #task.eventName == 'create'") + fun taskLogger(task: DelegateTask) { + logger.info("TASK LOGGER: Created user task ${task.id}") + } - @EventListener(condition = "#execution != null && #execution.eventName == 'start' && #execution.currentActivityId == 'start_order_created'") - fun processStartLogger(execution: DelegateExecution) { - logger.info { "INSTANCE LOGGER: Started process instance ${execution.processInstanceId}" } - } + @EventListener(condition = "#execution != null && #execution.eventName == 'start' && #execution.currentActivityId == 'start_order_created'") + fun processStartLogger(execution: DelegateExecution) { + logger.info { "INSTANCE LOGGER: Started process instance ${execution.processInstanceId}" } + } - @EventListener(condition = "#execution != null && #execution.eventName == 'end' && #execution.currentActivityId == 'end_order_approved'") - fun processEndLogger(execution: DelegateExecution) { - logger.info { "INSTANCE LOGGER: Finished process instance ${execution.processInstanceId}" } - } + @EventListener(condition = "#execution != null && #execution.eventName == 'end' && #execution.currentActivityId == 'end_order_approved'") + fun processEndLogger(execution: DelegateExecution) { + logger.info { "INSTANCE LOGGER: Finished process instance ${execution.processInstanceId}" } + } } diff --git a/example/example-kotlin/src/main/kotlin/process/OrderApprovalInstance.kt b/example/example-kotlin/src/main/kotlin/process/OrderApprovalInstance.kt index 83f78049..827ac0c6 100644 --- a/example/example-kotlin/src/main/kotlin/process/OrderApprovalInstance.kt +++ b/example/example-kotlin/src/main/kotlin/process/OrderApprovalInstance.kt @@ -6,5 +6,5 @@ import org.camunda.bpm.engine.runtime.ProcessInstance * Represents order delivery process instance. */ class OrderApprovalInstance( - private val delegate: ProcessInstance) : ProcessInstance by delegate { + private val delegate: ProcessInstance) : ProcessInstance by delegate { } diff --git a/example/example-kotlin/src/main/kotlin/process/OrderApprovalInstanceFactory.kt b/example/example-kotlin/src/main/kotlin/process/OrderApprovalInstanceFactory.kt index 49a90a7a..642a6cc9 100644 --- a/example/example-kotlin/src/main/kotlin/process/OrderApprovalInstanceFactory.kt +++ b/example/example-kotlin/src/main/kotlin/process/OrderApprovalInstanceFactory.kt @@ -12,16 +12,16 @@ import java.util.* */ @Component class OrderApprovalInstanceFactory( - private val runtimeService: RuntimeService + private val runtimeService: RuntimeService ) { - /** - * Starts the approval process. - */ - fun start(id: String): OrderApprovalInstance { - val vars = VariableMapBuilder().set(ORDER_ID, id).build() - val instance = runtimeService.startProcessInstanceByKey(OrderApproval.KEY, "order-${UUID.randomUUID()}", vars) - return OrderApprovalInstance(instance) - } + /** + * Starts the approval process. + */ + fun start(id: String): OrderApprovalInstance { + val vars = VariableMapBuilder().set(ORDER_ID, id).build() + val instance = runtimeService.startProcessInstanceByKey(OrderApproval.KEY, "order-${UUID.randomUUID()}", vars) + return OrderApprovalInstance(instance) + } } diff --git a/example/example-kotlin/src/main/kotlin/spin/KotlinJacksonDataFormatConfigurator.kt b/example/example-kotlin/src/main/kotlin/spin/KotlinJacksonDataFormatConfigurator.kt index 84821e8c..21fc3566 100644 --- a/example/example-kotlin/src/main/kotlin/spin/KotlinJacksonDataFormatConfigurator.kt +++ b/example/example-kotlin/src/main/kotlin/spin/KotlinJacksonDataFormatConfigurator.kt @@ -7,11 +7,11 @@ import org.camunda.spin.spi.DataFormatConfigurator class KotlinJacksonDataFormatConfigurator : DataFormatConfigurator { - override fun configure(dataFormat: JacksonJsonDataFormat) { - val objectMapper = dataFormat.objectMapper - objectMapper.registerModule(KotlinModule()) - objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false) - } + override fun configure(dataFormat: JacksonJsonDataFormat) { + val objectMapper = dataFormat.objectMapper + objectMapper.registerModule(KotlinModule()) + objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false) + } - override fun getDataFormatClass(): Class = JacksonJsonDataFormat::class.java -} \ No newline at end of file + override fun getDataFormatClass(): Class = JacksonJsonDataFormat::class.java +} diff --git a/example/itest/src/test/kotlin/itest/ActionStage.kt b/example/itest/src/test/kotlin/itest/ActionStage.kt index 75b25caf..d3f86150 100644 --- a/example/itest/src/test/kotlin/itest/ActionStage.kt +++ b/example/itest/src/test/kotlin/itest/ActionStage.kt @@ -23,185 +23,185 @@ import org.springframework.beans.factory.annotation.Autowired @JGivenStage class ActionStage : Stage() { - @Autowired - @ProvidedScenarioState - lateinit var repositoryService: RepositoryService - - @Autowired - @ProvidedScenarioState - lateinit var runtimeService: RuntimeService - - @Autowired - @ProvidedScenarioState - lateinit var taskService: TaskService - - @ProvidedScenarioState - lateinit var processDefinition: ProcessDefinition - - @ProvidedScenarioState - lateinit var processInstance: ProcessInstance - - @ProvidedScenarioState - lateinit var task: Task - - @Autowired - lateinit var delegateConfiguration: CamundaBpmDataITestBase.DelegateConfiguration - - @BeforeScenario - fun cleanUp() { - delegateConfiguration.vars.clear() - delegateConfiguration.optionalVars.clear() - delegateConfiguration.variableMap = Variables.createVariables() - } - - fun process_with_delegate_is_deployed( - processDefinitionKey: String = "process_with_delegate", - delegateExpression: String = "\${serviceTaskDelegate}" - ): ActionStage { - - val instance = Bpmn.createExecutableProcess(processDefinitionKey) - .startEvent("start") - .serviceTask("service_task") - .camundaDelegateExpression(delegateExpression) - .endEvent("end") - .done() - - deploy(processDefinitionKey, instance) - - return self() - } - - fun process_with_user_task_is_deployed( - processDefinitionKey: String = "process_with_user_task", - taskDefinitionKey: String = "user_task" - ): ActionStage { - - val instance = Bpmn.createExecutableProcess(processDefinitionKey) - .startEvent("start") - .userTask(taskDefinitionKey) - .endEvent("end") - .done() - - deploy(processDefinitionKey, instance) - - return self() - } - - fun process_with_user_task_and_delegate_is_deployed( - processDefinitionKey: String = "process_with_user_task", - taskDefinitionKey: String = "user_task", - delegateExpression: String = "\${serviceTaskDelegate}" - ): ActionStage { - - val instance = Bpmn.createExecutableProcess(processDefinitionKey) - .startEvent("start") - .userTask(taskDefinitionKey) - .serviceTask("service_task") - .camundaDelegateExpression(delegateExpression) - .endEvent("end") - .done() - deploy(processDefinitionKey, instance) - - return self() - } - - fun process_with_user_task_and_listener_is_deployed( - processDefinitionKey: String = "process_with_user_task_and_listener", - taskDefinitionKey: String = "user_task", - delegateExpression: String = "\${listenerDelegate}" - ): ActionStage { - - val instance = Bpmn.createExecutableProcess(processDefinitionKey) - .startEvent("start") - .userTask(taskDefinitionKey) - .camundaTaskListenerDelegateExpression("complete", delegateExpression) - .endEvent("end") - .done() - deploy(processDefinitionKey, instance) - - return self() - } - - fun process_with_modifying_delegate_is_deployed( - processDefinitionKey: String = "process_with_delegate", - modifyingDelegateExpression: String = "\${modifyingServiceTaskDelegate}", - delegateExpression: String = "\${serviceTaskDelegate}" - ): ActionStage { - - val instance = Bpmn.createExecutableProcess(processDefinitionKey) - .startEvent("start") - .serviceTask("modifying_service_task") - .camundaDelegateExpression(modifyingDelegateExpression) - .serviceTask("service_task") - .camundaDelegateExpression(delegateExpression) - .endEvent("end") - .done() - - deploy(processDefinitionKey, instance) - return self() - } - - /** - * Starts process with variables. - */ - fun process_is_started_with_variables( - processDefinitionKey: String = this.processDefinition.key, - variables: VariableMap - ): ActionStage { - - processInstance = runtimeService - .startProcessInstanceByKey(processDefinitionKey, variables) - - return self() - } - - /** - * Reads task. - */ - fun process_waits_in_task(taskDefinitionKey: String = "user_task"): ActionStage { - val query = taskService.createTaskQuery().processInstanceId(processInstance.id).taskDefinitionKey(taskDefinitionKey) - Assertions.assertThat(query.count()).isEqualTo(1L) - task = query.singleResult() - return self() - } - - /** - * Completes the task. - */ - fun task_is_completed(): ActionStage { - taskService.complete(task.id) - return self() - } - - /** - * Calls task callback with task service and task. - */ - fun task_is_accessed_in_user_task(taskServiceTaskCallback: (taskService: TaskService, taskId: String) -> Unit): ActionStage { - taskServiceTaskCallback.invoke(this.taskService, this.task.id) - return self() - } - - /** - * Calls execution callback with runtime service and execution. - */ - fun execution_is_accessed_in_wait_state(runtimeServiceExecutionCallback: (runtimeService: RuntimeService, executionId: String) -> Unit): ActionStage { - runtimeServiceExecutionCallback.invoke(this.runtimeService, this.processInstance.id) - return self() - } - - /** - * Deploys process model instance under specified process definition key. - */ - private fun deploy(processDefinitionKey: String, modelInstance: BpmnModelInstance) { - val deployment = repositoryService - .createDeployment() - .addModelInstance("$processDefinitionKey.bpmn", modelInstance) - .name(processDefinitionKey) - .deploy() - - processDefinition = repositoryService - .createProcessDefinitionQuery() - .deploymentId(deployment.id) - .singleResult() - } + @Autowired + @ProvidedScenarioState + lateinit var repositoryService: RepositoryService + + @Autowired + @ProvidedScenarioState + lateinit var runtimeService: RuntimeService + + @Autowired + @ProvidedScenarioState + lateinit var taskService: TaskService + + @ProvidedScenarioState + lateinit var processDefinition: ProcessDefinition + + @ProvidedScenarioState + lateinit var processInstance: ProcessInstance + + @ProvidedScenarioState + lateinit var task: Task + + @Autowired + lateinit var delegateConfiguration: CamundaBpmDataITestBase.DelegateConfiguration + + @BeforeScenario + fun cleanUp() { + delegateConfiguration.vars.clear() + delegateConfiguration.optionalVars.clear() + delegateConfiguration.variableMap = Variables.createVariables() + } + + fun process_with_delegate_is_deployed( + processDefinitionKey: String = "process_with_delegate", + delegateExpression: String = "\${serviceTaskDelegate}" + ): ActionStage { + + val instance = Bpmn.createExecutableProcess(processDefinitionKey) + .startEvent("start") + .serviceTask("service_task") + .camundaDelegateExpression(delegateExpression) + .endEvent("end") + .done() + + deploy(processDefinitionKey, instance) + + return self() + } + + fun process_with_user_task_is_deployed( + processDefinitionKey: String = "process_with_user_task", + taskDefinitionKey: String = "user_task" + ): ActionStage { + + val instance = Bpmn.createExecutableProcess(processDefinitionKey) + .startEvent("start") + .userTask(taskDefinitionKey) + .endEvent("end") + .done() + + deploy(processDefinitionKey, instance) + + return self() + } + + fun process_with_user_task_and_delegate_is_deployed( + processDefinitionKey: String = "process_with_user_task", + taskDefinitionKey: String = "user_task", + delegateExpression: String = "\${serviceTaskDelegate}" + ): ActionStage { + + val instance = Bpmn.createExecutableProcess(processDefinitionKey) + .startEvent("start") + .userTask(taskDefinitionKey) + .serviceTask("service_task") + .camundaDelegateExpression(delegateExpression) + .endEvent("end") + .done() + deploy(processDefinitionKey, instance) + + return self() + } + + fun process_with_user_task_and_listener_is_deployed( + processDefinitionKey: String = "process_with_user_task_and_listener", + taskDefinitionKey: String = "user_task", + delegateExpression: String = "\${listenerDelegate}" + ): ActionStage { + + val instance = Bpmn.createExecutableProcess(processDefinitionKey) + .startEvent("start") + .userTask(taskDefinitionKey) + .camundaTaskListenerDelegateExpression("complete", delegateExpression) + .endEvent("end") + .done() + deploy(processDefinitionKey, instance) + + return self() + } + + fun process_with_modifying_delegate_is_deployed( + processDefinitionKey: String = "process_with_delegate", + modifyingDelegateExpression: String = "\${modifyingServiceTaskDelegate}", + delegateExpression: String = "\${serviceTaskDelegate}" + ): ActionStage { + + val instance = Bpmn.createExecutableProcess(processDefinitionKey) + .startEvent("start") + .serviceTask("modifying_service_task") + .camundaDelegateExpression(modifyingDelegateExpression) + .serviceTask("service_task") + .camundaDelegateExpression(delegateExpression) + .endEvent("end") + .done() + + deploy(processDefinitionKey, instance) + return self() + } + + /** + * Starts process with variables. + */ + fun process_is_started_with_variables( + processDefinitionKey: String = this.processDefinition.key, + variables: VariableMap + ): ActionStage { + + processInstance = runtimeService + .startProcessInstanceByKey(processDefinitionKey, variables) + + return self() + } + + /** + * Reads task. + */ + fun process_waits_in_task(taskDefinitionKey: String = "user_task"): ActionStage { + val query = taskService.createTaskQuery().processInstanceId(processInstance.id).taskDefinitionKey(taskDefinitionKey) + Assertions.assertThat(query.count()).isEqualTo(1L) + task = query.singleResult() + return self() + } + + /** + * Completes the task. + */ + fun task_is_completed(): ActionStage { + taskService.complete(task.id) + return self() + } + + /** + * Calls task callback with task service and task. + */ + fun task_is_accessed_in_user_task(taskServiceTaskCallback: (taskService: TaskService, taskId: String) -> Unit): ActionStage { + taskServiceTaskCallback.invoke(this.taskService, this.task.id) + return self() + } + + /** + * Calls execution callback with runtime service and execution. + */ + fun execution_is_accessed_in_wait_state(runtimeServiceExecutionCallback: (runtimeService: RuntimeService, executionId: String) -> Unit): ActionStage { + runtimeServiceExecutionCallback.invoke(this.runtimeService, this.processInstance.id) + return self() + } + + /** + * Deploys process model instance under specified process definition key. + */ + private fun deploy(processDefinitionKey: String, modelInstance: BpmnModelInstance) { + val deployment = repositoryService + .createDeployment() + .addModelInstance("$processDefinitionKey.bpmn", modelInstance) + .name(processDefinitionKey) + .deploy() + + processDefinition = repositoryService + .createProcessDefinitionQuery() + .deploymentId(deployment.id) + .singleResult() + } } diff --git a/example/itest/src/test/kotlin/itest/AssertStage.kt b/example/itest/src/test/kotlin/itest/AssertStage.kt index fa6ee113..cf0e7b67 100644 --- a/example/itest/src/test/kotlin/itest/AssertStage.kt +++ b/example/itest/src/test/kotlin/itest/AssertStage.kt @@ -12,19 +12,19 @@ import java.util.* @JGivenStage class AssertStage : Stage() { - fun variables_had_value(readValues: Map, variablesWithValue: Set, Any>>): AssertStage { - variablesWithValue.forEach { - Assertions.assertThat(readValues).containsEntry(it.first.name, it.second) - } - return self() + fun variables_had_value(readValues: Map, variablesWithValue: Set, Any>>): AssertStage { + variablesWithValue.forEach { + Assertions.assertThat(readValues).containsEntry(it.first.name, it.second) } + return self() + } - fun variables_had_not_value(readValues: Map, vararg variableWithValue: VariableFactory<*>): AssertStage { - val emptyOptional = Optional.empty() + fun variables_had_not_value(readValues: Map, vararg variableWithValue: VariableFactory<*>): AssertStage { + val emptyOptional = Optional.empty() - variableWithValue.forEach { - Assertions.assertThat(readValues).containsEntry(it.name, emptyOptional) - } - return self() + variableWithValue.forEach { + Assertions.assertThat(readValues).containsEntry(it.name, emptyOptional) } + return self() + } } diff --git a/example/itest/src/test/kotlin/itest/RuntimeServiceAdapterITest.kt b/example/itest/src/test/kotlin/itest/RuntimeServiceAdapterITest.kt index f98f6ec0..a4721cff 100644 --- a/example/itest/src/test/kotlin/itest/RuntimeServiceAdapterITest.kt +++ b/example/itest/src/test/kotlin/itest/RuntimeServiceAdapterITest.kt @@ -29,107 +29,107 @@ import java.util.* class RuntimeServiceAdapterITest : CamundaBpmDataITestBase() { - @Autowired - lateinit var delegateConfiguration: DelegateConfiguration - - @Test - fun `should write to runtime service adapter`() { - - val variables = createVariables() - - given() - .process_with_user_task_and_delegate_is_deployed(delegateExpression = "\${${DelegateConfiguration::readFromVariableScope.name}}") - .and() - .process_is_started_with_variables(variables = variables) - .and() - .process_waits_in_task() - - whenever() - .execution_is_accessed_in_wait_state { runtimeService, executionId -> - STRING_VAR.on(runtimeService, executionId).set(STRING.value) - DATE_VAR.on(runtimeService, executionId).set(DATE.value) - SHORT_VAR.on(runtimeService, executionId).set(SHORT.value) - INT_VAR.on(runtimeService, executionId).set(INT.value) - LONG_VAR.on(runtimeService, executionId).set(LONG.value) - DOUBLE_VAR.on(runtimeService, executionId).set(DOUBLE.value) - BOOLEAN_VAR.on(runtimeService, executionId).set(BOOLEAN.value) - COMPLEX_VAR.on(runtimeService, executionId).set(COMPLEX.value) - LIST_STRING_VAR.on(runtimeService, executionId).set(LIST_STRING.value) - SET_STRING_VAR.on(runtimeService, executionId).set(SET_STRING.value) - MAP_STRING_LONG_VAR.on(runtimeService, executionId).set(MAP_STRING_LONG.value) - COMPLEX_SET_VAR.on(runtimeService, executionId).set(COMPLEX_SET.value) - COMPLEX_LIST_VAR.on(runtimeService, executionId).set(COMPLEX_LIST.value) - COMPLEX_MAP_VAR.on(runtimeService, executionId).set(COMPLEX_MAP.value) - } - .and() - .task_is_completed() - - then() - .variables_had_value(readValues = delegateConfiguration.vars, variablesWithValue = createKeyValuePairs()) - } - - @Test - fun `should remove on runtime service adapter`() { - - given() - .process_with_user_task_and_delegate_is_deployed(delegateExpression = "\${${DelegateConfiguration::readOptionalFromVariableScope.name}}") - .and() - .process_is_started_with_variables(variables = createVariableMapUntyped()) - .and() - .process_waits_in_task() - - whenever() - .execution_is_accessed_in_wait_state { runtimeService, executionId -> - STRING_VAR.on(runtimeService, executionId).remove() - LIST_STRING_VAR.on(runtimeService, executionId).remove() - SET_STRING_VAR.on(runtimeService, executionId).remove() - MAP_STRING_LONG_VAR.on(runtimeService, executionId).remove() - } - .and() - .task_is_completed() - - then() - .variables_had_not_value(delegateConfiguration.optionalVars, - STRING_VAR, - LIST_STRING_VAR, - SET_STRING_VAR, - MAP_STRING_LONG_VAR - ) - .and() - .variables_had_value(delegateConfiguration.optionalVars, setOf(LONG_VAR to Optional.of(LONG.value))) - } - - @Test - fun `should write to variables-map and read runtime adapter`() { - - val vars = HashMap() - - given() - .process_with_user_task_is_deployed() - .and() - .process_is_started_with_variables(variables = createVariableMapUntyped()) - - whenever() - .execution_is_accessed_in_wait_state { runtimeService, executionId -> - vars[STRING_VAR.name] = STRING_VAR.from(runtimeService, executionId).get() - vars[DATE_VAR.name] = DATE_VAR.from(runtimeService, executionId).get() - vars[SHORT_VAR.name] = SHORT_VAR.from(runtimeService, executionId).get() - vars[INT_VAR.name] = INT_VAR.from(runtimeService, executionId).get() - vars[LONG_VAR.name] = LONG_VAR.from(runtimeService, executionId).get() - vars[DOUBLE_VAR.name] = DOUBLE_VAR.from(runtimeService, executionId).get() - vars[BOOLEAN_VAR.name] = BOOLEAN_VAR.from(runtimeService, executionId).get() - vars[COMPLEX_VAR.name] = COMPLEX_VAR.from(runtimeService, executionId).get() - vars[LIST_STRING_VAR.name] = LIST_STRING_VAR.from(runtimeService, executionId).get() - vars[SET_STRING_VAR.name] = SET_STRING_VAR.from(runtimeService, executionId).get() - vars[MAP_STRING_LONG_VAR.name] = MAP_STRING_LONG_VAR.from(runtimeService, executionId).get() - vars[COMPLEX_SET_VAR.name] = COMPLEX_SET_VAR.from(runtimeService, executionId).get() - vars[COMPLEX_LIST_VAR.name] = COMPLEX_LIST_VAR.from(runtimeService, executionId).get() - vars[COMPLEX_MAP_VAR.name] = COMPLEX_MAP_VAR.from(runtimeService, executionId).get() - } - - then() - .variables_had_value(vars, variablesWithValue = createKeyValuePairs()) - } + @Autowired + lateinit var delegateConfiguration: DelegateConfiguration + + @Test + fun `should write to runtime service adapter`() { + + val variables = createVariables() + + given() + .process_with_user_task_and_delegate_is_deployed(delegateExpression = "\${${DelegateConfiguration::readFromVariableScope.name}}") + .and() + .process_is_started_with_variables(variables = variables) + .and() + .process_waits_in_task() + + whenever() + .execution_is_accessed_in_wait_state { runtimeService, executionId -> + STRING_VAR.on(runtimeService, executionId).set(STRING.value) + DATE_VAR.on(runtimeService, executionId).set(DATE.value) + SHORT_VAR.on(runtimeService, executionId).set(SHORT.value) + INT_VAR.on(runtimeService, executionId).set(INT.value) + LONG_VAR.on(runtimeService, executionId).set(LONG.value) + DOUBLE_VAR.on(runtimeService, executionId).set(DOUBLE.value) + BOOLEAN_VAR.on(runtimeService, executionId).set(BOOLEAN.value) + COMPLEX_VAR.on(runtimeService, executionId).set(COMPLEX.value) + LIST_STRING_VAR.on(runtimeService, executionId).set(LIST_STRING.value) + SET_STRING_VAR.on(runtimeService, executionId).set(SET_STRING.value) + MAP_STRING_LONG_VAR.on(runtimeService, executionId).set(MAP_STRING_LONG.value) + COMPLEX_SET_VAR.on(runtimeService, executionId).set(COMPLEX_SET.value) + COMPLEX_LIST_VAR.on(runtimeService, executionId).set(COMPLEX_LIST.value) + COMPLEX_MAP_VAR.on(runtimeService, executionId).set(COMPLEX_MAP.value) + } + .and() + .task_is_completed() + + then() + .variables_had_value(readValues = delegateConfiguration.vars, variablesWithValue = createKeyValuePairs()) + } + + @Test + fun `should remove on runtime service adapter`() { + + given() + .process_with_user_task_and_delegate_is_deployed(delegateExpression = "\${${DelegateConfiguration::readOptionalFromVariableScope.name}}") + .and() + .process_is_started_with_variables(variables = createVariableMapUntyped()) + .and() + .process_waits_in_task() + + whenever() + .execution_is_accessed_in_wait_state { runtimeService, executionId -> + STRING_VAR.on(runtimeService, executionId).remove() + LIST_STRING_VAR.on(runtimeService, executionId).remove() + SET_STRING_VAR.on(runtimeService, executionId).remove() + MAP_STRING_LONG_VAR.on(runtimeService, executionId).remove() + } + .and() + .task_is_completed() + + then() + .variables_had_not_value(delegateConfiguration.optionalVars, + STRING_VAR, + LIST_STRING_VAR, + SET_STRING_VAR, + MAP_STRING_LONG_VAR + ) + .and() + .variables_had_value(delegateConfiguration.optionalVars, setOf(LONG_VAR to Optional.of(LONG.value))) + } + + @Test + fun `should write to variables-map and read runtime adapter`() { + + val vars = HashMap() + + given() + .process_with_user_task_is_deployed() + .and() + .process_is_started_with_variables(variables = createVariableMapUntyped()) + + whenever() + .execution_is_accessed_in_wait_state { runtimeService, executionId -> + vars[STRING_VAR.name] = STRING_VAR.from(runtimeService, executionId).get() + vars[DATE_VAR.name] = DATE_VAR.from(runtimeService, executionId).get() + vars[SHORT_VAR.name] = SHORT_VAR.from(runtimeService, executionId).get() + vars[INT_VAR.name] = INT_VAR.from(runtimeService, executionId).get() + vars[LONG_VAR.name] = LONG_VAR.from(runtimeService, executionId).get() + vars[DOUBLE_VAR.name] = DOUBLE_VAR.from(runtimeService, executionId).get() + vars[BOOLEAN_VAR.name] = BOOLEAN_VAR.from(runtimeService, executionId).get() + vars[COMPLEX_VAR.name] = COMPLEX_VAR.from(runtimeService, executionId).get() + vars[LIST_STRING_VAR.name] = LIST_STRING_VAR.from(runtimeService, executionId).get() + vars[SET_STRING_VAR.name] = SET_STRING_VAR.from(runtimeService, executionId).get() + vars[MAP_STRING_LONG_VAR.name] = MAP_STRING_LONG_VAR.from(runtimeService, executionId).get() + vars[COMPLEX_SET_VAR.name] = COMPLEX_SET_VAR.from(runtimeService, executionId).get() + vars[COMPLEX_LIST_VAR.name] = COMPLEX_LIST_VAR.from(runtimeService, executionId).get() + vars[COMPLEX_MAP_VAR.name] = COMPLEX_MAP_VAR.from(runtimeService, executionId).get() + } + + then() + .variables_had_value(vars, variablesWithValue = createKeyValuePairs()) + } } diff --git a/example/itest/src/test/kotlin/itest/TaskServiceAdapterITest.kt b/example/itest/src/test/kotlin/itest/TaskServiceAdapterITest.kt index a803f008..70368d8a 100644 --- a/example/itest/src/test/kotlin/itest/TaskServiceAdapterITest.kt +++ b/example/itest/src/test/kotlin/itest/TaskServiceAdapterITest.kt @@ -30,145 +30,145 @@ import kotlin.collections.HashMap class TaskServiceAdapterITest : CamundaBpmDataITestBase() { - @Autowired - lateinit var delegateConfiguration: DelegateConfiguration - - @Test - fun `should write to task service adapter`() { - - given() - .process_with_user_task_and_delegate_is_deployed(delegateExpression = "\${${DelegateConfiguration::readFromVariableScope.name}}") - .and() - .process_is_started_with_variables(variables = createVariables()) - .and() - .process_waits_in_task() - - whenever() - .task_is_accessed_in_user_task { taskService, taskId -> - STRING_VAR.on(taskService, taskId).set(STRING.value) - DATE_VAR.on(taskService, taskId).set(DATE.value) - SHORT_VAR.on(taskService, taskId).set(SHORT.value) - INT_VAR.on(taskService, taskId).set(INT.value) - LONG_VAR.on(taskService, taskId).set(LONG.value) - DOUBLE_VAR.on(taskService, taskId).set(DOUBLE.value) - BOOLEAN_VAR.on(taskService, taskId).set(BOOLEAN.value) - COMPLEX_VAR.on(taskService, taskId).set(COMPLEX.value) - LIST_STRING_VAR.on(taskService, taskId).set(LIST_STRING.value) - SET_STRING_VAR.on(taskService, taskId).set(SET_STRING.value) - MAP_STRING_LONG_VAR.on(taskService, taskId).set(MAP_STRING_LONG.value) - COMPLEX_SET_VAR.on(taskService, taskId).set(Companion.Values.COMPLEX_SET.value) - COMPLEX_LIST_VAR.on(taskService, taskId).set(Companion.Values.COMPLEX_LIST.value) - COMPLEX_MAP_VAR.on(taskService, taskId).set(Companion.Values.COMPLEX_MAP.value) - - } - .and() - .task_is_completed() - - then() - .variables_had_value(readValues = delegateConfiguration.vars, variablesWithValue = createKeyValuePairs()) - } - - @Test - fun `should remove on task service adapter`() { - - given() - .process_with_user_task_and_delegate_is_deployed(delegateExpression = "\${${DelegateConfiguration::readOptionalFromVariableScope.name}}") - .and() - .process_is_started_with_variables(variables = createVariableMapUntyped()) - .and() - .process_waits_in_task() - - whenever() - .task_is_accessed_in_user_task { taskService, taskId -> - STRING_VAR.on(taskService, taskId).remove() - LIST_STRING_VAR.on(taskService, taskId).remove() - SET_STRING_VAR.on(taskService, taskId).remove() - MAP_STRING_LONG_VAR.on(taskService, taskId).remove() - } - .and() - .task_is_completed() - - then() - .variables_had_not_value(delegateConfiguration.optionalVars, - STRING_VAR, - LIST_STRING_VAR, - SET_STRING_VAR, - MAP_STRING_LONG_VAR - ) - .and() - .variables_had_value(delegateConfiguration.optionalVars, - setOf(LONG_VAR to Optional.of(LONG.value)) - ) - } - - - @Test - fun `should write to variables-map and read task service adapter`() { - - val vars = HashMap() - - given() - .process_with_user_task_is_deployed() - .and() - .process_is_started_with_variables(variables = createVariableMapUntyped()) - .and() - .process_waits_in_task() - - whenever() - .task_is_accessed_in_user_task { taskService, taskId -> - vars[STRING_VAR.name] = STRING_VAR.from(taskService, taskId).get() - vars[DATE_VAR.name] = DATE_VAR.from(taskService, taskId).get() - vars[SHORT_VAR.name] = SHORT_VAR.from(taskService, taskId).get() - vars[INT_VAR.name] = INT_VAR.from(taskService, taskId).get() - vars[LONG_VAR.name] = LONG_VAR.from(taskService, taskId).get() - vars[DOUBLE_VAR.name] = DOUBLE_VAR.from(taskService, taskId).get() - vars[BOOLEAN_VAR.name] = BOOLEAN_VAR.from(taskService, taskId).get() - vars[COMPLEX_VAR.name] = COMPLEX_VAR.from(taskService, taskId).get() - vars[LIST_STRING_VAR.name] = LIST_STRING_VAR.from(taskService, taskId).get() - vars[SET_STRING_VAR.name] = SET_STRING_VAR.from(taskService, taskId).get() - vars[MAP_STRING_LONG_VAR.name] = MAP_STRING_LONG_VAR.from(taskService, taskId).get() - vars[COMPLEX_SET_VAR.name] = COMPLEX_SET_VAR.from(taskService, taskId).get() - vars[COMPLEX_LIST_VAR.name] = COMPLEX_LIST_VAR.from(taskService, taskId).get() - vars[COMPLEX_MAP_VAR.name] = COMPLEX_MAP_VAR.from(taskService, taskId).get() - } - - then() - .variables_had_value(readValues = vars, variablesWithValue = createKeyValuePairs()) - } - - @Test - fun `should write local variables to task service adapter`() { - - given() - .process_with_user_task_and_listener_is_deployed(delegateExpression = "\${${DelegateConfiguration::readLocalFromDelegateTask.name}}") - .and() - .process_is_started_with_variables(variables = createVariables()) - .and() - .process_waits_in_task() - - whenever() - .task_is_accessed_in_user_task { taskService, taskId -> - STRING_VAR.on(taskService, taskId).setLocal(STRING_LOCAL.value) - DATE_VAR.on(taskService, taskId).setLocal(DATE_LOCAL.value) - SHORT_VAR.on(taskService, taskId).setLocal(SHORT_LOCAL.value) - INT_VAR.on(taskService, taskId).setLocal(INT_LOCAL.value) - LONG_VAR.on(taskService, taskId).setLocal(LONG_LOCAL.value) - DOUBLE_VAR.on(taskService, taskId).setLocal(DOUBLE_LOCAL.value) - BOOLEAN_VAR.on(taskService, taskId).setLocal(BOOLEAN_LOCAL.value) - COMPLEX_VAR.on(taskService, taskId).setLocal(COMPLEX_LOCAL.value) - LIST_STRING_VAR.on(taskService, taskId).setLocal(LIST_STRING_LOCAL.value) - SET_STRING_VAR.on(taskService, taskId).setLocal(SET_STRING_LOCAL.value) - MAP_STRING_LONG_VAR.on(taskService, taskId).setLocal(MAP_STRING_DATE_LOCAL.value) - COMPLEX_SET_VAR.on(taskService, taskId).setLocal(Companion.Values.COMPLEX_SET_LOCAL.value) - COMPLEX_LIST_VAR.on(taskService, taskId).setLocal(Companion.Values.COMPLEX_LIST_LOCAL.value) - COMPLEX_MAP_VAR.on(taskService, taskId).setLocal(Companion.Values.COMPLEX_MAP_LOCAL.value) - } - .and() - .task_is_completed() - - then() - .variables_had_value(readValues = delegateConfiguration.vars, variablesWithValue = createKeyLocalValuePairs()) - } + @Autowired + lateinit var delegateConfiguration: DelegateConfiguration + + @Test + fun `should write to task service adapter`() { + + given() + .process_with_user_task_and_delegate_is_deployed(delegateExpression = "\${${DelegateConfiguration::readFromVariableScope.name}}") + .and() + .process_is_started_with_variables(variables = createVariables()) + .and() + .process_waits_in_task() + + whenever() + .task_is_accessed_in_user_task { taskService, taskId -> + STRING_VAR.on(taskService, taskId).set(STRING.value) + DATE_VAR.on(taskService, taskId).set(DATE.value) + SHORT_VAR.on(taskService, taskId).set(SHORT.value) + INT_VAR.on(taskService, taskId).set(INT.value) + LONG_VAR.on(taskService, taskId).set(LONG.value) + DOUBLE_VAR.on(taskService, taskId).set(DOUBLE.value) + BOOLEAN_VAR.on(taskService, taskId).set(BOOLEAN.value) + COMPLEX_VAR.on(taskService, taskId).set(COMPLEX.value) + LIST_STRING_VAR.on(taskService, taskId).set(LIST_STRING.value) + SET_STRING_VAR.on(taskService, taskId).set(SET_STRING.value) + MAP_STRING_LONG_VAR.on(taskService, taskId).set(MAP_STRING_LONG.value) + COMPLEX_SET_VAR.on(taskService, taskId).set(Companion.Values.COMPLEX_SET.value) + COMPLEX_LIST_VAR.on(taskService, taskId).set(Companion.Values.COMPLEX_LIST.value) + COMPLEX_MAP_VAR.on(taskService, taskId).set(Companion.Values.COMPLEX_MAP.value) + + } + .and() + .task_is_completed() + + then() + .variables_had_value(readValues = delegateConfiguration.vars, variablesWithValue = createKeyValuePairs()) + } + + @Test + fun `should remove on task service adapter`() { + + given() + .process_with_user_task_and_delegate_is_deployed(delegateExpression = "\${${DelegateConfiguration::readOptionalFromVariableScope.name}}") + .and() + .process_is_started_with_variables(variables = createVariableMapUntyped()) + .and() + .process_waits_in_task() + + whenever() + .task_is_accessed_in_user_task { taskService, taskId -> + STRING_VAR.on(taskService, taskId).remove() + LIST_STRING_VAR.on(taskService, taskId).remove() + SET_STRING_VAR.on(taskService, taskId).remove() + MAP_STRING_LONG_VAR.on(taskService, taskId).remove() + } + .and() + .task_is_completed() + + then() + .variables_had_not_value(delegateConfiguration.optionalVars, + STRING_VAR, + LIST_STRING_VAR, + SET_STRING_VAR, + MAP_STRING_LONG_VAR + ) + .and() + .variables_had_value(delegateConfiguration.optionalVars, + setOf(LONG_VAR to Optional.of(LONG.value)) + ) + } + + + @Test + fun `should write to variables-map and read task service adapter`() { + + val vars = HashMap() + + given() + .process_with_user_task_is_deployed() + .and() + .process_is_started_with_variables(variables = createVariableMapUntyped()) + .and() + .process_waits_in_task() + + whenever() + .task_is_accessed_in_user_task { taskService, taskId -> + vars[STRING_VAR.name] = STRING_VAR.from(taskService, taskId).get() + vars[DATE_VAR.name] = DATE_VAR.from(taskService, taskId).get() + vars[SHORT_VAR.name] = SHORT_VAR.from(taskService, taskId).get() + vars[INT_VAR.name] = INT_VAR.from(taskService, taskId).get() + vars[LONG_VAR.name] = LONG_VAR.from(taskService, taskId).get() + vars[DOUBLE_VAR.name] = DOUBLE_VAR.from(taskService, taskId).get() + vars[BOOLEAN_VAR.name] = BOOLEAN_VAR.from(taskService, taskId).get() + vars[COMPLEX_VAR.name] = COMPLEX_VAR.from(taskService, taskId).get() + vars[LIST_STRING_VAR.name] = LIST_STRING_VAR.from(taskService, taskId).get() + vars[SET_STRING_VAR.name] = SET_STRING_VAR.from(taskService, taskId).get() + vars[MAP_STRING_LONG_VAR.name] = MAP_STRING_LONG_VAR.from(taskService, taskId).get() + vars[COMPLEX_SET_VAR.name] = COMPLEX_SET_VAR.from(taskService, taskId).get() + vars[COMPLEX_LIST_VAR.name] = COMPLEX_LIST_VAR.from(taskService, taskId).get() + vars[COMPLEX_MAP_VAR.name] = COMPLEX_MAP_VAR.from(taskService, taskId).get() + } + + then() + .variables_had_value(readValues = vars, variablesWithValue = createKeyValuePairs()) + } + + @Test + fun `should write local variables to task service adapter`() { + + given() + .process_with_user_task_and_listener_is_deployed(delegateExpression = "\${${DelegateConfiguration::readLocalFromDelegateTask.name}}") + .and() + .process_is_started_with_variables(variables = createVariables()) + .and() + .process_waits_in_task() + + whenever() + .task_is_accessed_in_user_task { taskService, taskId -> + STRING_VAR.on(taskService, taskId).setLocal(STRING_LOCAL.value) + DATE_VAR.on(taskService, taskId).setLocal(DATE_LOCAL.value) + SHORT_VAR.on(taskService, taskId).setLocal(SHORT_LOCAL.value) + INT_VAR.on(taskService, taskId).setLocal(INT_LOCAL.value) + LONG_VAR.on(taskService, taskId).setLocal(LONG_LOCAL.value) + DOUBLE_VAR.on(taskService, taskId).setLocal(DOUBLE_LOCAL.value) + BOOLEAN_VAR.on(taskService, taskId).setLocal(BOOLEAN_LOCAL.value) + COMPLEX_VAR.on(taskService, taskId).setLocal(COMPLEX_LOCAL.value) + LIST_STRING_VAR.on(taskService, taskId).setLocal(LIST_STRING_LOCAL.value) + SET_STRING_VAR.on(taskService, taskId).setLocal(SET_STRING_LOCAL.value) + MAP_STRING_LONG_VAR.on(taskService, taskId).setLocal(MAP_STRING_DATE_LOCAL.value) + COMPLEX_SET_VAR.on(taskService, taskId).setLocal(Companion.Values.COMPLEX_SET_LOCAL.value) + COMPLEX_LIST_VAR.on(taskService, taskId).setLocal(Companion.Values.COMPLEX_LIST_LOCAL.value) + COMPLEX_MAP_VAR.on(taskService, taskId).setLocal(Companion.Values.COMPLEX_MAP_LOCAL.value) + } + .and() + .task_is_completed() + + then() + .variables_had_value(readValues = delegateConfiguration.vars, variablesWithValue = createKeyLocalValuePairs()) + } } diff --git a/example/itest/src/test/kotlin/itest/VariableMapAdapterITest.kt b/example/itest/src/test/kotlin/itest/VariableMapAdapterITest.kt index 0f3bbdc7..1c9ad1ed 100644 --- a/example/itest/src/test/kotlin/itest/VariableMapAdapterITest.kt +++ b/example/itest/src/test/kotlin/itest/VariableMapAdapterITest.kt @@ -154,6 +154,7 @@ class VariableMapAdapterITest : CamundaBpmDataITestBase() { thrown.expect(UnsupportedOperationException::class.java) MAP_STRING_LONG_VAR.on(createVariableMapUntyped()).removeLocal() } + @Test fun `should throw correct UO exception on basic getLocal`() { thrown.expect(UnsupportedOperationException::class.java) diff --git a/example/itest/src/test/kotlin/spin/KotlinJacksonDataFormatConfigurator.kt b/example/itest/src/test/kotlin/spin/KotlinJacksonDataFormatConfigurator.kt index 7f7c0704..3d3ae1ad 100644 --- a/example/itest/src/test/kotlin/spin/KotlinJacksonDataFormatConfigurator.kt +++ b/example/itest/src/test/kotlin/spin/KotlinJacksonDataFormatConfigurator.kt @@ -7,11 +7,11 @@ import org.camunda.spin.spi.DataFormatConfigurator class KotlinJacksonDataFormatConfigurator : DataFormatConfigurator { - override fun configure(dataFormat: JacksonJsonDataFormat) { - val objectMapper = dataFormat.objectMapper - objectMapper.registerModule(KotlinModule()) - objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false) - } + override fun configure(dataFormat: JacksonJsonDataFormat) { + val objectMapper = dataFormat.objectMapper + objectMapper.registerModule(KotlinModule()) + objectMapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false) + } - override fun getDataFormatClass(): Class = JacksonJsonDataFormat::class.java + override fun getDataFormatClass(): Class = JacksonJsonDataFormat::class.java } diff --git a/example/itest/src/test/resources/logback.xml b/example/itest/src/test/resources/logback.xml index 2651c6ed..95d93801 100644 --- a/example/itest/src/test/resources/logback.xml +++ b/example/itest/src/test/resources/logback.xml @@ -9,6 +9,6 @@ - + diff --git a/example/spin-type-detector/src/main/java/io/holunda/camunda/bpm/data/spin/ErasedCollectionTypeDetector.java b/example/spin-type-detector/src/main/java/io/holunda/camunda/bpm/data/spin/ErasedCollectionTypeDetector.java index a5f11cd9..1dc88556 100644 --- a/example/spin-type-detector/src/main/java/io/holunda/camunda/bpm/data/spin/ErasedCollectionTypeDetector.java +++ b/example/spin-type-detector/src/main/java/io/holunda/camunda/bpm/data/spin/ErasedCollectionTypeDetector.java @@ -12,87 +12,82 @@ * Detects erased types of Java Collection classes and Map. */ public class ErasedCollectionTypeDetector implements TypeDetector { - /** - * Object instance to use. - */ - public static ErasedCollectionTypeDetector INSTANCE = new ErasedCollectionTypeDetector(); + /** + * Object instance to use. + */ + public static ErasedCollectionTypeDetector INSTANCE = new ErasedCollectionTypeDetector(); - @Override - public boolean canHandle(Object value) { - return value instanceof Collection - || value instanceof Map; - } + @Override + public boolean canHandle(Object value) { + return value instanceof Collection + || value instanceof Map; + } - @Override - public String detectType(Object value) { - return constructType(value).toCanonical(); - } + @Override + public String detectType(Object value) { + return constructType(value).toCanonical(); + } - /** - * Checks if the erased type has the correct number of type bindings. - * - * @param erasedType class of the type. - * @param expectedTypeParametersCount expected number of bindings. - * - * @return true if the number of type binding matches expected value. - */ - private static boolean bindingsArePresent(Class erasedType, int expectedTypeParametersCount) { - if (erasedType == null) { - return false; - } - final TypeVariable>[] typeParameters = erasedType.getTypeParameters(); - int varLen = typeParameters != null ? typeParameters.length : 0; - if (varLen == 0) { - return false; - } - if (varLen != expectedTypeParametersCount) { - throw new IllegalArgumentException("Cannot create TypeBindings for class " + erasedType.getName() + " with " + expectedTypeParametersCount + " type parameter: class expects " + varLen + " type parameters."); - } - return true; + /** + * Checks if the erased type has the correct number of type bindings. + * + * @param erasedType class of the type. + * @param expectedTypeParametersCount expected number of bindings. + * @return true if the number of type binding matches expected value. + */ + private static boolean bindingsArePresent(Class erasedType, int expectedTypeParametersCount) { + if (erasedType == null) { + return false; + } + final TypeVariable>[] typeParameters = erasedType.getTypeParameters(); + int varLen = typeParameters != null ? typeParameters.length : 0; + if (varLen == 0) { + return false; } + if (varLen != expectedTypeParametersCount) { + throw new IllegalArgumentException("Cannot create TypeBindings for class " + erasedType.getName() + " with " + expectedTypeParametersCount + " type parameter: class expects " + varLen + " type parameters."); + } + return true; + } - /** - * Constructs Java type based on the content values. - * - * @param value value with values. - * - * @return Java type. - */ - private static JavaType constructType(Object value) { - final TypeFactory typeFactory = TypeFactory.defaultInstance(); - if (value instanceof Collection && !((Collection) value).isEmpty()) { - final Object firstElement = ((Collection) value).iterator().next(); - if (bindingsArePresent(value.getClass(), 1)) { - final JavaType elementType = constructType(firstElement); - return typeFactory.constructCollectionType(guessCollectionType(value), elementType); - } - } else if (value instanceof Map && !((Map) value).isEmpty()) { - final Map.Entry firstEntry = ((Map) value).entrySet().iterator().next(); - if (bindingsArePresent(firstEntry.getClass(), 2)) { - final JavaType keyType = constructType(firstEntry.getKey()); - final JavaType valueType = constructType(firstEntry.getValue()); - return typeFactory.constructMapType(Map.class, keyType, valueType); - } - } - return typeFactory.constructType(value.getClass()); + /** + * Constructs Java type based on the content values. + * + * @param value value with values. + * @return Java type. + */ + private static JavaType constructType(Object value) { + final TypeFactory typeFactory = TypeFactory.defaultInstance(); + if (value instanceof Collection && !((Collection) value).isEmpty()) { + final Object firstElement = ((Collection) value).iterator().next(); + if (bindingsArePresent(value.getClass(), 1)) { + final JavaType elementType = constructType(firstElement); + return typeFactory.constructCollectionType(guessCollectionType(value), elementType); + } + } else if (value instanceof Map && !((Map) value).isEmpty()) { + final Map.Entry firstEntry = ((Map) value).entrySet().iterator().next(); + if (bindingsArePresent(firstEntry.getClass(), 2)) { + final JavaType keyType = constructType(firstEntry.getKey()); + final JavaType valueType = constructType(firstEntry.getValue()); + return typeFactory.constructMapType(Map.class, keyType, valueType); + } } + return typeFactory.constructType(value.getClass()); + } - /** - * Guess collection class. - * - * @param collection collection. - * - * @return class of th collection implementation. - */ - @SuppressWarnings({ "rawtypes", "unchecked" }) - private static Class guessCollectionType(Object collection) { - if (collection instanceof Collection) { - return (Class) collection.getClass(); - } else { - throw new IllegalArgumentException("Could not detect class for " + collection + " of type " + collection.getClass().getName()); - } + /** + * Guess collection class. + * + * @param collection collection. + * @return class of th collection implementation. + */ + @SuppressWarnings({"rawtypes", "unchecked"}) + private static Class guessCollectionType(Object collection) { + if (collection instanceof Collection) { + return (Class) collection.getClass(); + } else { + throw new IllegalArgumentException("Could not detect class for " + collection + " of type " + collection.getClass().getName()); } + } } - - diff --git a/example/spin-type-detector/src/main/java/io/holunda/camunda/bpm/data/spin/SpinTypeDetectorConfigurator.java b/example/spin-type-detector/src/main/java/io/holunda/camunda/bpm/data/spin/SpinTypeDetectorConfigurator.java index 3f37a8b5..e09c60db 100644 --- a/example/spin-type-detector/src/main/java/io/holunda/camunda/bpm/data/spin/SpinTypeDetectorConfigurator.java +++ b/example/spin-type-detector/src/main/java/io/holunda/camunda/bpm/data/spin/SpinTypeDetectorConfigurator.java @@ -9,13 +9,13 @@ */ public class SpinTypeDetectorConfigurator implements DataFormatConfigurator { - @Override - public Class getDataFormatClass() { - return JacksonJsonDataFormat.class; - } + @Override + public Class getDataFormatClass() { + return JacksonJsonDataFormat.class; + } - @Override - public void configure(JacksonJsonDataFormat dataFormat) { - dataFormat.addTypeDetector(ErasedCollectionTypeDetector.INSTANCE); - } + @Override + public void configure(JacksonJsonDataFormat dataFormat) { + dataFormat.addTypeDetector(ErasedCollectionTypeDetector.INSTANCE); + } } diff --git a/example/spin-type-detector/src/test/java/io/holunda/camunda/bpm/data/jackson/JacksonDeserializationTest.java b/example/spin-type-detector/src/test/java/io/holunda/camunda/bpm/data/jackson/JacksonDeserializationTest.java index 6fba8581..640510ca 100644 --- a/example/spin-type-detector/src/test/java/io/holunda/camunda/bpm/data/jackson/JacksonDeserializationTest.java +++ b/example/spin-type-detector/src/test/java/io/holunda/camunda/bpm/data/jackson/JacksonDeserializationTest.java @@ -11,18 +11,18 @@ public class JacksonDeserializationTest { - private static final MyComplexType value1 = new MyComplexType("value", 17); - private static final MyComplexType value2 = new MyComplexType("value2", 11); + private static final MyComplexType value1 = new MyComplexType("value", 17); + private static final MyComplexType value2 = new MyComplexType("value2", 11); - @Test - public void deserializeList() throws JsonProcessingException { - ObjectMapper objectMapper = new ObjectMapper(); + @Test + public void deserializeList() throws JsonProcessingException { + ObjectMapper objectMapper = new ObjectMapper(); - String json = "[ { \"foo\": \"value\", \"bar\": 17 }, { \"foo\": \"value2\", \"bar\": 11 } ]"; + String json = "[ { \"foo\": \"value\", \"bar\": 17 }, { \"foo\": \"value2\", \"bar\": 11 } ]"; - CollectionType collectionType = objectMapper.getTypeFactory().constructCollectionType(List.class, MyComplexType.class); - List deserialized = objectMapper.readValue(json, collectionType); - assertThat(deserialized).containsExactlyInAnyOrder(value1, value2); + CollectionType collectionType = objectMapper.getTypeFactory().constructCollectionType(List.class, MyComplexType.class); + List deserialized = objectMapper.readValue(json, collectionType); + assertThat(deserialized).containsExactlyInAnyOrder(value1, value2); - } + } } diff --git a/example/spin-type-detector/src/test/java/io/holunda/camunda/bpm/data/jackson/MyComplexType.java b/example/spin-type-detector/src/test/java/io/holunda/camunda/bpm/data/jackson/MyComplexType.java index 0d6a68ff..ee813a19 100644 --- a/example/spin-type-detector/src/test/java/io/holunda/camunda/bpm/data/jackson/MyComplexType.java +++ b/example/spin-type-detector/src/test/java/io/holunda/camunda/bpm/data/jackson/MyComplexType.java @@ -1,54 +1,54 @@ package io.holunda.camunda.bpm.data.jackson; public class MyComplexType { - private String foo; - private Integer bar; + private String foo; + private Integer bar; - public MyComplexType() { - } + public MyComplexType() { + } - public MyComplexType(String foo, Integer bar) { - this.bar = bar; - this.foo = foo; - } + public MyComplexType(String foo, Integer bar) { + this.bar = bar; + this.foo = foo; + } - public String getFoo() { - return foo; - } + public String getFoo() { + return foo; + } - public void setFoo(String foo) { - this.foo = foo; - } + public void setFoo(String foo) { + this.foo = foo; + } - public Integer getBar() { - return bar; - } + public Integer getBar() { + return bar; + } - public void setBar(Integer bar) { - this.bar = bar; - } + public void setBar(Integer bar) { + this.bar = bar; + } - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - - MyComplexType that = (MyComplexType) o; - - if (foo != null ? !foo.equals(that.foo) : that.foo != null) { - return false; - } - return bar != null ? bar.equals(that.bar) : that.bar == null; + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; } - @Override - public int hashCode() { - int result = foo != null ? foo.hashCode() : 0; - result = 31 * result + (bar != null ? bar.hashCode() : 0); - return result; + MyComplexType that = (MyComplexType) o; + + if (foo != null ? !foo.equals(that.foo) : that.foo != null) { + return false; } + return bar != null ? bar.equals(that.bar) : that.bar == null; + } + + @Override + public int hashCode() { + int result = foo != null ? foo.hashCode() : 0; + result = 31 * result + (bar != null ? bar.hashCode() : 0); + return result; + } } diff --git a/example/spin-type-detector/src/test/java/io/holunda/camunda/bpm/data/jackson/SpinDeserializationTest.java b/example/spin-type-detector/src/test/java/io/holunda/camunda/bpm/data/jackson/SpinDeserializationTest.java index d96818d9..46a866f9 100644 --- a/example/spin-type-detector/src/test/java/io/holunda/camunda/bpm/data/jackson/SpinDeserializationTest.java +++ b/example/spin-type-detector/src/test/java/io/holunda/camunda/bpm/data/jackson/SpinDeserializationTest.java @@ -11,23 +11,23 @@ public class SpinDeserializationTest { - private static final MyComplexType value1 = new MyComplexType("value", 17); - private static final MyComplexType value2 = new MyComplexType("value2", 11); - - @Test - public void deserializeList() { - - String json = "[{\"foo\":\"value\",\"bar\":17},{\"foo\":\"value2\",\"bar\":11}]"; - SpinJsonNode spinNode = JSON(json); - List deserialized = spinNode.mapTo("java.util.ArrayList<" + MyComplexType.class.getName() + ">"); - assertThat(deserialized).containsExactlyInAnyOrder(value1, value2); - } - - @Test - public void serializeList() { - List list = Lists.list(value1, value2); - String json = JSON(list).toString(); - assertThat(json).isEqualTo("[{\"foo\":\"value\",\"bar\":17},{\"foo\":\"value2\",\"bar\":11}]"); - } + private static final MyComplexType value1 = new MyComplexType("value", 17); + private static final MyComplexType value2 = new MyComplexType("value2", 11); + + @Test + public void deserializeList() { + + String json = "[{\"foo\":\"value\",\"bar\":17},{\"foo\":\"value2\",\"bar\":11}]"; + SpinJsonNode spinNode = JSON(json); + List deserialized = spinNode.mapTo("java.util.ArrayList<" + MyComplexType.class.getName() + ">"); + assertThat(deserialized).containsExactlyInAnyOrder(value1, value2); + } + + @Test + public void serializeList() { + List list = Lists.list(value1, value2); + String json = JSON(list).toString(); + assertThat(json).isEqualTo("[{\"foo\":\"value\",\"bar\":17},{\"foo\":\"value2\",\"bar\":11}]"); + } } diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/CamundaBpmData.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/CamundaBpmData.java index 28496a60..ad680ee2 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/CamundaBpmData.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/CamundaBpmData.java @@ -123,8 +123,8 @@ public static VariableFactory booleanVariable(@NotNull String variableN * Creates a variable factory for custom type. * * @param variableName name of the variable. - * @param clazz class of specifying the type. - * @param factory type. + * @param clazz class of specifying the type. + * @param factory type. * @return variable factory for given type. */ @NotNull @@ -136,8 +136,8 @@ public static VariableFactory customVariable(@NotNull String variableName * Creates a variable factory for list of custom type. * * @param variableName name of the variable. - * @param clazz class of specifying the member type. - * @param factory type. + * @param clazz class of specifying the member type. + * @param factory type. * @return variable factory for given type. */ @NotNull @@ -149,8 +149,8 @@ public static VariableFactory> listVariable(@NotNull String variable * Creates a variable factory for set of custom type. * * @param variableName name of the variable. - * @param clazz class of specifying the member type. - * @param factory type. + * @param clazz class of specifying the member type. + * @param factory type. * @return variable factory for given type. */ @NotNull @@ -162,15 +162,15 @@ public static VariableFactory> setVariable(@NotNull String variableNa * Creates a variable factory for map of custom key and custom value type. * * @param variableName name of the variable. - * @param keyClazz class of specifying the key member type. - * @param valueClazz class of specifying the value member type. - * @param factory key type. - * @param factory value type. + * @param keyClazz class of specifying the key member type. + * @param valueClazz class of specifying the value member type. + * @param factory key type. + * @param factory value type. * @return variable factory for given type. */ @NotNull public static VariableFactory> mapVariable(@NotNull String variableName, @NotNull Class keyClazz, - @NotNull Class valueClazz) { + @NotNull Class valueClazz) { return new MapVariableFactory<>(variableName, keyClazz, valueClazz); } @@ -209,7 +209,7 @@ public static VariableWriter writer(VariableScope variableScope) { * Creates a new execution variable writer. * * @param runtimeService runtime service to use. - * @param executionId id of the execution. + * @param executionId id of the execution. * @return new writer working on provided process execution. */ @NotNull @@ -221,7 +221,7 @@ public static VariableWriter writer(RuntimeService runtimeService, String exe * Creates a new task variable writer. * * @param taskService task service to use. - * @param taskId task id. + * @param taskId task id. * @return new writer working on provided user task. */ @NotNull @@ -232,7 +232,7 @@ public static VariableWriter writer(TaskService taskService, String taskId) { /** * Creates a new caseExecution variable writer. * - * @param caseService task service to use. + * @param caseService task service to use. * @param caseExecutionId caseExecution id. * @return new writer working on provided user task. */ @@ -245,7 +245,7 @@ public static VariableWriter writer(CaseService caseService, String caseExecu * Creates a new task variable reader. * * @param taskService the Camunda task service - * @param taskId the id of the task to use + * @param taskId the id of the task to use * @return variable reader working on task */ @NotNull @@ -257,7 +257,7 @@ public static VariableReader reader(TaskService taskService, String taskId) { * Creates a new execution variable reader. * * @param runtimeService the Camunda runtime service - * @param executionId the executionId to use + * @param executionId the executionId to use * @return variable reader working on execution */ public static VariableReader reader(RuntimeService runtimeService, String executionId) { @@ -267,7 +267,7 @@ public static VariableReader reader(RuntimeService runtimeService, String execut /** * Creates a new execution variable reader. * - * @param caseService the Camunda case service + * @param caseService the Camunda case service * @param caseExecutionId the caseExecutionId to use * @return variable reader working on execution */ @@ -287,6 +287,7 @@ public static VariableReader reader(VariableScope variableScope) { /** * Creates a new variableMap variable reader. + * * @param variableMap the variableMap to use * @return variable reader working on variableMap */ diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/AbstractReadWriteAdapter.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/AbstractReadWriteAdapter.java index 2cd83cee..180c961e 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/AbstractReadWriteAdapter.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/AbstractReadWriteAdapter.java @@ -9,56 +9,57 @@ */ public abstract class AbstractReadWriteAdapter implements ReadAdapter, WriteAdapter { - /** - * Variable name. - */ - protected final String variableName; + /** + * Variable name. + */ + protected final String variableName; - /** - * Constructs the adapter. - * - * @param variableName variable name, - */ - public AbstractReadWriteAdapter(String variableName) {this.variableName = variableName;} + /** + * Constructs the adapter. + * + * @param variableName variable name, + */ + public AbstractReadWriteAdapter(String variableName) { + this.variableName = variableName; + } - @Override - public void set(T value) { - set(value, false); - } + @Override + public void set(T value) { + set(value, false); + } - @Override - public void setLocal(T value) { - setLocal(value, false); - } + @Override + public void setLocal(T value) { + setLocal(value, false); + } - @Override - public T get() { - return getOptional().orElseThrow(() -> new VariableNotFoundException("Couldn't find required variable '" + variableName + "'")); - } + @Override + public T get() { + return getOptional().orElseThrow(() -> new VariableNotFoundException("Couldn't find required variable '" + variableName + "'")); + } - @Override - public T getLocal() { - return getLocalOptional().orElseThrow(() -> new VariableNotFoundException("Couldn't find required local variable '" + variableName + "'")); - } + @Override + public T getLocal() { + return getLocalOptional().orElseThrow(() -> new VariableNotFoundException("Couldn't find required local variable '" + variableName + "'")); + } - @Override - public void update(Function valueProcessor, boolean isTransient) { - set(valueProcessor.apply(get()), isTransient); - } + @Override + public void update(Function valueProcessor, boolean isTransient) { + set(valueProcessor.apply(get()), isTransient); + } - @Override - public void updateLocal(Function valueProcessor, boolean isTransient) { - setLocal(valueProcessor.apply(getLocal()), isTransient); - } + @Override + public void updateLocal(Function valueProcessor, boolean isTransient) { + setLocal(valueProcessor.apply(getLocal()), isTransient); + } - @Override - public void update(Function valueProcessor) { - update(valueProcessor, false); - } - - @Override - public void updateLocal(Function valueProcessor) { - updateLocal(valueProcessor, false); - } + @Override + public void update(Function valueProcessor) { + update(valueProcessor, false); + } + @Override + public void updateLocal(Function valueProcessor) { + updateLocal(valueProcessor, false); + } } diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/ReadAdapter.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/ReadAdapter.java index 2a9f4022..dea13d42 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/ReadAdapter.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/ReadAdapter.java @@ -4,32 +4,37 @@ /** * Adapter to read variables. + * * @param type of value. */ public interface ReadAdapter { /** * Reads a variable. + * * @return value. - * @exception IllegalStateException if the required variable is missing or can't be read. + * @throws IllegalStateException if the required variable is missing or can't be read. */ T get(); /** * Reads a variable and returns a value if exists or an empty. + * * @return optional. */ Optional getOptional(); /** * Reads a local variable. + * * @return value. - * @exception IllegalStateException if the required variable is missing or can't be read. + * @throws IllegalStateException if the required variable is missing or can't be read. */ T getLocal(); /** * Reads a local variable and returns a value if exists or an empty. + * * @return optional. */ Optional getLocalOptional(); diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/ValueWrapperUtil.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/ValueWrapperUtil.java index e9857360..be469f93 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/ValueWrapperUtil.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/ValueWrapperUtil.java @@ -19,133 +19,129 @@ */ public class ValueWrapperUtil { - /** - * Hide instantiation. - */ - private ValueWrapperUtil() { + /** + * Hide instantiation. + */ + private ValueWrapperUtil() { - } + } - /** - * Delivers typed value for a given type and value. - * - * @param clazz class of value. - * @param value value to encapsulate. - * @param isTransient transient flag. - * @param type of value. - * - * @return typed value. - * - * @throws IllegalArgumentException if value and clazz are incompatible. - */ - public static TypedValue getTypedValue(Class clazz, Object value, boolean isTransient) { - if (value != null && !clazz.isAssignableFrom(value.getClass())) { - throw new IllegalArgumentException("Couldn't create TypedValue for " + clazz.getSimpleName() + " from value " + value); - } + /** + * Delivers typed value for a given type and value. + * + * @param clazz class of value. + * @param value value to encapsulate. + * @param isTransient transient flag. + * @param type of value. + * @return typed value. + * @throws IllegalArgumentException if value and clazz are incompatible. + */ + public static TypedValue getTypedValue(Class clazz, Object value, boolean isTransient) { + if (value != null && !clazz.isAssignableFrom(value.getClass())) { + throw new IllegalArgumentException("Couldn't create TypedValue for " + clazz.getSimpleName() + " from value " + value); + } - if (String.class.equals(clazz)) { - return stringValue((String) value, isTransient); - } else if (Boolean.class.equals(clazz)) { - return booleanValue((Boolean) value, isTransient); - } else if (Integer.class.equals(clazz)) { - return integerValue((Integer) value, isTransient); - } else if (Short.class.equals(clazz)) { - return shortValue((Short) value, isTransient); - } else if (Long.class.equals(clazz)) { - return longValue((Long) value, isTransient); - } else if (Date.class.equals(clazz)) { - return dateValue((Date) value, isTransient); - } else if (Double.class.equals(clazz)) { - return doubleValue((Double) value, isTransient); - } else if (Object.class.equals(clazz)) { - return objectValue(value, isTransient).create(); - } else { - // fallback for unknown-type - return untypedValue(value, isTransient); - } + if (String.class.equals(clazz)) { + return stringValue((String) value, isTransient); + } else if (Boolean.class.equals(clazz)) { + return booleanValue((Boolean) value, isTransient); + } else if (Integer.class.equals(clazz)) { + return integerValue((Integer) value, isTransient); + } else if (Short.class.equals(clazz)) { + return shortValue((Short) value, isTransient); + } else if (Long.class.equals(clazz)) { + return longValue((Long) value, isTransient); + } else if (Date.class.equals(clazz)) { + return dateValue((Date) value, isTransient); + } else if (Double.class.equals(clazz)) { + return doubleValue((Double) value, isTransient); + } else if (Object.class.equals(clazz)) { + return objectValue(value, isTransient).create(); + } else { + // fallback for unknown-type + return untypedValue(value, isTransient); } + } - /** - * Tries to read a collection type from a typed value containing the serialized json. - * - * @param typedValue value from camunda. - * @param variableName name of the variable. - * @param memberClazz clazz of the collection member. - * @param objectMapper jackson object mapper. - * @param collectionType constructed collection type. - * @param type of collection member. - * @param type of collection. - * - * @return collection of specified type or null. - */ - public static > C readFromTypedValue( - TypedValue typedValue, String variableName, Class memberClazz, ObjectMapper objectMapper, CollectionType collectionType) { - if (typedValue == null) { - return null; - } - if (typedValue instanceof ObjectValueImpl) { - final ObjectValue objectValue = (ObjectValueImpl) typedValue; - final String json = objectValue.getValueSerialized(); - try { - final C values = objectMapper.readValue(json, collectionType); - if (values.isEmpty()) { - return values; - } else { - if (memberClazz.isAssignableFrom(values.iterator().next().getClass())) { - return values; - } else { - throw new WrongVariableTypeException("Error reading " + variableName + ": Wrong member type detected, expected " + memberClazz.getName() + ", but was not found in " + values); - } - } - } catch (JsonProcessingException jpe) { - throw new WrongVariableTypeException("Error reading " + variableName + ": Couldn't read value from " + json); - } + /** + * Tries to read a collection type from a typed value containing the serialized json. + * + * @param typedValue value from camunda. + * @param variableName name of the variable. + * @param memberClazz clazz of the collection member. + * @param objectMapper jackson object mapper. + * @param collectionType constructed collection type. + * @param type of collection member. + * @param type of collection. + * @return collection of specified type or null. + */ + public static > C readFromTypedValue( + TypedValue typedValue, String variableName, Class memberClazz, ObjectMapper objectMapper, CollectionType collectionType) { + if (typedValue == null) { + return null; + } + if (typedValue instanceof ObjectValueImpl) { + final ObjectValue objectValue = (ObjectValueImpl) typedValue; + final String json = objectValue.getValueSerialized(); + try { + final C values = objectMapper.readValue(json, collectionType); + if (values.isEmpty()) { + return values; } else { - throw new WrongVariableTypeException("Error reading " + variableName + ": Couldn't read value from " + typedValue); + if (memberClazz.isAssignableFrom(values.iterator().next().getClass())) { + return values; + } else { + throw new WrongVariableTypeException("Error reading " + variableName + ": Wrong member type detected, expected " + memberClazz.getName() + ", but was not found in " + values); + } } + } catch (JsonProcessingException jpe) { + throw new WrongVariableTypeException("Error reading " + variableName + ": Couldn't read value from " + json); + } + } else { + throw new WrongVariableTypeException("Error reading " + variableName + ": Couldn't read value from " + typedValue); } + } - /** - * Tries to read a collection type from a typed value containing the serialized json. - * - * @param typedValue value from camunda. - * @param variableName name of the variable. - * @param keyClazz clazz of the map key. - * @param valueClazz clazz of the map value. - * @param objectMapper jackson object mapper. - * @param mapType constructed map type. - * @param type of map key. - * @param type of myp value. - * - * @return map of specified types or null. - */ - public static Map readFromTypedValue( - TypedValue typedValue, String variableName, Class keyClazz, Class valueClazz, - ObjectMapper objectMapper, MapType mapType) { - if (typedValue == null) { - return null; - } - if (typedValue instanceof ObjectValueImpl) { - final ObjectValue objectValue = (ObjectValueImpl) typedValue; - final String json = objectValue.getValueSerialized(); - try { - final Map map = objectMapper.readValue(json, mapType); - if (map.isEmpty()) { - return map; - } else { - final Map.Entry entry = map.entrySet().iterator().next(); - if (valueClazz.isAssignableFrom(entry.getValue().getClass()) && keyClazz.isAssignableFrom(entry.getKey().getClass())) { - return map; - } else { - throw new WrongVariableTypeException("Error reading " + variableName + ": Wrong map type detected, expected key " - + keyClazz.getName() + " and value " + valueClazz.getName() + ", but was not found in " + map); - } - } - } catch (JsonProcessingException jpe) { - throw new WrongVariableTypeException("Error reading " + variableName + ": Couldn't read value from " + json); - } + /** + * Tries to read a collection type from a typed value containing the serialized json. + * + * @param typedValue value from camunda. + * @param variableName name of the variable. + * @param keyClazz clazz of the map key. + * @param valueClazz clazz of the map value. + * @param objectMapper jackson object mapper. + * @param mapType constructed map type. + * @param type of map key. + * @param type of myp value. + * @return map of specified types or null. + */ + public static Map readFromTypedValue( + TypedValue typedValue, String variableName, Class keyClazz, Class valueClazz, + ObjectMapper objectMapper, MapType mapType) { + if (typedValue == null) { + return null; + } + if (typedValue instanceof ObjectValueImpl) { + final ObjectValue objectValue = (ObjectValueImpl) typedValue; + final String json = objectValue.getValueSerialized(); + try { + final Map map = objectMapper.readValue(json, mapType); + if (map.isEmpty()) { + return map; } else { - throw new WrongVariableTypeException("Error reading " + variableName + ": Couldn't read value from " + typedValue); + final Map.Entry entry = map.entrySet().iterator().next(); + if (valueClazz.isAssignableFrom(entry.getValue().getClass()) && keyClazz.isAssignableFrom(entry.getKey().getClass())) { + return map; + } else { + throw new WrongVariableTypeException("Error reading " + variableName + ": Wrong map type detected, expected key " + + keyClazz.getName() + " and value " + valueClazz.getName() + ", but was not found in " + map); + } } + } catch (JsonProcessingException jpe) { + throw new WrongVariableTypeException("Error reading " + variableName + ": Couldn't read value from " + json); + } + } else { + throw new WrongVariableTypeException("Error reading " + variableName + ": Couldn't read value from " + typedValue); } + } } diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/VariableNotFoundException.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/VariableNotFoundException.java index e2858b54..5223d19c 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/VariableNotFoundException.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/VariableNotFoundException.java @@ -4,13 +4,13 @@ * Exception indicating that a variable is not found. */ public class VariableNotFoundException extends RuntimeException { - /** - * Constructs the exception. - * - * @param reason reason. - */ - VariableNotFoundException(String reason) { - super(reason); - } + /** + * Constructs the exception. + * + * @param reason reason. + */ + VariableNotFoundException(String reason) { + super(reason); + } } diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/WriteAdapter.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/WriteAdapter.java index fe47ac10..56d76550 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/WriteAdapter.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/WriteAdapter.java @@ -83,7 +83,8 @@ public interface WriteAdapter { /** * Constructs typed value. - * @param value raw value. + * + * @param value raw value. * @param isTransient transient flag. * @return typed value. */ diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/WrongVariableTypeException.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/WrongVariableTypeException.java index 6920ee5f..ee2fa07f 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/WrongVariableTypeException.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/WrongVariableTypeException.java @@ -4,10 +4,12 @@ * Exception indicating that a variable has a different type than requested. */ public class WrongVariableTypeException extends RuntimeException { - /** - * Constructs the exception. - * - * @param reason reason. - */ - public WrongVariableTypeException(String reason) { super(reason); } + /** + * Constructs the exception. + * + * @param reason reason. + */ + public WrongVariableTypeException(String reason) { + super(reason); + } } diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/basic/AbstractBasicReadWriteAdapter.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/basic/AbstractBasicReadWriteAdapter.java index 9c1d191e..d59653c9 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/basic/AbstractBasicReadWriteAdapter.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/basic/AbstractBasicReadWriteAdapter.java @@ -11,44 +11,43 @@ * @param variable type. */ public abstract class AbstractBasicReadWriteAdapter extends AbstractReadWriteAdapter { - /** - * Variable type. - */ - protected final Class clazz; + /** + * Variable type. + */ + protected final Class clazz; - /** - * Constructs the adapter. - * - * @param variableName name of the variable. - * @param clazz variable type. - */ - public AbstractBasicReadWriteAdapter(String variableName, Class clazz) { - super(variableName); - this.clazz = clazz; - } - - /** - * Retrieves the value or null. - * - * @param value raw value. - * - * @return value or null. - */ - @SuppressWarnings("unchecked") - protected T getOrNull(Object value) { + /** + * Constructs the adapter. + * + * @param variableName name of the variable. + * @param clazz variable type. + */ + public AbstractBasicReadWriteAdapter(String variableName, Class clazz) { + super(variableName); + this.clazz = clazz; + } - if (value == null) { - return null; - } + /** + * Retrieves the value or null. + * + * @param value raw value. + * @return value or null. + */ + @SuppressWarnings("unchecked") + protected T getOrNull(Object value) { - if (clazz.isAssignableFrom(value.getClass())) { - return (T) value; - } - throw new WrongVariableTypeException("Error reading " + variableName + ": Couldn't read value of " + clazz + " from " + value); + if (value == null) { + return null; } - @Override - public TypedValue getTypedValue(Object value, boolean isTransient) { - return ValueWrapperUtil.getTypedValue(clazz, value, isTransient); + if (clazz.isAssignableFrom(value.getClass())) { + return (T) value; } + throw new WrongVariableTypeException("Error reading " + variableName + ": Couldn't read value of " + clazz + " from " + value); + } + + @Override + public TypedValue getTypedValue(Object value, boolean isTransient) { + return ValueWrapperUtil.getTypedValue(clazz, value, isTransient); + } } diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/basic/ReadWriteAdapterRuntimeService.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/basic/ReadWriteAdapterRuntimeService.java index c67c38da..25a7683a 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/basic/ReadWriteAdapterRuntimeService.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/basic/ReadWriteAdapterRuntimeService.java @@ -11,50 +11,50 @@ */ public class ReadWriteAdapterRuntimeService extends AbstractBasicReadWriteAdapter { - private final RuntimeService runtimeService; - private final String executionId; - - /** - * Constructs the adapter. - * - * @param runtimeService runtime service to use. - * @param executionId id of the execution to read from and write to. - * @param variableName name of the variable. - * @param clazz class of the variable. - */ - public ReadWriteAdapterRuntimeService(RuntimeService runtimeService, String executionId, String variableName, Class clazz) { - super(variableName, clazz); - this.runtimeService = runtimeService; - this.executionId = executionId; - } - - @Override - public Optional getOptional() { - return Optional.ofNullable(getOrNull(runtimeService.getVariable(executionId, variableName))); - } - - @Override - public void set(T value, boolean isTransient) { - runtimeService.setVariable(executionId, variableName, getTypedValue(value, isTransient)); - } - - @Override - public Optional getLocalOptional() { - return Optional.ofNullable(getOrNull(runtimeService.getVariableLocal(executionId, variableName))); - } - - @Override - public void setLocal(T value, boolean isTransient) { - runtimeService.setVariableLocal(executionId, variableName, getTypedValue(value, isTransient)); - } - - @Override - public void remove() { - runtimeService.removeVariable(executionId, variableName); - } - - @Override - public void removeLocal() { - runtimeService.removeVariableLocal(executionId, variableName); - } + private final RuntimeService runtimeService; + private final String executionId; + + /** + * Constructs the adapter. + * + * @param runtimeService runtime service to use. + * @param executionId id of the execution to read from and write to. + * @param variableName name of the variable. + * @param clazz class of the variable. + */ + public ReadWriteAdapterRuntimeService(RuntimeService runtimeService, String executionId, String variableName, Class clazz) { + super(variableName, clazz); + this.runtimeService = runtimeService; + this.executionId = executionId; + } + + @Override + public Optional getOptional() { + return Optional.ofNullable(getOrNull(runtimeService.getVariable(executionId, variableName))); + } + + @Override + public void set(T value, boolean isTransient) { + runtimeService.setVariable(executionId, variableName, getTypedValue(value, isTransient)); + } + + @Override + public Optional getLocalOptional() { + return Optional.ofNullable(getOrNull(runtimeService.getVariableLocal(executionId, variableName))); + } + + @Override + public void setLocal(T value, boolean isTransient) { + runtimeService.setVariableLocal(executionId, variableName, getTypedValue(value, isTransient)); + } + + @Override + public void remove() { + runtimeService.removeVariable(executionId, variableName); + } + + @Override + public void removeLocal() { + runtimeService.removeVariableLocal(executionId, variableName); + } } diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/basic/ReadWriteAdapterTaskService.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/basic/ReadWriteAdapterTaskService.java index 95845fd2..6e1dabb8 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/basic/ReadWriteAdapterTaskService.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/basic/ReadWriteAdapterTaskService.java @@ -11,50 +11,50 @@ */ public class ReadWriteAdapterTaskService extends AbstractBasicReadWriteAdapter { - private final TaskService taskService; - private final String taskId; - - /** - * Constructs the adapter. - * - * @param taskService task service to use. - * @param taskId id of the task to read from and write to. - * @param variableName name of the variable. - * @param clazz class of the variable. - */ - public ReadWriteAdapterTaskService(TaskService taskService, String taskId, String variableName, Class clazz) { - super(variableName, clazz); - this.taskService = taskService; - this.taskId = taskId; - } - - @Override - public Optional getOptional() { - return Optional.ofNullable(getOrNull(taskService.getVariable(taskId, variableName))); - } - - @Override - public void set(T value, boolean isTransient) { - taskService.setVariable(taskId, variableName, getTypedValue(value, isTransient)); - } - - @Override - public Optional getLocalOptional() { - return Optional.ofNullable(getOrNull(taskService.getVariableLocal(taskId, variableName))); - } - - @Override - public void setLocal(T value, boolean isTransient) { - taskService.setVariableLocal(taskId, variableName, getTypedValue(value, isTransient)); - } - - @Override - public void remove() { - taskService.removeVariable(taskId, variableName); - } - - @Override - public void removeLocal() { - taskService.removeVariableLocal(taskId, variableName); - } + private final TaskService taskService; + private final String taskId; + + /** + * Constructs the adapter. + * + * @param taskService task service to use. + * @param taskId id of the task to read from and write to. + * @param variableName name of the variable. + * @param clazz class of the variable. + */ + public ReadWriteAdapterTaskService(TaskService taskService, String taskId, String variableName, Class clazz) { + super(variableName, clazz); + this.taskService = taskService; + this.taskId = taskId; + } + + @Override + public Optional getOptional() { + return Optional.ofNullable(getOrNull(taskService.getVariable(taskId, variableName))); + } + + @Override + public void set(T value, boolean isTransient) { + taskService.setVariable(taskId, variableName, getTypedValue(value, isTransient)); + } + + @Override + public Optional getLocalOptional() { + return Optional.ofNullable(getOrNull(taskService.getVariableLocal(taskId, variableName))); + } + + @Override + public void setLocal(T value, boolean isTransient) { + taskService.setVariableLocal(taskId, variableName, getTypedValue(value, isTransient)); + } + + @Override + public void remove() { + taskService.removeVariable(taskId, variableName); + } + + @Override + public void removeLocal() { + taskService.removeVariableLocal(taskId, variableName); + } } diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/basic/ReadWriteAdapterVariableMap.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/basic/ReadWriteAdapterVariableMap.java index ac997a3a..f73a7e43 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/basic/ReadWriteAdapterVariableMap.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/basic/ReadWriteAdapterVariableMap.java @@ -11,47 +11,47 @@ */ public class ReadWriteAdapterVariableMap extends AbstractBasicReadWriteAdapter { - private final VariableMap variableMap; - - /** - * Constructs the adapter. - * - * @param variableMap variable map to access. - * @param variableName variable to access. - * @param clazz class of variable value. - */ - public ReadWriteAdapterVariableMap(VariableMap variableMap, String variableName, Class clazz) { - super(variableName, clazz); - this.variableMap = variableMap; - } - - @Override - public Optional getOptional() { - return Optional.ofNullable(getOrNull(variableMap.get(variableName))); - } - - @Override - public void set(T value, boolean isTransient) { - variableMap.putValueTyped(variableName, getTypedValue(value, isTransient)); - } - - @Override - public Optional getLocalOptional() { - throw new UnsupportedOperationException("Can't get a local variable on a variable map"); - } - - @Override - public void setLocal(T value, boolean isTransient) { - throw new UnsupportedOperationException("Can't set a local variable on a variable map"); - } - - @Override - public void remove() { - variableMap.remove(variableName); - } - - @Override - public void removeLocal() { - throw new UnsupportedOperationException("Can't set a local variable on a variable map"); - } + private final VariableMap variableMap; + + /** + * Constructs the adapter. + * + * @param variableMap variable map to access. + * @param variableName variable to access. + * @param clazz class of variable value. + */ + public ReadWriteAdapterVariableMap(VariableMap variableMap, String variableName, Class clazz) { + super(variableName, clazz); + this.variableMap = variableMap; + } + + @Override + public Optional getOptional() { + return Optional.ofNullable(getOrNull(variableMap.get(variableName))); + } + + @Override + public void set(T value, boolean isTransient) { + variableMap.putValueTyped(variableName, getTypedValue(value, isTransient)); + } + + @Override + public Optional getLocalOptional() { + throw new UnsupportedOperationException("Can't get a local variable on a variable map"); + } + + @Override + public void setLocal(T value, boolean isTransient) { + throw new UnsupportedOperationException("Can't set a local variable on a variable map"); + } + + @Override + public void remove() { + variableMap.remove(variableName); + } + + @Override + public void removeLocal() { + throw new UnsupportedOperationException("Can't set a local variable on a variable map"); + } } diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/basic/ReadWriteAdapterVariableScope.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/basic/ReadWriteAdapterVariableScope.java index 90b69daa..70a15887 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/basic/ReadWriteAdapterVariableScope.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/basic/ReadWriteAdapterVariableScope.java @@ -11,48 +11,48 @@ */ public class ReadWriteAdapterVariableScope extends AbstractBasicReadWriteAdapter { - private final VariableScope variableScope; - - /** - * Constructs the adapter. - * - * @param variableScope variable scope to access. - * @param variableName variable to access. - * @param clazz class of variable value. - */ - public ReadWriteAdapterVariableScope(VariableScope variableScope, String variableName, Class clazz) { - super(variableName, clazz); - this.variableScope = variableScope; - } - - @Override - public void set(T value, boolean isTransient) { - variableScope.setVariable(variableName, getTypedValue(value, isTransient)); - } - - @Override - public Optional getLocalOptional() { - return Optional.ofNullable(getOrNull(variableScope.getVariableLocal(variableName))); - } - - @Override - public void setLocal(T value, boolean isTransient) { - variableScope.setVariableLocal(variableName, getTypedValue(value, isTransient)); - } - - @Override - public Optional getOptional() { - return Optional.ofNullable(getOrNull(variableScope.getVariable(variableName))); - } - - @Override - public void remove() { - variableScope.removeVariable(variableName); - } - - @Override - public void removeLocal() { - variableScope.removeVariableLocal(variableName); - } + private final VariableScope variableScope; + + /** + * Constructs the adapter. + * + * @param variableScope variable scope to access. + * @param variableName variable to access. + * @param clazz class of variable value. + */ + public ReadWriteAdapterVariableScope(VariableScope variableScope, String variableName, Class clazz) { + super(variableName, clazz); + this.variableScope = variableScope; + } + + @Override + public void set(T value, boolean isTransient) { + variableScope.setVariable(variableName, getTypedValue(value, isTransient)); + } + + @Override + public Optional getLocalOptional() { + return Optional.ofNullable(getOrNull(variableScope.getVariableLocal(variableName))); + } + + @Override + public void setLocal(T value, boolean isTransient) { + variableScope.setVariableLocal(variableName, getTypedValue(value, isTransient)); + } + + @Override + public Optional getOptional() { + return Optional.ofNullable(getOrNull(variableScope.getVariable(variableName))); + } + + @Override + public void remove() { + variableScope.removeVariable(variableName); + } + + @Override + public void removeLocal() { + variableScope.removeVariableLocal(variableName); + } } diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/list/AbstractListReadWriteAdapter.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/list/AbstractListReadWriteAdapter.java index 548e35b8..dfb9b84e 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/list/AbstractListReadWriteAdapter.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/list/AbstractListReadWriteAdapter.java @@ -15,54 +15,52 @@ */ public abstract class AbstractListReadWriteAdapter extends AbstractReadWriteAdapter> { - /** - * Member class. - */ - protected final Class memberClazz; + /** + * Member class. + */ + protected final Class memberClazz; - /** - * Constructs the adapter. - * - * @param variableName name of variable. - * @param memberClazz member class. - */ - public AbstractListReadWriteAdapter(String variableName, Class memberClazz) { - super(variableName); - this.memberClazz = memberClazz; - } + /** + * Constructs the adapter. + * + * @param variableName name of variable. + * @param memberClazz member class. + */ + public AbstractListReadWriteAdapter(String variableName, Class memberClazz) { + super(variableName); + this.memberClazz = memberClazz; + } - /** - * Read the value of null. - * - * @param value raw value. - * - * @return list or null. - */ - @SuppressWarnings("unchecked") - protected List getOrNull(Object value) { - if (value == null) { - return null; - } + /** + * Read the value of null. + * + * @param value raw value. + * @return list or null. + */ + @SuppressWarnings("unchecked") + protected List getOrNull(Object value) { + if (value == null) { + return null; + } - if (List.class.isAssignableFrom(value.getClass())) { - List valueAsList = (List) value; - if (valueAsList.isEmpty()) { - return Collections.emptyList(); - } else { - if (memberClazz.isAssignableFrom(valueAsList.iterator().next().getClass())) { - return (List) valueAsList; - } else { - throw new WrongVariableTypeException("Error reading " + variableName + ": Wrong list type detected, expected " + memberClazz.getName() + ", but was not found in " + valueAsList); - } - } + if (List.class.isAssignableFrom(value.getClass())) { + List valueAsList = (List) value; + if (valueAsList.isEmpty()) { + return Collections.emptyList(); + } else { + if (memberClazz.isAssignableFrom(valueAsList.iterator().next().getClass())) { + return (List) valueAsList; + } else { + throw new WrongVariableTypeException("Error reading " + variableName + ": Wrong list type detected, expected " + memberClazz.getName() + ", but was not found in " + valueAsList); } - - throw new WrongVariableTypeException("Error reading " + variableName + ": Couldn't read value of type List from " + value); + } } - @Override - public TypedValue getTypedValue(Object value, boolean isTransient) { - return ValueWrapperUtil.getTypedValue(List.class, value, isTransient); - } + throw new WrongVariableTypeException("Error reading " + variableName + ": Couldn't read value of type List from " + value); + } + @Override + public TypedValue getTypedValue(Object value, boolean isTransient) { + return ValueWrapperUtil.getTypedValue(List.class, value, isTransient); + } } diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/list/ListReadWriteAdapterCaseService.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/list/ListReadWriteAdapterCaseService.java index cb32ec7c..7b846597 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/list/ListReadWriteAdapterCaseService.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/list/ListReadWriteAdapterCaseService.java @@ -12,50 +12,50 @@ */ public class ListReadWriteAdapterCaseService extends AbstractListReadWriteAdapter { - private final CaseService caseService; - private final String caseExecutionId; - - /** - * Constructs the adapter. - * - * @param caseService case service to use. - * @param caseExecutionId id of the execution to read from and write to. - * @param variableName name of the variable. - * @param memberClazz class of the variable. - */ - public ListReadWriteAdapterCaseService(CaseService caseService, String caseExecutionId, String variableName, Class memberClazz) { - super(variableName, memberClazz); - this.caseService = caseService; - this.caseExecutionId = caseExecutionId; - } - - @Override - public Optional> getOptional() { - return Optional.ofNullable(getOrNull(caseService.getVariable(caseExecutionId, variableName))); - } - - @Override - public void set(List value, boolean isTransient) { - caseService.setVariable(caseExecutionId, variableName, getTypedValue(value, isTransient)); - } - - @Override - public Optional> getLocalOptional() { - return Optional.ofNullable(getOrNull(caseService.getVariableLocal(caseExecutionId, variableName))); - } - - @Override - public void setLocal(List value, boolean isTransient) { - caseService.setVariableLocal(caseExecutionId, variableName, getTypedValue(value, isTransient)); - } - - @Override - public void remove() { - caseService.removeVariable(caseExecutionId, variableName); - } - - @Override - public void removeLocal() { - caseService.removeVariableLocal(caseExecutionId, variableName); - } + private final CaseService caseService; + private final String caseExecutionId; + + /** + * Constructs the adapter. + * + * @param caseService case service to use. + * @param caseExecutionId id of the execution to read from and write to. + * @param variableName name of the variable. + * @param memberClazz class of the variable. + */ + public ListReadWriteAdapterCaseService(CaseService caseService, String caseExecutionId, String variableName, Class memberClazz) { + super(variableName, memberClazz); + this.caseService = caseService; + this.caseExecutionId = caseExecutionId; + } + + @Override + public Optional> getOptional() { + return Optional.ofNullable(getOrNull(caseService.getVariable(caseExecutionId, variableName))); + } + + @Override + public void set(List value, boolean isTransient) { + caseService.setVariable(caseExecutionId, variableName, getTypedValue(value, isTransient)); + } + + @Override + public Optional> getLocalOptional() { + return Optional.ofNullable(getOrNull(caseService.getVariableLocal(caseExecutionId, variableName))); + } + + @Override + public void setLocal(List value, boolean isTransient) { + caseService.setVariableLocal(caseExecutionId, variableName, getTypedValue(value, isTransient)); + } + + @Override + public void remove() { + caseService.removeVariable(caseExecutionId, variableName); + } + + @Override + public void removeLocal() { + caseService.removeVariableLocal(caseExecutionId, variableName); + } } diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/list/ListReadWriteAdapterRuntimeService.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/list/ListReadWriteAdapterRuntimeService.java index 2deb4ffd..11904fe1 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/list/ListReadWriteAdapterRuntimeService.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/list/ListReadWriteAdapterRuntimeService.java @@ -12,50 +12,50 @@ */ public class ListReadWriteAdapterRuntimeService extends AbstractListReadWriteAdapter { - private final RuntimeService runtimeService; - private final String executionId; - - /** - * Constructs the adapter. - * - * @param runtimeService runtime service to use. - * @param executionId id of the execution to read from and write to. - * @param variableName name of the variable. - * @param memberClazz class of the variable. - */ - public ListReadWriteAdapterRuntimeService(RuntimeService runtimeService, String executionId, String variableName, Class memberClazz) { - super(variableName, memberClazz); - this.runtimeService = runtimeService; - this.executionId = executionId; - } - - @Override - public Optional> getOptional() { - return Optional.ofNullable(getOrNull(runtimeService.getVariable(executionId, variableName))); - } - - @Override - public void set(List value, boolean isTransient) { - runtimeService.setVariable(executionId, variableName, getTypedValue(value, isTransient)); - } - - @Override - public Optional> getLocalOptional() { - return Optional.ofNullable(getOrNull(runtimeService.getVariableLocal(executionId, variableName))); - } - - @Override - public void setLocal(List value, boolean isTransient) { - runtimeService.setVariableLocal(executionId, variableName, getTypedValue(value, isTransient)); - } - - @Override - public void remove() { - runtimeService.removeVariable(executionId, variableName); - } - - @Override - public void removeLocal() { - runtimeService.removeVariableLocal(executionId, variableName); - } + private final RuntimeService runtimeService; + private final String executionId; + + /** + * Constructs the adapter. + * + * @param runtimeService runtime service to use. + * @param executionId id of the execution to read from and write to. + * @param variableName name of the variable. + * @param memberClazz class of the variable. + */ + public ListReadWriteAdapterRuntimeService(RuntimeService runtimeService, String executionId, String variableName, Class memberClazz) { + super(variableName, memberClazz); + this.runtimeService = runtimeService; + this.executionId = executionId; + } + + @Override + public Optional> getOptional() { + return Optional.ofNullable(getOrNull(runtimeService.getVariable(executionId, variableName))); + } + + @Override + public void set(List value, boolean isTransient) { + runtimeService.setVariable(executionId, variableName, getTypedValue(value, isTransient)); + } + + @Override + public Optional> getLocalOptional() { + return Optional.ofNullable(getOrNull(runtimeService.getVariableLocal(executionId, variableName))); + } + + @Override + public void setLocal(List value, boolean isTransient) { + runtimeService.setVariableLocal(executionId, variableName, getTypedValue(value, isTransient)); + } + + @Override + public void remove() { + runtimeService.removeVariable(executionId, variableName); + } + + @Override + public void removeLocal() { + runtimeService.removeVariableLocal(executionId, variableName); + } } diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/list/ListReadWriteAdapterTaskService.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/list/ListReadWriteAdapterTaskService.java index 350e2824..f6df765b 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/list/ListReadWriteAdapterTaskService.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/list/ListReadWriteAdapterTaskService.java @@ -12,51 +12,51 @@ */ public class ListReadWriteAdapterTaskService extends AbstractListReadWriteAdapter { - private final TaskService taskService; - private final String taskId; - - /** - * Constructs the adapter. - * - * @param taskService task service to use. - * @param taskId id of the task to read from and write to. - * @param variableName name of the variable. - * @param memberClazz class of the variable. - */ - public ListReadWriteAdapterTaskService(TaskService taskService, String taskId, String variableName, Class memberClazz) { - super(variableName, memberClazz); - this.taskService = taskService; - this.taskId = taskId; - } - - @Override - public Optional> getOptional() { - return Optional.ofNullable(getOrNull(taskService.getVariable(taskId, variableName))); - } - - @Override - public void set(List value, boolean isTransient) { - taskService.setVariable(taskId, variableName, getTypedValue(value, isTransient)); - } - - @Override - public Optional> getLocalOptional() { - return Optional.ofNullable(getOrNull(taskService.getVariableLocal(taskId, variableName))); - } - - @Override - public void setLocal(List value, boolean isTransient) { - taskService.setVariableLocal(taskId, variableName, getTypedValue(value, isTransient)); - } - - @Override - public void remove() { - taskService.removeVariable(taskId, variableName); - } - - @Override - public void removeLocal() { - taskService.removeVariableLocal(taskId, variableName); - } + private final TaskService taskService; + private final String taskId; + + /** + * Constructs the adapter. + * + * @param taskService task service to use. + * @param taskId id of the task to read from and write to. + * @param variableName name of the variable. + * @param memberClazz class of the variable. + */ + public ListReadWriteAdapterTaskService(TaskService taskService, String taskId, String variableName, Class memberClazz) { + super(variableName, memberClazz); + this.taskService = taskService; + this.taskId = taskId; + } + + @Override + public Optional> getOptional() { + return Optional.ofNullable(getOrNull(taskService.getVariable(taskId, variableName))); + } + + @Override + public void set(List value, boolean isTransient) { + taskService.setVariable(taskId, variableName, getTypedValue(value, isTransient)); + } + + @Override + public Optional> getLocalOptional() { + return Optional.ofNullable(getOrNull(taskService.getVariableLocal(taskId, variableName))); + } + + @Override + public void setLocal(List value, boolean isTransient) { + taskService.setVariableLocal(taskId, variableName, getTypedValue(value, isTransient)); + } + + @Override + public void remove() { + taskService.removeVariable(taskId, variableName); + } + + @Override + public void removeLocal() { + taskService.removeVariableLocal(taskId, variableName); + } } diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/list/ListReadWriteAdapterVariableMap.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/list/ListReadWriteAdapterVariableMap.java index 2d5e6715..16e48a53 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/list/ListReadWriteAdapterVariableMap.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/list/ListReadWriteAdapterVariableMap.java @@ -12,48 +12,48 @@ */ public class ListReadWriteAdapterVariableMap extends AbstractListReadWriteAdapter { - private final VariableMap variableMap; - - /** - * Constructs the adapter. - * - * @param variableMap variable map to access. - * @param variableName variable to access. - * @param memberClazz class of variable value. - */ - public ListReadWriteAdapterVariableMap(VariableMap variableMap, String variableName, Class memberClazz) { - super(variableName, memberClazz); - this.variableMap = variableMap; - } - - @Override - public Optional> getOptional() { - return Optional.ofNullable(getOrNull(variableMap.get(variableName))); - } - - @Override - public void set(List value, boolean isTransient) { - variableMap.putValueTyped(variableName, getTypedValue(value, isTransient)); - } - - @Override - public Optional> getLocalOptional() { - throw new UnsupportedOperationException("Can't get a local variable on a variable map"); - } - - @Override - public void setLocal(List value, boolean isTransient) { - throw new UnsupportedOperationException("Can't set a local variable on a variable map"); - } - - @Override - public void remove() { - variableMap.remove(variableName); - } - - @Override - public void removeLocal() { - throw new UnsupportedOperationException("Can't set a local variable on a variable map"); - } + private final VariableMap variableMap; + + /** + * Constructs the adapter. + * + * @param variableMap variable map to access. + * @param variableName variable to access. + * @param memberClazz class of variable value. + */ + public ListReadWriteAdapterVariableMap(VariableMap variableMap, String variableName, Class memberClazz) { + super(variableName, memberClazz); + this.variableMap = variableMap; + } + + @Override + public Optional> getOptional() { + return Optional.ofNullable(getOrNull(variableMap.get(variableName))); + } + + @Override + public void set(List value, boolean isTransient) { + variableMap.putValueTyped(variableName, getTypedValue(value, isTransient)); + } + + @Override + public Optional> getLocalOptional() { + throw new UnsupportedOperationException("Can't get a local variable on a variable map"); + } + + @Override + public void setLocal(List value, boolean isTransient) { + throw new UnsupportedOperationException("Can't set a local variable on a variable map"); + } + + @Override + public void remove() { + variableMap.remove(variableName); + } + + @Override + public void removeLocal() { + throw new UnsupportedOperationException("Can't set a local variable on a variable map"); + } } diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/list/ListReadWriteAdapterVariableScope.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/list/ListReadWriteAdapterVariableScope.java index d0dbcf08..675e42ed 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/list/ListReadWriteAdapterVariableScope.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/list/ListReadWriteAdapterVariableScope.java @@ -12,48 +12,48 @@ */ public class ListReadWriteAdapterVariableScope extends AbstractListReadWriteAdapter { - private final VariableScope variableScope; - - /** - * Constructs the adapter. - * - * @param variableScope variable scope to access. - * @param variableName variable to access. - * @param memberClazz class of member variable value. - */ - public ListReadWriteAdapterVariableScope(VariableScope variableScope, String variableName, Class memberClazz) { - super(variableName, memberClazz); - this.variableScope = variableScope; - } - - @Override - public Optional> getOptional() { - return Optional.ofNullable(getOrNull(variableScope.getVariable(variableName))); - } - - @Override - public void set(List value, boolean isTransient) { - variableScope.setVariable(variableName, getTypedValue(value, isTransient)); - } - - @Override - public Optional> getLocalOptional() { - return Optional.ofNullable(getOrNull(variableScope.getVariableLocal(variableName))); - } - - @Override - public void setLocal(List value, boolean isTransient) { - variableScope.setVariableLocal(variableName, getTypedValue(value, isTransient)); - } - - @Override - public void remove() { - variableScope.removeVariable(variableName); - } - - @Override - public void removeLocal() { - variableScope.removeVariableLocal(variableName); - } + private final VariableScope variableScope; + + /** + * Constructs the adapter. + * + * @param variableScope variable scope to access. + * @param variableName variable to access. + * @param memberClazz class of member variable value. + */ + public ListReadWriteAdapterVariableScope(VariableScope variableScope, String variableName, Class memberClazz) { + super(variableName, memberClazz); + this.variableScope = variableScope; + } + + @Override + public Optional> getOptional() { + return Optional.ofNullable(getOrNull(variableScope.getVariable(variableName))); + } + + @Override + public void set(List value, boolean isTransient) { + variableScope.setVariable(variableName, getTypedValue(value, isTransient)); + } + + @Override + public Optional> getLocalOptional() { + return Optional.ofNullable(getOrNull(variableScope.getVariableLocal(variableName))); + } + + @Override + public void setLocal(List value, boolean isTransient) { + variableScope.setVariableLocal(variableName, getTypedValue(value, isTransient)); + } + + @Override + public void remove() { + variableScope.removeVariable(variableName); + } + + @Override + public void removeLocal() { + variableScope.removeVariableLocal(variableName); + } } diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/map/AbstractMapReadWriteAdapter.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/map/AbstractMapReadWriteAdapter.java index 95a8d0cb..acc31b55 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/map/AbstractMapReadWriteAdapter.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/map/AbstractMapReadWriteAdapter.java @@ -16,63 +16,61 @@ */ public abstract class AbstractMapReadWriteAdapter extends AbstractReadWriteAdapter> { - /** - * Key type. - */ - protected final Class keyClazz; - /** - * Value type. - */ - protected final Class valueClazz; + /** + * Key type. + */ + protected final Class keyClazz; + /** + * Value type. + */ + protected final Class valueClazz; - /** - * Constructs adapter. - * - * @param variableName name of the variable. - * @param keyClazz key class. - * @param valueClazz value class. - */ - public AbstractMapReadWriteAdapter(String variableName, Class keyClazz, Class valueClazz) { - super(variableName); - this.keyClazz = keyClazz; - this.valueClazz = valueClazz; - } + /** + * Constructs adapter. + * + * @param variableName name of the variable. + * @param keyClazz key class. + * @param valueClazz value class. + */ + public AbstractMapReadWriteAdapter(String variableName, Class keyClazz, Class valueClazz) { + super(variableName); + this.keyClazz = keyClazz; + this.valueClazz = valueClazz; + } - /** - * Retrieves the value or null. - * - * @param value raw value. - * - * @return set or null. - */ - @SuppressWarnings("unchecked") - protected Map getOrNull(Object value) { - if (value == null) { - return null; - } + /** + * Retrieves the value or null. + * + * @param value raw value. + * @return set or null. + */ + @SuppressWarnings("unchecked") + protected Map getOrNull(Object value) { + if (value == null) { + return null; + } - if (Map.class.isAssignableFrom(value.getClass())) { - Map valueAsMap = (Map) value; - if (valueAsMap.isEmpty()) { - return Collections.emptyMap(); - } else { - Map.Entry entry = valueAsMap.entrySet().iterator().next(); - if (keyClazz.isAssignableFrom(entry.getKey().getClass()) && valueClazz.isAssignableFrom(entry.getValue().getClass())) { - return (Map) valueAsMap; - } else { - throw new WrongVariableTypeException("Error reading " + variableName + ": Wrong map type detected, expected Map<" - + keyClazz.getName() + "," + valueClazz.getName() - + ", but was not found in " + valueAsMap); - } - } + if (Map.class.isAssignableFrom(value.getClass())) { + Map valueAsMap = (Map) value; + if (valueAsMap.isEmpty()) { + return Collections.emptyMap(); + } else { + Map.Entry entry = valueAsMap.entrySet().iterator().next(); + if (keyClazz.isAssignableFrom(entry.getKey().getClass()) && valueClazz.isAssignableFrom(entry.getValue().getClass())) { + return (Map) valueAsMap; + } else { + throw new WrongVariableTypeException("Error reading " + variableName + ": Wrong map type detected, expected Map<" + + keyClazz.getName() + "," + valueClazz.getName() + + ", but was not found in " + valueAsMap); } - - throw new WrongVariableTypeException("Error reading " + variableName + ": Couldn't read value of type Map from " + value); + } } - @Override - public TypedValue getTypedValue(Object value, boolean isTransient) { - return ValueWrapperUtil.getTypedValue(Map.class, value, isTransient); - } + throw new WrongVariableTypeException("Error reading " + variableName + ": Couldn't read value of type Map from " + value); + } + @Override + public TypedValue getTypedValue(Object value, boolean isTransient) { + return ValueWrapperUtil.getTypedValue(Map.class, value, isTransient); + } } diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/map/MapReadWriteAdapterCaseService.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/map/MapReadWriteAdapterCaseService.java index 821b372b..72161449 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/map/MapReadWriteAdapterCaseService.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/map/MapReadWriteAdapterCaseService.java @@ -13,52 +13,52 @@ */ public class MapReadWriteAdapterCaseService extends AbstractMapReadWriteAdapter { - private final CaseService caseService; - private final String caseExecutionId; + private final CaseService caseService; + private final String caseExecutionId; - /** - * Constructs the adapter. - * - * @param caseService case service to use. - * @param caseExecutionId id of the execution to read from and write to. - * @param variableName name of the variable. - * @param keyClazz class of the key variable. - * @param valueClazz class of the value variable. - */ - public MapReadWriteAdapterCaseService( - CaseService caseService, String caseExecutionId, String variableName, Class keyClazz, Class valueClazz) { - super(variableName, keyClazz, valueClazz); - this.caseService = caseService; - this.caseExecutionId = caseExecutionId; - } + /** + * Constructs the adapter. + * + * @param caseService case service to use. + * @param caseExecutionId id of the execution to read from and write to. + * @param variableName name of the variable. + * @param keyClazz class of the key variable. + * @param valueClazz class of the value variable. + */ + public MapReadWriteAdapterCaseService( + CaseService caseService, String caseExecutionId, String variableName, Class keyClazz, Class valueClazz) { + super(variableName, keyClazz, valueClazz); + this.caseService = caseService; + this.caseExecutionId = caseExecutionId; + } - @Override - public Optional> getOptional() { - return Optional.ofNullable(getOrNull(caseService.getVariable(caseExecutionId, variableName))); - } + @Override + public Optional> getOptional() { + return Optional.ofNullable(getOrNull(caseService.getVariable(caseExecutionId, variableName))); + } - @Override - public void set(Map value, boolean isTransient) { - caseService.setVariable(caseExecutionId, variableName, getTypedValue(value, isTransient)); - } + @Override + public void set(Map value, boolean isTransient) { + caseService.setVariable(caseExecutionId, variableName, getTypedValue(value, isTransient)); + } - @Override - public Optional> getLocalOptional() { - return Optional.ofNullable(getOrNull(caseService.getVariableLocal(caseExecutionId, variableName))); - } + @Override + public Optional> getLocalOptional() { + return Optional.ofNullable(getOrNull(caseService.getVariableLocal(caseExecutionId, variableName))); + } - @Override - public void setLocal(Map value, boolean isTransient) { - caseService.setVariableLocal(caseExecutionId, variableName, getTypedValue(value, isTransient)); - } + @Override + public void setLocal(Map value, boolean isTransient) { + caseService.setVariableLocal(caseExecutionId, variableName, getTypedValue(value, isTransient)); + } - @Override - public void remove() { - caseService.removeVariable(caseExecutionId, variableName); - } + @Override + public void remove() { + caseService.removeVariable(caseExecutionId, variableName); + } - @Override - public void removeLocal() { - caseService.removeVariableLocal(caseExecutionId, variableName); - } + @Override + public void removeLocal() { + caseService.removeVariableLocal(caseExecutionId, variableName); + } } diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/map/MapReadWriteAdapterRuntimeService.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/map/MapReadWriteAdapterRuntimeService.java index 6d78f75d..7806a46d 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/map/MapReadWriteAdapterRuntimeService.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/map/MapReadWriteAdapterRuntimeService.java @@ -13,52 +13,52 @@ */ public class MapReadWriteAdapterRuntimeService extends AbstractMapReadWriteAdapter { - private final RuntimeService runtimeService; - private final String executionId; + private final RuntimeService runtimeService; + private final String executionId; - /** - * Constructs the adapter. - * - * @param runtimeService runtime service to use. - * @param executionId id of the execution to read from and write to. - * @param variableName name of the variable. - * @param keyClazz class of the key variable. - * @param valueClazz class of the value variable. - */ - public MapReadWriteAdapterRuntimeService( - RuntimeService runtimeService, String executionId, String variableName, Class keyClazz, Class valueClazz) { - super(variableName, keyClazz, valueClazz); - this.runtimeService = runtimeService; - this.executionId = executionId; - } + /** + * Constructs the adapter. + * + * @param runtimeService runtime service to use. + * @param executionId id of the execution to read from and write to. + * @param variableName name of the variable. + * @param keyClazz class of the key variable. + * @param valueClazz class of the value variable. + */ + public MapReadWriteAdapterRuntimeService( + RuntimeService runtimeService, String executionId, String variableName, Class keyClazz, Class valueClazz) { + super(variableName, keyClazz, valueClazz); + this.runtimeService = runtimeService; + this.executionId = executionId; + } - @Override - public Optional> getOptional() { - return Optional.ofNullable(getOrNull(runtimeService.getVariable(executionId, variableName))); - } + @Override + public Optional> getOptional() { + return Optional.ofNullable(getOrNull(runtimeService.getVariable(executionId, variableName))); + } - @Override - public void set(Map value, boolean isTransient) { - runtimeService.setVariable(executionId, variableName, getTypedValue(value, isTransient)); - } + @Override + public void set(Map value, boolean isTransient) { + runtimeService.setVariable(executionId, variableName, getTypedValue(value, isTransient)); + } - @Override - public Optional> getLocalOptional() { - return Optional.ofNullable(getOrNull(runtimeService.getVariableLocal(executionId, variableName))); - } + @Override + public Optional> getLocalOptional() { + return Optional.ofNullable(getOrNull(runtimeService.getVariableLocal(executionId, variableName))); + } - @Override - public void setLocal(Map value, boolean isTransient) { - runtimeService.setVariableLocal(executionId, variableName, getTypedValue(value, isTransient)); - } + @Override + public void setLocal(Map value, boolean isTransient) { + runtimeService.setVariableLocal(executionId, variableName, getTypedValue(value, isTransient)); + } - @Override - public void remove() { - runtimeService.removeVariable(executionId, variableName); - } + @Override + public void remove() { + runtimeService.removeVariable(executionId, variableName); + } - @Override - public void removeLocal() { - runtimeService.removeVariableLocal(executionId, variableName); - } + @Override + public void removeLocal() { + runtimeService.removeVariableLocal(executionId, variableName); + } } diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/map/MapReadWriteAdapterTaskService.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/map/MapReadWriteAdapterTaskService.java index 75089aee..5bee832b 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/map/MapReadWriteAdapterTaskService.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/map/MapReadWriteAdapterTaskService.java @@ -13,53 +13,53 @@ */ public class MapReadWriteAdapterTaskService extends AbstractMapReadWriteAdapter { - private final TaskService taskService; - private final String taskId; + private final TaskService taskService; + private final String taskId; - /** - * Constructs the adapter. - * - * @param taskService task service to use. - * @param taskId id of the task to read from and write to. - * @param variableName name of the variable. - * @param keyClazz class of the key of variable. - * @param valueClazz class of variable. - */ - public MapReadWriteAdapterTaskService( - TaskService taskService, String taskId, String variableName, Class keyClazz, Class valueClazz) { - super(variableName, keyClazz, valueClazz); - this.taskService = taskService; - this.taskId = taskId; - } + /** + * Constructs the adapter. + * + * @param taskService task service to use. + * @param taskId id of the task to read from and write to. + * @param variableName name of the variable. + * @param keyClazz class of the key of variable. + * @param valueClazz class of variable. + */ + public MapReadWriteAdapterTaskService( + TaskService taskService, String taskId, String variableName, Class keyClazz, Class valueClazz) { + super(variableName, keyClazz, valueClazz); + this.taskService = taskService; + this.taskId = taskId; + } - @Override - public Optional> getOptional() { - return Optional.ofNullable(getOrNull(taskService.getVariable(taskId, variableName))); - } + @Override + public Optional> getOptional() { + return Optional.ofNullable(getOrNull(taskService.getVariable(taskId, variableName))); + } - @Override - public void set(Map value, boolean isTransient) { - taskService.setVariable(taskId, variableName, getTypedValue(value, isTransient)); - } + @Override + public void set(Map value, boolean isTransient) { + taskService.setVariable(taskId, variableName, getTypedValue(value, isTransient)); + } - @Override - public Optional> getLocalOptional() { - return Optional.ofNullable(getOrNull(taskService.getVariableLocal(taskId, variableName))); - } + @Override + public Optional> getLocalOptional() { + return Optional.ofNullable(getOrNull(taskService.getVariableLocal(taskId, variableName))); + } - @Override - public void setLocal(Map value, boolean isTransient) { - taskService.setVariableLocal(taskId, variableName, getTypedValue(value, isTransient)); - } + @Override + public void setLocal(Map value, boolean isTransient) { + taskService.setVariableLocal(taskId, variableName, getTypedValue(value, isTransient)); + } - @Override - public void remove() { - taskService.removeVariable(taskId, variableName); - } + @Override + public void remove() { + taskService.removeVariable(taskId, variableName); + } - @Override - public void removeLocal() { - taskService.removeVariableLocal(taskId, variableName); - } + @Override + public void removeLocal() { + taskService.removeVariableLocal(taskId, variableName); + } } diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/map/MapReadWriteAdapterVariableMap.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/map/MapReadWriteAdapterVariableMap.java index 2c202a8a..13edf5b9 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/map/MapReadWriteAdapterVariableMap.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/map/MapReadWriteAdapterVariableMap.java @@ -13,49 +13,49 @@ */ public class MapReadWriteAdapterVariableMap extends AbstractMapReadWriteAdapter { - private final VariableMap variableMap; - - /** - * Constructs the adapter. - * - * @param variableMap variable map to access. - * @param variableName variable to access. - * @param keyClazz class of variable key. - * @param valueClazz class of variable value. - */ - public MapReadWriteAdapterVariableMap(VariableMap variableMap, String variableName, Class keyClazz, Class valueClazz) { - super(variableName, keyClazz, valueClazz); - this.variableMap = variableMap; - } - - @Override - public Optional> getOptional() { - return Optional.ofNullable(getOrNull(variableMap.get(variableName))); - } - - @Override - public void set(Map value, boolean isTransient) { - variableMap.putValueTyped(variableName, getTypedValue(value, isTransient)); - } - - @Override - public Optional> getLocalOptional() { - throw new UnsupportedOperationException("Can't get a local variable on a variable map"); - } - - @Override - public void setLocal(Map value, boolean isTransient) { - throw new UnsupportedOperationException("Can't set a local variable on a variable map"); - } - - @Override - public void remove() { - variableMap.remove(variableName); - } - - @Override - public void removeLocal() { - throw new UnsupportedOperationException("Can't set a local variable on a variable map"); - } + private final VariableMap variableMap; + + /** + * Constructs the adapter. + * + * @param variableMap variable map to access. + * @param variableName variable to access. + * @param keyClazz class of variable key. + * @param valueClazz class of variable value. + */ + public MapReadWriteAdapterVariableMap(VariableMap variableMap, String variableName, Class keyClazz, Class valueClazz) { + super(variableName, keyClazz, valueClazz); + this.variableMap = variableMap; + } + + @Override + public Optional> getOptional() { + return Optional.ofNullable(getOrNull(variableMap.get(variableName))); + } + + @Override + public void set(Map value, boolean isTransient) { + variableMap.putValueTyped(variableName, getTypedValue(value, isTransient)); + } + + @Override + public Optional> getLocalOptional() { + throw new UnsupportedOperationException("Can't get a local variable on a variable map"); + } + + @Override + public void setLocal(Map value, boolean isTransient) { + throw new UnsupportedOperationException("Can't set a local variable on a variable map"); + } + + @Override + public void remove() { + variableMap.remove(variableName); + } + + @Override + public void removeLocal() { + throw new UnsupportedOperationException("Can't set a local variable on a variable map"); + } } diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/map/MapReadWriteAdapterVariableScope.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/map/MapReadWriteAdapterVariableScope.java index fa89f147..c369fc76 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/map/MapReadWriteAdapterVariableScope.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/map/MapReadWriteAdapterVariableScope.java @@ -13,49 +13,49 @@ */ public class MapReadWriteAdapterVariableScope extends AbstractMapReadWriteAdapter { - private final VariableScope variableScope; - - /** - * Constructs the adapter. - * - * @param variableScope variable scope to access. - * @param variableName variable to access. - * @param keyClazz class of variable key. - * @param valueClazz class of variable value. - */ - public MapReadWriteAdapterVariableScope(VariableScope variableScope, String variableName, Class keyClazz, Class valueClazz) { - super(variableName, keyClazz, valueClazz); - this.variableScope = variableScope; - } - - @Override - public Optional> getOptional() { - return Optional.ofNullable(getOrNull(variableScope.getVariable(variableName))); - } - - @Override - public void set(Map value, boolean isTransient) { - variableScope.setVariable(variableName, getTypedValue(value, isTransient)); - } - - @Override - public Optional> getLocalOptional() { - return Optional.ofNullable(getOrNull(variableScope.getVariableLocal(variableName))); - } - - @Override - public void setLocal(Map value, boolean isTransient) { - variableScope.setVariableLocal(variableName, getTypedValue(value, isTransient)); - } - - @Override - public void remove() { - variableScope.removeVariable(variableName); - } - - @Override - public void removeLocal() { - variableScope.removeVariableLocal(variableName); - } + private final VariableScope variableScope; + + /** + * Constructs the adapter. + * + * @param variableScope variable scope to access. + * @param variableName variable to access. + * @param keyClazz class of variable key. + * @param valueClazz class of variable value. + */ + public MapReadWriteAdapterVariableScope(VariableScope variableScope, String variableName, Class keyClazz, Class valueClazz) { + super(variableName, keyClazz, valueClazz); + this.variableScope = variableScope; + } + + @Override + public Optional> getOptional() { + return Optional.ofNullable(getOrNull(variableScope.getVariable(variableName))); + } + + @Override + public void set(Map value, boolean isTransient) { + variableScope.setVariable(variableName, getTypedValue(value, isTransient)); + } + + @Override + public Optional> getLocalOptional() { + return Optional.ofNullable(getOrNull(variableScope.getVariableLocal(variableName))); + } + + @Override + public void setLocal(Map value, boolean isTransient) { + variableScope.setVariableLocal(variableName, getTypedValue(value, isTransient)); + } + + @Override + public void remove() { + variableScope.removeVariable(variableName); + } + + @Override + public void removeLocal() { + variableScope.removeVariableLocal(variableName); + } } diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/set/AbstractSetReadWriteAdapter.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/set/AbstractSetReadWriteAdapter.java index 5dee4b39..345d2f78 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/set/AbstractSetReadWriteAdapter.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/set/AbstractSetReadWriteAdapter.java @@ -15,53 +15,52 @@ */ public abstract class AbstractSetReadWriteAdapter extends AbstractReadWriteAdapter> { - /** - * Member type. - */ - protected final Class memberClazz; + /** + * Member type. + */ + protected final Class memberClazz; - /** - * Constructs adapter. - * - * @param variableName name of the variable. - * @param memberClazz member class. - */ - public AbstractSetReadWriteAdapter(String variableName, Class memberClazz) { - super(variableName); - this.memberClazz = memberClazz; - } + /** + * Constructs adapter. + * + * @param variableName name of the variable. + * @param memberClazz member class. + */ + public AbstractSetReadWriteAdapter(String variableName, Class memberClazz) { + super(variableName); + this.memberClazz = memberClazz; + } - /** - * Retrieves the value or null. - * - * @param value raw value. - * - * @return set or null. - */ - @SuppressWarnings("unchecked") - protected Set getOrNull(Object value) { - if (value == null) { - return null; - } + /** + * Retrieves the value or null. + * + * @param value raw value. + * @return set or null. + */ + @SuppressWarnings("unchecked") + protected Set getOrNull(Object value) { + if (value == null) { + return null; + } - if (Set.class.isAssignableFrom(value.getClass())) { - Set valueAsList = (Set) value; - if (valueAsList.isEmpty()) { - return Collections.emptySet(); - } else { - if (memberClazz.isAssignableFrom(valueAsList.iterator().next().getClass())) { - return (Set) valueAsList; - } else { - throw new WrongVariableTypeException("Error reading " + variableName + ": Wrong set type detected, expected " + memberClazz.getName() + ", but was not found in " + valueAsList); - } - } + if (Set.class.isAssignableFrom(value.getClass())) { + Set valueAsList = (Set) value; + if (valueAsList.isEmpty()) { + return Collections.emptySet(); + } else { + if (memberClazz.isAssignableFrom(valueAsList.iterator().next().getClass())) { + return (Set) valueAsList; + } else { + throw new WrongVariableTypeException("Error reading " + variableName + ": Wrong set type detected, expected " + memberClazz.getName() + ", but was not found in " + valueAsList); } - - throw new WrongVariableTypeException("Error reading " + variableName + ": Couldn't read value of type Set from " + value); + } } - @Override - public TypedValue getTypedValue(Object value, boolean isTransient) { - return ValueWrapperUtil.getTypedValue(Set.class, value, isTransient); - } + throw new WrongVariableTypeException("Error reading " + variableName + ": Couldn't read value of type Set from " + value); + } + + @Override + public TypedValue getTypedValue(Object value, boolean isTransient) { + return ValueWrapperUtil.getTypedValue(Set.class, value, isTransient); + } } diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/set/SetReadWriteAdapterCaseService.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/set/SetReadWriteAdapterCaseService.java index dc806425..df4c38b9 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/set/SetReadWriteAdapterCaseService.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/set/SetReadWriteAdapterCaseService.java @@ -12,51 +12,51 @@ */ public class SetReadWriteAdapterCaseService extends AbstractSetReadWriteAdapter { - private final CaseService caseService; - private final String caseExecutionId; - - /** - * Constructs the adapter. - * - * @param caseService case service to use. - * @param caseExecutionId id of the execution to read from and write to. - * @param variableName name of the variable. - * @param memberClazz class of the variable. - */ - public SetReadWriteAdapterCaseService(CaseService caseService, String caseExecutionId, String variableName, Class memberClazz) { - super(variableName, memberClazz); - this.caseService = caseService; - this.caseExecutionId = caseExecutionId; - } - - @Override - public Optional> getOptional() { - return Optional.ofNullable(getOrNull(caseService.getVariable(caseExecutionId, variableName))); - } - - @Override - public void set(Set value, boolean isTransient) { - caseService.setVariable(caseExecutionId, variableName, getTypedValue(value, isTransient)); - } - - @Override - public Optional> getLocalOptional() { - return Optional.ofNullable(getOrNull(caseService.getVariableLocal(caseExecutionId, variableName))); - } - - @Override - public void setLocal(Set value, boolean isTransient) { - caseService.setVariableLocal(caseExecutionId, variableName, getTypedValue(value, isTransient)); - } - - @Override - public void remove() { - caseService.removeVariable(caseExecutionId, variableName); - } - - @Override - public void removeLocal() { - caseService.removeVariableLocal(caseExecutionId, variableName); - } + private final CaseService caseService; + private final String caseExecutionId; + + /** + * Constructs the adapter. + * + * @param caseService case service to use. + * @param caseExecutionId id of the execution to read from and write to. + * @param variableName name of the variable. + * @param memberClazz class of the variable. + */ + public SetReadWriteAdapterCaseService(CaseService caseService, String caseExecutionId, String variableName, Class memberClazz) { + super(variableName, memberClazz); + this.caseService = caseService; + this.caseExecutionId = caseExecutionId; + } + + @Override + public Optional> getOptional() { + return Optional.ofNullable(getOrNull(caseService.getVariable(caseExecutionId, variableName))); + } + + @Override + public void set(Set value, boolean isTransient) { + caseService.setVariable(caseExecutionId, variableName, getTypedValue(value, isTransient)); + } + + @Override + public Optional> getLocalOptional() { + return Optional.ofNullable(getOrNull(caseService.getVariableLocal(caseExecutionId, variableName))); + } + + @Override + public void setLocal(Set value, boolean isTransient) { + caseService.setVariableLocal(caseExecutionId, variableName, getTypedValue(value, isTransient)); + } + + @Override + public void remove() { + caseService.removeVariable(caseExecutionId, variableName); + } + + @Override + public void removeLocal() { + caseService.removeVariableLocal(caseExecutionId, variableName); + } } diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/set/SetReadWriteAdapterRuntimeService.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/set/SetReadWriteAdapterRuntimeService.java index b09ea4e3..6b73061f 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/set/SetReadWriteAdapterRuntimeService.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/set/SetReadWriteAdapterRuntimeService.java @@ -12,51 +12,51 @@ */ public class SetReadWriteAdapterRuntimeService extends AbstractSetReadWriteAdapter { - private final RuntimeService runtimeService; - private final String executionId; - - /** - * Constructs the adapter. - * - * @param runtimeService runtime service to use. - * @param executionId id of the execution to read from and write to. - * @param variableName name of the variable. - * @param memberClazz class of the variable. - */ - public SetReadWriteAdapterRuntimeService(RuntimeService runtimeService, String executionId, String variableName, Class memberClazz) { - super(variableName, memberClazz); - this.runtimeService = runtimeService; - this.executionId = executionId; - } - - @Override - public Optional> getOptional() { - return Optional.ofNullable(getOrNull(runtimeService.getVariable(executionId, variableName))); - } - - @Override - public void set(Set value, boolean isTransient) { - runtimeService.setVariable(executionId, variableName, getTypedValue(value, isTransient)); - } - - @Override - public Optional> getLocalOptional() { - return Optional.ofNullable(getOrNull(runtimeService.getVariableLocal(executionId, variableName))); - } - - @Override - public void setLocal(Set value, boolean isTransient) { - runtimeService.setVariableLocal(executionId, variableName, getTypedValue(value, isTransient)); - } - - @Override - public void remove() { - runtimeService.removeVariable(executionId, variableName); - } - - @Override - public void removeLocal() { - runtimeService.removeVariableLocal(executionId, variableName); - } + private final RuntimeService runtimeService; + private final String executionId; + + /** + * Constructs the adapter. + * + * @param runtimeService runtime service to use. + * @param executionId id of the execution to read from and write to. + * @param variableName name of the variable. + * @param memberClazz class of the variable. + */ + public SetReadWriteAdapterRuntimeService(RuntimeService runtimeService, String executionId, String variableName, Class memberClazz) { + super(variableName, memberClazz); + this.runtimeService = runtimeService; + this.executionId = executionId; + } + + @Override + public Optional> getOptional() { + return Optional.ofNullable(getOrNull(runtimeService.getVariable(executionId, variableName))); + } + + @Override + public void set(Set value, boolean isTransient) { + runtimeService.setVariable(executionId, variableName, getTypedValue(value, isTransient)); + } + + @Override + public Optional> getLocalOptional() { + return Optional.ofNullable(getOrNull(runtimeService.getVariableLocal(executionId, variableName))); + } + + @Override + public void setLocal(Set value, boolean isTransient) { + runtimeService.setVariableLocal(executionId, variableName, getTypedValue(value, isTransient)); + } + + @Override + public void remove() { + runtimeService.removeVariable(executionId, variableName); + } + + @Override + public void removeLocal() { + runtimeService.removeVariableLocal(executionId, variableName); + } } diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/set/SetReadWriteAdapterTaskService.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/set/SetReadWriteAdapterTaskService.java index 462e812c..02620781 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/set/SetReadWriteAdapterTaskService.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/set/SetReadWriteAdapterTaskService.java @@ -12,51 +12,51 @@ */ public class SetReadWriteAdapterTaskService extends AbstractSetReadWriteAdapter { - private final TaskService taskService; - private final String taskId; - - /** - * Constructs the adapter. - * - * @param taskService task service to use. - * @param taskId id of the task to read from and write to. - * @param variableName name of the variable. - * @param memberClazz class of the variable. - */ - public SetReadWriteAdapterTaskService(TaskService taskService, String taskId, String variableName, Class memberClazz) { - super(variableName, memberClazz); - this.taskService = taskService; - this.taskId = taskId; - } - - @Override - public Optional> getOptional() { - return Optional.ofNullable(getOrNull(taskService.getVariable(taskId, variableName))); - } - - @Override - public void set(Set value, boolean isTransient) { - taskService.setVariable(taskId, variableName, getTypedValue(value, isTransient)); - } - - @Override - public Optional> getLocalOptional() { - return Optional.ofNullable(getOrNull(taskService.getVariableLocal(taskId, variableName))); - } - - @Override - public void setLocal(Set value, boolean isTransient) { - taskService.setVariableLocal(taskId, variableName, getTypedValue(value, isTransient)); - } - - @Override - public void remove() { - taskService.removeVariable(taskId, variableName); - } - - @Override - public void removeLocal() { - taskService.removeVariableLocal(taskId, variableName); - } + private final TaskService taskService; + private final String taskId; + + /** + * Constructs the adapter. + * + * @param taskService task service to use. + * @param taskId id of the task to read from and write to. + * @param variableName name of the variable. + * @param memberClazz class of the variable. + */ + public SetReadWriteAdapterTaskService(TaskService taskService, String taskId, String variableName, Class memberClazz) { + super(variableName, memberClazz); + this.taskService = taskService; + this.taskId = taskId; + } + + @Override + public Optional> getOptional() { + return Optional.ofNullable(getOrNull(taskService.getVariable(taskId, variableName))); + } + + @Override + public void set(Set value, boolean isTransient) { + taskService.setVariable(taskId, variableName, getTypedValue(value, isTransient)); + } + + @Override + public Optional> getLocalOptional() { + return Optional.ofNullable(getOrNull(taskService.getVariableLocal(taskId, variableName))); + } + + @Override + public void setLocal(Set value, boolean isTransient) { + taskService.setVariableLocal(taskId, variableName, getTypedValue(value, isTransient)); + } + + @Override + public void remove() { + taskService.removeVariable(taskId, variableName); + } + + @Override + public void removeLocal() { + taskService.removeVariableLocal(taskId, variableName); + } } diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/set/SetReadWriteAdapterVariableMap.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/set/SetReadWriteAdapterVariableMap.java index 8deb4266..47cd63b6 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/set/SetReadWriteAdapterVariableMap.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/set/SetReadWriteAdapterVariableMap.java @@ -12,48 +12,48 @@ */ public class SetReadWriteAdapterVariableMap extends AbstractSetReadWriteAdapter { - private final VariableMap variableMap; - - /** - * Constructs the adapter. - * - * @param variableMap variable map to access. - * @param variableName variable to access. - * @param memberClazz class of variable value. - */ - public SetReadWriteAdapterVariableMap(VariableMap variableMap, String variableName, Class memberClazz) { - super(variableName, memberClazz); - this.variableMap = variableMap; - } - - @Override - public Optional> getOptional() { - return Optional.ofNullable(getOrNull(variableMap.get(variableName))); - } - - @Override - public void set(Set value, boolean isTransient) { - variableMap.putValueTyped(variableName, getTypedValue(value, isTransient)); - } - - @Override - public Optional> getLocalOptional() { - throw new UnsupportedOperationException("Can't get a local variable on a variable map"); - } - - @Override - public void setLocal(Set value, boolean isTransient) { - throw new UnsupportedOperationException("Can't set a local variable on a variable map"); - } - - @Override - public void remove() { - variableMap.remove(variableName); - } - - @Override - public void removeLocal() { - throw new UnsupportedOperationException("Can't set a local variable on a variable map"); - } + private final VariableMap variableMap; + + /** + * Constructs the adapter. + * + * @param variableMap variable map to access. + * @param variableName variable to access. + * @param memberClazz class of variable value. + */ + public SetReadWriteAdapterVariableMap(VariableMap variableMap, String variableName, Class memberClazz) { + super(variableName, memberClazz); + this.variableMap = variableMap; + } + + @Override + public Optional> getOptional() { + return Optional.ofNullable(getOrNull(variableMap.get(variableName))); + } + + @Override + public void set(Set value, boolean isTransient) { + variableMap.putValueTyped(variableName, getTypedValue(value, isTransient)); + } + + @Override + public Optional> getLocalOptional() { + throw new UnsupportedOperationException("Can't get a local variable on a variable map"); + } + + @Override + public void setLocal(Set value, boolean isTransient) { + throw new UnsupportedOperationException("Can't set a local variable on a variable map"); + } + + @Override + public void remove() { + variableMap.remove(variableName); + } + + @Override + public void removeLocal() { + throw new UnsupportedOperationException("Can't set a local variable on a variable map"); + } } diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/set/SetReadWriteAdapterVariableScope.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/set/SetReadWriteAdapterVariableScope.java index f86ec650..2d880221 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/set/SetReadWriteAdapterVariableScope.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/set/SetReadWriteAdapterVariableScope.java @@ -12,48 +12,48 @@ */ public class SetReadWriteAdapterVariableScope extends AbstractSetReadWriteAdapter { - private final VariableScope variableScope; - - /** - * Constructs the adapter. - * - * @param variableScope variable scope to access. - * @param variableName variable to access. - * @param memberClazz class of member variable value. - */ - public SetReadWriteAdapterVariableScope(VariableScope variableScope, String variableName, Class memberClazz) { - super(variableName, memberClazz); - this.variableScope = variableScope; - } - - @Override - public Optional> getOptional() { - return Optional.ofNullable(getOrNull(variableScope.getVariable(variableName))); - } - - @Override - public void set(Set value, boolean isTransient) { - variableScope.setVariable(variableName, getTypedValue(value, isTransient)); - } - - @Override - public Optional> getLocalOptional() { - return Optional.ofNullable(getOrNull(variableScope.getVariableLocal(variableName))); - } - - @Override - public void setLocal(Set value, boolean isTransient) { - variableScope.setVariableLocal(variableName, getTypedValue(value, isTransient)); - } - - @Override - public void remove() { - variableScope.removeVariable(variableName); - } - - @Override - public void removeLocal() { - variableScope.removeVariableLocal(variableName); - } + private final VariableScope variableScope; + + /** + * Constructs the adapter. + * + * @param variableScope variable scope to access. + * @param variableName variable to access. + * @param memberClazz class of member variable value. + */ + public SetReadWriteAdapterVariableScope(VariableScope variableScope, String variableName, Class memberClazz) { + super(variableName, memberClazz); + this.variableScope = variableScope; + } + + @Override + public Optional> getOptional() { + return Optional.ofNullable(getOrNull(variableScope.getVariable(variableName))); + } + + @Override + public void set(Set value, boolean isTransient) { + variableScope.setVariable(variableName, getTypedValue(value, isTransient)); + } + + @Override + public Optional> getLocalOptional() { + return Optional.ofNullable(getOrNull(variableScope.getVariableLocal(variableName))); + } + + @Override + public void setLocal(Set value, boolean isTransient) { + variableScope.setVariableLocal(variableName, getTypedValue(value, isTransient)); + } + + @Override + public void remove() { + variableScope.removeVariable(variableName); + } + + @Override + public void removeLocal() { + variableScope.removeVariableLocal(variableName); + } } diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/builder/VariableMapBuilder.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/builder/VariableMapBuilder.java index 4f083b2e..5cad112e 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/builder/VariableMapBuilder.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/builder/VariableMapBuilder.java @@ -2,6 +2,7 @@ import io.holunda.camunda.bpm.data.factory.VariableFactory; import io.holunda.camunda.bpm.data.writer.VariableMapWriter; + import java.util.Collections; import java.util.Objects; @@ -27,8 +28,8 @@ public VariableMapBuilder() { * Sets the value for the provided variable and returns the builder (fluently). * * @param variableFactory the variable - * @param value the value - * @param type of value + * @param value the value + * @param type of value * @return current builder instance */ @NotNull @@ -41,9 +42,9 @@ public VariableMapBuilder set(VariableFactory variableFactory, T value) { * Sets the (transient) value for the provided variable and returns the builder (fluently). * * @param variableFactory the variable - * @param value the value - * @param isTransient if true, the variable is transient, default false. - * @param type of value + * @param value the value + * @param isTransient if true, the variable is transient, default false. + * @param type of value * @return current builder instance */ @NotNull @@ -54,6 +55,7 @@ public VariableMapBuilder set(VariableFactory variableFactory, T value, b /** * Creates the variable map. + * * @return instance of {@link VariableMap} containing set values */ @NotNull diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/factory/BasicVariableFactory.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/factory/BasicVariableFactory.java index 7c14f3e1..3f81b0f5 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/factory/BasicVariableFactory.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/factory/BasicVariableFactory.java @@ -94,7 +94,6 @@ public ReadAdapter from(CaseService caseService, String caseExecutionId) { * Creates a reusable adapter builder using a runtime service. * * @param runtimeService runtime service to operate on. - * * @return adapter builder. */ public BasicRuntimeServiceAdapterBuilder using(RuntimeService runtimeService) { @@ -105,7 +104,6 @@ public BasicRuntimeServiceAdapterBuilder using(RuntimeService runtimeService) * Creates a reusable adapter builder using a task service. * * @param taskService task service to operate on. - * * @return adapter builder. */ public BasicTaskServiceAdapterBuilder using(TaskService taskService) { @@ -116,7 +114,6 @@ public BasicTaskServiceAdapterBuilder using(TaskService taskService) { * Creates a reusable adapter builder using a case service. * * @param caseService case service to operate on. - * * @return adapter builder. */ public BasicCaseServiceAdapterBuilder using(CaseService caseService) { @@ -139,7 +136,8 @@ public Class getVariableClass() { return clazz; } - @Override public boolean equals(Object o) { + @Override + public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) @@ -157,9 +155,9 @@ public int hashCode() { @Override public String toString() { return "BasicVariableFactory{" + - "name='" + name + '\'' + - ", clazz=" + clazz + - '}'; + "name='" + name + '\'' + + ", clazz=" + clazz + + '}'; } /** @@ -196,7 +194,6 @@ private ReadWriteAdapterRuntimeService readWriteAdapter(String executionId) { * Creates a write adapter on execution. * * @param executionId id identifying execution. - * * @return write adapter */ public WriteAdapter on(String executionId) { @@ -207,7 +204,6 @@ public WriteAdapter on(String executionId) { * Creates a read adapter on execution. * * @param executionId id identifying execution. - * * @return read adapter. */ public ReadAdapter from(String executionId) { @@ -249,7 +245,6 @@ private ReadWriteAdapterTaskService readWriteAdapter(String taskId) { * Creates a write adapter on task. * * @param taskId id identifying task. - * * @return write adapter */ public WriteAdapter on(String taskId) { @@ -260,7 +255,6 @@ public WriteAdapter on(String taskId) { * Creates a read adapter on task. * * @param taskId id identifying task. - * * @return read adapter. */ public ReadAdapter from(String taskId) { @@ -303,7 +297,6 @@ private ReadWriteAdapterCaseService readWriteAdapter(String caseExecutionId) * Creates a write adapter on caseExecution. * * @param caseExecutionId id identifying caseExecution. - * * @return write adapter */ public WriteAdapter on(String caseExecutionId) { @@ -314,7 +307,6 @@ public WriteAdapter on(String caseExecutionId) { * Creates a read adapter on caseExecution. * * @param caseExecutionId id identifying caseExecution. - * * @return read adapter. */ public ReadAdapter from(String caseExecutionId) { diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/factory/SetVariableFactory.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/factory/SetVariableFactory.java index 46c45c7d..777f29b1 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/factory/SetVariableFactory.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/factory/SetVariableFactory.java @@ -96,7 +96,8 @@ public Class getMemberClass() { return memberClazz; } - @Override public boolean equals(Object o) { + @Override + public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) @@ -106,15 +107,16 @@ public Class getMemberClass() { memberClazz.equals(that.memberClazz); } - @Override public int hashCode() { + @Override + public int hashCode() { return Objects.hash(name, memberClazz); } @Override public String toString() { return "SetVariableFactory{" + - "name='" + name + '\'' + - ", memberClazz=" + memberClazz + - '}'; + "name='" + name + '\'' + + ", memberClazz=" + memberClazz + + '}'; } } diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/reader/CaseServiceVariableReader.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/reader/CaseServiceVariableReader.java index 79fbf84b..b172cd4c 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/reader/CaseServiceVariableReader.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/reader/CaseServiceVariableReader.java @@ -17,7 +17,8 @@ public class CaseServiceVariableReader implements VariableReader { /** * Constructs a reader operating on execution. - * @param caseService runtime service to use. + * + * @param caseService runtime service to use. * @param caseExecutionId execution id. */ public CaseServiceVariableReader(CaseService caseService, String caseExecutionId) { diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/reader/RuntimeServiceVariableReader.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/reader/RuntimeServiceVariableReader.java index bef54551..f6fb0a89 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/reader/RuntimeServiceVariableReader.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/reader/RuntimeServiceVariableReader.java @@ -4,6 +4,7 @@ import java.util.Objects; import java.util.Optional; + import org.camunda.bpm.engine.RuntimeService; import org.jetbrains.annotations.NotNull; @@ -17,8 +18,9 @@ public class RuntimeServiceVariableReader implements VariableReader { /** * Constructs a reader operating on execution. + * * @param runtimeService runtime service to use. - * @param executionId execution id. + * @param executionId execution id. */ public RuntimeServiceVariableReader(RuntimeService runtimeService, String executionId) { this.runtimeService = runtimeService; diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/reader/TaskServiceVariableReader.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/reader/TaskServiceVariableReader.java index b5da36a0..cc96335d 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/reader/TaskServiceVariableReader.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/reader/TaskServiceVariableReader.java @@ -4,6 +4,7 @@ import java.util.Objects; import java.util.Optional; + import org.camunda.bpm.engine.TaskService; import org.jetbrains.annotations.NotNull; @@ -17,8 +18,9 @@ public class TaskServiceVariableReader implements VariableReader { /** * Constructs a reader operating on task service. + * * @param taskService task service to operate on. - * @param taskId task id. + * @param taskId task id. */ public TaskServiceVariableReader(TaskService taskService, String taskId) { this.taskService = taskService; diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/reader/VariableMapReader.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/reader/VariableMapReader.java index 6b5188d6..3b9a6669 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/reader/VariableMapReader.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/reader/VariableMapReader.java @@ -4,6 +4,7 @@ import java.util.Objects; import java.util.Optional; + import org.camunda.bpm.engine.variable.VariableMap; /** @@ -15,6 +16,7 @@ public class VariableMapReader implements VariableReader { /** * Constructs the reader using the specified variable map. + * * @param variableMap map to operate on. */ public VariableMapReader(VariableMap variableMap) { diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/reader/VariableReader.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/reader/VariableReader.java index 261f850b..6ebf4eb9 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/reader/VariableReader.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/reader/VariableReader.java @@ -15,42 +15,38 @@ public interface VariableReader { * Uses {@link ReadAdapter#getOptional()} to access variable value. * * @param variableFactory the variable to read - * @param type of value + * @param type of value * @return value of variable or empty() */ - @NotNull - Optional getOptional(VariableFactory variableFactory); + @NotNull Optional getOptional(VariableFactory variableFactory); /** * Uses {@link ReadAdapter#get()} to access variable value. * * @param variableFactory the variable to read - * @param type of value + * @param type of value * @return value of variable * @throws IllegalStateException if variable is not set */ - @NotNull - T get(VariableFactory variableFactory); + @NotNull T get(VariableFactory variableFactory); /** * Uses {@link ReadAdapter#getLocal()} to access variable value. * * @param variableFactory the variable to read - * @param type of value + * @param type of value * @return value of variable * @throws IllegalStateException if variable is not set */ - @NotNull - T getLocal(VariableFactory variableFactory); + @NotNull T getLocal(VariableFactory variableFactory); /** * Uses {@link ReadAdapter#getLocalOptional()} ()} to access variable value. * * @param variableFactory the variable to read - * @param type of value + * @param type of value * @return value of variable or empty() */ - @NotNull - Optional getLocalOptional(VariableFactory variableFactory); + @NotNull Optional getLocalOptional(VariableFactory variableFactory); } diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/reader/VariableScopeReader.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/reader/VariableScopeReader.java index 86f26f33..3bae0e8c 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/reader/VariableScopeReader.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/reader/VariableScopeReader.java @@ -4,18 +4,20 @@ import java.util.Objects; import java.util.Optional; + import org.camunda.bpm.engine.delegate.VariableScope; import org.jetbrains.annotations.NotNull; /** * Allows reading multiple variable values from {@link VariableScope} (such as {@link org.camunda.bpm.engine.delegate.DelegateExecution} and {@link org.camunda.bpm.engine.delegate.DelegateTask}). */ -public class VariableScopeReader implements VariableReader{ +public class VariableScopeReader implements VariableReader { private final VariableScope variableScope; /** * Constructs a reader operating on variable scope (e.g. DelegateExecution or DelegateTask). + * * @param variableScope scope to operate on. */ public VariableScopeReader(VariableScope variableScope) { diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/GlobalVariableWriter.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/GlobalVariableWriter.java index 7c505336..2f5ce747 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/GlobalVariableWriter.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/GlobalVariableWriter.java @@ -16,37 +16,34 @@ public interface GlobalVariableWriter> { * Sets the value for the provided variable and returns the builder (fluently). * * @param variableFactory the variable - * @param value the value - * @param type of value + * @param value the value + * @param type of value * @return current writer instance * @see io.holunda.camunda.bpm.data.adapter.WriteAdapter#set(Object) */ - @NotNull - S set(VariableFactory variableFactory, T value); + @NotNull S set(VariableFactory variableFactory, T value); /** * Sets the (transient) value for the provided variable and returns the builder (fluently). * * @param variableFactory the variable - * @param value the value - * @param isTransient if true, the variable is transient, default false. - * @param type of value + * @param value the value + * @param isTransient if true, the variable is transient, default false. + * @param type of value * @return current writer instance * @see io.holunda.camunda.bpm.data.adapter.WriteAdapter#set(Object, boolean) */ - @NotNull - S set(VariableFactory variableFactory, T value, boolean isTransient); + @NotNull S set(VariableFactory variableFactory, T value, boolean isTransient); /** * Removes the value for the provided variable and returns the builder (fluently). * * @param variableFactory the variable - * @param type of value + * @param type of value * @return current writer instance * @see WriteAdapter#remove() */ - @NotNull - S remove(VariableFactory variableFactory); + @NotNull S remove(VariableFactory variableFactory); /** * Returns the resulting variables. diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/LocalVariableWriter.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/LocalVariableWriter.java index 45b231e4..d5699943 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/LocalVariableWriter.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/LocalVariableWriter.java @@ -16,37 +16,34 @@ public interface LocalVariableWriter> { * Sets the local value for the provided variable and returns the builder (fluently). * * @param variableFactory the variable - * @param value the value - * @param type of value + * @param value the value + * @param type of value * @return current writer instance * @see WriteAdapter#setLocal(Object) */ - @NotNull - S setLocal(VariableFactory variableFactory, T value); + @NotNull S setLocal(VariableFactory variableFactory, T value); /** * Sets the local (transient) value for the provided variable and returns the builder (fluently). * * @param variableFactory the variable - * @param value the value - * @param isTransient if true, the variable is transient - * @param type of value + * @param value the value + * @param isTransient if true, the variable is transient + * @param type of value * @return current writer instance * @see WriteAdapter#setLocal(Object, boolean) */ - @NotNull - S setLocal(VariableFactory variableFactory, T value, boolean isTransient); + @NotNull S setLocal(VariableFactory variableFactory, T value, boolean isTransient); /** * Removes the local value for the provided variable and returns the builder (fluently). * * @param variableFactory the variable - * @param type of value + * @param type of value * @return current writer instance * @see WriteAdapter#removeLocal() */ - @NotNull - S removeLocal(VariableFactory variableFactory); + @NotNull S removeLocal(VariableFactory variableFactory); /** * Returns the resulting local variables. diff --git a/extension/core/src/main/kotlin/CamundaBpmDataKotlin.kt b/extension/core/src/main/kotlin/CamundaBpmDataKotlin.kt index 07542cbb..bd9f63be 100644 --- a/extension/core/src/main/kotlin/CamundaBpmDataKotlin.kt +++ b/extension/core/src/main/kotlin/CamundaBpmDataKotlin.kt @@ -8,101 +8,101 @@ import java.util.* */ object CamundaBpmDataKotlin { - /** - * Creates a string variable factory. - * - * @param variableName name of the variable. - * - * @return variable factory for string. - */ - fun stringVariable(variableName: String): VariableFactory = BasicVariableFactory(variableName, String::class.java) + /** + * Creates a string variable factory. + * + * @param variableName name of the variable. + * + * @return variable factory for string. + */ + fun stringVariable(variableName: String): VariableFactory = BasicVariableFactory(variableName, String::class.java) - /** - * Creates a date variable factory. - * - * @param variableName name of the variable. - * - * @return variable factory for date. - */ - fun dateVariable(variableName: String): VariableFactory = BasicVariableFactory(variableName, Date::class.java) + /** + * Creates a date variable factory. + * + * @param variableName name of the variable. + * + * @return variable factory for date. + */ + fun dateVariable(variableName: String): VariableFactory = BasicVariableFactory(variableName, Date::class.java) - /** - * Creates an integer variable factory. - * - * @param variableName name of the variable. - * - * @return variable factory for integer. - */ - fun intVariable(variableName: String): VariableFactory = BasicVariableFactory(variableName, Int::class.java) + /** + * Creates an integer variable factory. + * + * @param variableName name of the variable. + * + * @return variable factory for integer. + */ + fun intVariable(variableName: String): VariableFactory = BasicVariableFactory(variableName, Int::class.java) - /** - * Creates a long variable factory. - * - * @param variableName name of the variable. - * - * @return variable factory for long. - */ - fun longVariable(variableName: String): VariableFactory = BasicVariableFactory(variableName, Long::class.java) + /** + * Creates a long variable factory. + * + * @param variableName name of the variable. + * + * @return variable factory for long. + */ + fun longVariable(variableName: String): VariableFactory = BasicVariableFactory(variableName, Long::class.java) - /** - * Creates a short variable factory. - * - * @param variableName name of the variable. - * - * @return variable factory for short. - */ - fun shortVariable(variableName: String): VariableFactory = BasicVariableFactory(variableName, Short::class.java) + /** + * Creates a short variable factory. + * + * @param variableName name of the variable. + * + * @return variable factory for short. + */ + fun shortVariable(variableName: String): VariableFactory = BasicVariableFactory(variableName, Short::class.java) - /** - * Creates a double variable factory. - * - * @param variableName name of the variable. - * - * @return variable factory for double. - */ - fun doubleVariable(variableName: String): VariableFactory = BasicVariableFactory(variableName, Double::class.java) + /** + * Creates a double variable factory. + * + * @param variableName name of the variable. + * + * @return variable factory for double. + */ + fun doubleVariable(variableName: String): VariableFactory = BasicVariableFactory(variableName, Double::class.java) - /** - * Creates a boolean variable factory. - * - * @param variableName name of the variable. - * - * @return variable factory for boolean. - */ - fun booleanVariable(variableName: String): VariableFactory = BasicVariableFactory(variableName, Boolean::class.java) + /** + * Creates a boolean variable factory. + * + * @param variableName name of the variable. + * + * @return variable factory for boolean. + */ + fun booleanVariable(variableName: String): VariableFactory = BasicVariableFactory(variableName, Boolean::class.java) - /** - * Reified version of the basic variable factory. - * @param name The name of the variable. - * @param T The type of the variable. - * @return instance of [VariableFactory] - */ - inline fun customVariable(name: String): VariableFactory = BasicVariableFactory(name, T::class.java) + /** + * Reified version of the basic variable factory. + * @param name The name of the variable. + * @param T The type of the variable. + * @return instance of [VariableFactory] + */ + inline fun customVariable(name: String): VariableFactory = BasicVariableFactory(name, T::class.java) - /** - * Reified version of list variable factory. - * @param name The name of the variable. - * @param T The type of the variable. - * @return instance of [VariableFactory] - */ - inline fun listVariable(name: String): VariableFactory> = ListVariableFactory(name, T::class.java) + /** + * Reified version of list variable factory. + * @param name The name of the variable. + * @param T The type of the variable. + * @return instance of [VariableFactory] + */ + inline fun listVariable(name: String): VariableFactory> = ListVariableFactory(name, T::class.java) - /** - * Reified version of set variable factory. - * @param name The name of the variable. - * @param T The type of the variable. - * @param wrap a boolean flag controlling if the serializer should wrap a list into a wrapper object. Set this flag to true, if you use complex types as T. - * @return instance of [VariableFactory] - */ - inline fun setVariable(name: String): VariableFactory> = SetVariableFactory(name, T::class.java) + /** + * Reified version of set variable factory. + * @param name The name of the variable. + * @param T The type of the variable. + * @param wrap a boolean flag controlling if the serializer should wrap a list into a wrapper object. Set this flag to true, if you use complex types as T. + * @return instance of [VariableFactory] + */ + inline fun setVariable(name: String): VariableFactory> = SetVariableFactory(name, T::class.java) - /** - * Reified version of map variable factory. - * @param name The name of the variable. - * @param K The type of the variable key. - * @param V The type of the variable value. - * @return instance of [VariableFactory] - */ - inline fun mapVariable(name: String): VariableFactory> = MapVariableFactory(name, K::class.java, V::class.java) + /** + * Reified version of map variable factory. + * @param name The name of the variable. + * @param K The type of the variable key. + * @param V The type of the variable value. + * @return instance of [VariableFactory] + */ + inline fun mapVariable(name: String): VariableFactory> = MapVariableFactory(name, K::class.java, V::class.java) } diff --git a/extension/core/src/main/kotlin/VariableFactoryFluentApi.kt b/extension/core/src/main/kotlin/VariableFactoryFluentApi.kt index ab087492..7b220e6a 100644 --- a/extension/core/src/main/kotlin/VariableFactoryFluentApi.kt +++ b/extension/core/src/main/kotlin/VariableFactoryFluentApi.kt @@ -17,7 +17,7 @@ import org.camunda.bpm.engine.variable.VariableMap * @param isTransient flag for transient access, false by default. */ fun VariableMap.set(factory: VariableFactory, value: T, isTransient: Boolean = false) = this.apply { - factory.on(this).set(value, isTransient) + factory.on(this).set(value, isTransient) } /** @@ -25,7 +25,7 @@ fun VariableMap.set(factory: VariableFactory, value: T, isTransient: Bool * @param factory factory defining the variable. */ fun VariableMap.remove(factory: VariableFactory) = this.apply { - factory.on(this).remove() + factory.on(this).remove() } /** @@ -35,7 +35,7 @@ fun VariableMap.remove(factory: VariableFactory) = this.apply { * @param isTransient flag for transient access, false by default. */ fun VariableMap.update(factory: VariableFactory, valueProcessor: (T) -> T, isTransient: Boolean = false) = this.apply { - factory.on(this).update(valueProcessor, isTransient) + factory.on(this).update(valueProcessor, isTransient) } @@ -46,7 +46,7 @@ fun VariableMap.update(factory: VariableFactory, valueProcessor: (T) -> T * @param isTransient flag for transient access, false by default. */ fun VariableScope.set(factory: VariableFactory, value: T, isTransient: Boolean = false) = this.apply { - factory.on(this).set(value, isTransient) + factory.on(this).set(value, isTransient) } /** @@ -54,7 +54,7 @@ fun VariableScope.set(factory: VariableFactory, value: T, isTransient: Bo * @param factory factory defining the variable. */ fun VariableScope.remove(factory: VariableFactory) = this.apply { - factory.on(this).remove() + factory.on(this).remove() } /** @@ -64,7 +64,7 @@ fun VariableScope.remove(factory: VariableFactory) = this.apply { * @param isTransient flag for transient access, false by default. */ fun VariableScope.update(factory: VariableFactory, valueProcessor: (T) -> T, isTransient: Boolean = false) = this.apply { - factory.on(this).update(valueProcessor, isTransient) + factory.on(this).update(valueProcessor, isTransient) } /** @@ -74,7 +74,7 @@ fun VariableScope.update(factory: VariableFactory, valueProcessor: (T) -> * @param isTransient flag for transient access, false by default. */ fun VariableScope.setLocal(factory: VariableFactory, value: T, isTransient: Boolean = false) = this.apply { - factory.on(this).setLocal(value, isTransient) + factory.on(this).setLocal(value, isTransient) } /** @@ -82,7 +82,7 @@ fun VariableScope.setLocal(factory: VariableFactory, value: T, isTransien * @param factory factory defining the variable. */ fun VariableScope.removeLocal(factory: VariableFactory) = this.apply { - factory.on(this).removeLocal() + factory.on(this).removeLocal() } /** @@ -92,7 +92,7 @@ fun VariableScope.removeLocal(factory: VariableFactory) = this.apply { * @param isTransient flag for transient access, false by default. */ fun VariableScope.updateLocal(factory: VariableFactory, valueProcessor: (T) -> T, isTransient: Boolean = false) = this.apply { - factory.on(this).updateLocal(valueProcessor, isTransient) + factory.on(this).updateLocal(valueProcessor, isTransient) } /** diff --git a/extension/core/src/main/kotlin/acl/AntiCorruptionLayer.kt b/extension/core/src/main/kotlin/acl/AntiCorruptionLayer.kt index d1df0f70..3621df7a 100644 --- a/extension/core/src/main/kotlin/acl/AntiCorruptionLayer.kt +++ b/extension/core/src/main/kotlin/acl/AntiCorruptionLayer.kt @@ -24,76 +24,76 @@ import org.camunda.bpm.engine.variable.Variables * @property valueApplicationStrategy Strategy to apply values from transformer to given variable scope. */ class AntiCorruptionLayer( - val precondition: VariablesGuard, - val variableMapTransformer: VariableMapTransformer, - internal val factory: VariableFactory, - internal val valueApplicationStrategy: ValueApplicationStrategy + val precondition: VariablesGuard, + val variableMapTransformer: VariableMapTransformer, + internal val factory: VariableFactory, + internal val valueApplicationStrategy: ValueApplicationStrategy ) { - companion object { - const val DEFAULT = "_transient" - - /** - * Helper to create a Map containing transient variables hidden in the given map under the given key. - * - * @param variableName the variable name to use for the additional variables - * @param variables the variables to store - * - * @return a newly created map containing the given variables as transient objectTypedValue. - */ - fun wrapAsTypedTransientVariable(variableName: String, variables: VariableMap): VariableMap { - return Variables.createVariables() - .putValueTyped(variableName, Variables - .objectValue(variables, true) - .serializationDataFormat(Variables.SerializationDataFormats.JAVA) - .create() - ) - } - } + companion object { + const val DEFAULT = "_transient" /** - * Retrieves the ACL in form of an execution listener. - * @return Camunda Execution Listener responsible for variable extraction, guard check and modification. + * Helper to create a Map containing transient variables hidden in the given map under the given key. + * + * @param variableName the variable name to use for the additional variables + * @param variables the variables to store + * + * @return a newly created map containing the given variables as transient objectTypedValue. */ - fun getExecutionListener() = ExecutionListener { execution -> - val variablesExternal = factory.from(execution).get() - if (precondition.evaluate(variablesExternal).isEmpty()) { - val variableInternal = variableMapTransformer.transform(variablesExternal) - valueApplicationStrategy.apply(variableInternal, execution) - } + fun wrapAsTypedTransientVariable(variableName: String, variables: VariableMap): VariableMap { + return Variables.createVariables() + .putValueTyped(variableName, Variables + .objectValue(variables, true) + .serializationDataFormat(Variables.SerializationDataFormats.JAVA) + .create() + ) } + } - /** - * Retrieves the ACL in form of a task listener. - * @return Camunda Task Listener responsible for variable extraction, guard check and modification. - */ - fun getTaskListener() = TaskListener { task -> - val variablesExternal = factory.from(task).get() - if (precondition.evaluate(variablesExternal).isEmpty()) { - val variableInternal = variableMapTransformer.transform(variablesExternal) - valueApplicationStrategy.apply(variableInternal, task) - } + /** + * Retrieves the ACL in form of an execution listener. + * @return Camunda Execution Listener responsible for variable extraction, guard check and modification. + */ + fun getExecutionListener() = ExecutionListener { execution -> + val variablesExternal = factory.from(execution).get() + if (precondition.evaluate(variablesExternal).isEmpty()) { + val variableInternal = variableMapTransformer.transform(variablesExternal) + valueApplicationStrategy.apply(variableInternal, execution) } + } - /** - * Checks if the preconditions are satisfied and constructs a variable map wrapping the variables. - * @param variableMap variable map containing the variables. - * @return new variable map - */ - fun checkAndWrap(variableMap: VariableMap): VariableMap { - val violations = precondition.evaluate(variableMap) - if (violations.isNotEmpty()) { - throw GuardViolationException(violations = violations, reason = "ACL Guard Error:") - } - return wrap(variableMap) + /** + * Retrieves the ACL in form of a task listener. + * @return Camunda Task Listener responsible for variable extraction, guard check and modification. + */ + fun getTaskListener() = TaskListener { task -> + val variablesExternal = factory.from(task).get() + if (precondition.evaluate(variablesExternal).isEmpty()) { + val variableInternal = variableMapTransformer.transform(variablesExternal) + valueApplicationStrategy.apply(variableInternal, task) } + } - /** - * Constructs a variable map wrapping the variables. - * @param variableMap variable map containing the variables. - * @return new variable map - */ - fun wrap(variableMap: VariableMap): VariableMap { - return wrapAsTypedTransientVariable(variableName = factory.name, variables = variableMap) + /** + * Checks if the preconditions are satisfied and constructs a variable map wrapping the variables. + * @param variableMap variable map containing the variables. + * @return new variable map + */ + fun checkAndWrap(variableMap: VariableMap): VariableMap { + val violations = precondition.evaluate(variableMap) + if (violations.isNotEmpty()) { + throw GuardViolationException(violations = violations, reason = "ACL Guard Error:") } + return wrap(variableMap) + } + + /** + * Constructs a variable map wrapping the variables. + * @param variableMap variable map containing the variables. + * @return new variable map + */ + fun wrap(variableMap: VariableMap): VariableMap { + return wrapAsTypedTransientVariable(variableName = factory.name, variables = variableMap) + } } diff --git a/extension/core/src/main/kotlin/acl/CamundaBpmDataACL.kt b/extension/core/src/main/kotlin/acl/CamundaBpmDataACL.kt index 979046aa..5e5ec720 100644 --- a/extension/core/src/main/kotlin/acl/CamundaBpmDataACL.kt +++ b/extension/core/src/main/kotlin/acl/CamundaBpmDataACL.kt @@ -12,46 +12,46 @@ import org.camunda.bpm.engine.variable.VariableMap */ object CamundaBpmDataACL { - /** - * Constructs an ACL with a guard, maps variables using transformer and replaces them in a local scope. - * @param variableName name of the transient variable to use. - * @param variableMapTransformer transformer to map from external to internal representation. - * @param variablesGuard preconditions protecting the ACL. - */ - @JvmStatic - fun guardTransformingLocalReplace(variableName: String, variablesGuard: VariablesGuard, variableMapTransformer: VariableMapTransformer) = AntiCorruptionLayer( - precondition = variablesGuard, - variableMapTransformer = variableMapTransformer, - factory = CamundaBpmData.customVariable(variableName, VariableMap::class.java), - valueApplicationStrategy = LocalScopeReplaceStrategy - ) + /** + * Constructs an ACL with a guard, maps variables using transformer and replaces them in a local scope. + * @param variableName name of the transient variable to use. + * @param variableMapTransformer transformer to map from external to internal representation. + * @param variablesGuard preconditions protecting the ACL. + */ + @JvmStatic + fun guardTransformingLocalReplace(variableName: String, variablesGuard: VariablesGuard, variableMapTransformer: VariableMapTransformer) = AntiCorruptionLayer( + precondition = variablesGuard, + variableMapTransformer = variableMapTransformer, + factory = CamundaBpmData.customVariable(variableName, VariableMap::class.java), + valueApplicationStrategy = LocalScopeReplaceStrategy + ) - /** - * Constructs an ACL with a guard, maps variables using transformer and replaces them in a global scope. - * @param variableName name of the transient variable to use. - * @param variableMapTransformer transformer to map from external to internal representation. - * @param variablesGuard preconditions protecting the ACL. - */ - @JvmStatic - fun guardTransformingGlobalReplace(variableName: String, variablesGuard: VariablesGuard, variableMapTransformer: VariableMapTransformer) = AntiCorruptionLayer( - precondition = variablesGuard, - variableMapTransformer = variableMapTransformer, - factory = CamundaBpmData.customVariable(variableName, VariableMap::class.java), - valueApplicationStrategy = GlobalScopeReplaceStrategy - ) + /** + * Constructs an ACL with a guard, maps variables using transformer and replaces them in a global scope. + * @param variableName name of the transient variable to use. + * @param variableMapTransformer transformer to map from external to internal representation. + * @param variablesGuard preconditions protecting the ACL. + */ + @JvmStatic + fun guardTransformingGlobalReplace(variableName: String, variablesGuard: VariablesGuard, variableMapTransformer: VariableMapTransformer) = AntiCorruptionLayer( + precondition = variablesGuard, + variableMapTransformer = variableMapTransformer, + factory = CamundaBpmData.customVariable(variableName, VariableMap::class.java), + valueApplicationStrategy = GlobalScopeReplaceStrategy + ) - /** - * Constructs an ACL with a guard, maps variables using transformer and replaces them in a scope controlled by the . - * @param variableName name of the transient variable to use. - * @param local flag to control the scope. - * @param variableMapTransformer transformer to map from external to internal representation. - * @param variablesGuard preconditions protecting the ACL. - */ - @JvmStatic - fun guardTransformingReplace(variableName: String, local: Boolean, variablesGuard: VariablesGuard, variableMapTransformer: VariableMapTransformer) = if (local) { - guardTransformingLocalReplace(variableName, variablesGuard, variableMapTransformer) - } else { - guardTransformingGlobalReplace(variableName, variablesGuard, variableMapTransformer) - } + /** + * Constructs an ACL with a guard, maps variables using transformer and replaces them in a scope controlled by the . + * @param variableName name of the transient variable to use. + * @param local flag to control the scope. + * @param variableMapTransformer transformer to map from external to internal representation. + * @param variablesGuard preconditions protecting the ACL. + */ + @JvmStatic + fun guardTransformingReplace(variableName: String, local: Boolean, variablesGuard: VariablesGuard, variableMapTransformer: VariableMapTransformer) = if (local) { + guardTransformingLocalReplace(variableName, variablesGuard, variableMapTransformer) + } else { + guardTransformingGlobalReplace(variableName, variablesGuard, variableMapTransformer) + } -} \ No newline at end of file +} diff --git a/extension/core/src/main/kotlin/acl/CamundaBpmDataMapper.kt b/extension/core/src/main/kotlin/acl/CamundaBpmDataMapper.kt index c1587969..9651cd92 100644 --- a/extension/core/src/main/kotlin/acl/CamundaBpmDataMapper.kt +++ b/extension/core/src/main/kotlin/acl/CamundaBpmDataMapper.kt @@ -12,79 +12,79 @@ import org.camunda.bpm.engine.variable.VariableMap * Helper methods to create unconditional transient variable mappers. */ object CamundaBpmDataMapper { - /** - * Constructs a mapper, maps variables using transformer and replaces them in a local scope. - * @param variableName name of the transient variable to use. - * @param variableMapTransformer transformer to map from external to internal representation. - */ - @JvmStatic - fun transformingLocalReplace(variableName: String, variableMapTransformer: VariableMapTransformer) = AntiCorruptionLayer( - precondition = VariablesGuard.EMPTY, - variableMapTransformer = variableMapTransformer, - factory = CamundaBpmData.customVariable(variableName, VariableMap::class.java), - valueApplicationStrategy = LocalScopeReplaceStrategy - ) + /** + * Constructs a mapper, maps variables using transformer and replaces them in a local scope. + * @param variableName name of the transient variable to use. + * @param variableMapTransformer transformer to map from external to internal representation. + */ + @JvmStatic + fun transformingLocalReplace(variableName: String, variableMapTransformer: VariableMapTransformer) = AntiCorruptionLayer( + precondition = VariablesGuard.EMPTY, + variableMapTransformer = variableMapTransformer, + factory = CamundaBpmData.customVariable(variableName, VariableMap::class.java), + valueApplicationStrategy = LocalScopeReplaceStrategy + ) - /** - * Constructs a mapper, maps variables using transformer and replaces them in a global scope. - * @param variableName name of the transient variable to use. - * @param variableMapTransformer transformer to map from external to internal representation. - */ - @JvmStatic - fun transformingGlobalReplace(variableName: String, variableMapTransformer: VariableMapTransformer) = AntiCorruptionLayer( - precondition = VariablesGuard.EMPTY, - variableMapTransformer = variableMapTransformer, - factory = CamundaBpmData.customVariable(variableName, VariableMap::class.java), - valueApplicationStrategy = GlobalScopeReplaceStrategy - ) + /** + * Constructs a mapper, maps variables using transformer and replaces them in a global scope. + * @param variableName name of the transient variable to use. + * @param variableMapTransformer transformer to map from external to internal representation. + */ + @JvmStatic + fun transformingGlobalReplace(variableName: String, variableMapTransformer: VariableMapTransformer) = AntiCorruptionLayer( + precondition = VariablesGuard.EMPTY, + variableMapTransformer = variableMapTransformer, + factory = CamundaBpmData.customVariable(variableName, VariableMap::class.java), + valueApplicationStrategy = GlobalScopeReplaceStrategy + ) - /** - * Constructs a mapper, maps variables using transformer and replaces them in a scope depending on flag. - * @param variableName name of the transient variable to use. - * @param variableMapTransformer transformer to map from external to internal representation. - * @param local flag to control local or global scope - */ - @JvmStatic - fun transformingReplace(variableName: String, local: Boolean, variableMapTransformer: VariableMapTransformer) = if (local) { - transformingLocalReplace(variableName, variableMapTransformer) - } else { - transformingGlobalReplace(variableName, variableMapTransformer) - } + /** + * Constructs a mapper, maps variables using transformer and replaces them in a scope depending on flag. + * @param variableName name of the transient variable to use. + * @param variableMapTransformer transformer to map from external to internal representation. + * @param local flag to control local or global scope + */ + @JvmStatic + fun transformingReplace(variableName: String, local: Boolean, variableMapTransformer: VariableMapTransformer) = if (local) { + transformingLocalReplace(variableName, variableMapTransformer) + } else { + transformingGlobalReplace(variableName, variableMapTransformer) + } - /** - * Constructs a mapper, maps variables 1:1 and replaces them in a local scope. - * @param variableName name of the transient variable to use. - */ - @JvmStatic - fun identityLocalReplace(variableName: String) = AntiCorruptionLayer( - precondition = VariablesGuard.EMPTY, - variableMapTransformer = IdentityVariableMapTransformer, - factory = CamundaBpmData.customVariable(variableName, VariableMap::class.java), - valueApplicationStrategy = LocalScopeReplaceStrategy - ) + /** + * Constructs a mapper, maps variables 1:1 and replaces them in a local scope. + * @param variableName name of the transient variable to use. + */ + @JvmStatic + fun identityLocalReplace(variableName: String) = AntiCorruptionLayer( + precondition = VariablesGuard.EMPTY, + variableMapTransformer = IdentityVariableMapTransformer, + factory = CamundaBpmData.customVariable(variableName, VariableMap::class.java), + valueApplicationStrategy = LocalScopeReplaceStrategy + ) - /** - * Constructs a mapper, maps variables 1:1 and replaces them in a global scope. - * @param variableName name of the transient variable to use. - */ - @JvmStatic - fun identityGlobalReplace(variableName: String) = AntiCorruptionLayer( - precondition = VariablesGuard.EMPTY, - variableMapTransformer = IdentityVariableMapTransformer, - factory = CamundaBpmData.customVariable(variableName, VariableMap::class.java), - valueApplicationStrategy = GlobalScopeReplaceStrategy - ) + /** + * Constructs a mapper, maps variables 1:1 and replaces them in a global scope. + * @param variableName name of the transient variable to use. + */ + @JvmStatic + fun identityGlobalReplace(variableName: String) = AntiCorruptionLayer( + precondition = VariablesGuard.EMPTY, + variableMapTransformer = IdentityVariableMapTransformer, + factory = CamundaBpmData.customVariable(variableName, VariableMap::class.java), + valueApplicationStrategy = GlobalScopeReplaceStrategy + ) - /** - * Constructs a mapper, maps variables 1:1 and replaces them in scope depending on flag. - * @param variableName name of the transient variable to use. - * @param local flag to control local or global scope - */ - @JvmStatic - fun identityReplace(variableName: String, local: Boolean) = if (local) { - identityLocalReplace(variableName) - } else { - identityGlobalReplace(variableName) - } + /** + * Constructs a mapper, maps variables 1:1 and replaces them in scope depending on flag. + * @param variableName name of the transient variable to use. + * @param local flag to control local or global scope + */ + @JvmStatic + fun identityReplace(variableName: String, local: Boolean) = if (local) { + identityLocalReplace(variableName) + } else { + identityGlobalReplace(variableName) + } -} \ No newline at end of file +} diff --git a/extension/core/src/main/kotlin/acl/apply/GlobalScopeReplaceStrategy.kt b/extension/core/src/main/kotlin/acl/apply/GlobalScopeReplaceStrategy.kt index 84d6f1bc..45f2c478 100644 --- a/extension/core/src/main/kotlin/acl/apply/GlobalScopeReplaceStrategy.kt +++ b/extension/core/src/main/kotlin/acl/apply/GlobalScopeReplaceStrategy.kt @@ -9,12 +9,12 @@ import org.camunda.bpm.engine.variable.VariableMap */ object GlobalScopeReplaceStrategy : ValueApplicationStrategy { - override fun apply(variableMap: VariableMap, variableScope: VariableScope): VariableScope = - variableScope.apply { - this.variables = variableMap - } - - override fun toString(): String { - return javaClass.canonicalName + override fun apply(variableMap: VariableMap, variableScope: VariableScope): VariableScope = + variableScope.apply { + this.variables = variableMap } -} \ No newline at end of file + + override fun toString(): String { + return javaClass.canonicalName + } +} diff --git a/extension/core/src/main/kotlin/acl/apply/LocalScopeReplaceStrategy.kt b/extension/core/src/main/kotlin/acl/apply/LocalScopeReplaceStrategy.kt index 78ea0862..1d182965 100644 --- a/extension/core/src/main/kotlin/acl/apply/LocalScopeReplaceStrategy.kt +++ b/extension/core/src/main/kotlin/acl/apply/LocalScopeReplaceStrategy.kt @@ -9,12 +9,12 @@ import org.camunda.bpm.engine.variable.VariableMap */ object LocalScopeReplaceStrategy : ValueApplicationStrategy { - override fun apply(variableMap: VariableMap, variableScope: VariableScope): VariableScope = - variableScope.apply { - this.variablesLocal = variableMap - } - - override fun toString(): String { - return javaClass.canonicalName + override fun apply(variableMap: VariableMap, variableScope: VariableScope): VariableScope = + variableScope.apply { + this.variablesLocal = variableMap } -} \ No newline at end of file + + override fun toString(): String { + return javaClass.canonicalName + } +} diff --git a/extension/core/src/main/kotlin/acl/apply/ValueApplicationStrategy.kt b/extension/core/src/main/kotlin/acl/apply/ValueApplicationStrategy.kt index f58692f7..63272e98 100644 --- a/extension/core/src/main/kotlin/acl/apply/ValueApplicationStrategy.kt +++ b/extension/core/src/main/kotlin/acl/apply/ValueApplicationStrategy.kt @@ -9,8 +9,8 @@ import org.camunda.bpm.engine.variable.VariableMap */ @FunctionalInterface interface ValueApplicationStrategy { - /** - * Strategy to assign variables stored in a map to the given variable scope. - */ - fun apply(variableMap: VariableMap, variableScope: VariableScope): VariableScope -} \ No newline at end of file + /** + * Strategy to assign variables stored in a map to the given variable scope. + */ + fun apply(variableMap: VariableMap, variableScope: VariableScope): VariableScope +} diff --git a/extension/core/src/main/kotlin/acl/transform/IdentityVariableMapTransformer.kt b/extension/core/src/main/kotlin/acl/transform/IdentityVariableMapTransformer.kt index a97b85c4..b8fe09aa 100644 --- a/extension/core/src/main/kotlin/acl/transform/IdentityVariableMapTransformer.kt +++ b/extension/core/src/main/kotlin/acl/transform/IdentityVariableMapTransformer.kt @@ -6,5 +6,5 @@ import org.camunda.bpm.engine.variable.VariableMap * Performs no transformation (1:1 mapping). */ object IdentityVariableMapTransformer : VariableMapTransformer { - override fun transform(variableMap: VariableMap): VariableMap = variableMap -} \ No newline at end of file + override fun transform(variableMap: VariableMap): VariableMap = variableMap +} diff --git a/extension/core/src/main/kotlin/acl/transform/VariableMapTransformer.kt b/extension/core/src/main/kotlin/acl/transform/VariableMapTransformer.kt index ee3b3106..9c32a501 100644 --- a/extension/core/src/main/kotlin/acl/transform/VariableMapTransformer.kt +++ b/extension/core/src/main/kotlin/acl/transform/VariableMapTransformer.kt @@ -7,10 +7,10 @@ import org.camunda.bpm.engine.variable.VariableMap */ @FunctionalInterface interface VariableMapTransformer { - /** - * Performs transformation on variable map. - * @param variableMap containing the values. - * @return new variable map - */ - fun transform(variableMap: VariableMap): VariableMap -} \ No newline at end of file + /** + * Performs transformation on variable map. + * @param variableMap containing the values. + * @return new variable map + */ + fun transform(variableMap: VariableMap): VariableMap +} diff --git a/extension/core/src/main/kotlin/guard/CamundaBpmDataGuards.kt b/extension/core/src/main/kotlin/guard/CamundaBpmDataGuards.kt index 70491656..4fa60239 100644 --- a/extension/core/src/main/kotlin/guard/CamundaBpmDataGuards.kt +++ b/extension/core/src/main/kotlin/guard/CamundaBpmDataGuards.kt @@ -10,89 +10,87 @@ import java.util.function.Function @Suppress("unused") object CamundaBpmDataGuards { - /** - * Creates exists condition. - * @param variableFactory factory to work on. - * @param local flag indicating scope (global/local). - */ - @JvmStatic - fun exists(variableFactory: VariableFactory, local: Boolean = false) = variableFactory.exists(local) + /** + * Creates exists condition. + * @param variableFactory factory to work on. + * @param local flag indicating scope (global/local). + */ + @JvmStatic + fun exists(variableFactory: VariableFactory, local: Boolean = false) = variableFactory.exists(local) - /** - * Creates exists condition. - * @param variableFactory factory to work on. - */ - @JvmStatic - fun exists(variableFactory: VariableFactory) = variableFactory.exists() + /** + * Creates exists condition. + * @param variableFactory factory to work on. + */ + @JvmStatic + fun exists(variableFactory: VariableFactory) = variableFactory.exists() - /** - * Creates not exists condition. - * @param variableFactory factory to work on. - * @param local flag indicating scope (global/local). - */ - @JvmStatic - fun notExists(variableFactory: VariableFactory, local: Boolean = false) = variableFactory.notExists(local) + /** + * Creates not exists condition. + * @param variableFactory factory to work on. + * @param local flag indicating scope (global/local). + */ + @JvmStatic + fun notExists(variableFactory: VariableFactory, local: Boolean = false) = variableFactory.notExists(local) - /** - * Creates not exists condition. - * @param variableFactory factory to work on. - */ - @JvmStatic - fun notExists(variableFactory: VariableFactory) = variableFactory.notExists() + /** + * Creates not exists condition. + * @param variableFactory factory to work on. + */ + @JvmStatic + fun notExists(variableFactory: VariableFactory) = variableFactory.notExists() - /** - * Creates has value condition. - * @param variableFactory factory to work on. - * @param local flag indicating scope (global/local). - * @param value value that the variable must have. - */ - @JvmStatic - fun hasValue(variableFactory: VariableFactory, value: T, local: Boolean = false) = variableFactory.hasValue(value, local) + /** + * Creates has value condition. + * @param variableFactory factory to work on. + * @param local flag indicating scope (global/local). + * @param value value that the variable must have. + */ + @JvmStatic + fun hasValue(variableFactory: VariableFactory, value: T, local: Boolean = false) = variableFactory.hasValue(value, local) - /** - * Creates has value condition. - * @param variableFactory factory to work on. - * @param value value that the variable must have. - */ - @JvmStatic - fun hasValue(variableFactory: VariableFactory, value: T) = variableFactory.hasValue(value) + /** + * Creates has value condition. + * @param variableFactory factory to work on. + * @param value value that the variable must have. + */ + @JvmStatic + fun hasValue(variableFactory: VariableFactory, value: T) = variableFactory.hasValue(value) - /** - * Creates has value condition. - * @param variableFactory factory to work on. - * @param local flag indicating scope (global/local). - * @param values set of values to compare with the variable value. - */ - @JvmStatic - fun hasOneOfValues(variableFactory: VariableFactory, values: Set, local: Boolean = false) = variableFactory.hasOneOfValues(values, local) + /** + * Creates has value condition. + * @param variableFactory factory to work on. + * @param local flag indicating scope (global/local). + * @param values set of values to compare with the variable value. + */ + @JvmStatic + fun hasOneOfValues(variableFactory: VariableFactory, values: Set, local: Boolean = false) = variableFactory.hasOneOfValues(values, local) - /** - * Creates has value condition. - * @param variableFactory factory to work on. - * @param values set of values to compare with the variable value. - */ - @JvmStatic - fun hasOneOfValues(variableFactory: VariableFactory, values: Set) = variableFactory.hasOneOfValues(values) + /** + * Creates has value condition. + * @param variableFactory factory to work on. + * @param values set of values to compare with the variable value. + */ + @JvmStatic + fun hasOneOfValues(variableFactory: VariableFactory, values: Set) = variableFactory.hasOneOfValues(values) - /** - * Creates matches condition. - * @param variableFactory factory to work on. - * @param local flag indicating scope (global/local). - * @param matcher a matcher function to check the variable value. - */ - @JvmStatic - fun matches(variableFactory: VariableFactory, - matcher: Function, local: Boolean = false) = variableFactory.matches(local) { matcher.apply(it) } + /** + * Creates matches condition. + * @param variableFactory factory to work on. + * @param local flag indicating scope (global/local). + * @param matcher a matcher function to check the variable value. + */ + @JvmStatic + fun matches(variableFactory: VariableFactory, + matcher: Function, local: Boolean = false) = variableFactory.matches(local) { matcher.apply(it) } - /** - * Creates matches condition. - * @param variableFactory factory to work on. - * @param matcher a matcher function to check the variable value. - */ - @JvmStatic - fun matches(variableFactory: VariableFactory, - matcher: Function) = variableFactory.matches { matcher.apply(it) } + /** + * Creates matches condition. + * @param variableFactory factory to work on. + * @param matcher a matcher function to check the variable value. + */ + @JvmStatic + fun matches(variableFactory: VariableFactory, + matcher: Function) = variableFactory.matches { matcher.apply(it) } } - - diff --git a/extension/core/src/main/kotlin/guard/GuardViolation.kt b/extension/core/src/main/kotlin/guard/GuardViolation.kt index 5cbc2e92..817a8fce 100644 --- a/extension/core/src/main/kotlin/guard/GuardViolation.kt +++ b/extension/core/src/main/kotlin/guard/GuardViolation.kt @@ -12,16 +12,16 @@ import java.util.* * @property message violation message */ data class GuardViolation( - /** - * Guard condition. - */ - val condition: VariableGuardCondition, - /** - * Retrieved value. - */ - val option: Optional, - /** - * Message, explaining the violation. - */ - val message: String + /** + * Guard condition. + */ + val condition: VariableGuardCondition, + /** + * Retrieved value. + */ + val option: Optional, + /** + * Message, explaining the violation. + */ + val message: String ) diff --git a/extension/core/src/main/kotlin/guard/condition/VariableExistsGuardCondition.kt b/extension/core/src/main/kotlin/guard/condition/VariableExistsGuardCondition.kt index bc4716ef..1d81c0ca 100644 --- a/extension/core/src/main/kotlin/guard/condition/VariableExistsGuardCondition.kt +++ b/extension/core/src/main/kotlin/guard/condition/VariableExistsGuardCondition.kt @@ -11,24 +11,24 @@ import java.util.* * @param local flag indicating if local or global scope is required. */ class VariableExistsGuardCondition( - variableFactory: VariableFactory, - local: Boolean = false + variableFactory: VariableFactory, + local: Boolean = false ) : VariableGuardCondition(variableFactory, local) { - override fun evaluate(option: Optional) = - if (option.isPresent) { - super.evaluate(option) - } else { - listOf(GuardViolation( - condition = this, - option = option, - message = "Expecting$localLabel variable '${variableFactory.name}' to be set, but it was not found.") - ) - } - - override fun toString(): String { - return "Exists condition for$localLabel variable '${super.variableFactory.name}'" + override fun evaluate(option: Optional) = + if (option.isPresent) { + super.evaluate(option) + } else { + listOf(GuardViolation( + condition = this, + option = option, + message = "Expecting$localLabel variable '${variableFactory.name}' to be set, but it was not found.") + ) } + + override fun toString(): String { + return "Exists condition for$localLabel variable '${super.variableFactory.name}'" + } } /** diff --git a/extension/core/src/main/kotlin/guard/condition/VariableGuardCondition.kt b/extension/core/src/main/kotlin/guard/condition/VariableGuardCondition.kt index 3e78a851..3fa15246 100644 --- a/extension/core/src/main/kotlin/guard/condition/VariableGuardCondition.kt +++ b/extension/core/src/main/kotlin/guard/condition/VariableGuardCondition.kt @@ -20,76 +20,76 @@ import java.util.* * @property local flag indicating the variable scope (global/local). Defaults to global. */ abstract class VariableGuardCondition( - internal val variableFactory: VariableFactory, - internal val local: Boolean = false + internal val variableFactory: VariableFactory, + internal val local: Boolean = false ) { - /** - * Label for messages indicating the variable scope (local or global, which is a default). - */ - val localLabel: String by lazy { if (local) " local" else "" } + /** + * Label for messages indicating the variable scope (local or global, which is a default). + */ + val localLabel: String by lazy { if (local) " local" else "" } - /** - * Evaluate the condition on a value option. - * @param option optional value for the variable, contaning the value or nothing. - * @return list of guard violations. - */ - internal open fun evaluate(option: Optional): List> = emptyList() + /** + * Evaluate the condition on a value option. + * @param option optional value for the variable, contaning the value or nothing. + * @return list of guard violations. + */ + internal open fun evaluate(option: Optional): List> = emptyList() - /** - * Evaluate the condition on a value retrieved from the variable map. - * @param variableMap variables to run the evaluation on. - * @return list of guard violations - */ - fun evaluate(variableMap: VariableMap): List> { - return evaluate(if (local) variableFactory.from(variableMap).localOptional else variableFactory.from(variableMap).optional) - } + /** + * Evaluate the condition on a value retrieved from the variable map. + * @param variableMap variables to run the evaluation on. + * @return list of guard violations + */ + fun evaluate(variableMap: VariableMap): List> { + return evaluate(if (local) variableFactory.from(variableMap).localOptional else variableFactory.from(variableMap).optional) + } - /** - * Evaluate the condition on a value retrieved from the variable map. - * @param variableScope variable scope (e.g. delegate execution or delegate task) to run the evaluation on. - * @return list of guard violations - */ - fun evaluate(variableScope: VariableScope): List> { - return evaluate(if (local) variableFactory.from(variableScope).localOptional else variableFactory.from(variableScope).optional) - } + /** + * Evaluate the condition on a value retrieved from the variable map. + * @param variableScope variable scope (e.g. delegate execution or delegate task) to run the evaluation on. + * @return list of guard violations + */ + fun evaluate(variableScope: VariableScope): List> { + return evaluate(if (local) variableFactory.from(variableScope).localOptional else variableFactory.from(variableScope).optional) + } - /** - * Evaluate the condition on a value retrieved from the task service. - * @param taskService to retrieve the task from. - * @param taskId id of the task to work on. - * @return list of guard violations - */ - fun evaluate(taskService: TaskService, taskId: String): List> { - return evaluate(if (local) variableFactory.from(taskService, taskId).localOptional else variableFactory.from(taskService, taskId).optional) - } + /** + * Evaluate the condition on a value retrieved from the task service. + * @param taskService to retrieve the task from. + * @param taskId id of the task to work on. + * @return list of guard violations + */ + fun evaluate(taskService: TaskService, taskId: String): List> { + return evaluate(if (local) variableFactory.from(taskService, taskId).localOptional else variableFactory.from(taskService, taskId).optional) + } - /** - * Evaluate the condition on a value retrieved from the runtime service. - * @param runtimeService to retrieve the execution from. - * @param executionId id of the execution to work on. - * @return list of guard violations - */ - fun evaluate(runtimeService: RuntimeService, executionId: String): List> { - return evaluate(if (local) variableFactory.from(runtimeService, executionId).localOptional else variableFactory.from(runtimeService, executionId).optional) - } + /** + * Evaluate the condition on a value retrieved from the runtime service. + * @param runtimeService to retrieve the execution from. + * @param executionId id of the execution to work on. + * @return list of guard violations + */ + fun evaluate(runtimeService: RuntimeService, executionId: String): List> { + return evaluate(if (local) variableFactory.from(runtimeService, executionId).localOptional else variableFactory.from(runtimeService, executionId).optional) + } - override fun equals(other: Any?): Boolean { - if (this === other) return true - if (javaClass != other?.javaClass) return false + override fun equals(other: Any?): Boolean { + if (this === other) return true + if (javaClass != other?.javaClass) return false - other as VariableGuardCondition<*> + other as VariableGuardCondition<*> - if (variableFactory != other.variableFactory) return false - if (local != other.local) return false + if (variableFactory != other.variableFactory) return false + if (local != other.local) return false - return true - } + return true + } - override fun hashCode(): Int { - var result = variableFactory.hashCode() - result = 31 * result + local.hashCode() - return result - } + override fun hashCode(): Int { + var result = variableFactory.hashCode() + result = 31 * result + local.hashCode() + return result + } } diff --git a/extension/core/src/main/kotlin/guard/condition/VariableMatchesGuardCondition.kt b/extension/core/src/main/kotlin/guard/condition/VariableMatchesGuardCondition.kt index 22c333fb..40ae72ad 100644 --- a/extension/core/src/main/kotlin/guard/condition/VariableMatchesGuardCondition.kt +++ b/extension/core/src/main/kotlin/guard/condition/VariableMatchesGuardCondition.kt @@ -13,33 +13,33 @@ import java.util.* * @property matcher matcher function, specifying the condition. */ class VariableMatchesGuardCondition( - /** - * Variable factory to work with. - */ - variableFactory: VariableFactory, - local: Boolean = false, - private val matcher: (value: T) -> Boolean + /** + * Variable factory to work with. + */ + variableFactory: VariableFactory, + local: Boolean = false, + private val matcher: (value: T) -> Boolean ) : VariableGuardCondition(variableFactory, local) { - private val existsCondition = VariableExistsGuardCondition(variableFactory, local) + private val existsCondition = VariableExistsGuardCondition(variableFactory, local) - override fun evaluate(option: Optional): List> { - val violations = existsCondition.evaluate(option).toMutableList() - if (option.isPresent && !matcher.invoke(option.get())) { - violations.add( - GuardViolation( - condition = this, - option = option, - message = "Expecting$localLabel variable '${variableFactory.name}' to match the condition, but its value '${option.get()}' has not." - ) - ) - } - return violations + override fun evaluate(option: Optional): List> { + val violations = existsCondition.evaluate(option).toMutableList() + if (option.isPresent && !matcher.invoke(option.get())) { + violations.add( + GuardViolation( + condition = this, + option = option, + message = "Expecting$localLabel variable '${variableFactory.name}' to match the condition, but its value '${option.get()}' has not." + ) + ) } + return violations + } - override fun toString(): String { - return "Matches condition for$localLabel variable '${super.variableFactory.name}'" - } + override fun toString(): String { + return "Matches condition for$localLabel variable '${super.variableFactory.name}'" + } } diff --git a/extension/core/src/main/kotlin/guard/condition/VariableNotExistsGuardCondition.kt b/extension/core/src/main/kotlin/guard/condition/VariableNotExistsGuardCondition.kt index 2858ddfa..1e2d2bda 100644 --- a/extension/core/src/main/kotlin/guard/condition/VariableNotExistsGuardCondition.kt +++ b/extension/core/src/main/kotlin/guard/condition/VariableNotExistsGuardCondition.kt @@ -11,25 +11,25 @@ import java.util.* * @param local flag indicating if local or global scope is required. */ class VariableNotExistsGuardCondition( - variableFactory: VariableFactory, - local: Boolean = false + variableFactory: VariableFactory, + local: Boolean = false ) : VariableGuardCondition(variableFactory, local) { - override fun evaluate(option: Optional) = - if (!option.isPresent) { - super.evaluate(option) - } else { - listOf(GuardViolation( - condition = this, - option = option, - message = "Expecting$localLabel variable '${variableFactory.name}' not to be set, but it had a value of '${option.get()}'.") - ) - } - - override fun toString(): String { - return "NotExists condition for$localLabel variable '${super.variableFactory.name}'" + override fun evaluate(option: Optional) = + if (!option.isPresent) { + super.evaluate(option) + } else { + listOf(GuardViolation( + condition = this, + option = option, + message = "Expecting$localLabel variable '${variableFactory.name}' not to be set, but it had a value of '${option.get()}'.") + ) } + override fun toString(): String { + return "NotExists condition for$localLabel variable '${super.variableFactory.name}'" + } + } /** diff --git a/extension/core/src/main/kotlin/guard/condition/VariableValueGuardCondition.kt b/extension/core/src/main/kotlin/guard/condition/VariableValueGuardCondition.kt index c719167e..25153756 100644 --- a/extension/core/src/main/kotlin/guard/condition/VariableValueGuardCondition.kt +++ b/extension/core/src/main/kotlin/guard/condition/VariableValueGuardCondition.kt @@ -12,32 +12,32 @@ import java.util.* * @param local flag indicating if local or global scope is required. */ class VariableValueGuardCondition( - variableFactory: VariableFactory, - val value: T, - local: Boolean = false + variableFactory: VariableFactory, + val value: T, + local: Boolean = false ) : VariableGuardCondition(variableFactory, local) { - private val existsCondition = VariableExistsGuardCondition(variableFactory, local) - - override fun evaluate(option: Optional): List> { - val violations = existsCondition.evaluate(option).toMutableList() - if (option.isPresent) { - if (option.get() != value) { - violations.add( - GuardViolation( - condition = this, - option = option, - message = "Expecting$localLabel variable '${variableFactory.name}' to have value '$value', but it was '${option.get()}'." - ) - ) - } - } - return violations + private val existsCondition = VariableExistsGuardCondition(variableFactory, local) + + override fun evaluate(option: Optional): List> { + val violations = existsCondition.evaluate(option).toMutableList() + if (option.isPresent) { + if (option.get() != value) { + violations.add( + GuardViolation( + condition = this, + option = option, + message = "Expecting$localLabel variable '${variableFactory.name}' to have value '$value', but it was '${option.get()}'." + ) + ) + } } + return violations + } - override fun toString(): String { - return "Value condition for$localLabel variable '${super.variableFactory.name}', value $value" - } + override fun toString(): String { + return "Value condition for$localLabel variable '${super.variableFactory.name}', value $value" + } } diff --git a/extension/core/src/main/kotlin/guard/condition/VariableValueOneOfGuardCondition.kt b/extension/core/src/main/kotlin/guard/condition/VariableValueOneOfGuardCondition.kt index 979b9cd0..7e3a851c 100644 --- a/extension/core/src/main/kotlin/guard/condition/VariableValueOneOfGuardCondition.kt +++ b/extension/core/src/main/kotlin/guard/condition/VariableValueOneOfGuardCondition.kt @@ -12,33 +12,33 @@ import java.util.* * @param local flag indicating if local or global scope is required. */ class VariableValueOneOfGuardCondition( - variableFactory: VariableFactory, - val values: Set, - local: Boolean = false + variableFactory: VariableFactory, + val values: Set, + local: Boolean = false ) : VariableGuardCondition(variableFactory, local) { - private val existsCondition = VariableExistsGuardCondition(variableFactory, local) - private val valueConditions = values.map { VariableValueGuardCondition(variableFactory, it, local) } + private val existsCondition = VariableExistsGuardCondition(variableFactory, local) + private val valueConditions = values.map { VariableValueGuardCondition(variableFactory, it, local) } - override fun evaluate(option: Optional): List> { - val violations = existsCondition.evaluate(option).toMutableList() - if (option.isPresent) { - if (valueConditions.none { it.evaluate(option).isEmpty() }) { - violations.add( - GuardViolation( - condition = this, - option = option, - message = "Expecting$localLabel variable '${variableFactory.name}' to be one of [${values.joinToString("', '", "'", "'")}], but it was '${option.get()}'." - ) - ) - } - } - return violations + override fun evaluate(option: Optional): List> { + val violations = existsCondition.evaluate(option).toMutableList() + if (option.isPresent) { + if (valueConditions.none { it.evaluate(option).isEmpty() }) { + violations.add( + GuardViolation( + condition = this, + option = option, + message = "Expecting$localLabel variable '${variableFactory.name}' to be one of [${values.joinToString("', '", "'", "'")}], but it was '${option.get()}'." + ) + ) + } } + return violations + } - override fun toString(): String { - return "ValueIn condition for$localLabel variable '${super.variableFactory.name}', values [${values.joinToString("', '", "'", "'")}]" - } + override fun toString(): String { + return "ValueIn condition for$localLabel variable '${super.variableFactory.name}', values [${values.joinToString("', '", "'", "'")}]" + } } diff --git a/extension/core/src/main/kotlin/guard/integration/DefaultGuardExecutionListener.kt b/extension/core/src/main/kotlin/guard/integration/DefaultGuardExecutionListener.kt index 775166dd..139ec87c 100644 --- a/extension/core/src/main/kotlin/guard/integration/DefaultGuardExecutionListener.kt +++ b/extension/core/src/main/kotlin/guard/integration/DefaultGuardExecutionListener.kt @@ -13,31 +13,31 @@ import org.slf4j.LoggerFactory * @property throwViolations flag controlling if the violation should lead to an exception. */ class DefaultGuardExecutionListener( - val guard: VariablesGuard, - val throwViolations: Boolean = true + val guard: VariablesGuard, + val throwViolations: Boolean = true ) : ExecutionListener { - companion object { - private val logger = LoggerFactory.getLogger(DefaultGuardExecutionListener::class.java) - } + companion object { + private val logger = LoggerFactory.getLogger(DefaultGuardExecutionListener::class.java) + } - /** - * Constructs an execution listener using the provided conditions. - * @param variableConditions condition to check by the guard. - * @param throwViolations flag controlling if the violation should lead to an exception. - */ - constructor(variableConditions: List>, throwViolations: Boolean) : this(VariablesGuard(variableConditions), throwViolations) + /** + * Constructs an execution listener using the provided conditions. + * @param variableConditions condition to check by the guard. + * @param throwViolations flag controlling if the violation should lead to an exception. + */ + constructor(variableConditions: List>, throwViolations: Boolean) : this(VariablesGuard(variableConditions), throwViolations) - override fun notify(execution: DelegateExecution) { - val violations = guard.evaluate(execution) - if (violations.isNotEmpty()) { - val message = "Guard violated by execution '${execution.id}' in activity '${execution.currentActivityName}'" - violations.forEach { - logger.error("$message: ${it.message}") - } - if (throwViolations) { - throw GuardViolationException(violations = violations, reason = message) - } - } + override fun notify(execution: DelegateExecution) { + val violations = guard.evaluate(execution) + if (violations.isNotEmpty()) { + val message = "Guard violated by execution '${execution.id}' in activity '${execution.currentActivityName}'" + violations.forEach { + logger.error("$message: ${it.message}") + } + if (throwViolations) { + throw GuardViolationException(violations = violations, reason = message) + } } + } } diff --git a/extension/core/src/main/kotlin/guard/integration/DefaultGuardTaskListener.kt b/extension/core/src/main/kotlin/guard/integration/DefaultGuardTaskListener.kt index 8a2a8862..68c7aafd 100644 --- a/extension/core/src/main/kotlin/guard/integration/DefaultGuardTaskListener.kt +++ b/extension/core/src/main/kotlin/guard/integration/DefaultGuardTaskListener.kt @@ -13,37 +13,37 @@ import org.slf4j.LoggerFactory * @property throwViolations flag controlling if the violation should lead to an exception. */ class DefaultGuardTaskListener( - val guard: VariablesGuard, - val throwViolations: Boolean = true + val guard: VariablesGuard, + val throwViolations: Boolean = true ) : TaskListener { - companion object { - private val logger = LoggerFactory.getLogger(DefaultGuardTaskListener::class.java) - } + companion object { + private val logger = LoggerFactory.getLogger(DefaultGuardTaskListener::class.java) + } - /** - * Constructs an execution listener using the provided conditions. - * @param variableConditions condition to check by the guard. - * @param throwViolations flag controlling if the violation should lead to an exception. - */ - constructor(variableConditions: List>, throwViolations: Boolean) : this(VariablesGuard(variableConditions), throwViolations) + /** + * Constructs an execution listener using the provided conditions. + * @param variableConditions condition to check by the guard. + * @param throwViolations flag controlling if the violation should lead to an exception. + */ + constructor(variableConditions: List>, throwViolations: Boolean) : this(VariablesGuard(variableConditions), throwViolations) - override fun notify(task: DelegateTask) { - val violations = guard.evaluate(task) - if (violations.isNotEmpty()) { - val message = "Guard violated in task '${task.name.removeNewLines()}' (taskId: '${task.id}')" - violations.forEach { - logger.error("$message: ${it.message}") - } - if (throwViolations) { - throw GuardViolationException(violations = violations, reason = message) - } - } + override fun notify(task: DelegateTask) { + val violations = guard.evaluate(task) + if (violations.isNotEmpty()) { + val message = "Guard violated in task '${task.name.removeNewLines()}' (taskId: '${task.id}')" + violations.forEach { + logger.error("$message: ${it.message}") + } + if (throwViolations) { + throw GuardViolationException(violations = violations, reason = message) + } } + } - /** - * Removes new lines from the task name. - */ - private fun String.removeNewLines() = this - .replace("\n", " ") + /** + * Removes new lines from the task name. + */ + private fun String.removeNewLines() = this + .replace("\n", " ") } diff --git a/extension/core/src/main/kotlin/guard/integration/GuardViolationException.kt b/extension/core/src/main/kotlin/guard/integration/GuardViolationException.kt index aad37442..b87fa0a1 100644 --- a/extension/core/src/main/kotlin/guard/integration/GuardViolationException.kt +++ b/extension/core/src/main/kotlin/guard/integration/GuardViolationException.kt @@ -10,19 +10,19 @@ import org.camunda.bpm.engine.ProcessEngineException * @param reason reason of failure. */ class GuardViolationException( - violations: List>, - reason: String + violations: List>, + reason: String ) : ProcessEngineException(createMessage(reason, violations)) { - companion object { - /** - * Create a message from a provided message prefix and a list of violations. - * @param message message prefix. - * @param violations list of violations. - * @return message. - */ - @JvmStatic - fun createMessage(message: String, violations: List>): String { - return "$message\n" + violations.joinToString(separator = ",\n") { "\t${it.message}" } - } + companion object { + /** + * Create a message from a provided message prefix and a list of violations. + * @param message message prefix. + * @param violations list of violations. + * @return message. + */ + @JvmStatic + fun createMessage(message: String, violations: List>): String { + return "$message\n" + violations.joinToString(separator = ",\n") { "\t${it.message}" } } + } } diff --git a/extension/core/src/test/java/io/holunda/camunda/bpm/data/acl/CamundaBpmDataACLFactoryTest.java b/extension/core/src/test/java/io/holunda/camunda/bpm/data/acl/CamundaBpmDataACLFactoryTest.java index 09e5469a..fed2923e 100644 --- a/extension/core/src/test/java/io/holunda/camunda/bpm/data/acl/CamundaBpmDataACLFactoryTest.java +++ b/extension/core/src/test/java/io/holunda/camunda/bpm/data/acl/CamundaBpmDataACLFactoryTest.java @@ -12,15 +12,15 @@ public class CamundaBpmDataACLFactoryTest { - private RuntimeService runtimeService; - private static VariableFactory FOO = stringVariable("foo"); - private static AntiCorruptionLayer MY_ACL = CamundaBpmDataACL.guardTransformingReplace("__transient", true, - new VariablesGuard(exists(FOO)), - IdentityVariableMapTransformer.INSTANCE - ); + private RuntimeService runtimeService; + private static VariableFactory FOO = stringVariable("foo"); + private static AntiCorruptionLayer MY_ACL = CamundaBpmDataACL.guardTransformingReplace("__transient", true, + new VariablesGuard(exists(FOO)), + IdentityVariableMapTransformer.INSTANCE + ); - public void testCallFromJava(String value) { - VariableMap variableMap = MY_ACL.checkAndWrap(CamundaBpmData.builder().set(FOO, value).build()); - runtimeService.correlateMessage("message", variableMap); - } + public void testCallFromJava(String value) { + VariableMap variableMap = MY_ACL.checkAndWrap(CamundaBpmData.builder().set(FOO, value).build()); + runtimeService.correlateMessage("message", variableMap); + } } diff --git a/extension/core/src/test/java/io/holunda/camunda/bpm/data/adapter/ValueWrapperUtilTest.java b/extension/core/src/test/java/io/holunda/camunda/bpm/data/adapter/ValueWrapperUtilTest.java index 0d026d21..9e4892eb 100644 --- a/extension/core/src/test/java/io/holunda/camunda/bpm/data/adapter/ValueWrapperUtilTest.java +++ b/extension/core/src/test/java/io/holunda/camunda/bpm/data/adapter/ValueWrapperUtilTest.java @@ -5,6 +5,7 @@ import java.time.Instant; import java.util.Date; + import org.camunda.bpm.engine.variable.type.PrimitiveValueType; import org.camunda.bpm.engine.variable.value.BooleanValue; import org.camunda.bpm.engine.variable.value.DateValue; diff --git a/extension/core/src/test/java/io/holunda/camunda/bpm/data/reader/ProcessExecutionVariableReaderTest.java b/extension/core/src/test/java/io/holunda/camunda/bpm/data/reader/ProcessExecutionVariableReaderTest.java index 994f280a..7beb478f 100644 --- a/extension/core/src/test/java/io/holunda/camunda/bpm/data/reader/ProcessExecutionVariableReaderTest.java +++ b/extension/core/src/test/java/io/holunda/camunda/bpm/data/reader/ProcessExecutionVariableReaderTest.java @@ -6,7 +6,9 @@ import io.holunda.camunda.bpm.data.CamundaBpmData; import io.holunda.camunda.bpm.data.factory.VariableFactory; + import java.util.UUID; + import org.camunda.bpm.engine.RuntimeService; import org.junit.After; import org.junit.Before; diff --git a/extension/core/src/test/kotlin/VariablesGuardTest.kt b/extension/core/src/test/kotlin/VariablesGuardTest.kt index 3d854985..5df41a68 100644 --- a/extension/core/src/test/kotlin/VariablesGuardTest.kt +++ b/extension/core/src/test/kotlin/VariablesGuardTest.kt @@ -10,28 +10,28 @@ import org.junit.Test class VariablesGuardTest { - val FOO = stringVariable("foo") - val c1 = exists(FOO) - val c2 = hasValue(FOO, "bar") - val c3 = hasOneOfValues(FOO, setOf("bar", "baz")) - - @Test - fun equals() { - val g1 = VariablesGuard(c1) - val g2 = VariablesGuard(listOf(c2, c3)) - val g3 = VariablesGuard(listOf(c2, c3)) - - assertThat(g1).isNotEqualTo(g2) - - assertThat(g2).isNotSameAs(g3) - assertThat(g2).isEqualTo(g3) - } - - @Test - fun fromExisting() { - val g1 = VariablesGuard.EMPTY - val g2 = g1.fromExisting(c1).fromExisting(c2).fromExisting(c3) - assertThat(g2).isEqualTo(VariablesGuard(listOf(c1, c2, c3))) - - } -} \ No newline at end of file + val FOO = stringVariable("foo") + val c1 = exists(FOO) + val c2 = hasValue(FOO, "bar") + val c3 = hasOneOfValues(FOO, setOf("bar", "baz")) + + @Test + fun equals() { + val g1 = VariablesGuard(c1) + val g2 = VariablesGuard(listOf(c2, c3)) + val g3 = VariablesGuard(listOf(c2, c3)) + + assertThat(g1).isNotEqualTo(g2) + + assertThat(g2).isNotSameAs(g3) + assertThat(g2).isEqualTo(g3) + } + + @Test + fun fromExisting() { + val g1 = VariablesGuard.EMPTY + val g2 = g1.fromExisting(c1).fromExisting(c2).fromExisting(c3) + assertThat(g2).isEqualTo(VariablesGuard(listOf(c1, c2, c3))) + + } +} diff --git a/extension/core/src/test/kotlin/acl/ACLTest.kt b/extension/core/src/test/kotlin/acl/ACLTest.kt index 163fdab1..f1623190 100644 --- a/extension/core/src/test/kotlin/acl/ACLTest.kt +++ b/extension/core/src/test/kotlin/acl/ACLTest.kt @@ -22,145 +22,145 @@ import org.junit.Test @Deployment(resources = ["eventBasedSubprocess_no_transientMapping.bpmn", "eventBasedSubprocess_with_transientMapping.bpmn"]) class TransientVariableMappingListenerTest { - @Suppress("RedundantVisibilityModifier") - @get: Rule - public val camunda = camunda() - - @Test - fun `NO ACL signal sub-process with variables sets variables on processInstance`() { - - // given - val processInstance = camunda.runtimeService.startProcessInstanceByKey("eventBasedSubprocess_no_transientMapping") - BpmnAwareTests.assertThat(processInstance).isWaitingAt("event_wait_forever") - - // when - val variables = CamundaBpmData.builder().set(FOO, "bar").build() - camunda.runtimeService - .createSignalEvent("startSubProcess_" + processInstance.id) - .setVariables(variables) - .send() - - // then - FOO.hasValue("bar").assertFor(camunda.taskService, task().id) - FOO.hasValue("bar").assertFor(camunda.runtimeService, processInstance.id) - } - - @Test - fun `ACL signal sub-process with variables does not set variables on processInstance`() { - - // given - CamundaMockito.registerInstance("mapper", ACL_LR.getExecutionListener()) - - val processInstance = camunda.runtimeService.startProcessInstanceByKey( - "eventBasedSubprocess_with_transientMapping" - ) - BpmnAwareTests.assertThat(processInstance).isWaitingAt("event_wait_forever") - // when - // Here the magic happens: all variables are wrapped in one transient variable - val variables = ACL_LR.wrap(CamundaBpmData.builder().set(FOO, "bar").build()) - camunda.runtimeService - .createSignalEvent("startSubProcess_" + processInstance.id) - .setVariables(variables) - .send() - - // then - // global scope - FOO.notExists().assertFor(camunda.runtimeService, processInstance.id) - // local scope - FOO.hasValue("bar").assertFor(camunda.taskService, task().id) - } - - @Test - fun `ACL signal sub-process with variables passes guard sets does not set variables on process instance`() { - - // given - CamundaMockito.registerInstance("mapper", ACL_GTLR.getExecutionListener()) - - val processInstance = camunda.runtimeService.startProcessInstanceByKey( - "eventBasedSubprocess_with_transientMapping" - ) - BpmnAwareTests.assertThat(processInstance).isWaitingAt("event_wait_forever") - // when - // Here the magic happens: all variables are wrapped in one transient variable - val variables = ACL_GTLR.checkAndWrap( - CamundaBpmData.builder() - .set(FOO, "bar") - .set(BAZ, 42L) - .build() - ) - // only one transient variable inside. - assertThat(variables).containsOnlyKeys("transient_acl") - - camunda.runtimeService - .createSignalEvent("startSubProcess_" + processInstance.id) - .setVariables(variables) - .send() - - // then - // global scope - FOO.notExists().assertFor(camunda.runtimeService, processInstance.id) - // local scope - FOO.hasValue("bar").assertFor(camunda.taskService, task().id) - } - - companion object { - - private val FOO = CamundaBpmData.stringVariable("foo") - private val BAZ = CamundaBpmData.longVariable("baz") - private val BAZ_INTERNAL = CamundaBpmData.longVariable("baz__int") - - private val ACL_LR = CamundaBpmDataMapper.identityReplace("transient", true) - - /** - * This demonstrates the power of the Anti-Corruption-Layer. - * - * The warp method will check the pre-conditions and create the transient representation. - * The ACL is attached as an execution listener to the signal and verifies the pre-condition, - * and then performs a transformation of variables. - * - * The conditions are: - * - variable foo eís set - * - variable baz is set and its value is greater than 40L - * - * The transformations are: - * - foo -> foo - * - baz / 2 -> baz_internal - */ - private val ACL_GTLR = CamundaBpmDataACL.guardTransformingLocalReplace( - variableName = "transient_acl", - variablesGuard = VariablesGuard( - listOf( - BAZ.matches { it > 40L }, - FOO.exists()) - ), - variableMapTransformer = object : VariableMapTransformer { - override fun transform(variableMap: VariableMap): VariableMap { - return CamundaBpmData - .builder() - .set(BAZ_INTERNAL, BAZ.from(variableMap).get() / 2L) - .set(FOO, FOO.from(variableMap).get()) - .build() - } - } - ) - - private fun camunda(): ProcessEngineRule { - return ProcessEngineRule( - object : StandaloneInMemProcessEngineConfiguration() { - init { - history = ProcessEngineConfiguration.HISTORY_FULL - databaseSchemaUpdate = ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE - jobExecutorActivate = false - expressionManager = MockExpressionManager() - } - }.buildProcessEngine()) + @Suppress("RedundantVisibilityModifier") + @get: Rule + public val camunda = camunda() + + @Test + fun `NO ACL signal sub-process with variables sets variables on processInstance`() { + + // given + val processInstance = camunda.runtimeService.startProcessInstanceByKey("eventBasedSubprocess_no_transientMapping") + BpmnAwareTests.assertThat(processInstance).isWaitingAt("event_wait_forever") + + // when + val variables = CamundaBpmData.builder().set(FOO, "bar").build() + camunda.runtimeService + .createSignalEvent("startSubProcess_" + processInstance.id) + .setVariables(variables) + .send() + + // then + FOO.hasValue("bar").assertFor(camunda.taskService, task().id) + FOO.hasValue("bar").assertFor(camunda.runtimeService, processInstance.id) + } + + @Test + fun `ACL signal sub-process with variables does not set variables on processInstance`() { + + // given + CamundaMockito.registerInstance("mapper", ACL_LR.getExecutionListener()) + + val processInstance = camunda.runtimeService.startProcessInstanceByKey( + "eventBasedSubprocess_with_transientMapping" + ) + BpmnAwareTests.assertThat(processInstance).isWaitingAt("event_wait_forever") + // when + // Here the magic happens: all variables are wrapped in one transient variable + val variables = ACL_LR.wrap(CamundaBpmData.builder().set(FOO, "bar").build()) + camunda.runtimeService + .createSignalEvent("startSubProcess_" + processInstance.id) + .setVariables(variables) + .send() + + // then + // global scope + FOO.notExists().assertFor(camunda.runtimeService, processInstance.id) + // local scope + FOO.hasValue("bar").assertFor(camunda.taskService, task().id) + } + + @Test + fun `ACL signal sub-process with variables passes guard sets does not set variables on process instance`() { + + // given + CamundaMockito.registerInstance("mapper", ACL_GTLR.getExecutionListener()) + + val processInstance = camunda.runtimeService.startProcessInstanceByKey( + "eventBasedSubprocess_with_transientMapping" + ) + BpmnAwareTests.assertThat(processInstance).isWaitingAt("event_wait_forever") + // when + // Here the magic happens: all variables are wrapped in one transient variable + val variables = ACL_GTLR.checkAndWrap( + CamundaBpmData.builder() + .set(FOO, "bar") + .set(BAZ, 42L) + .build() + ) + // only one transient variable inside. + assertThat(variables).containsOnlyKeys("transient_acl") + + camunda.runtimeService + .createSignalEvent("startSubProcess_" + processInstance.id) + .setVariables(variables) + .send() + + // then + // global scope + FOO.notExists().assertFor(camunda.runtimeService, processInstance.id) + // local scope + FOO.hasValue("bar").assertFor(camunda.taskService, task().id) + } + + companion object { + + private val FOO = CamundaBpmData.stringVariable("foo") + private val BAZ = CamundaBpmData.longVariable("baz") + private val BAZ_INTERNAL = CamundaBpmData.longVariable("baz__int") + + private val ACL_LR = CamundaBpmDataMapper.identityReplace("transient", true) + + /** + * This demonstrates the power of the Anti-Corruption-Layer. + * + * The warp method will check the pre-conditions and create the transient representation. + * The ACL is attached as an execution listener to the signal and verifies the pre-condition, + * and then performs a transformation of variables. + * + * The conditions are: + * - variable foo eís set + * - variable baz is set and its value is greater than 40L + * + * The transformations are: + * - foo -> foo + * - baz / 2 -> baz_internal + */ + private val ACL_GTLR = CamundaBpmDataACL.guardTransformingLocalReplace( + variableName = "transient_acl", + variablesGuard = VariablesGuard( + listOf( + BAZ.matches { it > 40L }, + FOO.exists()) + ), + variableMapTransformer = object : VariableMapTransformer { + override fun transform(variableMap: VariableMap): VariableMap { + return CamundaBpmData + .builder() + .set(BAZ_INTERNAL, BAZ.from(variableMap).get() / 2L) + .set(FOO, FOO.from(variableMap).get()) + .build() } + } + ) + + private fun camunda(): ProcessEngineRule { + return ProcessEngineRule( + object : StandaloneInMemProcessEngineConfiguration() { + init { + history = ProcessEngineConfiguration.HISTORY_FULL + databaseSchemaUpdate = ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE + jobExecutorActivate = false + expressionManager = MockExpressionManager() + } + }.buildProcessEngine()) } + } } fun VariableGuardCondition.assertFor(taskService: TaskService, taskId: String) = - assertThat(this.evaluate(taskService, taskId)).isEmpty() + assertThat(this.evaluate(taskService, taskId)).isEmpty() fun VariableGuardCondition.assertFor(runtimeService: RuntimeService, processInstanceId: String) = - assertThat(this.evaluate(runtimeService, processInstanceId)).isEmpty() + assertThat(this.evaluate(runtimeService, processInstanceId)).isEmpty() diff --git a/extension/core/src/test/kotlin/acl/AntiCorruptionLayerTest.kt b/extension/core/src/test/kotlin/acl/AntiCorruptionLayerTest.kt index f246a5cc..d4027002 100644 --- a/extension/core/src/test/kotlin/acl/AntiCorruptionLayerTest.kt +++ b/extension/core/src/test/kotlin/acl/AntiCorruptionLayerTest.kt @@ -22,119 +22,118 @@ import org.junit.rules.ExpectedException class AntiCorruptionLayerTest { - val FOO = stringVariable("foo") - val BAZ = stringVariable("baz") + val FOO = stringVariable("foo") + val BAZ = stringVariable("baz") - val TRANSIENT = customVariable("__transient", VariableMap::class.java) + val TRANSIENT = customVariable("__transient", VariableMap::class.java) - val MY_ACL = CamundaBpmDataACL.guardTransformingLocalReplace( - TRANSIENT.name, - VariablesGuard(listOf(exists(FOO), BAZ.matches { it.length > 2 })), - IdentityVariableMapTransformer - ) + val MY_ACL = CamundaBpmDataACL.guardTransformingLocalReplace( + TRANSIENT.name, + VariablesGuard(listOf(exists(FOO), BAZ.matches { it.length > 2 })), + IdentityVariableMapTransformer + ) - @Suppress("RedundantVisibilityModifier") - @get: Rule - public val expectedException: ExpectedException = ExpectedException.none() + @Suppress("RedundantVisibilityModifier") + @get: Rule + public val expectedException: ExpectedException = ExpectedException.none() - @Test - fun `should wrap variables directly`() { + @Test + fun `should wrap variables directly`() { - val vars = CamundaBpmData.builder().set(FOO, "foo1").set(BAZ, "baz2").build() + val vars = CamundaBpmData.builder().set(FOO, "foo1").set(BAZ, "baz2").build() - val wrapped = AntiCorruptionLayer.wrapAsTypedTransientVariable(TRANSIENT.name, vars) - assertThat(wrapped).containsOnlyKeys(TRANSIENT.name) - assertThat(wrapped.getValueTyped(TRANSIENT.name).isTransient).isTrue() - assertThat(TRANSIENT.from(wrapped).get()).isEqualTo(vars) - } + val wrapped = AntiCorruptionLayer.wrapAsTypedTransientVariable(TRANSIENT.name, vars) + assertThat(wrapped).containsOnlyKeys(TRANSIENT.name) + assertThat(wrapped.getValueTyped(TRANSIENT.name).isTransient).isTrue() + assertThat(TRANSIENT.from(wrapped).get()).isEqualTo(vars) + } - @Test - fun `should wrap variables using ACL`() { + @Test + fun `should wrap variables using ACL`() { - val vars = CamundaBpmData.builder().set(FOO, "foo1").set(BAZ, "baz2").build() + val vars = CamundaBpmData.builder().set(FOO, "foo1").set(BAZ, "baz2").build() - val wrapped = MY_ACL.wrap(vars) - assertThat(wrapped).containsOnlyKeys(TRANSIENT.name) - assertThat(wrapped.getValueTyped(TRANSIENT.name).isTransient).isTrue() - assertThat(TRANSIENT.from(wrapped).get()).isEqualTo(vars) - } + val wrapped = MY_ACL.wrap(vars) + assertThat(wrapped).containsOnlyKeys(TRANSIENT.name) + assertThat(wrapped.getValueTyped(TRANSIENT.name).isTransient).isTrue() + assertThat(TRANSIENT.from(wrapped).get()).isEqualTo(vars) + } - @Test - fun `should check and wrap variables`() { - val vars = CamundaBpmData.builder().set(FOO, "foo1").set(BAZ, "baz2").build() - val wrapped = MY_ACL.checkAndWrap(vars) - - assertThat(wrapped).containsOnlyKeys(TRANSIENT.name) - assertThat(wrapped.getValueTyped(TRANSIENT.name).isTransient).isTrue() - assertThat(TRANSIENT.from(wrapped).get()).isEqualTo(vars) - } + @Test + fun `should check and wrap variables`() { + val vars = CamundaBpmData.builder().set(FOO, "foo1").set(BAZ, "baz2").build() + val wrapped = MY_ACL.checkAndWrap(vars) - @Test - fun `should fail checking and wrapping variables`() { - expectedException.expectMessage("ACL Guard Error:\n\tExpecting variable 'baz' to match the condition, but its value 'ba' has not.") + assertThat(wrapped).containsOnlyKeys(TRANSIENT.name) + assertThat(wrapped.getValueTyped(TRANSIENT.name).isTransient).isTrue() + assertThat(TRANSIENT.from(wrapped).get()).isEqualTo(vars) + } - val vars = CamundaBpmData.builder().set(FOO, "foo1").set(BAZ, "ba").build() - MY_ACL.checkAndWrap(vars) - } + @Test + fun `should fail checking and wrapping variables`() { + expectedException.expectMessage("ACL Guard Error:\n\tExpecting variable 'baz' to match the condition, but its value 'ba' has not.") - @Test - fun `should act as execution listener`() { + val vars = CamundaBpmData.builder().set(FOO, "foo1").set(BAZ, "ba").build() + MY_ACL.checkAndWrap(vars) + } - setupEngineConfiguration() + @Test + fun `should act as execution listener`() { - val listener = MY_ACL.getExecutionListener() - val wrappedVars = MY_ACL.checkAndWrap( - CamundaBpmData - .builder() - .set(FOO, "foo1") - .set(BAZ, "baz2") - .build() - ) + setupEngineConfiguration() - val fake = DelegateExecutionFake().withVariables(wrappedVars) - listener.notify(fake) + val listener = MY_ACL.getExecutionListener() + val wrappedVars = MY_ACL.checkAndWrap( + CamundaBpmData + .builder() + .set(FOO, "foo1") + .set(BAZ, "baz2") + .build() + ) - assertThat(fake.hasVariableLocal(FOO.name)).isTrue() - assertThat(fake.hasVariableLocal(BAZ.name)).isTrue() + val fake = DelegateExecutionFake().withVariables(wrappedVars) + listener.notify(fake) - } + assertThat(fake.hasVariableLocal(FOO.name)).isTrue() + assertThat(fake.hasVariableLocal(BAZ.name)).isTrue() - @Test - fun `should act as task listener`() { + } - setupEngineConfiguration() + @Test + fun `should act as task listener`() { - val listener = MY_ACL.getTaskListener() - val wrappedVars = MY_ACL.checkAndWrap( - CamundaBpmData - .builder() - .set(FOO, "foo1") - .set(BAZ, "baz2") - .build() - ) + setupEngineConfiguration() - val fake = DelegateTaskFake().withVariables(wrappedVars) - listener.notify(fake) + val listener = MY_ACL.getTaskListener() + val wrappedVars = MY_ACL.checkAndWrap( + CamundaBpmData + .builder() + .set(FOO, "foo1") + .set(BAZ, "baz2") + .build() + ) - assertThat(fake.hasVariableLocal(FOO.name)).isTrue() - assertThat(fake.hasVariableLocal(BAZ.name)).isTrue() + val fake = DelegateTaskFake().withVariables(wrappedVars) + listener.notify(fake) - } + assertThat(fake.hasVariableLocal(FOO.name)).isTrue() + assertThat(fake.hasVariableLocal(BAZ.name)).isTrue() + } - private fun setupEngineConfiguration() { - val config = object : StandaloneInMemProcessEngineConfiguration() { - init { - history = ProcessEngineConfiguration.HISTORY_FULL - databaseSchemaUpdate = ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE - jobExecutorActivate = false - expressionManager = MockExpressionManager() - javaSerializationFormatEnabled = true - } - } - Context.setProcessEngineConfiguration(config) + private fun setupEngineConfiguration() { + val config = object : StandaloneInMemProcessEngineConfiguration() { + init { + history = ProcessEngineConfiguration.HISTORY_FULL + databaseSchemaUpdate = ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE + jobExecutorActivate = false + expressionManager = MockExpressionManager() + javaSerializationFormatEnabled = true + } } -} \ No newline at end of file + Context.setProcessEngineConfiguration(config) + } +} diff --git a/extension/core/src/test/kotlin/acl/CamundaBpmDataACLTest.kt b/extension/core/src/test/kotlin/acl/CamundaBpmDataACLTest.kt index c174de80..6f2c54ce 100644 --- a/extension/core/src/test/kotlin/acl/CamundaBpmDataACLTest.kt +++ b/extension/core/src/test/kotlin/acl/CamundaBpmDataACLTest.kt @@ -13,61 +13,61 @@ import org.junit.Test class CamundaBpmDataACLTest { - val TRANSIENT_VAR = CamundaBpmData.customVariable("__transient__", VariableMap::class.java) - val FOO = CamundaBpmData.stringVariable("foo") + val TRANSIENT_VAR = CamundaBpmData.customVariable("__transient__", VariableMap::class.java) + val FOO = CamundaBpmData.stringVariable("foo") - @Test - fun `should create guardTransformingLocalReplace`() { - val acl = CamundaBpmDataACL.guardTransformingLocalReplace( - TRANSIENT_VAR.name, - VariablesGuard(exists(FOO)), - IdentityVariableMapTransformer - ) - assertThat(acl.precondition).isEqualTo(VariablesGuard(exists(FOO))) - assertThat(acl.variableMapTransformer).isEqualTo(IdentityVariableMapTransformer) - assertThat(acl.factory).isEqualTo(TRANSIENT_VAR) - assertThat(acl.valueApplicationStrategy).isEqualTo(LocalScopeReplaceStrategy) - } + @Test + fun `should create guardTransformingLocalReplace`() { + val acl = CamundaBpmDataACL.guardTransformingLocalReplace( + TRANSIENT_VAR.name, + VariablesGuard(exists(FOO)), + IdentityVariableMapTransformer + ) + assertThat(acl.precondition).isEqualTo(VariablesGuard(exists(FOO))) + assertThat(acl.variableMapTransformer).isEqualTo(IdentityVariableMapTransformer) + assertThat(acl.factory).isEqualTo(TRANSIENT_VAR) + assertThat(acl.valueApplicationStrategy).isEqualTo(LocalScopeReplaceStrategy) + } - @Test - fun `should create guardTransformingGlobalReplace`() { - val acl = CamundaBpmDataACL.guardTransformingGlobalReplace( - TRANSIENT_VAR.name, - VariablesGuard(exists(FOO)), - IdentityVariableMapTransformer - ) - assertThat(acl.precondition).isEqualTo(VariablesGuard(exists(FOO))) - assertThat(acl.variableMapTransformer).isEqualTo(IdentityVariableMapTransformer) - assertThat(acl.factory).isEqualTo(TRANSIENT_VAR) - assertThat(acl.valueApplicationStrategy).isEqualTo(GlobalScopeReplaceStrategy) - } + @Test + fun `should create guardTransformingGlobalReplace`() { + val acl = CamundaBpmDataACL.guardTransformingGlobalReplace( + TRANSIENT_VAR.name, + VariablesGuard(exists(FOO)), + IdentityVariableMapTransformer + ) + assertThat(acl.precondition).isEqualTo(VariablesGuard(exists(FOO))) + assertThat(acl.variableMapTransformer).isEqualTo(IdentityVariableMapTransformer) + assertThat(acl.factory).isEqualTo(TRANSIENT_VAR) + assertThat(acl.valueApplicationStrategy).isEqualTo(GlobalScopeReplaceStrategy) + } - @Test - fun `should create guardTransformingReplace global`() { - val acl = CamundaBpmDataACL.guardTransformingReplace( - TRANSIENT_VAR.name, - false, - VariablesGuard(exists(FOO)), - IdentityVariableMapTransformer - ) - assertThat(acl.precondition).isEqualTo(VariablesGuard(exists(FOO))) - assertThat(acl.variableMapTransformer).isEqualTo(IdentityVariableMapTransformer) - assertThat(acl.factory).isEqualTo(TRANSIENT_VAR) - assertThat(acl.valueApplicationStrategy).isEqualTo(GlobalScopeReplaceStrategy) - } + @Test + fun `should create guardTransformingReplace global`() { + val acl = CamundaBpmDataACL.guardTransformingReplace( + TRANSIENT_VAR.name, + false, + VariablesGuard(exists(FOO)), + IdentityVariableMapTransformer + ) + assertThat(acl.precondition).isEqualTo(VariablesGuard(exists(FOO))) + assertThat(acl.variableMapTransformer).isEqualTo(IdentityVariableMapTransformer) + assertThat(acl.factory).isEqualTo(TRANSIENT_VAR) + assertThat(acl.valueApplicationStrategy).isEqualTo(GlobalScopeReplaceStrategy) + } - @Test - fun `should create guardTransformingReplace local`() { - val acl = CamundaBpmDataACL.guardTransformingReplace( - TRANSIENT_VAR.name, - true, - VariablesGuard(exists(FOO)), - IdentityVariableMapTransformer - ) - assertThat(acl.precondition).isEqualTo(VariablesGuard(exists(FOO))) - assertThat(acl.variableMapTransformer).isEqualTo(IdentityVariableMapTransformer) - assertThat(acl.factory).isEqualTo(TRANSIENT_VAR) - assertThat(acl.valueApplicationStrategy).isEqualTo(LocalScopeReplaceStrategy) - } + @Test + fun `should create guardTransformingReplace local`() { + val acl = CamundaBpmDataACL.guardTransformingReplace( + TRANSIENT_VAR.name, + true, + VariablesGuard(exists(FOO)), + IdentityVariableMapTransformer + ) + assertThat(acl.precondition).isEqualTo(VariablesGuard(exists(FOO))) + assertThat(acl.variableMapTransformer).isEqualTo(IdentityVariableMapTransformer) + assertThat(acl.factory).isEqualTo(TRANSIENT_VAR) + assertThat(acl.valueApplicationStrategy).isEqualTo(LocalScopeReplaceStrategy) + } -} \ No newline at end of file +} diff --git a/extension/core/src/test/kotlin/acl/CamundaBpmDataMapperTest.kt b/extension/core/src/test/kotlin/acl/CamundaBpmDataMapperTest.kt index 967e93a6..2fdb76f5 100644 --- a/extension/core/src/test/kotlin/acl/CamundaBpmDataMapperTest.kt +++ b/extension/core/src/test/kotlin/acl/CamundaBpmDataMapperTest.kt @@ -12,103 +12,103 @@ import org.junit.Test class CamundaBpmDataMapperTest { - val TRANSIENT_VAR = CamundaBpmData.customVariable("__transient__", VariableMap::class.java) + val TRANSIENT_VAR = CamundaBpmData.customVariable("__transient__", VariableMap::class.java) - @Test - fun `should create transformingLocalReplace`() { - val acl = CamundaBpmDataMapper.transformingLocalReplace( - TRANSIENT_VAR.name, - IdentityVariableMapTransformer - ) - assertThat(acl.precondition).isEqualTo(VariablesGuard.EMPTY) - assertThat(acl.variableMapTransformer).isEqualTo(IdentityVariableMapTransformer) - assertThat(acl.factory).isEqualTo(TRANSIENT_VAR) - assertThat(acl.valueApplicationStrategy).isEqualTo(LocalScopeReplaceStrategy) - } + @Test + fun `should create transformingLocalReplace`() { + val acl = CamundaBpmDataMapper.transformingLocalReplace( + TRANSIENT_VAR.name, + IdentityVariableMapTransformer + ) + assertThat(acl.precondition).isEqualTo(VariablesGuard.EMPTY) + assertThat(acl.variableMapTransformer).isEqualTo(IdentityVariableMapTransformer) + assertThat(acl.factory).isEqualTo(TRANSIENT_VAR) + assertThat(acl.valueApplicationStrategy).isEqualTo(LocalScopeReplaceStrategy) + } - @Test - fun `should create transformingGlobalReplace`() { - val acl = CamundaBpmDataMapper.transformingGlobalReplace( - TRANSIENT_VAR.name, - IdentityVariableMapTransformer - ) - assertThat(acl.precondition).isEqualTo(VariablesGuard.EMPTY) - assertThat(acl.variableMapTransformer).isEqualTo(IdentityVariableMapTransformer) - assertThat(acl.factory).isEqualTo(TRANSIENT_VAR) - assertThat(acl.valueApplicationStrategy).isEqualTo(GlobalScopeReplaceStrategy) - } + @Test + fun `should create transformingGlobalReplace`() { + val acl = CamundaBpmDataMapper.transformingGlobalReplace( + TRANSIENT_VAR.name, + IdentityVariableMapTransformer + ) + assertThat(acl.precondition).isEqualTo(VariablesGuard.EMPTY) + assertThat(acl.variableMapTransformer).isEqualTo(IdentityVariableMapTransformer) + assertThat(acl.factory).isEqualTo(TRANSIENT_VAR) + assertThat(acl.valueApplicationStrategy).isEqualTo(GlobalScopeReplaceStrategy) + } - @Test - fun `should create transformingReplace local`() { - val acl = CamundaBpmDataMapper.transformingReplace( - TRANSIENT_VAR.name, - true, - IdentityVariableMapTransformer - ) - assertThat(acl.precondition).isEqualTo(VariablesGuard.EMPTY) - assertThat(acl.variableMapTransformer).isEqualTo(IdentityVariableMapTransformer) - assertThat(acl.factory).isEqualTo(TRANSIENT_VAR) - assertThat(acl.valueApplicationStrategy).isEqualTo(LocalScopeReplaceStrategy) - } + @Test + fun `should create transformingReplace local`() { + val acl = CamundaBpmDataMapper.transformingReplace( + TRANSIENT_VAR.name, + true, + IdentityVariableMapTransformer + ) + assertThat(acl.precondition).isEqualTo(VariablesGuard.EMPTY) + assertThat(acl.variableMapTransformer).isEqualTo(IdentityVariableMapTransformer) + assertThat(acl.factory).isEqualTo(TRANSIENT_VAR) + assertThat(acl.valueApplicationStrategy).isEqualTo(LocalScopeReplaceStrategy) + } - @Test - fun `should create transformingReplace global`() { - val acl = CamundaBpmDataMapper.transformingReplace( - TRANSIENT_VAR.name, - false, - IdentityVariableMapTransformer - ) - assertThat(acl.precondition).isEqualTo(VariablesGuard.EMPTY) - assertThat(acl.variableMapTransformer).isEqualTo(IdentityVariableMapTransformer) - assertThat(acl.factory).isEqualTo(TRANSIENT_VAR) - assertThat(acl.valueApplicationStrategy).isEqualTo(GlobalScopeReplaceStrategy) - } + @Test + fun `should create transformingReplace global`() { + val acl = CamundaBpmDataMapper.transformingReplace( + TRANSIENT_VAR.name, + false, + IdentityVariableMapTransformer + ) + assertThat(acl.precondition).isEqualTo(VariablesGuard.EMPTY) + assertThat(acl.variableMapTransformer).isEqualTo(IdentityVariableMapTransformer) + assertThat(acl.factory).isEqualTo(TRANSIENT_VAR) + assertThat(acl.valueApplicationStrategy).isEqualTo(GlobalScopeReplaceStrategy) + } - @Test - fun `should create identityLocalReplace`() { - val acl = CamundaBpmDataMapper.identityLocalReplace( - TRANSIENT_VAR.name - ) - assertThat(acl.precondition).isEqualTo(VariablesGuard.EMPTY) - assertThat(acl.variableMapTransformer).isEqualTo(IdentityVariableMapTransformer) - assertThat(acl.factory).isEqualTo(TRANSIENT_VAR) - assertThat(acl.valueApplicationStrategy).isEqualTo(LocalScopeReplaceStrategy) - } + @Test + fun `should create identityLocalReplace`() { + val acl = CamundaBpmDataMapper.identityLocalReplace( + TRANSIENT_VAR.name + ) + assertThat(acl.precondition).isEqualTo(VariablesGuard.EMPTY) + assertThat(acl.variableMapTransformer).isEqualTo(IdentityVariableMapTransformer) + assertThat(acl.factory).isEqualTo(TRANSIENT_VAR) + assertThat(acl.valueApplicationStrategy).isEqualTo(LocalScopeReplaceStrategy) + } - @Test - fun `should create identityGlobalReplace`() { - val acl = CamundaBpmDataMapper.identityGlobalReplace( - TRANSIENT_VAR.name - ) - assertThat(acl.precondition).isEqualTo(VariablesGuard.EMPTY) - assertThat(acl.variableMapTransformer).isEqualTo(IdentityVariableMapTransformer) - assertThat(acl.factory).isEqualTo(TRANSIENT_VAR) - assertThat(acl.valueApplicationStrategy).isEqualTo(GlobalScopeReplaceStrategy) - } + @Test + fun `should create identityGlobalReplace`() { + val acl = CamundaBpmDataMapper.identityGlobalReplace( + TRANSIENT_VAR.name + ) + assertThat(acl.precondition).isEqualTo(VariablesGuard.EMPTY) + assertThat(acl.variableMapTransformer).isEqualTo(IdentityVariableMapTransformer) + assertThat(acl.factory).isEqualTo(TRANSIENT_VAR) + assertThat(acl.valueApplicationStrategy).isEqualTo(GlobalScopeReplaceStrategy) + } - @Test - fun `should create identityGlobalReplace local`() { - val acl = CamundaBpmDataMapper.identityReplace( - TRANSIENT_VAR.name, - true - ) - assertThat(acl.precondition).isEqualTo(VariablesGuard.EMPTY) - assertThat(acl.variableMapTransformer).isEqualTo(IdentityVariableMapTransformer) - assertThat(acl.factory).isEqualTo(TRANSIENT_VAR) - assertThat(acl.valueApplicationStrategy).isEqualTo(LocalScopeReplaceStrategy) - } + @Test + fun `should create identityGlobalReplace local`() { + val acl = CamundaBpmDataMapper.identityReplace( + TRANSIENT_VAR.name, + true + ) + assertThat(acl.precondition).isEqualTo(VariablesGuard.EMPTY) + assertThat(acl.variableMapTransformer).isEqualTo(IdentityVariableMapTransformer) + assertThat(acl.factory).isEqualTo(TRANSIENT_VAR) + assertThat(acl.valueApplicationStrategy).isEqualTo(LocalScopeReplaceStrategy) + } - @Test - fun `should create identityGlobalReplace global`() { - val acl = CamundaBpmDataMapper.identityReplace( - TRANSIENT_VAR.name, - false - ) - assertThat(acl.precondition).isEqualTo(VariablesGuard.EMPTY) - assertThat(acl.variableMapTransformer).isEqualTo(IdentityVariableMapTransformer) - assertThat(acl.factory).isEqualTo(TRANSIENT_VAR) - assertThat(acl.valueApplicationStrategy).isEqualTo(GlobalScopeReplaceStrategy) - } + @Test + fun `should create identityGlobalReplace global`() { + val acl = CamundaBpmDataMapper.identityReplace( + TRANSIENT_VAR.name, + false + ) + assertThat(acl.precondition).isEqualTo(VariablesGuard.EMPTY) + assertThat(acl.variableMapTransformer).isEqualTo(IdentityVariableMapTransformer) + assertThat(acl.factory).isEqualTo(TRANSIENT_VAR) + assertThat(acl.valueApplicationStrategy).isEqualTo(GlobalScopeReplaceStrategy) + } -} \ No newline at end of file +} diff --git a/extension/core/src/test/kotlin/acl/apply/GlobalScopeReplaceStrategyTest.kt b/extension/core/src/test/kotlin/acl/apply/GlobalScopeReplaceStrategyTest.kt index 91686f8e..39d175fe 100644 --- a/extension/core/src/test/kotlin/acl/apply/GlobalScopeReplaceStrategyTest.kt +++ b/extension/core/src/test/kotlin/acl/apply/GlobalScopeReplaceStrategyTest.kt @@ -10,17 +10,17 @@ import org.mockito.Mockito.verifyNoMoreInteractions class GlobalScopeReplaceStrategyTest { - val FOO = stringVariable("foo") + val FOO = stringVariable("foo") - @Test - fun `should apply global`() { - val variables = CamundaBpmData.builder().set(FOO, "bar").build() - val executionMock = Mockito.mock(DelegateExecution::class.java) + @Test + fun `should apply global`() { + val variables = CamundaBpmData.builder().set(FOO, "bar").build() + val executionMock = Mockito.mock(DelegateExecution::class.java) - GlobalScopeReplaceStrategy.apply(variables, executionMock) + GlobalScopeReplaceStrategy.apply(variables, executionMock) - verify(executionMock, Mockito.never()).setVariablesLocal(Mockito.any()) - verify(executionMock).setVariables(variables) - verifyNoMoreInteractions(executionMock) - } -} \ No newline at end of file + verify(executionMock, Mockito.never()).setVariablesLocal(Mockito.any()) + verify(executionMock).setVariables(variables) + verifyNoMoreInteractions(executionMock) + } +} diff --git a/extension/core/src/test/kotlin/acl/apply/LocalScopeReplaceStrategyTest.kt b/extension/core/src/test/kotlin/acl/apply/LocalScopeReplaceStrategyTest.kt index be6b829e..71d0f78a 100644 --- a/extension/core/src/test/kotlin/acl/apply/LocalScopeReplaceStrategyTest.kt +++ b/extension/core/src/test/kotlin/acl/apply/LocalScopeReplaceStrategyTest.kt @@ -8,17 +8,17 @@ import org.mockito.Mockito.* class LocalScopeReplaceStrategyTest { - val FOO = stringVariable("foo") + val FOO = stringVariable("foo") - @Test - fun `should apply local`() { - val variables = CamundaBpmData.builder().set(FOO, "bar").build() - val executionMock = mock(DelegateExecution::class.java) + @Test + fun `should apply local`() { + val variables = CamundaBpmData.builder().set(FOO, "bar").build() + val executionMock = mock(DelegateExecution::class.java) - LocalScopeReplaceStrategy.apply(variables, executionMock) + LocalScopeReplaceStrategy.apply(variables, executionMock) - verify(executionMock, never()).setVariables(any()) - verify(executionMock).setVariablesLocal(variables) - verifyNoMoreInteractions(executionMock) - } -} \ No newline at end of file + verify(executionMock, never()).setVariables(any()) + verify(executionMock).setVariablesLocal(variables) + verifyNoMoreInteractions(executionMock) + } +} diff --git a/extension/core/src/test/kotlin/acl/transform/IdentityVariableMapTransformerTest.kt b/extension/core/src/test/kotlin/acl/transform/IdentityVariableMapTransformerTest.kt index 1592acc2..1e60aec0 100644 --- a/extension/core/src/test/kotlin/acl/transform/IdentityVariableMapTransformerTest.kt +++ b/extension/core/src/test/kotlin/acl/transform/IdentityVariableMapTransformerTest.kt @@ -6,13 +6,13 @@ import org.junit.Test class IdentityVariableMapTransformerTest { - @Test - fun `should pass the input to output`() { + @Test + fun `should pass the input to output`() { - val vars = CamundaBpmData.builder().build() + val vars = CamundaBpmData.builder().build() - assertThat(IdentityVariableMapTransformer.transform(vars)) - .isEqualTo(vars) // equals comparison - .isSameAs(vars) // == comparison - } -} \ No newline at end of file + assertThat(IdentityVariableMapTransformer.transform(vars)) + .isEqualTo(vars) // equals comparison + .isSameAs(vars) // == comparison + } +} diff --git a/extension/core/src/test/kotlin/guard/CamundaBpmDataGuardsTest.kt b/extension/core/src/test/kotlin/guard/CamundaBpmDataGuardsTest.kt index bed54891..7362db26 100644 --- a/extension/core/src/test/kotlin/guard/CamundaBpmDataGuardsTest.kt +++ b/extension/core/src/test/kotlin/guard/CamundaBpmDataGuardsTest.kt @@ -9,178 +9,178 @@ import java.util.function.Function class CamundaBpmDataGuardsTest { - val FOO = stringVariable("foo") - - @Test - fun `should construct exists condition`() { - val condition = CamundaBpmDataGuards.exists(FOO) - assertThat(condition).isInstanceOf(VariableExistsGuardCondition::class.java) - assertThat(condition.variableFactory).isEqualTo(FOO) - assertThat(condition.local).isEqualTo(false) - } - - @Test - fun `should construct exists local condition`() { - val condition = CamundaBpmDataGuards.exists(FOO, true) - assertThat(condition).isInstanceOf(VariableExistsGuardCondition::class.java) - assertThat(condition.variableFactory).isEqualTo(FOO) - assertThat(condition.local).isEqualTo(true) - } - - @Test - fun `should construct notExists condition`() { - val condition = CamundaBpmDataGuards.notExists(FOO) - assertThat(condition).isInstanceOf(VariableNotExistsGuardCondition::class.java) - assertThat(condition.variableFactory).isEqualTo(FOO) - assertThat(condition.local).isEqualTo(false) - } - - @Test - fun `should construct notExists local condition`() { - val condition = CamundaBpmDataGuards.notExists(FOO, true) - assertThat(condition).isInstanceOf(VariableNotExistsGuardCondition::class.java) - assertThat(condition.variableFactory).isEqualTo(FOO) - assertThat(condition.local).isEqualTo(true) - } - - @Test - fun `should construct hasValue condition`() { - val condition = CamundaBpmDataGuards.hasValue(FOO, "val") - assertThat(condition).isInstanceOf(VariableValueGuardCondition::class.java) - assertThat(condition.variableFactory).isEqualTo(FOO) - assertThat(condition.local).isEqualTo(false) - assertThat(condition.value).isEqualTo("val") - } - - @Test - fun `should construct hasValue local condition`() { - val condition = CamundaBpmDataGuards.hasValue(FOO, "valLocal", true) - assertThat(condition).isInstanceOf(VariableValueGuardCondition::class.java) - assertThat(condition.variableFactory).isEqualTo(FOO) - assertThat(condition.local).isEqualTo(true) - assertThat(condition.value).isEqualTo("valLocal") - } - - @Test - fun `should construct hasOneOfValues condition`() { - val condition = CamundaBpmDataGuards.hasOneOfValues(FOO, setOf("val1", "val2") ) - assertThat(condition).isInstanceOf(VariableValueOneOfGuardCondition::class.java) - assertThat(condition.variableFactory).isEqualTo(FOO) - assertThat(condition.local).isEqualTo(false) - assertThat(condition.values).containsExactlyInAnyOrder("val1", "val2") - } - - @Test - fun `should construct hasOneOfValues local condition`() { - val condition = CamundaBpmDataGuards.hasOneOfValues(FOO, setOf("valLocal1", "valLocal2"), true) - assertThat(condition).isInstanceOf(VariableValueOneOfGuardCondition::class.java) - assertThat(condition.variableFactory).isEqualTo(FOO) - assertThat(condition.local).isEqualTo(true) - assertThat(condition.values).containsExactlyInAnyOrder("valLocal1", "valLocal2") - } - - @Test - fun `should construct matches condition`() { - val condition = CamundaBpmDataGuards.matches(FOO, Function { it == "special_val" }) - assertThat(condition).isInstanceOf(VariableMatchesGuardCondition::class.java) - assertThat(condition.variableFactory).isEqualTo(FOO) - assertThat(condition.local).isEqualTo(false) - assertThat(condition.evaluate(Optional.of("special_val"))).isEmpty() - } - - @Test - fun `should construct matches local condition`() { - val condition = CamundaBpmDataGuards.matches(FOO, Function { it == "special_val_local" }, true) - assertThat(condition).isInstanceOf(VariableMatchesGuardCondition::class.java) - assertThat(condition.variableFactory).isEqualTo(FOO) - assertThat(condition.local).isEqualTo(true) - assertThat(condition.evaluate(Optional.of("special_val_local"))).isEmpty() - } - - @Test - fun `kotlin should construct exists condition`() { - val condition = FOO.exists() - assertThat(condition).isInstanceOf(VariableExistsGuardCondition::class.java) - assertThat(condition.variableFactory).isEqualTo(FOO) - assertThat(condition.local).isEqualTo(false) - } - - @Test - fun `kotlin should construct exists local condition`() { - val condition = FOO.exists(true) - assertThat(condition).isInstanceOf(VariableExistsGuardCondition::class.java) - assertThat(condition.variableFactory).isEqualTo(FOO) - assertThat(condition.local).isEqualTo(true) - } - - @Test - fun `kotlin should construct notExists condition`() { - val condition = FOO.notExists() - assertThat(condition).isInstanceOf(VariableNotExistsGuardCondition::class.java) - assertThat(condition.variableFactory).isEqualTo(FOO) - assertThat(condition.local).isEqualTo(false) - } - - @Test - fun `kotlin should construct notExists local condition`() { - val condition = FOO.notExists(true) - assertThat(condition).isInstanceOf(VariableNotExistsGuardCondition::class.java) - assertThat(condition.variableFactory).isEqualTo(FOO) - assertThat(condition.local).isEqualTo(true) - } - - @Test - fun `kotlin should construct hasValue condition`() { - val condition = FOO.hasValue("val") - assertThat(condition).isInstanceOf(VariableValueGuardCondition::class.java) - assertThat(condition.variableFactory).isEqualTo(FOO) - assertThat(condition.local).isEqualTo(false) - assertThat(condition.value).isEqualTo("val") - } - - @Test - fun `kotlin should construct hasValue local condition`() { - val condition = FOO.hasValue("valLocal", true) - assertThat(condition).isInstanceOf(VariableValueGuardCondition::class.java) - assertThat(condition.variableFactory).isEqualTo(FOO) - assertThat(condition.local).isEqualTo(true) - assertThat(condition.value).isEqualTo("valLocal") - } - - @Test - fun `kotlin should construct hasOneOfValues condition`() { - val condition = FOO.hasOneOfValues(setOf("val1", "val2") ) - assertThat(condition).isInstanceOf(VariableValueOneOfGuardCondition::class.java) - assertThat(condition.variableFactory).isEqualTo(FOO) - assertThat(condition.local).isEqualTo(false) - assertThat(condition.values).containsExactlyInAnyOrder("val1", "val2") - } - - @Test - fun `kotlin should construct hasOneOfValues local condition`() { - val condition = FOO.hasOneOfValues(setOf("valLocal1", "valLocal2"), true) - assertThat(condition).isInstanceOf(VariableValueOneOfGuardCondition::class.java) - assertThat(condition.variableFactory).isEqualTo(FOO) - assertThat(condition.local).isEqualTo(true) - assertThat(condition.values).containsExactlyInAnyOrder("valLocal1", "valLocal2") - } - - @Test - fun `kotlin should construct matches condition`() { - val condition = FOO.matches { it == "special_val" } - assertThat(condition).isInstanceOf(VariableMatchesGuardCondition::class.java) - assertThat(condition.variableFactory).isEqualTo(FOO) - assertThat(condition.local).isEqualTo(false) - assertThat(condition.evaluate(Optional.of("special_val"))).isEmpty() - } - - @Test - fun `kotlin should construct matches local condition`() { - val condition = FOO.matches(true){ it == "special_val_local" } - assertThat(condition).isInstanceOf(VariableMatchesGuardCondition::class.java) - assertThat(condition.variableFactory).isEqualTo(FOO) - assertThat(condition.local).isEqualTo(true) - assertThat(condition.evaluate(Optional.of("special_val_local"))).isEmpty() - } - -} \ No newline at end of file + val FOO = stringVariable("foo") + + @Test + fun `should construct exists condition`() { + val condition = CamundaBpmDataGuards.exists(FOO) + assertThat(condition).isInstanceOf(VariableExistsGuardCondition::class.java) + assertThat(condition.variableFactory).isEqualTo(FOO) + assertThat(condition.local).isEqualTo(false) + } + + @Test + fun `should construct exists local condition`() { + val condition = CamundaBpmDataGuards.exists(FOO, true) + assertThat(condition).isInstanceOf(VariableExistsGuardCondition::class.java) + assertThat(condition.variableFactory).isEqualTo(FOO) + assertThat(condition.local).isEqualTo(true) + } + + @Test + fun `should construct notExists condition`() { + val condition = CamundaBpmDataGuards.notExists(FOO) + assertThat(condition).isInstanceOf(VariableNotExistsGuardCondition::class.java) + assertThat(condition.variableFactory).isEqualTo(FOO) + assertThat(condition.local).isEqualTo(false) + } + + @Test + fun `should construct notExists local condition`() { + val condition = CamundaBpmDataGuards.notExists(FOO, true) + assertThat(condition).isInstanceOf(VariableNotExistsGuardCondition::class.java) + assertThat(condition.variableFactory).isEqualTo(FOO) + assertThat(condition.local).isEqualTo(true) + } + + @Test + fun `should construct hasValue condition`() { + val condition = CamundaBpmDataGuards.hasValue(FOO, "val") + assertThat(condition).isInstanceOf(VariableValueGuardCondition::class.java) + assertThat(condition.variableFactory).isEqualTo(FOO) + assertThat(condition.local).isEqualTo(false) + assertThat(condition.value).isEqualTo("val") + } + + @Test + fun `should construct hasValue local condition`() { + val condition = CamundaBpmDataGuards.hasValue(FOO, "valLocal", true) + assertThat(condition).isInstanceOf(VariableValueGuardCondition::class.java) + assertThat(condition.variableFactory).isEqualTo(FOO) + assertThat(condition.local).isEqualTo(true) + assertThat(condition.value).isEqualTo("valLocal") + } + + @Test + fun `should construct hasOneOfValues condition`() { + val condition = CamundaBpmDataGuards.hasOneOfValues(FOO, setOf("val1", "val2")) + assertThat(condition).isInstanceOf(VariableValueOneOfGuardCondition::class.java) + assertThat(condition.variableFactory).isEqualTo(FOO) + assertThat(condition.local).isEqualTo(false) + assertThat(condition.values).containsExactlyInAnyOrder("val1", "val2") + } + + @Test + fun `should construct hasOneOfValues local condition`() { + val condition = CamundaBpmDataGuards.hasOneOfValues(FOO, setOf("valLocal1", "valLocal2"), true) + assertThat(condition).isInstanceOf(VariableValueOneOfGuardCondition::class.java) + assertThat(condition.variableFactory).isEqualTo(FOO) + assertThat(condition.local).isEqualTo(true) + assertThat(condition.values).containsExactlyInAnyOrder("valLocal1", "valLocal2") + } + + @Test + fun `should construct matches condition`() { + val condition = CamundaBpmDataGuards.matches(FOO, Function { it == "special_val" }) + assertThat(condition).isInstanceOf(VariableMatchesGuardCondition::class.java) + assertThat(condition.variableFactory).isEqualTo(FOO) + assertThat(condition.local).isEqualTo(false) + assertThat(condition.evaluate(Optional.of("special_val"))).isEmpty() + } + + @Test + fun `should construct matches local condition`() { + val condition = CamundaBpmDataGuards.matches(FOO, Function { it == "special_val_local" }, true) + assertThat(condition).isInstanceOf(VariableMatchesGuardCondition::class.java) + assertThat(condition.variableFactory).isEqualTo(FOO) + assertThat(condition.local).isEqualTo(true) + assertThat(condition.evaluate(Optional.of("special_val_local"))).isEmpty() + } + + @Test + fun `kotlin should construct exists condition`() { + val condition = FOO.exists() + assertThat(condition).isInstanceOf(VariableExistsGuardCondition::class.java) + assertThat(condition.variableFactory).isEqualTo(FOO) + assertThat(condition.local).isEqualTo(false) + } + + @Test + fun `kotlin should construct exists local condition`() { + val condition = FOO.exists(true) + assertThat(condition).isInstanceOf(VariableExistsGuardCondition::class.java) + assertThat(condition.variableFactory).isEqualTo(FOO) + assertThat(condition.local).isEqualTo(true) + } + + @Test + fun `kotlin should construct notExists condition`() { + val condition = FOO.notExists() + assertThat(condition).isInstanceOf(VariableNotExistsGuardCondition::class.java) + assertThat(condition.variableFactory).isEqualTo(FOO) + assertThat(condition.local).isEqualTo(false) + } + + @Test + fun `kotlin should construct notExists local condition`() { + val condition = FOO.notExists(true) + assertThat(condition).isInstanceOf(VariableNotExistsGuardCondition::class.java) + assertThat(condition.variableFactory).isEqualTo(FOO) + assertThat(condition.local).isEqualTo(true) + } + + @Test + fun `kotlin should construct hasValue condition`() { + val condition = FOO.hasValue("val") + assertThat(condition).isInstanceOf(VariableValueGuardCondition::class.java) + assertThat(condition.variableFactory).isEqualTo(FOO) + assertThat(condition.local).isEqualTo(false) + assertThat(condition.value).isEqualTo("val") + } + + @Test + fun `kotlin should construct hasValue local condition`() { + val condition = FOO.hasValue("valLocal", true) + assertThat(condition).isInstanceOf(VariableValueGuardCondition::class.java) + assertThat(condition.variableFactory).isEqualTo(FOO) + assertThat(condition.local).isEqualTo(true) + assertThat(condition.value).isEqualTo("valLocal") + } + + @Test + fun `kotlin should construct hasOneOfValues condition`() { + val condition = FOO.hasOneOfValues(setOf("val1", "val2")) + assertThat(condition).isInstanceOf(VariableValueOneOfGuardCondition::class.java) + assertThat(condition.variableFactory).isEqualTo(FOO) + assertThat(condition.local).isEqualTo(false) + assertThat(condition.values).containsExactlyInAnyOrder("val1", "val2") + } + + @Test + fun `kotlin should construct hasOneOfValues local condition`() { + val condition = FOO.hasOneOfValues(setOf("valLocal1", "valLocal2"), true) + assertThat(condition).isInstanceOf(VariableValueOneOfGuardCondition::class.java) + assertThat(condition.variableFactory).isEqualTo(FOO) + assertThat(condition.local).isEqualTo(true) + assertThat(condition.values).containsExactlyInAnyOrder("valLocal1", "valLocal2") + } + + @Test + fun `kotlin should construct matches condition`() { + val condition = FOO.matches { it == "special_val" } + assertThat(condition).isInstanceOf(VariableMatchesGuardCondition::class.java) + assertThat(condition.variableFactory).isEqualTo(FOO) + assertThat(condition.local).isEqualTo(false) + assertThat(condition.evaluate(Optional.of("special_val"))).isEmpty() + } + + @Test + fun `kotlin should construct matches local condition`() { + val condition = FOO.matches(true) { it == "special_val_local" } + assertThat(condition).isInstanceOf(VariableMatchesGuardCondition::class.java) + assertThat(condition.variableFactory).isEqualTo(FOO) + assertThat(condition.local).isEqualTo(true) + assertThat(condition.evaluate(Optional.of("special_val_local"))).isEmpty() + } + +} diff --git a/extension/core/src/test/kotlin/guard/VariableGuardConditionTest.kt b/extension/core/src/test/kotlin/guard/VariableGuardConditionTest.kt index ad3f06e6..97384831 100644 --- a/extension/core/src/test/kotlin/guard/VariableGuardConditionTest.kt +++ b/extension/core/src/test/kotlin/guard/VariableGuardConditionTest.kt @@ -8,75 +8,75 @@ import org.junit.Test class VariableGuardConditionTest { - companion object { - private val STRING_VAR = stringVariable("stringVariable") - } + companion object { + private val STRING_VAR = stringVariable("stringVariable") + } - @Test - fun test_exists() { + @Test + fun test_exists() { - val guard = VariablesGuard(STRING_VAR.exists()) + val guard = VariablesGuard(STRING_VAR.exists()) - val result = guard.evaluate(createVariables()) + val result = guard.evaluate(createVariables()) - assertThat(result.size).isEqualTo(1) - assertThat(result.first().message).isEqualTo("Expecting variable 'stringVariable' to be set, but it was not found.") - } + assertThat(result.size).isEqualTo(1) + assertThat(result.first().message).isEqualTo("Expecting variable 'stringVariable' to be set, but it was not found.") + } - @Test - fun test_not_exists() { + @Test + fun test_not_exists() { - val guard = VariablesGuard(STRING_VAR.notExists()) + val guard = VariablesGuard(STRING_VAR.notExists()) - val vars = createVariables() - STRING_VAR.on(vars).set("some") + val vars = createVariables() + STRING_VAR.on(vars).set("some") - val result = guard.evaluate(vars) + val result = guard.evaluate(vars) - assertThat(result.size).isEqualTo(1) - assertThat(result.first().message).isEqualTo("Expecting variable 'stringVariable' not to be set, but it had a value of 'some'.") - } + assertThat(result.size).isEqualTo(1) + assertThat(result.first().message).isEqualTo("Expecting variable 'stringVariable' not to be set, but it had a value of 'some'.") + } - @Test - fun test_wrong_value() { + @Test + fun test_wrong_value() { - val guard = VariablesGuard(STRING_VAR.hasValue("expected")) + val guard = VariablesGuard(STRING_VAR.hasValue("expected")) - val vars = createVariables() - STRING_VAR.on(vars).set("some") + val vars = createVariables() + STRING_VAR.on(vars).set("some") - val result = guard.evaluate(vars) + val result = guard.evaluate(vars) - assertThat(result.size).isEqualTo(1) - assertThat(result.first().message).isEqualTo("Expecting variable 'stringVariable' to have value 'expected', but it was 'some'.") - } + assertThat(result.size).isEqualTo(1) + assertThat(result.first().message).isEqualTo("Expecting variable 'stringVariable' to have value 'expected', but it was 'some'.") + } - @Test - fun test_wrong_value_one_of() { + @Test + fun test_wrong_value_one_of() { - val guard = VariablesGuard(STRING_VAR.hasOneOfValues(setOf("expected", "another expected"))) + val guard = VariablesGuard(STRING_VAR.hasOneOfValues(setOf("expected", "another expected"))) - val vars = createVariables() - STRING_VAR.on(vars).set("some") + val vars = createVariables() + STRING_VAR.on(vars).set("some") - val result = guard.evaluate(vars) + val result = guard.evaluate(vars) - assertThat(result.size).isEqualTo(1) - assertThat(result.first().message).isEqualTo("Expecting variable 'stringVariable' to be one of ['expected', 'another expected'], but it was 'some'.") - } + assertThat(result.size).isEqualTo(1) + assertThat(result.first().message).isEqualTo("Expecting variable 'stringVariable' to be one of ['expected', 'another expected'], but it was 'some'.") + } - @Test - fun test_matches() { + @Test + fun test_matches() { - val guard = VariablesGuard(STRING_VAR.matches { it.startsWith("expected") }) + val guard = VariablesGuard(STRING_VAR.matches { it.startsWith("expected") }) - val vars = createVariables() - STRING_VAR.on(vars).set("some") + val vars = createVariables() + STRING_VAR.on(vars).set("some") - val result = guard.evaluate(vars) + val result = guard.evaluate(vars) - assertThat(result.size).isEqualTo(1) - assertThat(result.first().message).isEqualTo("Expecting variable 'stringVariable' to match the condition, but its value 'some' has not.") - } + assertThat(result.size).isEqualTo(1) + assertThat(result.first().message).isEqualTo("Expecting variable 'stringVariable' to match the condition, but its value 'some' has not.") + } } diff --git a/extension/core/src/test/kotlin/guard/integration/GuardExecutionListenerTest.kt b/extension/core/src/test/kotlin/guard/integration/GuardExecutionListenerTest.kt index 5a5e27fb..2173c767 100644 --- a/extension/core/src/test/kotlin/guard/integration/GuardExecutionListenerTest.kt +++ b/extension/core/src/test/kotlin/guard/integration/GuardExecutionListenerTest.kt @@ -12,47 +12,47 @@ val ORDER_REFERENCE = stringVariable("orderReference") class GuardExecutionListenerTest { - @Suppress("RedundantVisibilityModifier") - @get: Rule - public val thrown = ExpectedException.none() + @Suppress("RedundantVisibilityModifier") + @get: Rule + public val thrown = ExpectedException.none() - @Test - fun `should do nothing`() { - val delegate = DelegateExecutionFake().withId("4711").withCurrentActivityName("some") - ORDER_REFERENCE.on(delegate).set("1") + @Test + fun `should do nothing`() { + val delegate = DelegateExecutionFake().withId("4711").withCurrentActivityName("some") + ORDER_REFERENCE.on(delegate).set("1") - val listener = createListener(true) - listener.notify(delegate) + val listener = createListener(true) + listener.notify(delegate) - // nothing to do here - assertThat(true).isTrue() - } + // nothing to do here + assertThat(true).isTrue() + } - @Test - fun `should not throw exception if disabled `() { - val delegate = DelegateExecutionFake().withId("4711").withCurrentActivityName("some") - ORDER_REFERENCE.on(delegate).set("2") + @Test + fun `should not throw exception if disabled `() { + val delegate = DelegateExecutionFake().withId("4711").withCurrentActivityName("some") + ORDER_REFERENCE.on(delegate).set("2") - val listener = createListener(false) - listener.notify(delegate) + val listener = createListener(false) + listener.notify(delegate) - // nothing to do here - assertThat(true).isTrue() - } + // nothing to do here + assertThat(true).isTrue() + } - @Test - fun `should throw exception if enabled `() { - val delegate = DelegateExecutionFake().withId("4711").withCurrentActivityName("some") - ORDER_REFERENCE.on(delegate).set("2") + @Test + fun `should throw exception if enabled `() { + val delegate = DelegateExecutionFake().withId("4711").withCurrentActivityName("some") + ORDER_REFERENCE.on(delegate).set("2") - thrown.expectMessage("Guard violated by execution '${delegate.id}' in activity '${delegate.currentActivityName}'") + thrown.expectMessage("Guard violated by execution '${delegate.id}' in activity '${delegate.currentActivityName}'") - val listener = createListener(true) - listener.notify(delegate) + val listener = createListener(true) + listener.notify(delegate) - // nothing to do here - assertThat(true).isTrue() - } + // nothing to do here + assertThat(true).isTrue() + } - private fun createListener(throwE: Boolean = true) = DefaultGuardExecutionListener(listOf(ORDER_REFERENCE.hasValue("1")), throwE) -} \ No newline at end of file + private fun createListener(throwE: Boolean = true) = DefaultGuardExecutionListener(listOf(ORDER_REFERENCE.hasValue("1")), throwE) +} diff --git a/extension/core/src/test/kotlin/guard/integration/GuardTaskListenerTest.kt b/extension/core/src/test/kotlin/guard/integration/GuardTaskListenerTest.kt index 35d88e83..72935674 100644 --- a/extension/core/src/test/kotlin/guard/integration/GuardTaskListenerTest.kt +++ b/extension/core/src/test/kotlin/guard/integration/GuardTaskListenerTest.kt @@ -12,47 +12,47 @@ val ORDER_ID = stringVariable("orderID") class GuardTaskListenerTest { - @Suppress("RedundantVisibilityModifier") - @get: Rule - public val thrown = ExpectedException.none() + @Suppress("RedundantVisibilityModifier") + @get: Rule + public val thrown = ExpectedException.none() - @Test - fun `should do nothing`() { - val delegateTask = DelegateTaskFake().withId("4711") - ORDER_ID.on(delegateTask).set("1") + @Test + fun `should do nothing`() { + val delegateTask = DelegateTaskFake().withId("4711") + ORDER_ID.on(delegateTask).set("1") - val listener = createListener(true) - listener.notify(delegateTask) + val listener = createListener(true) + listener.notify(delegateTask) - // nothing to do here - assertThat(true).isTrue() - } + // nothing to do here + assertThat(true).isTrue() + } - @Test - fun `should not throw exception if disabled `() { - val delegateTask = DelegateTaskFake().withId("4711").withName("task name") - ORDER_ID.on(delegateTask).set("2") + @Test + fun `should not throw exception if disabled `() { + val delegateTask = DelegateTaskFake().withId("4711").withName("task name") + ORDER_ID.on(delegateTask).set("2") - val listener = createListener(false) - listener.notify(delegateTask) + val listener = createListener(false) + listener.notify(delegateTask) - // nothing to do here - assertThat(true).isTrue() - } + // nothing to do here + assertThat(true).isTrue() + } - @Test - fun `should throw exception if enabled `() { - val delegateTask = DelegateTaskFake().withId("4711").withName("task name") - ORDER_ID.on(delegateTask).set("2") + @Test + fun `should throw exception if enabled `() { + val delegateTask = DelegateTaskFake().withId("4711").withName("task name") + ORDER_ID.on(delegateTask).set("2") - thrown.expectMessage("Guard violated in task '${delegateTask.name}' (taskId: '${delegateTask.id}')") + thrown.expectMessage("Guard violated in task '${delegateTask.name}' (taskId: '${delegateTask.id}')") - val listener = createListener(true) - listener.notify(delegateTask) + val listener = createListener(true) + listener.notify(delegateTask) - // nothing to do here - assertThat(true).isTrue() - } + // nothing to do here + assertThat(true).isTrue() + } - private fun createListener(throwE: Boolean = true) = DefaultGuardTaskListener(listOf(ORDER_ID.hasValue("1")), throwE) -} \ No newline at end of file + private fun createListener(throwE: Boolean = true) = DefaultGuardTaskListener(listOf(ORDER_ID.hasValue("1")), throwE) +} diff --git a/extension/core/src/test/kotlin/guard/integration/GuardViolationExceptionTest.kt b/extension/core/src/test/kotlin/guard/integration/GuardViolationExceptionTest.kt index c2211f2a..9a1cf468 100644 --- a/extension/core/src/test/kotlin/guard/integration/GuardViolationExceptionTest.kt +++ b/extension/core/src/test/kotlin/guard/integration/GuardViolationExceptionTest.kt @@ -9,19 +9,19 @@ import java.util.* class GuardViolationExceptionTest { - val FOO = CamundaBpmData.stringVariable("foo") - val c1 = CamundaBpmDataGuards.exists(FOO) - val c2 = CamundaBpmDataGuards.hasValue(FOO, "bar") + val FOO = CamundaBpmData.stringVariable("foo") + val c1 = CamundaBpmDataGuards.exists(FOO) + val c2 = CamundaBpmDataGuards.hasValue(FOO, "bar") - @Test - fun buildMessage() { + @Test + fun buildMessage() { - val expected = "reason\n\tnot exists,\n\twrong VAL" - val ex = GuardViolationException(reason = "reason", violations = listOf( - GuardViolation(c1, Optional.empty(), "not exists"), - GuardViolation(c2, Optional.of("VAL"), "wrong VAL") - )) + val expected = "reason\n\tnot exists,\n\twrong VAL" + val ex = GuardViolationException(reason = "reason", violations = listOf( + GuardViolation(c1, Optional.empty(), "not exists"), + GuardViolation(c2, Optional.of("VAL"), "wrong VAL") + )) - assertThat(ex.message).isEqualTo(expected) - } -} \ No newline at end of file + assertThat(ex.message).isEqualTo(expected) + } +} diff --git a/extension/test/src/main/kotlin/CamundaBpmDataMockito.kt b/extension/test/src/main/kotlin/CamundaBpmDataMockito.kt index 102e5ad7..a4e2c0d2 100644 --- a/extension/test/src/main/kotlin/CamundaBpmDataMockito.kt +++ b/extension/test/src/main/kotlin/CamundaBpmDataMockito.kt @@ -10,82 +10,82 @@ import org.camunda.bpm.engine.variable.VariableMap */ object CamundaBpmDataMockito { - /** - * Constructs a task service variable mock builder. - * @param taskService task service mock. - * @return fluent builder. - */ - @JvmStatic - fun taskServiceVariableMockBuilder(taskService: TaskService) = TaskServiceVariableMockBuilder(taskService = taskService) + /** + * Constructs a task service variable mock builder. + * @param taskService task service mock. + * @return fluent builder. + */ + @JvmStatic + fun taskServiceVariableMockBuilder(taskService: TaskService) = TaskServiceVariableMockBuilder(taskService = taskService) - /** - * Constructs a task service variable mock builder. - * @param taskService task service mock. - * @param variables variable map to reuse. - * @param localVariables local variable map to reuse. - * @return fluent builder. - */ - @JvmStatic - fun taskServiceVariableMockBuilder(taskService: TaskService, variables: VariableMap, localVariables: VariableMap) = TaskServiceVariableMockBuilder(taskService = taskService, variables = variables, localVariables = localVariables) + /** + * Constructs a task service variable mock builder. + * @param taskService task service mock. + * @param variables variable map to reuse. + * @param localVariables local variable map to reuse. + * @return fluent builder. + */ + @JvmStatic + fun taskServiceVariableMockBuilder(taskService: TaskService, variables: VariableMap, localVariables: VariableMap) = TaskServiceVariableMockBuilder(taskService = taskService, variables = variables, localVariables = localVariables) - /** - * Constructs a verifier for task service mock. - * @param taskService a mock to work on. - * @return verifier to simplify assertions. - */ - @JvmStatic - fun taskServiceMockVerifier(taskService: TaskService) = TaskServiceMockVerifier(taskService) + /** + * Constructs a verifier for task service mock. + * @param taskService a mock to work on. + * @return verifier to simplify assertions. + */ + @JvmStatic + fun taskServiceMockVerifier(taskService: TaskService) = TaskServiceMockVerifier(taskService) - /** - * Constructs a runtime service variable mock builder. - * @param runtimeService runtime service mock. - * @return fluent builder. - */ - @JvmStatic - fun runtimeServiceVariableMockBuilder(runtimeService: RuntimeService) = RuntimeServiceVariableMockBuilder(runtimeService = runtimeService) + /** + * Constructs a runtime service variable mock builder. + * @param runtimeService runtime service mock. + * @return fluent builder. + */ + @JvmStatic + fun runtimeServiceVariableMockBuilder(runtimeService: RuntimeService) = RuntimeServiceVariableMockBuilder(runtimeService = runtimeService) - /** - * Constructs a runtime service variable mock builder. - * @param runtimeService runtime service mock. - * @param variables variable map to reuse. - * @param localVariables local variable map to reuse. - * @return fluent builder. - */ - @JvmStatic - fun runtimeServiceVariableMockBuilder(runtimeService: RuntimeService, variables: VariableMap, localVariables: VariableMap) = RuntimeServiceVariableMockBuilder(runtimeService = runtimeService, variables = variables, localVariables = localVariables) + /** + * Constructs a runtime service variable mock builder. + * @param runtimeService runtime service mock. + * @param variables variable map to reuse. + * @param localVariables local variable map to reuse. + * @return fluent builder. + */ + @JvmStatic + fun runtimeServiceVariableMockBuilder(runtimeService: RuntimeService, variables: VariableMap, localVariables: VariableMap) = RuntimeServiceVariableMockBuilder(runtimeService = runtimeService, variables = variables, localVariables = localVariables) - /** - * Constructs a verifier for runtime service mock. - * @param runtimeService a mock to work on. - * @return verifier to simplify assertions. - */ - @JvmStatic - fun runtimeServiceMockVerifier(runtimeService: RuntimeService) = RuntimeServiceMockVerifier(runtimeService) + /** + * Constructs a verifier for runtime service mock. + * @param runtimeService a mock to work on. + * @return verifier to simplify assertions. + */ + @JvmStatic + fun runtimeServiceMockVerifier(runtimeService: RuntimeService) = RuntimeServiceMockVerifier(runtimeService) /** - * Constructs a case service variable mock builder. - * @param caseService case service mock. - * @return fluent builder. - */ - @JvmStatic - fun caseServiceVariableMockBuilder(caseService: CaseService) = CaseServiceVariableMockBuilder(caseService = caseService) + * Constructs a case service variable mock builder. + * @param caseService case service mock. + * @return fluent builder. + */ + @JvmStatic + fun caseServiceVariableMockBuilder(caseService: CaseService) = CaseServiceVariableMockBuilder(caseService = caseService) - /** - * Constructs a case service variable mock builder. - * @param caseService case service mock. - * @param variables variable map to reuse. - * @param localVariables local variable map to reuse. - * @return fluent builder. - */ - @JvmStatic - fun caseServiceVariableMockBuilder(caseService: CaseService, variables: VariableMap, localVariables: VariableMap) = CaseServiceVariableMockBuilder(caseService = caseService, variables = variables, localVariables = localVariables) + /** + * Constructs a case service variable mock builder. + * @param caseService case service mock. + * @param variables variable map to reuse. + * @param localVariables local variable map to reuse. + * @return fluent builder. + */ + @JvmStatic + fun caseServiceVariableMockBuilder(caseService: CaseService, variables: VariableMap, localVariables: VariableMap) = CaseServiceVariableMockBuilder(caseService = caseService, variables = variables, localVariables = localVariables) - /** - * Constructs a verifier for case service mock. - * @param caseService a mock to work on. - * @return verifier to simplify assertions. - */ - @JvmStatic - fun caseServiceMockVerifier(caseService: CaseService) = CaseServiceMockVerifier(caseService) + /** + * Constructs a verifier for case service mock. + * @param caseService a mock to work on. + * @return verifier to simplify assertions. + */ + @JvmStatic + fun caseServiceMockVerifier(caseService: CaseService) = CaseServiceMockVerifier(caseService) } diff --git a/extension/test/src/main/kotlin/CaseServiceMockVerifier.kt b/extension/test/src/main/kotlin/CaseServiceMockVerifier.kt index 96fd2ecc..76b08587 100644 --- a/extension/test/src/main/kotlin/CaseServiceMockVerifier.kt +++ b/extension/test/src/main/kotlin/CaseServiceMockVerifier.kt @@ -10,76 +10,76 @@ import org.camunda.bpm.engine.CaseService * Provides methods for easy verification. */ class CaseServiceMockVerifier( - private val caseService: CaseService + private val caseService: CaseService ) { - /** - * Verifies if the variable has been set globally. - * @param variableFactory factory defining the variable. - * @param value value to set. - * @param executionId execution id. - * @param T type of variable. - */ - fun verifySet(variableFactory: VariableFactory, value: T, executionId: String) { - verify(caseService).setVariable(executionId, variableFactory.name, variableFactory.on(caseService, executionId).getTypedValue(value, false)) - } + /** + * Verifies if the variable has been set globally. + * @param variableFactory factory defining the variable. + * @param value value to set. + * @param executionId execution id. + * @param T type of variable. + */ + fun verifySet(variableFactory: VariableFactory, value: T, executionId: String) { + verify(caseService).setVariable(executionId, variableFactory.name, variableFactory.on(caseService, executionId).getTypedValue(value, false)) + } - /** - * Verifies if the variable has been set locally. - * @param variableFactory factory defining the variable. - * @param value value to set. - * @param executionId execution id. - * @param T type of variable. - */ - fun verifySetLocal(variableFactory: VariableFactory, value: T, executionId: String) { - verify(caseService).setVariableLocal(executionId, variableFactory.name, variableFactory.on(caseService, executionId).getTypedValue(value, false)) - } + /** + * Verifies if the variable has been set locally. + * @param variableFactory factory defining the variable. + * @param value value to set. + * @param executionId execution id. + * @param T type of variable. + */ + fun verifySetLocal(variableFactory: VariableFactory, value: T, executionId: String) { + verify(caseService).setVariableLocal(executionId, variableFactory.name, variableFactory.on(caseService, executionId).getTypedValue(value, false)) + } - /** - * Verifies if the variable has been retrieved from a global scope. - * @param variableFactory factory defining the variable. - * @param executionId execution id. - * @param T type of variable. - */ - fun verifyGet(variableFactory: VariableFactory, executionId: String) { - verify(caseService).getVariable(executionId, variableFactory.name) - } + /** + * Verifies if the variable has been retrieved from a global scope. + * @param variableFactory factory defining the variable. + * @param executionId execution id. + * @param T type of variable. + */ + fun verifyGet(variableFactory: VariableFactory, executionId: String) { + verify(caseService).getVariable(executionId, variableFactory.name) + } - /** - * Verifies if the variable has been retrieved from a local scope. - * @param variableFactory factory defining the variable. - * @param executionId execution id. - * @param T type of variable. - */ - fun verifyGetLocal(variableFactory: VariableFactory, executionId: String) { - verify(caseService).getVariableLocal(executionId, variableFactory.name) - } + /** + * Verifies if the variable has been retrieved from a local scope. + * @param variableFactory factory defining the variable. + * @param executionId execution id. + * @param T type of variable. + */ + fun verifyGetLocal(variableFactory: VariableFactory, executionId: String) { + verify(caseService).getVariableLocal(executionId, variableFactory.name) + } - /** - * Verifies if the variable has been removed from a global scope. - * @param variableFactory factory defining the variable. - * @param executionId execution id. - * @param T type of variable. - */ - fun verifyRemove(variableFactory: VariableFactory, executionId: String) { - verify(caseService).removeVariable(executionId, variableFactory.name) - } + /** + * Verifies if the variable has been removed from a global scope. + * @param variableFactory factory defining the variable. + * @param executionId execution id. + * @param T type of variable. + */ + fun verifyRemove(variableFactory: VariableFactory, executionId: String) { + verify(caseService).removeVariable(executionId, variableFactory.name) + } - /** - * Verifies if the variable has been removed from a local scope. - * @param variableFactory factory defining the variable. - * @param executionId execution id. - * @param T type of variable. - */ - fun verifyRemoveLocal(variableFactory: VariableFactory, executionId: String) { - verify(caseService).removeVariable(executionId, variableFactory.name) - } + /** + * Verifies if the variable has been removed from a local scope. + * @param variableFactory factory defining the variable. + * @param executionId execution id. + * @param T type of variable. + */ + fun verifyRemoveLocal(variableFactory: VariableFactory, executionId: String) { + verify(caseService).removeVariable(executionId, variableFactory.name) + } - /** - * Verifies no more interaction has been performed with the mock. - * @see com.nhaarman.mockito_kotlin.verifyNoMoreInteractions - */ - fun verifyNoMoreInteractions() { - verifyNoMoreInteractions(caseService) - } + /** + * Verifies no more interaction has been performed with the mock. + * @see com.nhaarman.mockito_kotlin.verifyNoMoreInteractions + */ + fun verifyNoMoreInteractions() { + verifyNoMoreInteractions(caseService) + } } diff --git a/extension/test/src/main/kotlin/CaseServiceVariableMockBuilder.kt b/extension/test/src/main/kotlin/CaseServiceVariableMockBuilder.kt index 4b44f32d..4ed20039 100644 --- a/extension/test/src/main/kotlin/CaseServiceVariableMockBuilder.kt +++ b/extension/test/src/main/kotlin/CaseServiceVariableMockBuilder.kt @@ -22,82 +22,82 @@ class CaseServiceVariableMockBuilder( private val factories: MutableList> = mutableListOf() ) { - /** - * Defines a variable. - * @param variableFactory variable to define. - * @return fluent builder. - */ - fun define(variableFactory: VariableFactory): CaseServiceVariableMockBuilder { - factories.add(variableFactory) - return this - } + /** + * Defines a variable. + * @param variableFactory variable to define. + * @return fluent builder. + */ + fun define(variableFactory: VariableFactory): CaseServiceVariableMockBuilder { + factories.add(variableFactory) + return this + } - /** - * Defines a variable and sets a global value. - * @param variableFactory factory to use. - * @param value initial value. - * @return fluent builder. - */ - fun initial(variableFactory: VariableFactory, value: T): CaseServiceVariableMockBuilder { - define(variableFactory) - variableFactory.on(variables).set(value) - return this - } + /** + * Defines a variable and sets a global value. + * @param variableFactory factory to use. + * @param value initial value. + * @return fluent builder. + */ + fun initial(variableFactory: VariableFactory, value: T): CaseServiceVariableMockBuilder { + define(variableFactory) + variableFactory.on(variables).set(value) + return this + } - /** - * Defines a variable and sets a local value. - * @param variableFactory factory to use. - * @param value initial value. - * @return fluent builder. - */ - fun initialLocal(variableFactory: VariableFactory, value: T): CaseServiceVariableMockBuilder { - define(variableFactory) - variableFactory.on(localVariables).set(value) - return this - } + /** + * Defines a variable and sets a local value. + * @param variableFactory factory to use. + * @param value initial value. + * @return fluent builder. + */ + fun initialLocal(variableFactory: VariableFactory, value: T): CaseServiceVariableMockBuilder { + define(variableFactory) + variableFactory.on(localVariables).set(value) + return this + } - /** - * Performs the modifications on the task service. - */ - fun build() { + /** + * Performs the modifications on the task service. + */ + fun build() { - factories.forEach { factory -> + factories.forEach { factory -> - // global - doAnswer { - factory.from(variables).get() - }.whenever(caseService).getVariable(anyString(), eq(factory.name)) + // global + doAnswer { + factory.from(variables).get() + }.whenever(caseService).getVariable(anyString(), eq(factory.name)) - doAnswer { invocation -> - // Arguments: 0: taskId, 1: variable name, 2: value - val value = invocation.getArgument(2) - variables[factory.name] = value - }.whenever(caseService).setVariable(anyString(), eq(factory.name), any()) + doAnswer { invocation -> + // Arguments: 0: taskId, 1: variable name, 2: value + val value = invocation.getArgument(2) + variables[factory.name] = value + }.whenever(caseService).setVariable(anyString(), eq(factory.name), any()) - // local - doAnswer { - factory.from(localVariables).get() - }.whenever(caseService).getVariableLocal(anyString(), eq(factory.name)) + // local + doAnswer { + factory.from(localVariables).get() + }.whenever(caseService).getVariableLocal(anyString(), eq(factory.name)) - doAnswer { invocation -> - // Arguments: 0: taskId, 1: variable name, 2: value - val value = invocation.getArgument(2) - localVariables[factory.name] = value - }.whenever(caseService).setVariableLocal(anyString(), eq(factory.name), any()) - } + doAnswer { invocation -> + // Arguments: 0: taskId, 1: variable name, 2: value + val value = invocation.getArgument(2) + localVariables[factory.name] = value + }.whenever(caseService).setVariableLocal(anyString(), eq(factory.name), any()) + } - doAnswer { variables }.whenever(caseService).getVariables(anyString()) - doAnswer { invocation -> - // Arguments: 0: taskId, 1: licat of variables - val variablesList = invocation.getArgument>(1) - variables.filter { variablesList.contains(it.key) } - }.whenever(caseService).getVariables(anyString(), anyList()) + doAnswer { variables }.whenever(caseService).getVariables(anyString()) + doAnswer { invocation -> + // Arguments: 0: taskId, 1: licat of variables + val variablesList = invocation.getArgument>(1) + variables.filter { variablesList.contains(it.key) } + }.whenever(caseService).getVariables(anyString(), anyList()) - doAnswer { localVariables }.whenever(caseService).getVariablesLocal(anyString()) - doAnswer { invocation -> - // Arguments: 0: taskId, 1: licat of variables - val variablesList = invocation.getArgument>(1) - localVariables.filter { variablesList.contains(it.key) } - }.whenever(caseService).getVariablesLocal(anyString(), anyList()) - } + doAnswer { localVariables }.whenever(caseService).getVariablesLocal(anyString()) + doAnswer { invocation -> + // Arguments: 0: taskId, 1: licat of variables + val variablesList = invocation.getArgument>(1) + localVariables.filter { variablesList.contains(it.key) } + }.whenever(caseService).getVariablesLocal(anyString(), anyList()) + } } diff --git a/extension/test/src/main/kotlin/RuntimeServiceMockVerifier.kt b/extension/test/src/main/kotlin/RuntimeServiceMockVerifier.kt index 4563393c..6818da9e 100644 --- a/extension/test/src/main/kotlin/RuntimeServiceMockVerifier.kt +++ b/extension/test/src/main/kotlin/RuntimeServiceMockVerifier.kt @@ -10,76 +10,76 @@ import org.camunda.bpm.engine.RuntimeService * Provides methods for easy verification. */ class RuntimeServiceMockVerifier( - private val runtimeService: RuntimeService + private val runtimeService: RuntimeService ) { - /** - * Verifies if the variable has been set globally. - * @param variableFactory factory defining the variable. - * @param value value to set. - * @param executionId execution id. - * @param T type of variable. - */ - fun verifySet(variableFactory: VariableFactory, value: T, executionId: String) { - verify(runtimeService).setVariable(executionId, variableFactory.name, variableFactory.on(runtimeService, executionId).getTypedValue(value, false)) - } + /** + * Verifies if the variable has been set globally. + * @param variableFactory factory defining the variable. + * @param value value to set. + * @param executionId execution id. + * @param T type of variable. + */ + fun verifySet(variableFactory: VariableFactory, value: T, executionId: String) { + verify(runtimeService).setVariable(executionId, variableFactory.name, variableFactory.on(runtimeService, executionId).getTypedValue(value, false)) + } - /** - * Verifies if the variable has been set locally. - * @param variableFactory factory defining the variable. - * @param value value to set. - * @param executionId execution id. - * @param T type of variable. - */ - fun verifySetLocal(variableFactory: VariableFactory, value: T, executionId: String) { - verify(runtimeService).setVariableLocal(executionId, variableFactory.name, variableFactory.on(runtimeService, executionId).getTypedValue(value, false)) - } + /** + * Verifies if the variable has been set locally. + * @param variableFactory factory defining the variable. + * @param value value to set. + * @param executionId execution id. + * @param T type of variable. + */ + fun verifySetLocal(variableFactory: VariableFactory, value: T, executionId: String) { + verify(runtimeService).setVariableLocal(executionId, variableFactory.name, variableFactory.on(runtimeService, executionId).getTypedValue(value, false)) + } - /** - * Verifies if the variable has been retrieved from a global scope. - * @param variableFactory factory defining the variable. - * @param executionId execution id. - * @param T type of variable. - */ - fun verifyGet(variableFactory: VariableFactory, executionId: String) { - verify(runtimeService).getVariable(executionId, variableFactory.name) - } + /** + * Verifies if the variable has been retrieved from a global scope. + * @param variableFactory factory defining the variable. + * @param executionId execution id. + * @param T type of variable. + */ + fun verifyGet(variableFactory: VariableFactory, executionId: String) { + verify(runtimeService).getVariable(executionId, variableFactory.name) + } - /** - * Verifies if the variable has been retrieved from a local scope. - * @param variableFactory factory defining the variable. - * @param executionId execution id. - * @param T type of variable. - */ - fun verifyGetLocal(variableFactory: VariableFactory, executionId: String) { - verify(runtimeService).getVariableLocal(executionId, variableFactory.name) - } + /** + * Verifies if the variable has been retrieved from a local scope. + * @param variableFactory factory defining the variable. + * @param executionId execution id. + * @param T type of variable. + */ + fun verifyGetLocal(variableFactory: VariableFactory, executionId: String) { + verify(runtimeService).getVariableLocal(executionId, variableFactory.name) + } - /** - * Verifies if the variable has been removed from a global scope. - * @param variableFactory factory defining the variable. - * @param executionId execution id. - * @param T type of variable. - */ - fun verifyRemove(variableFactory: VariableFactory, executionId: String) { - verify(runtimeService).removeVariable(executionId, variableFactory.name) - } + /** + * Verifies if the variable has been removed from a global scope. + * @param variableFactory factory defining the variable. + * @param executionId execution id. + * @param T type of variable. + */ + fun verifyRemove(variableFactory: VariableFactory, executionId: String) { + verify(runtimeService).removeVariable(executionId, variableFactory.name) + } - /** - * Verifies if the variable has been removed from a local scope. - * @param variableFactory factory defining the variable. - * @param executionId execution id. - * @param T type of variable. - */ - fun verifyRemoveLocal(variableFactory: VariableFactory, executionId: String) { - verify(runtimeService).removeVariable(executionId, variableFactory.name) - } + /** + * Verifies if the variable has been removed from a local scope. + * @param variableFactory factory defining the variable. + * @param executionId execution id. + * @param T type of variable. + */ + fun verifyRemoveLocal(variableFactory: VariableFactory, executionId: String) { + verify(runtimeService).removeVariable(executionId, variableFactory.name) + } - /** - * Verifies no more interaction has been performed with the mock. - * @see com.nhaarman.mockito_kotlin.verifyNoMoreInteractions - */ - fun verifyNoMoreInteractions() { - verifyNoMoreInteractions(runtimeService) - } -} \ No newline at end of file + /** + * Verifies no more interaction has been performed with the mock. + * @see com.nhaarman.mockito_kotlin.verifyNoMoreInteractions + */ + fun verifyNoMoreInteractions() { + verifyNoMoreInteractions(runtimeService) + } +} diff --git a/extension/test/src/main/kotlin/RuntimeServiceVariableMockBuilder.kt b/extension/test/src/main/kotlin/RuntimeServiceVariableMockBuilder.kt index efaeea18..8b281e3e 100644 --- a/extension/test/src/main/kotlin/RuntimeServiceVariableMockBuilder.kt +++ b/extension/test/src/main/kotlin/RuntimeServiceVariableMockBuilder.kt @@ -15,88 +15,88 @@ import org.mockito.ArgumentMatchers.anyString * Builder to mock the runtime service behavior regarding variables. */ class RuntimeServiceVariableMockBuilder( - private val runtimeService: RuntimeService, - private val variables: VariableMap = createVariables(), - private val localVariables: VariableMap = createVariables(), - private val factories: MutableList> = mutableListOf() + private val runtimeService: RuntimeService, + private val variables: VariableMap = createVariables(), + private val localVariables: VariableMap = createVariables(), + private val factories: MutableList> = mutableListOf() ) { - /** - * Defines a variable. - * @param variableFactory variable to define. - * @return fluent builder. - */ - fun define(variableFactory: VariableFactory): RuntimeServiceVariableMockBuilder { - factories.add(variableFactory) - return this - } + /** + * Defines a variable. + * @param variableFactory variable to define. + * @return fluent builder. + */ + fun define(variableFactory: VariableFactory): RuntimeServiceVariableMockBuilder { + factories.add(variableFactory) + return this + } - /** - * Defines a variable and sets a global value. - * @param variableFactory factory to use. - * @param value initial value. - * @return fluent builder. - */ - fun initial(variableFactory: VariableFactory, value: T): RuntimeServiceVariableMockBuilder { - define(variableFactory) - variableFactory.on(variables).set(value) - return this - } + /** + * Defines a variable and sets a global value. + * @param variableFactory factory to use. + * @param value initial value. + * @return fluent builder. + */ + fun initial(variableFactory: VariableFactory, value: T): RuntimeServiceVariableMockBuilder { + define(variableFactory) + variableFactory.on(variables).set(value) + return this + } - /** - * Defines a variable and sets a local value. - * @param variableFactory factory to use. - * @param value initial value. - * @return fluent builder. - */ - fun initialLocal(variableFactory: VariableFactory, value: T): RuntimeServiceVariableMockBuilder { - define(variableFactory) - variableFactory.on(localVariables).set(value) - return this - } + /** + * Defines a variable and sets a local value. + * @param variableFactory factory to use. + * @param value initial value. + * @return fluent builder. + */ + fun initialLocal(variableFactory: VariableFactory, value: T): RuntimeServiceVariableMockBuilder { + define(variableFactory) + variableFactory.on(localVariables).set(value) + return this + } - /** - * Performs the modifications on the task service. - */ - fun build() { + /** + * Performs the modifications on the task service. + */ + fun build() { - factories.forEach { factory -> + factories.forEach { factory -> - // global - doAnswer { - factory.from(variables).get() - }.whenever(runtimeService).getVariable(anyString(), eq(factory.name)) + // global + doAnswer { + factory.from(variables).get() + }.whenever(runtimeService).getVariable(anyString(), eq(factory.name)) - doAnswer { invocation -> - // Arguments: 0: taskId, 1: variable name, 2: value - val value = invocation.getArgument(2) - variables[factory.name] = value - }.whenever(runtimeService).setVariable(anyString(), eq(factory.name), any()) + doAnswer { invocation -> + // Arguments: 0: taskId, 1: variable name, 2: value + val value = invocation.getArgument(2) + variables[factory.name] = value + }.whenever(runtimeService).setVariable(anyString(), eq(factory.name), any()) - // local - doAnswer { - factory.from(localVariables).get() - }.whenever(runtimeService).getVariableLocal(anyString(), eq(factory.name)) + // local + doAnswer { + factory.from(localVariables).get() + }.whenever(runtimeService).getVariableLocal(anyString(), eq(factory.name)) - doAnswer { invocation -> - // Arguments: 0: taskId, 1: variable name, 2: value - val value = invocation.getArgument(2) - localVariables[factory.name] = value - }.whenever(runtimeService).setVariableLocal(anyString(), eq(factory.name), any()) - } + doAnswer { invocation -> + // Arguments: 0: taskId, 1: variable name, 2: value + val value = invocation.getArgument(2) + localVariables[factory.name] = value + }.whenever(runtimeService).setVariableLocal(anyString(), eq(factory.name), any()) + } - doAnswer { variables }.whenever(runtimeService).getVariables(anyString()) - doAnswer { invocation -> - // Arguments: 0: taskId, 1: licat of variables - val variablesList = invocation.getArgument>(1) - variables.filter { variablesList.contains(it.key) } - }.whenever(runtimeService).getVariables(anyString(), anyList()) + doAnswer { variables }.whenever(runtimeService).getVariables(anyString()) + doAnswer { invocation -> + // Arguments: 0: taskId, 1: licat of variables + val variablesList = invocation.getArgument>(1) + variables.filter { variablesList.contains(it.key) } + }.whenever(runtimeService).getVariables(anyString(), anyList()) - doAnswer { localVariables }.whenever(runtimeService).getVariablesLocal(anyString()) - doAnswer { invocation -> - // Arguments: 0: taskId, 1: licat of variables - val variablesList = invocation.getArgument>(1) - localVariables.filter { variablesList.contains(it.key) } - }.whenever(runtimeService).getVariablesLocal(anyString(), anyList()) - } -} \ No newline at end of file + doAnswer { localVariables }.whenever(runtimeService).getVariablesLocal(anyString()) + doAnswer { invocation -> + // Arguments: 0: taskId, 1: licat of variables + val variablesList = invocation.getArgument>(1) + localVariables.filter { variablesList.contains(it.key) } + }.whenever(runtimeService).getVariablesLocal(anyString(), anyList()) + } +} diff --git a/extension/test/src/main/kotlin/TaskServiceMockVerifier.kt b/extension/test/src/main/kotlin/TaskServiceMockVerifier.kt index 9247b3c0..83edff74 100644 --- a/extension/test/src/main/kotlin/TaskServiceMockVerifier.kt +++ b/extension/test/src/main/kotlin/TaskServiceMockVerifier.kt @@ -11,93 +11,93 @@ import org.camunda.bpm.engine.variable.VariableMap * Provides methods for easy verification. */ class TaskServiceMockVerifier( - private val taskService: TaskService + private val taskService: TaskService ) { - /** - * Verifies if the variable has been set globally. - * @param variableFactory factory defining the variable. - * @param value value to set. - * @param taskId task id. - * @param T type of variable. - */ - fun verifySet(variableFactory: VariableFactory, value: T, taskId: String) { - verify(taskService).setVariable(taskId, variableFactory.name, variableFactory.on(taskService, taskId).getTypedValue(value, false)) - } + /** + * Verifies if the variable has been set globally. + * @param variableFactory factory defining the variable. + * @param value value to set. + * @param taskId task id. + * @param T type of variable. + */ + fun verifySet(variableFactory: VariableFactory, value: T, taskId: String) { + verify(taskService).setVariable(taskId, variableFactory.name, variableFactory.on(taskService, taskId).getTypedValue(value, false)) + } - /** - * Verifies if the variable has been set locally. - * @param variableFactory factory defining the variable. - * @param value value to set. - * @param taskId task id. - * @param T type of variable. - */ - fun verifySetLocal(variableFactory: VariableFactory, value: T, taskId: String) { - verify(taskService).setVariableLocal(taskId, variableFactory.name, variableFactory.on(taskService, taskId).getTypedValue(value, false)) - } + /** + * Verifies if the variable has been set locally. + * @param variableFactory factory defining the variable. + * @param value value to set. + * @param taskId task id. + * @param T type of variable. + */ + fun verifySetLocal(variableFactory: VariableFactory, value: T, taskId: String) { + verify(taskService).setVariableLocal(taskId, variableFactory.name, variableFactory.on(taskService, taskId).getTypedValue(value, false)) + } - /** - * Verifies if the variable has been retrieved from a global scope. - * @param variableFactory factory defining the variable. - * @param taskId task id. - * @param T type of variable. - */ - fun verifyGet(variableFactory: VariableFactory, taskId: String) { - verify(taskService).getVariable(taskId, variableFactory.name) - } + /** + * Verifies if the variable has been retrieved from a global scope. + * @param variableFactory factory defining the variable. + * @param taskId task id. + * @param T type of variable. + */ + fun verifyGet(variableFactory: VariableFactory, taskId: String) { + verify(taskService).getVariable(taskId, variableFactory.name) + } - /** - * Verifies if the variable has been retrieved from a local scope. - * @param variableFactory factory defining the variable. - * @param taskId task id. - * @param T type of variable. - */ - fun verifyGetLocal(variableFactory: VariableFactory, taskId: String) { - verify(taskService).getVariableLocal(taskId, variableFactory.name) - } + /** + * Verifies if the variable has been retrieved from a local scope. + * @param variableFactory factory defining the variable. + * @param taskId task id. + * @param T type of variable. + */ + fun verifyGetLocal(variableFactory: VariableFactory, taskId: String) { + verify(taskService).getVariableLocal(taskId, variableFactory.name) + } - /** - * Verifies if the variable has been removed from a global scope. - * @param variableFactory factory defining the variable. - * @param taskId task id. - * @param T type of variable. - */ - fun verifyRemove(variableFactory: VariableFactory, taskId: String) { - verify(taskService).removeVariable(taskId, variableFactory.name) - } + /** + * Verifies if the variable has been removed from a global scope. + * @param variableFactory factory defining the variable. + * @param taskId task id. + * @param T type of variable. + */ + fun verifyRemove(variableFactory: VariableFactory, taskId: String) { + verify(taskService).removeVariable(taskId, variableFactory.name) + } - /** - * Verifies if the variable has been removed from a local scope. - * @param variableFactory factory defining the variable. - * @param taskId task id. - * @param T type of variable. - */ - fun verifyRemoveLocal(variableFactory: VariableFactory, taskId: String) { - verify(taskService).removeVariable(taskId, variableFactory.name) - } + /** + * Verifies if the variable has been removed from a local scope. + * @param variableFactory factory defining the variable. + * @param taskId task id. + * @param T type of variable. + */ + fun verifyRemoveLocal(variableFactory: VariableFactory, taskId: String) { + verify(taskService).removeVariable(taskId, variableFactory.name) + } - /** - * Verifies if the task has been completed without variables. - * @param taskId task id. - */ - fun verifyComplete(taskId: String) { - verify(taskService).complete(taskId) - } + /** + * Verifies if the task has been completed without variables. + * @param taskId task id. + */ + fun verifyComplete(taskId: String) { + verify(taskService).complete(taskId) + } - /** - * Verifies if the task has been completed with variables. - * @param taskId task id. - * @param variables variables to complete the task. - */ - fun verifyComplete(variables: VariableMap, taskId: String) { - verify(taskService).complete(taskId, variables) - } + /** + * Verifies if the task has been completed with variables. + * @param taskId task id. + * @param variables variables to complete the task. + */ + fun verifyComplete(variables: VariableMap, taskId: String) { + verify(taskService).complete(taskId, variables) + } - /** - * Verifies no more interaction has been performed with the mock. - * @see com.nhaarman.mockito_kotlin.verifyNoMoreInteractions - */ - fun verifyNoMoreInteractions() { - verifyNoMoreInteractions(taskService) - } -} \ No newline at end of file + /** + * Verifies no more interaction has been performed with the mock. + * @see com.nhaarman.mockito_kotlin.verifyNoMoreInteractions + */ + fun verifyNoMoreInteractions() { + verifyNoMoreInteractions(taskService) + } +} diff --git a/extension/test/src/main/kotlin/TaskServiceVariableMockBuilder.kt b/extension/test/src/main/kotlin/TaskServiceVariableMockBuilder.kt index d9b2cb8f..03678334 100644 --- a/extension/test/src/main/kotlin/TaskServiceVariableMockBuilder.kt +++ b/extension/test/src/main/kotlin/TaskServiceVariableMockBuilder.kt @@ -15,87 +15,87 @@ import org.mockito.ArgumentMatchers.anyString * Builder to mock the task service behavior regarding variables. */ class TaskServiceVariableMockBuilder( - private val taskService: TaskService, - private val variables: VariableMap = createVariables(), - private val localVariables: VariableMap = createVariables(), - private val factories: MutableList> = mutableListOf() + private val taskService: TaskService, + private val variables: VariableMap = createVariables(), + private val localVariables: VariableMap = createVariables(), + private val factories: MutableList> = mutableListOf() ) { - /** - * Defines a global variable. - * @param variableFactory variable to define. - * @return fluent builder. - */ - fun define(variableFactory: VariableFactory): TaskServiceVariableMockBuilder { - factories.add(variableFactory) - return this - } + /** + * Defines a global variable. + * @param variableFactory variable to define. + * @return fluent builder. + */ + fun define(variableFactory: VariableFactory): TaskServiceVariableMockBuilder { + factories.add(variableFactory) + return this + } - /** - * Defines a variable and sets an initial global value. - * @param variableFactory factory to use. - * @param value initial value. - * @return fluent builder. - */ - fun initial(variableFactory: VariableFactory, value: T): TaskServiceVariableMockBuilder { - define(variableFactory) - variableFactory.on(variables).set(value) - return this - } + /** + * Defines a variable and sets an initial global value. + * @param variableFactory factory to use. + * @param value initial value. + * @return fluent builder. + */ + fun initial(variableFactory: VariableFactory, value: T): TaskServiceVariableMockBuilder { + define(variableFactory) + variableFactory.on(variables).set(value) + return this + } - /** - * Defines a variable and sets an initial local value. - * @param variableFactory factory to use. - * @param value initial value. - * @return fluent builder. - */ - fun initialLocal(variableFactory: VariableFactory, value: T): TaskServiceVariableMockBuilder { - factories.add(variableFactory) - variableFactory.on(localVariables).set(value) - return this - } + /** + * Defines a variable and sets an initial local value. + * @param variableFactory factory to use. + * @param value initial value. + * @return fluent builder. + */ + fun initialLocal(variableFactory: VariableFactory, value: T): TaskServiceVariableMockBuilder { + factories.add(variableFactory) + variableFactory.on(localVariables).set(value) + return this + } - /** - * Performs the modifications on the task service. - */ - fun build() { + /** + * Performs the modifications on the task service. + */ + fun build() { - factories.forEach { factory -> + factories.forEach { factory -> - // global - doAnswer { - factory.from(variables).get() - }.whenever(taskService).getVariable(anyString(), eq(factory.name)) + // global + doAnswer { + factory.from(variables).get() + }.whenever(taskService).getVariable(anyString(), eq(factory.name)) - doAnswer { invocation -> - // Arguments: 0: taskId, 1: variable name, 2: value - val value = invocation.getArgument(2) - variables[factory.name] = value - }.whenever(taskService).setVariable(anyString(), eq(factory.name), any()) + doAnswer { invocation -> + // Arguments: 0: taskId, 1: variable name, 2: value + val value = invocation.getArgument(2) + variables[factory.name] = value + }.whenever(taskService).setVariable(anyString(), eq(factory.name), any()) - // local - doAnswer { - factory.from(localVariables).get() - }.whenever(taskService).getVariableLocal(anyString(), eq(factory.name)) + // local + doAnswer { + factory.from(localVariables).get() + }.whenever(taskService).getVariableLocal(anyString(), eq(factory.name)) - doAnswer { invocation -> - // Arguments: 0: taskId, 1: variable name, 2: value - val value = invocation.getArgument(2) - localVariables[factory.name] = value - }.whenever(taskService).setVariableLocal(anyString(), eq(factory.name), any()) - } - - doAnswer { variables }.whenever(taskService).getVariables(anyString()) - doAnswer { invocation -> - // Arguments: 0: taskId, 1: licat of variables - val variablesList = invocation.getArgument>(1) - variables.filter { variablesList.contains(it.key) } - }.whenever(taskService).getVariables(anyString(), anyList()) - doAnswer { localVariables }.whenever(taskService).getVariablesLocal(anyString()) - doAnswer { invocation -> - // Arguments: 0: taskId, 1: licat of variables - val variablesList = invocation.getArgument>(1) - localVariables.filter { variablesList.contains(it.key) } - }.whenever(taskService).getVariablesLocal(anyString(), anyList()) + doAnswer { invocation -> + // Arguments: 0: taskId, 1: variable name, 2: value + val value = invocation.getArgument(2) + localVariables[factory.name] = value + }.whenever(taskService).setVariableLocal(anyString(), eq(factory.name), any()) } -} \ No newline at end of file + + doAnswer { variables }.whenever(taskService).getVariables(anyString()) + doAnswer { invocation -> + // Arguments: 0: taskId, 1: licat of variables + val variablesList = invocation.getArgument>(1) + variables.filter { variablesList.contains(it.key) } + }.whenever(taskService).getVariables(anyString(), anyList()) + doAnswer { localVariables }.whenever(taskService).getVariablesLocal(anyString()) + doAnswer { invocation -> + // Arguments: 0: taskId, 1: licat of variables + val variablesList = invocation.getArgument>(1) + localVariables.filter { variablesList.contains(it.key) } + }.whenever(taskService).getVariablesLocal(anyString(), anyList()) + } +} diff --git a/extension/test/src/test/kotlin/CaseServiceMockingTest.kt b/extension/test/src/test/kotlin/CaseServiceMockingTest.kt index c40346c1..09a8844e 100644 --- a/extension/test/src/test/kotlin/CaseServiceMockingTest.kt +++ b/extension/test/src/test/kotlin/CaseServiceMockingTest.kt @@ -13,56 +13,56 @@ import java.util.* */ class CaseServiceMockingTest { - companion object { - val ORDER_ID = stringVariable("orderId") - val ORDER_FLAG = booleanVariable("orderFlag") - } + companion object { + val ORDER_ID = stringVariable("orderId") + val ORDER_FLAG = booleanVariable("orderFlag") + } - private val caseService = mock() - private val testService = CaseServiceAwareService(caseService) + private val caseService = mock() + private val testService = CaseServiceAwareService(caseService) - @Test - fun should_mock_task_service() { + @Test + fun should_mock_task_service() { - val executionId = UUID.randomUUID().toString() + val executionId = UUID.randomUUID().toString() - CaseServiceVariableMockBuilder(caseService) - .initialLocal(ORDER_ID, "initial-Value") - .define(ORDER_FLAG) - .build() + CaseServiceVariableMockBuilder(caseService) + .initialLocal(ORDER_ID, "initial-Value") + .define(ORDER_FLAG) + .build() - testService.writeLocalOrderId(executionId, "4712") - val orderId = testService.readLocalOrderId(executionId) + testService.writeLocalOrderId(executionId, "4712") + val orderId = testService.readLocalOrderId(executionId) - assertThat(testService.flagExists(executionId)).isFalse() - testService.writeFlag(executionId, true) - assertThat(testService.flagExists(executionId)).isTrue() - val orderFlag = testService.readFlag(executionId) + assertThat(testService.flagExists(executionId)).isFalse() + testService.writeFlag(executionId, true) + assertThat(testService.flagExists(executionId)).isTrue() + val orderFlag = testService.readFlag(executionId) - assertThat(orderId).isEqualTo("4712") - assertThat(orderFlag).isEqualTo(true) - } + assertThat(orderId).isEqualTo("4712") + assertThat(orderFlag).isEqualTo(true) + } - /** - * Test service. - * @param runtimeService task service to work on. - */ - class CaseServiceAwareService(val caseService: CaseService) { + /** + * Test service. + * @param runtimeService task service to work on. + */ + class CaseServiceAwareService(val caseService: CaseService) { - fun readLocalOrderId(executionId: String): String = - ORDER_ID.from(caseService, executionId).local + fun readLocalOrderId(executionId: String): String = + ORDER_ID.from(caseService, executionId).local - fun writeLocalOrderId(executionId: String, value: String) = - ORDER_ID.on(caseService, executionId).setLocal(value) + fun writeLocalOrderId(executionId: String, value: String) = + ORDER_ID.on(caseService, executionId).setLocal(value) - fun flagExists(executionId: String) = - caseService.getVariables(executionId).containsKey(ORDER_FLAG.name) + fun flagExists(executionId: String) = + caseService.getVariables(executionId).containsKey(ORDER_FLAG.name) - fun writeFlag(executionId: String, flag: Boolean) = - ORDER_FLAG.on(caseService, executionId).set(flag) + fun writeFlag(executionId: String, flag: Boolean) = + ORDER_FLAG.on(caseService, executionId).set(flag) - fun readFlag(executionId: String): Boolean = - ORDER_FLAG.from(caseService, executionId).get() - } + fun readFlag(executionId: String): Boolean = + ORDER_FLAG.from(caseService, executionId).get() + } } diff --git a/extension/test/src/test/kotlin/RuntimeServiceMockingTest.kt b/extension/test/src/test/kotlin/RuntimeServiceMockingTest.kt index 0653e517..abbc5c74 100644 --- a/extension/test/src/test/kotlin/RuntimeServiceMockingTest.kt +++ b/extension/test/src/test/kotlin/RuntimeServiceMockingTest.kt @@ -13,56 +13,56 @@ import java.util.* */ class RuntimeServiceMockingTest { - companion object { - val ORDER_ID = stringVariable("orderId") - val ORDER_FLAG = booleanVariable("orderFlag") - } + companion object { + val ORDER_ID = stringVariable("orderId") + val ORDER_FLAG = booleanVariable("orderFlag") + } - private val runtimeService = mock() - private val testService = RuntimeServiceAwareService(runtimeService) + private val runtimeService = mock() + private val testService = RuntimeServiceAwareService(runtimeService) - @Test - fun should_mock_task_service() { + @Test + fun should_mock_task_service() { - val executionId = UUID.randomUUID().toString() + val executionId = UUID.randomUUID().toString() - RuntimeServiceVariableMockBuilder(runtimeService) - .initialLocal(ORDER_ID, "initial-Value") - .define(ORDER_FLAG) - .build() + RuntimeServiceVariableMockBuilder(runtimeService) + .initialLocal(ORDER_ID, "initial-Value") + .define(ORDER_FLAG) + .build() - testService.writeLocalOrderId(executionId, "4712") - val orderId = testService.readLocalOrderId(executionId) + testService.writeLocalOrderId(executionId, "4712") + val orderId = testService.readLocalOrderId(executionId) - assertThat(testService.flagExists(executionId)).isFalse() - testService.writeFlag(executionId, true) - assertThat(testService.flagExists(executionId)).isTrue() - val orderFlag = testService.readFlag(executionId) + assertThat(testService.flagExists(executionId)).isFalse() + testService.writeFlag(executionId, true) + assertThat(testService.flagExists(executionId)).isTrue() + val orderFlag = testService.readFlag(executionId) - assertThat(orderId).isEqualTo("4712") - assertThat(orderFlag).isEqualTo(true) - } + assertThat(orderId).isEqualTo("4712") + assertThat(orderFlag).isEqualTo(true) + } - /** - * Test service. - * @param runtimeService task service to work on. - */ - class RuntimeServiceAwareService(val runtimeService: RuntimeService) { + /** + * Test service. + * @param runtimeService task service to work on. + */ + class RuntimeServiceAwareService(val runtimeService: RuntimeService) { - fun readLocalOrderId(executionId: String): String = - ORDER_ID.from(runtimeService, executionId).local + fun readLocalOrderId(executionId: String): String = + ORDER_ID.from(runtimeService, executionId).local - fun writeLocalOrderId(executionId: String, value: String) = - ORDER_ID.on(runtimeService, executionId).setLocal(value) + fun writeLocalOrderId(executionId: String, value: String) = + ORDER_ID.on(runtimeService, executionId).setLocal(value) - fun flagExists(executionId: String) = - runtimeService.getVariables(executionId).containsKey(ORDER_FLAG.name) + fun flagExists(executionId: String) = + runtimeService.getVariables(executionId).containsKey(ORDER_FLAG.name) - fun writeFlag(executionId: String, flag: Boolean) = - ORDER_FLAG.on(runtimeService, executionId).set(flag) + fun writeFlag(executionId: String, flag: Boolean) = + ORDER_FLAG.on(runtimeService, executionId).set(flag) - fun readFlag(executionId: String): Boolean = - ORDER_FLAG.from(runtimeService, executionId).get() - } -} \ No newline at end of file + fun readFlag(executionId: String): Boolean = + ORDER_FLAG.from(runtimeService, executionId).get() + } +} diff --git a/extension/test/src/test/kotlin/RuntimeServiceVerifierTest.kt b/extension/test/src/test/kotlin/RuntimeServiceVerifierTest.kt index 5c4fa03b..5e87869d 100644 --- a/extension/test/src/test/kotlin/RuntimeServiceVerifierTest.kt +++ b/extension/test/src/test/kotlin/RuntimeServiceVerifierTest.kt @@ -12,74 +12,74 @@ import java.util.* class RuntimeServiceVerifierTest { - companion object { - val VAR = stringVariable("var") - } + companion object { + val VAR = stringVariable("var") + } - private val runtimeService = mock() + private val runtimeService = mock() - @Before - fun resetMocks() { - reset(runtimeService) - } + @Before + fun resetMocks() { + reset(runtimeService) + } - @Test - fun verifyGetSuccess() { - runtimeServiceVariableMockBuilder(runtimeService).initial(VAR, "value").build() - val verifier = runtimeServiceMockVerifier(runtimeService) - val executionId = UUID.randomUUID().toString() - VAR.from(runtimeService, executionId).get() - verifier.verifyGet(VAR, executionId) - verifier.verifyNoMoreInteractions() - } + @Test + fun verifyGetSuccess() { + runtimeServiceVariableMockBuilder(runtimeService).initial(VAR, "value").build() + val verifier = runtimeServiceMockVerifier(runtimeService) + val executionId = UUID.randomUUID().toString() + VAR.from(runtimeService, executionId).get() + verifier.verifyGet(VAR, executionId) + verifier.verifyNoMoreInteractions() + } - @Test - fun testVerifyGetLocal() { - runtimeServiceVariableMockBuilder(runtimeService).initialLocal(VAR, "value").build() - val verifier = runtimeServiceMockVerifier(runtimeService) - val executionId = UUID.randomUUID().toString() - VAR.from(runtimeService, executionId).local - verifier.verifyGetLocal(VAR, executionId) - verifier.verifyNoMoreInteractions() - } + @Test + fun testVerifyGetLocal() { + runtimeServiceVariableMockBuilder(runtimeService).initialLocal(VAR, "value").build() + val verifier = runtimeServiceMockVerifier(runtimeService) + val executionId = UUID.randomUUID().toString() + VAR.from(runtimeService, executionId).local + verifier.verifyGetLocal(VAR, executionId) + verifier.verifyNoMoreInteractions() + } - @Test - fun verifySetSuccess() { - runtimeServiceVariableMockBuilder(runtimeService).define(VAR).build() - val verifier = runtimeServiceMockVerifier(runtimeService) - val executionId = UUID.randomUUID().toString() - VAR.on(runtimeService, executionId).set("value") - verifier.verifySet(VAR, "value", executionId) - verifier.verifyNoMoreInteractions() - } + @Test + fun verifySetSuccess() { + runtimeServiceVariableMockBuilder(runtimeService).define(VAR).build() + val verifier = runtimeServiceMockVerifier(runtimeService) + val executionId = UUID.randomUUID().toString() + VAR.on(runtimeService, executionId).set("value") + verifier.verifySet(VAR, "value", executionId) + verifier.verifyNoMoreInteractions() + } - @Test - fun testVerifySetLocal() { - runtimeServiceVariableMockBuilder(runtimeService).define(VAR).build() - val verifier = runtimeServiceMockVerifier(runtimeService) - val executionId = UUID.randomUUID().toString() - VAR.on(runtimeService, executionId).setLocal("valueLocal") - verifier.verifySetLocal(VAR, "valueLocal", executionId) - verifier.verifyNoMoreInteractions() - } + @Test + fun testVerifySetLocal() { + runtimeServiceVariableMockBuilder(runtimeService).define(VAR).build() + val verifier = runtimeServiceMockVerifier(runtimeService) + val executionId = UUID.randomUUID().toString() + VAR.on(runtimeService, executionId).setLocal("valueLocal") + verifier.verifySetLocal(VAR, "valueLocal", executionId) + verifier.verifyNoMoreInteractions() + } - @Test - fun verifyRemoveSuccess() { - runtimeServiceVariableMockBuilder(runtimeService).initial(VAR, "value").build() - val verifier = runtimeServiceMockVerifier(runtimeService) - val executionId = UUID.randomUUID().toString() - VAR.on(runtimeService, executionId).remove() - verifier.verifyRemove(VAR, executionId) - verifier.verifyNoMoreInteractions() - } + @Test + fun verifyRemoveSuccess() { + runtimeServiceVariableMockBuilder(runtimeService).initial(VAR, "value").build() + val verifier = runtimeServiceMockVerifier(runtimeService) + val executionId = UUID.randomUUID().toString() + VAR.on(runtimeService, executionId).remove() + verifier.verifyRemove(VAR, executionId) + verifier.verifyNoMoreInteractions() + } - @Test - fun testVerifyRemoveLocal() { - runtimeServiceVariableMockBuilder(runtimeService).initialLocal(VAR, "localValue").build() - val verifier = runtimeServiceMockVerifier(runtimeService) - val executionId = UUID.randomUUID().toString() - VAR.on(runtimeService, executionId).remove() - verifier.verifyRemoveLocal(VAR, executionId) - verifier.verifyNoMoreInteractions() - } -} \ No newline at end of file + @Test + fun testVerifyRemoveLocal() { + runtimeServiceVariableMockBuilder(runtimeService).initialLocal(VAR, "localValue").build() + val verifier = runtimeServiceMockVerifier(runtimeService) + val executionId = UUID.randomUUID().toString() + VAR.on(runtimeService, executionId).remove() + verifier.verifyRemoveLocal(VAR, executionId) + verifier.verifyNoMoreInteractions() + } +} diff --git a/extension/test/src/test/kotlin/TaskServiceMockingTest.kt b/extension/test/src/test/kotlin/TaskServiceMockingTest.kt index 6154f5a1..17ceb8c9 100644 --- a/extension/test/src/test/kotlin/TaskServiceMockingTest.kt +++ b/extension/test/src/test/kotlin/TaskServiceMockingTest.kt @@ -13,56 +13,56 @@ import java.util.* */ class TaskServiceMockingTest { - companion object { - val ORDER_ID = stringVariable("orderId") - val ORDER_FLAG = booleanVariable("orderFlag") - } + companion object { + val ORDER_ID = stringVariable("orderId") + val ORDER_FLAG = booleanVariable("orderFlag") + } - private val taskService = mock() - private val testService = TaskServiceAwareService(taskService) + private val taskService = mock() + private val testService = TaskServiceAwareService(taskService) - @Test - fun should_mock_task_service() { + @Test + fun should_mock_task_service() { - val taskId = UUID.randomUUID().toString() + val taskId = UUID.randomUUID().toString() - TaskServiceVariableMockBuilder(taskService) - .initial(ORDER_ID, "initial-Value") - .define(ORDER_FLAG) - .build() + TaskServiceVariableMockBuilder(taskService) + .initial(ORDER_ID, "initial-Value") + .define(ORDER_FLAG) + .build() - testService.writeOrderId(taskId, "4712") - val orderId = testService.readOrderId(taskId) + testService.writeOrderId(taskId, "4712") + val orderId = testService.readOrderId(taskId) - assertThat(testService.localFlagExists(taskId)).isFalse() - testService.writeLocalFlag(taskId, true) - assertThat(testService.localFlagExists(taskId)).isTrue() - val orderFlag = testService.readLocalFlag(taskId) + assertThat(testService.localFlagExists(taskId)).isFalse() + testService.writeLocalFlag(taskId, true) + assertThat(testService.localFlagExists(taskId)).isTrue() + val orderFlag = testService.readLocalFlag(taskId) - assertThat(orderId).isEqualTo("4712") - assertThat(orderFlag).isEqualTo(true) - } + assertThat(orderId).isEqualTo("4712") + assertThat(orderFlag).isEqualTo(true) + } - /** - * Test service. - * @param taskService task service to work on. - */ - class TaskServiceAwareService(val taskService: TaskService) { + /** + * Test service. + * @param taskService task service to work on. + */ + class TaskServiceAwareService(val taskService: TaskService) { - fun readOrderId(taskId: String): String = - ORDER_ID.from(taskService, taskId).get() + fun readOrderId(taskId: String): String = + ORDER_ID.from(taskService, taskId).get() - fun writeOrderId(taskId: String, value: String) = - ORDER_ID.on(taskService, taskId).set(value) + fun writeOrderId(taskId: String, value: String) = + ORDER_ID.on(taskService, taskId).set(value) - fun localFlagExists(taskId: String) = - taskService.getVariablesLocal(taskId).containsKey(ORDER_FLAG.name) + fun localFlagExists(taskId: String) = + taskService.getVariablesLocal(taskId).containsKey(ORDER_FLAG.name) - fun writeLocalFlag(taskId: String, flag: Boolean) = - ORDER_FLAG.on(taskService, taskId).setLocal(flag) + fun writeLocalFlag(taskId: String, flag: Boolean) = + ORDER_FLAG.on(taskService, taskId).setLocal(flag) - fun readLocalFlag(taskId: String): Boolean = - ORDER_FLAG.from(taskService, taskId).local - } -} \ No newline at end of file + fun readLocalFlag(taskId: String): Boolean = + ORDER_FLAG.from(taskService, taskId).local + } +} diff --git a/extension/test/src/test/kotlin/TaskServiceVerifierTest.kt b/extension/test/src/test/kotlin/TaskServiceVerifierTest.kt index 27c86381..cbae90d9 100644 --- a/extension/test/src/test/kotlin/TaskServiceVerifierTest.kt +++ b/extension/test/src/test/kotlin/TaskServiceVerifierTest.kt @@ -14,96 +14,94 @@ import java.util.* class TaskServiceVerifierTest { - companion object { - val VAR = stringVariable("var") - } + companion object { + val VAR = stringVariable("var") + } - private val taskService = mock() + private val taskService = mock() - @Before - fun resetMocks() { - reset(taskService) - } + @Before + fun resetMocks() { + reset(taskService) + } - @Test - fun verifyGetSuccess() { - taskServiceVariableMockBuilder(taskService).initial(VAR, "value").build() - val verifier = taskServiceMockVerifier(taskService) - val taskId = UUID.randomUUID().toString() - VAR.from(taskService, taskId).get() - verifier.verifyGet(VAR, taskId) - verifier.verifyNoMoreInteractions() - } + @Test + fun verifyGetSuccess() { + taskServiceVariableMockBuilder(taskService).initial(VAR, "value").build() + val verifier = taskServiceMockVerifier(taskService) + val taskId = UUID.randomUUID().toString() + VAR.from(taskService, taskId).get() + verifier.verifyGet(VAR, taskId) + verifier.verifyNoMoreInteractions() + } - @Test - fun testVerifyGetLocal() { - taskServiceVariableMockBuilder(taskService).initialLocal(VAR, "value").build() - val verifier = taskServiceMockVerifier(taskService) - val taskId = UUID.randomUUID().toString() - VAR.from(taskService, taskId).local - verifier.verifyGetLocal(VAR, taskId) - verifier.verifyNoMoreInteractions() - } + @Test + fun testVerifyGetLocal() { + taskServiceVariableMockBuilder(taskService).initialLocal(VAR, "value").build() + val verifier = taskServiceMockVerifier(taskService) + val taskId = UUID.randomUUID().toString() + VAR.from(taskService, taskId).local + verifier.verifyGetLocal(VAR, taskId) + verifier.verifyNoMoreInteractions() + } - @Test - fun verifySetSuccess() { - taskServiceVariableMockBuilder(taskService).define(VAR).build() - val verifier = taskServiceMockVerifier(taskService) - val taskId = UUID.randomUUID().toString() - VAR.on(taskService, taskId).set("value") - verifier.verifySet(VAR, "value", taskId) - verifier.verifyNoMoreInteractions() - } + @Test + fun verifySetSuccess() { + taskServiceVariableMockBuilder(taskService).define(VAR).build() + val verifier = taskServiceMockVerifier(taskService) + val taskId = UUID.randomUUID().toString() + VAR.on(taskService, taskId).set("value") + verifier.verifySet(VAR, "value", taskId) + verifier.verifyNoMoreInteractions() + } - @Test - fun testVerifySetLocal() { - taskServiceVariableMockBuilder(taskService).define(VAR).build() - val verifier = taskServiceMockVerifier(taskService) - val taskId = UUID.randomUUID().toString() - VAR.on(taskService, taskId).setLocal("valueLocal") - verifier.verifySetLocal(VAR, "valueLocal", taskId) - verifier.verifyNoMoreInteractions() - } + @Test + fun testVerifySetLocal() { + taskServiceVariableMockBuilder(taskService).define(VAR).build() + val verifier = taskServiceMockVerifier(taskService) + val taskId = UUID.randomUUID().toString() + VAR.on(taskService, taskId).setLocal("valueLocal") + verifier.verifySetLocal(VAR, "valueLocal", taskId) + verifier.verifyNoMoreInteractions() + } - @Test - fun verifyRemoveSuccess() { - taskServiceVariableMockBuilder(taskService).initial(VAR, "value").build() - val verifier = taskServiceMockVerifier(taskService) - val taskId = UUID.randomUUID().toString() - VAR.on(taskService, taskId).remove() - verifier.verifyRemove(VAR, taskId) - verifier.verifyNoMoreInteractions() - } + @Test + fun verifyRemoveSuccess() { + taskServiceVariableMockBuilder(taskService).initial(VAR, "value").build() + val verifier = taskServiceMockVerifier(taskService) + val taskId = UUID.randomUUID().toString() + VAR.on(taskService, taskId).remove() + verifier.verifyRemove(VAR, taskId) + verifier.verifyNoMoreInteractions() + } - @Test - fun testVerifyRemoveLocal() { - taskServiceVariableMockBuilder(taskService).initialLocal(VAR, "localValue").build() - val verifier = taskServiceMockVerifier(taskService) - val taskId = UUID.randomUUID().toString() - VAR.on(taskService, taskId).remove() - verifier.verifyRemoveLocal(VAR, taskId) - verifier.verifyNoMoreInteractions() - } + @Test + fun testVerifyRemoveLocal() { + taskServiceVariableMockBuilder(taskService).initialLocal(VAR, "localValue").build() + val verifier = taskServiceMockVerifier(taskService) + val taskId = UUID.randomUUID().toString() + VAR.on(taskService, taskId).remove() + verifier.verifyRemoveLocal(VAR, taskId) + verifier.verifyNoMoreInteractions() + } - @Test - fun testVerifyComplete() { - val verifier = taskServiceMockVerifier(taskService) - val taskId = UUID.randomUUID().toString() - taskService.complete(taskId) - verifier.verifyComplete(taskId) - verifier.verifyNoMoreInteractions() - } + @Test + fun testVerifyComplete() { + val verifier = taskServiceMockVerifier(taskService) + val taskId = UUID.randomUUID().toString() + taskService.complete(taskId) + verifier.verifyComplete(taskId) + verifier.verifyNoMoreInteractions() + } - @Test - fun testVerifyCompleteWithVars() { - val verifier = taskServiceMockVerifier(taskService) - val taskId = UUID.randomUUID().toString() - val vars = createVariables() - .set(VAR, "someValue") - taskService.complete(taskId, vars) - verifier.verifyComplete(vars, taskId) - verifier.verifyNoMoreInteractions() - } - - -} \ No newline at end of file + @Test + fun testVerifyCompleteWithVars() { + val verifier = taskServiceMockVerifier(taskService) + val taskId = UUID.randomUUID().toString() + val vars = createVariables() + .set(VAR, "someValue") + taskService.complete(taskId, vars) + verifier.verifyComplete(vars, taskId) + verifier.verifyNoMoreInteractions() + } +} From 4444374b08910c21b04b56af223ea62055d8d66d Mon Sep 17 00:00:00 2001 From: Jan Galinski Date: Sun, 26 Jul 2020 20:53:29 +0200 Subject: [PATCH 02/23] Update for next development version --- docs/pom.xml | 2 +- example/coverage-report-aggregator/pom.xml | 2 +- example/example-java/pom.xml | 2 +- example/example-kotlin/pom.xml | 2 +- example/itest/pom.xml | 2 +- example/pom.xml | 2 +- example/spin-type-detector/pom.xml | 2 +- extension/core/pom.xml | 2 +- extension/test/pom.xml | 2 +- pom.xml | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/pom.xml b/docs/pom.xml index 145e16aa..e4275cb3 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -6,7 +6,7 @@ io.holunda.data camunda-bpm-data-parent - 1.0.2 + 1.0.3-SNAPSHOT camunda-bpm-data-docs diff --git a/example/coverage-report-aggregator/pom.xml b/example/coverage-report-aggregator/pom.xml index 46d1fc13..b5d13e90 100644 --- a/example/coverage-report-aggregator/pom.xml +++ b/example/coverage-report-aggregator/pom.xml @@ -6,7 +6,7 @@ io.holunda.data.example camunda-bpm-data-example-parent - 1.0.2 + 1.0.3-SNAPSHOT camunda-bpm-data-coverage-report diff --git a/example/example-java/pom.xml b/example/example-java/pom.xml index c8d355ac..496da041 100644 --- a/example/example-java/pom.xml +++ b/example/example-java/pom.xml @@ -6,7 +6,7 @@ io.holunda.data.example camunda-bpm-data-example-parent - 1.0.2 + 1.0.3-SNAPSHOT camunda-bpm-data-example-java diff --git a/example/example-kotlin/pom.xml b/example/example-kotlin/pom.xml index 19d919b0..955a6e28 100644 --- a/example/example-kotlin/pom.xml +++ b/example/example-kotlin/pom.xml @@ -6,7 +6,7 @@ io.holunda.data.example camunda-bpm-data-example-parent - 1.0.2 + 1.0.3-SNAPSHOT camunda-bpm-data-example-kotlin diff --git a/example/itest/pom.xml b/example/itest/pom.xml index a769c52d..a1e582b1 100644 --- a/example/itest/pom.xml +++ b/example/itest/pom.xml @@ -6,7 +6,7 @@ io.holunda.data.example camunda-bpm-data-example-parent - 1.0.2 + 1.0.3-SNAPSHOT camunda-bpm-data-integration-test diff --git a/example/pom.xml b/example/pom.xml index f41ff694..e00b7d10 100644 --- a/example/pom.xml +++ b/example/pom.xml @@ -6,7 +6,7 @@ io.holunda.data camunda-bpm-data-parent - 1.0.2 + 1.0.3-SNAPSHOT io.holunda.data.example diff --git a/example/spin-type-detector/pom.xml b/example/spin-type-detector/pom.xml index f0de0f88..17863377 100644 --- a/example/spin-type-detector/pom.xml +++ b/example/spin-type-detector/pom.xml @@ -6,7 +6,7 @@ io.holunda.data.example camunda-bpm-data-example-parent - 1.0.2 + 1.0.3-SNAPSHOT camunda-bpm-data-spin-type-detector diff --git a/extension/core/pom.xml b/extension/core/pom.xml index ed89fcc3..bfa9e0b2 100644 --- a/extension/core/pom.xml +++ b/extension/core/pom.xml @@ -6,7 +6,7 @@ io.holunda.data camunda-bpm-data-parent - 1.0.2 + 1.0.3-SNAPSHOT ../.. diff --git a/extension/test/pom.xml b/extension/test/pom.xml index ef0ce6e2..7fc425ce 100644 --- a/extension/test/pom.xml +++ b/extension/test/pom.xml @@ -6,7 +6,7 @@ io.holunda.data camunda-bpm-data-parent - 1.0.2 + 1.0.3-SNAPSHOT ../.. diff --git a/pom.xml b/pom.xml index b51cfc54..e6ced303 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.holunda.data camunda-bpm-data-parent - 1.0.2 + 1.0.3-SNAPSHOT ${project.artifactId} Camunda BPM Data https://github.com/holunda-io/camunda-bpm-data/ From 06c7d370cd955ee26f8e498c8e13cac695c2b6b7 Mon Sep 17 00:00:00 2001 From: Simon Zambrovski Date: Tue, 25 Aug 2020 10:46:32 +0200 Subject: [PATCH 03/23] minor improvements --- .../bpm/data/acl/CamundaBpmDataACLFactoryTest.java | 10 +++++++--- .../bpm/data/builder/VariableMapBuilderTest.java | 5 ++++- .../reader/ProcessExecutionVariableReaderTest.java | 2 ++ .../test/src/test/kotlin/RuntimeServiceMockingTest.kt | 4 ++-- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/extension/core/src/test/java/io/holunda/camunda/bpm/data/acl/CamundaBpmDataACLFactoryTest.java b/extension/core/src/test/java/io/holunda/camunda/bpm/data/acl/CamundaBpmDataACLFactoryTest.java index 09e5469a..201c6cc1 100644 --- a/extension/core/src/test/java/io/holunda/camunda/bpm/data/acl/CamundaBpmDataACLFactoryTest.java +++ b/extension/core/src/test/java/io/holunda/camunda/bpm/data/acl/CamundaBpmDataACLFactoryTest.java @@ -19,8 +19,12 @@ public class CamundaBpmDataACLFactoryTest { IdentityVariableMapTransformer.INSTANCE ); - public void testCallFromJava(String value) { - VariableMap variableMap = MY_ACL.checkAndWrap(CamundaBpmData.builder().set(FOO, value).build()); - runtimeService.correlateMessage("message", variableMap); + + public void testCallFromJava(String value) { + VariableMap variableMap = CamundaBpmData.builder().set(FOO, value).build(); + + runtimeService.correlateMessage("message", MY_ACL.checkAndWrap(variableMap)); + + } } diff --git a/extension/core/src/test/java/io/holunda/camunda/bpm/data/builder/VariableMapBuilderTest.java b/extension/core/src/test/java/io/holunda/camunda/bpm/data/builder/VariableMapBuilderTest.java index 3b2d30a4..c20b6fbb 100644 --- a/extension/core/src/test/java/io/holunda/camunda/bpm/data/builder/VariableMapBuilderTest.java +++ b/extension/core/src/test/java/io/holunda/camunda/bpm/data/builder/VariableMapBuilderTest.java @@ -2,6 +2,7 @@ import static io.holunda.camunda.bpm.data.CamundaBpmData.stringVariable; import static org.assertj.core.api.Assertions.assertThat; +import static org.camunda.bpm.engine.variable.Variables.createVariables; import io.holunda.camunda.bpm.data.CamundaBpmData; import io.holunda.camunda.bpm.data.factory.VariableFactory; @@ -26,7 +27,9 @@ public void builderCanWriteVariable() { @Test public void buildCreatesANewInstanceEveryTime() { - VariableMapBuilder builder = CamundaBpmData.builder().set(FOO, "bar"); + + VariableMapBuilder builder = CamundaBpmData.builder() + .set(FOO, "bar"); // build copy with "bar" VariableMap bar = builder.build(); diff --git a/extension/core/src/test/java/io/holunda/camunda/bpm/data/reader/ProcessExecutionVariableReaderTest.java b/extension/core/src/test/java/io/holunda/camunda/bpm/data/reader/ProcessExecutionVariableReaderTest.java index 994f280a..59cebf4b 100644 --- a/extension/core/src/test/java/io/holunda/camunda/bpm/data/reader/ProcessExecutionVariableReaderTest.java +++ b/extension/core/src/test/java/io/holunda/camunda/bpm/data/reader/ProcessExecutionVariableReaderTest.java @@ -52,5 +52,7 @@ public void shouldDelegateGetLocalOptional() { @Test public void shouldDelegateGetLocal() { assertThat(CamundaBpmData.reader(runtimeService, executionId).getLocal(STRING)).isEqualTo(valueLocal); + + VariableReader reader = CamundaBpmData.reader(runtimeService, executionId); } } diff --git a/extension/test/src/test/kotlin/RuntimeServiceMockingTest.kt b/extension/test/src/test/kotlin/RuntimeServiceMockingTest.kt index 0653e517..d8d00d1f 100644 --- a/extension/test/src/test/kotlin/RuntimeServiceMockingTest.kt +++ b/extension/test/src/test/kotlin/RuntimeServiceMockingTest.kt @@ -22,7 +22,7 @@ class RuntimeServiceMockingTest { private val testService = RuntimeServiceAwareService(runtimeService) @Test - fun should_mock_task_service() { + fun should_mock_runtime_service() { val executionId = UUID.randomUUID().toString() @@ -65,4 +65,4 @@ class RuntimeServiceMockingTest { fun readFlag(executionId: String): Boolean = ORDER_FLAG.from(runtimeService, executionId).get() } -} \ No newline at end of file +} From 23308d91ad75e80b6853ada9dafd47332c8e4912 Mon Sep 17 00:00:00 2001 From: Simon Zambrovski Date: Tue, 25 Aug 2020 11:36:40 +0200 Subject: [PATCH 04/23] chore: kotlin goes 1.4 --- .../orchid/resources/changelog/1.1/1.1.0.ad | 19 +++++++++++++++++++ pom.xml | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 docs/src/orchid/resources/changelog/1.1/1.1.0.ad diff --git a/docs/src/orchid/resources/changelog/1.1/1.1.0.ad b/docs/src/orchid/resources/changelog/1.1/1.1.0.ad new file mode 100644 index 00000000..8c0dcc93 --- /dev/null +++ b/docs/src/orchid/resources/changelog/1.1/1.1.0.ad @@ -0,0 +1,19 @@ +--- +version: 1.1.0 +--- + +== Features + +* `noneExcept` and `noneExceptLocal` conditions implemented + +== Breaking Changes + +* Guard API follows conventions of VariableFactory API (adding `Local` to method name for local scope), #67 + +== Chore + +* Upgrade to Kotlin 1.4.0, see #69 +* Upgrade to Camunda BPM 7.13, see #69 +* Upgrade to SpringBoot 2.3.2, see #69 + + diff --git a/pom.xml b/pom.xml index e6ced303..55354f4a 100644 --- a/pom.xml +++ b/pom.xml @@ -30,7 +30,7 @@ 5.0.0 0.18.2 - 1.3.61 + 1.4.0 1.7.6 4.12.0 2.23.4 From 32db22149d590942a63910051825e136e0d00847 Mon Sep 17 00:00:00 2001 From: Simon Zambrovski Date: Tue, 25 Aug 2020 11:46:51 +0200 Subject: [PATCH 05/23] feature: Kotlin API improve, fix #58 --- .../orchid/resources/changelog/1.1/1.1.0.ad | 3 +- .../main/kotlin/VariableFactoryFluentApi.kt | 59 +++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/docs/src/orchid/resources/changelog/1.1/1.1.0.ad b/docs/src/orchid/resources/changelog/1.1/1.1.0.ad index 8c0dcc93..d9149e7f 100644 --- a/docs/src/orchid/resources/changelog/1.1/1.1.0.ad +++ b/docs/src/orchid/resources/changelog/1.1/1.1.0.ad @@ -4,7 +4,8 @@ version: 1.1.0 == Features -* `noneExcept` and `noneExceptLocal` conditions implemented +* `noneExcept` and `noneExceptLocal` conditions implemented, see #68 +* Improve Kotlin API with extension functions on `VariableMap` and `VariableScope` == Breaking Changes diff --git a/extension/core/src/main/kotlin/VariableFactoryFluentApi.kt b/extension/core/src/main/kotlin/VariableFactoryFluentApi.kt index ab087492..27d1bc1c 100644 --- a/extension/core/src/main/kotlin/VariableFactoryFluentApi.kt +++ b/extension/core/src/main/kotlin/VariableFactoryFluentApi.kt @@ -3,13 +3,32 @@ package io.holunda.camunda.bpm.data import io.holunda.camunda.bpm.data.writer.RuntimeServiceVariableWriter import io.holunda.camunda.bpm.data.writer.TaskServiceVariableWriter import io.holunda.camunda.bpm.data.factory.VariableFactory +import io.holunda.camunda.bpm.data.reader.CaseServiceVariableReader import io.holunda.camunda.bpm.data.reader.RuntimeServiceVariableReader import io.holunda.camunda.bpm.data.reader.TaskServiceVariableReader +import io.holunda.camunda.bpm.data.writer.CaseServiceVariableWriter +import org.camunda.bpm.engine.CaseService import org.camunda.bpm.engine.RuntimeService import org.camunda.bpm.engine.TaskService import org.camunda.bpm.engine.delegate.VariableScope import org.camunda.bpm.engine.variable.VariableMap +/** + * Getter from global scope. + * @param factory factory defining the variable. + */ +fun VariableMap.get(factory: VariableFactory) = this.apply { + factory.from(this).get() +} + +/** + * Getter from local scope. + * @param factory factory defining the variable. + */ +fun VariableMap.getLocal(factory: VariableFactory) = this.apply { + factory.from(this).local +} + /** * Fluent setter. * @param factory factory defining the variable. @@ -20,6 +39,16 @@ fun VariableMap.set(factory: VariableFactory, value: T, isTransient: Bool factory.on(this).set(value, isTransient) } +/** + * Fluent local setter. + * @param factory factory defining the variable. + * @param value new value. + * @param isTransient flag for transient access, false by default. + */ +fun VariableMap.setLocal(factory: VariableFactory, value: T, isTransient: Boolean = false) = this.apply { + factory.on(this).setLocal(value, isTransient) +} + /** * Fluent remover. * @param factory factory defining the variable. @@ -28,6 +57,14 @@ fun VariableMap.remove(factory: VariableFactory) = this.apply { factory.on(this).remove() } +/** + * Fluent local remover. + * @param factory factory defining the variable. + */ +fun VariableMap.removeLocal(factory: VariableFactory) = this.apply { + factory.on(this).removeLocal() +} + /** * Fluent updater. * @param factory factory defining the variable. @@ -38,6 +75,16 @@ fun VariableMap.update(factory: VariableFactory, valueProcessor: (T) -> T factory.on(this).update(valueProcessor, isTransient) } +/** + * Fluent updater. + * @param factory factory defining the variable. + * @param valueProcessor update function. + * @param isTransient flag for transient access, false by default. + */ +fun VariableMap.updateLocal(factory: VariableFactory, valueProcessor: (T) -> T, isTransient: Boolean = false) = this.apply { + factory.on(this).updateLocal(valueProcessor, isTransient) +} + /** * Fluent setter. @@ -95,6 +142,12 @@ fun VariableScope.updateLocal(factory: VariableFactory, valueProcessor: ( factory.on(this).updateLocal(valueProcessor, isTransient) } +/** + * Helper to access case service writer. + * @param caseExecutionId id of the execution. + */ +fun CaseService.writer(caseExecutionId: String) = CaseServiceVariableWriter(this, caseExecutionId) + /** * Helper to access runtime service writer. * @param executionId id of the execution. @@ -107,6 +160,12 @@ fun RuntimeService.writer(executionId: String) = RuntimeServiceVariableWriter(th */ fun TaskService.writer(taskId: String) = TaskServiceVariableWriter(this, taskId) +/** + * Helper to access case service reader. + * @param caseExecutionId id of the execution. + */ +fun CaseService.reader(caseExecutionId: String) = CaseServiceVariableReader(this, caseExecutionId) + /** * Helper to access runtime service reader. * @param executionId id of the execution. From 784544cf1cf2d278a0138e040cbe243c8d04979d Mon Sep 17 00:00:00 2001 From: Simon Zambrovski Date: Tue, 25 Aug 2020 15:08:57 +0200 Subject: [PATCH 06/23] upgrade versions, more tests, fix #69 --- .../orchid/resources/changelog/1.1/1.1.0.ad | 4 +- example/example-kotlin/pom.xml | 4 + example/itest/pom.xml | 4 + extension/core/pom.xml | 11 +- .../main/kotlin/VariableFactoryFluentApi.kt | 51 +++----- .../main/kotlin/VariableFactoryOperatorApi.kt | 18 +++ .../data/builder/VariableMapBuilderTest.java | 7 +- .../ProcessExecutionVariableReaderTest.java | 11 +- .../core/src/test/kotlin/FluentApiTest.kt | 109 ++++++++++++++++++ extension/test/pom.xml | 4 + pom.xml | 34 ++++-- 11 files changed, 202 insertions(+), 55 deletions(-) create mode 100644 extension/core/src/main/kotlin/VariableFactoryOperatorApi.kt create mode 100644 extension/core/src/test/kotlin/FluentApiTest.kt diff --git a/docs/src/orchid/resources/changelog/1.1/1.1.0.ad b/docs/src/orchid/resources/changelog/1.1/1.1.0.ad index d9149e7f..f6af1372 100644 --- a/docs/src/orchid/resources/changelog/1.1/1.1.0.ad +++ b/docs/src/orchid/resources/changelog/1.1/1.1.0.ad @@ -4,8 +4,8 @@ version: 1.1.0 == Features -* `noneExcept` and `noneExceptLocal` conditions implemented, see #68 -* Improve Kotlin API with extension functions on `VariableMap` and `VariableScope` +* Improve Kotlin API with extension functions on `VariableMap` and `VariableScope`, see #58 +* Provides Kotlin operators for read/write from/on `VariableMap` and `VariableScope`, see #65 == Breaking Changes diff --git a/example/example-kotlin/pom.xml b/example/example-kotlin/pom.xml index 955a6e28..6b1fee1c 100644 --- a/example/example-kotlin/pom.xml +++ b/example/example-kotlin/pom.xml @@ -114,6 +114,10 @@ org.jetbrains.kotlin kotlin-stdlib + + org.jetbrains.kotlin + kotlin-stdlib-common + org.jetbrains.kotlin kotlin-stdlib-jdk8 diff --git a/example/itest/pom.xml b/example/itest/pom.xml index a1e582b1..5053b403 100644 --- a/example/itest/pom.xml +++ b/example/itest/pom.xml @@ -112,6 +112,10 @@ org.jetbrains.kotlin kotlin-stdlib + + org.jetbrains.kotlin + kotlin-stdlib-common + org.jetbrains.kotlin kotlin-stdlib-jdk8 diff --git a/extension/core/pom.xml b/extension/core/pom.xml index bfa9e0b2..5fbc2460 100644 --- a/extension/core/pom.xml +++ b/extension/core/pom.xml @@ -7,7 +7,7 @@ io.holunda.data camunda-bpm-data-parent 1.0.3-SNAPSHOT - ../.. + ../../pom.xml camunda-bpm-data @@ -24,6 +24,10 @@ org.jetbrains.kotlin kotlin-stdlib + + org.jetbrains.kotlin + kotlin-stdlib-common + org.jetbrains.kotlin kotlin-stdlib-jdk8 @@ -53,6 +57,11 @@ camunda-bpm-mockito test + + com.nhaarman.mockitokotlin2 + mockito-kotlin + test + org.slf4j slf4j-simple diff --git a/extension/core/src/main/kotlin/VariableFactoryFluentApi.kt b/extension/core/src/main/kotlin/VariableFactoryFluentApi.kt index 27d1bc1c..0afdb0f6 100644 --- a/extension/core/src/main/kotlin/VariableFactoryFluentApi.kt +++ b/extension/core/src/main/kotlin/VariableFactoryFluentApi.kt @@ -12,22 +12,13 @@ import org.camunda.bpm.engine.RuntimeService import org.camunda.bpm.engine.TaskService import org.camunda.bpm.engine.delegate.VariableScope import org.camunda.bpm.engine.variable.VariableMap - -/** - * Getter from global scope. - * @param factory factory defining the variable. - */ -fun VariableMap.get(factory: VariableFactory) = this.apply { - factory.from(this).get() -} +import java.util.* /** * Getter from local scope. * @param factory factory defining the variable. */ -fun VariableMap.getLocal(factory: VariableFactory) = this.apply { - factory.from(this).local -} +fun VariableMap.getOptional(factory: VariableFactory): Optional = factory.from(this).optional /** * Fluent setter. @@ -39,16 +30,6 @@ fun VariableMap.set(factory: VariableFactory, value: T, isTransient: Bool factory.on(this).set(value, isTransient) } -/** - * Fluent local setter. - * @param factory factory defining the variable. - * @param value new value. - * @param isTransient flag for transient access, false by default. - */ -fun VariableMap.setLocal(factory: VariableFactory, value: T, isTransient: Boolean = false) = this.apply { - factory.on(this).setLocal(value, isTransient) -} - /** * Fluent remover. * @param factory factory defining the variable. @@ -57,14 +38,6 @@ fun VariableMap.remove(factory: VariableFactory) = this.apply { factory.on(this).remove() } -/** - * Fluent local remover. - * @param factory factory defining the variable. - */ -fun VariableMap.removeLocal(factory: VariableFactory) = this.apply { - factory.on(this).removeLocal() -} - /** * Fluent updater. * @param factory factory defining the variable. @@ -76,15 +49,22 @@ fun VariableMap.update(factory: VariableFactory, valueProcessor: (T) -> T } /** - * Fluent updater. + * Getter from local scope. * @param factory factory defining the variable. - * @param valueProcessor update function. - * @param isTransient flag for transient access, false by default. */ -fun VariableMap.updateLocal(factory: VariableFactory, valueProcessor: (T) -> T, isTransient: Boolean = false) = this.apply { - factory.on(this).updateLocal(valueProcessor, isTransient) -} +fun VariableScope.getOptional(factory: VariableFactory): Optional = factory.from(this).optional +/** + * Getter from local scope. + * @param factory factory defining the variable. + */ +fun VariableScope.getLocal(factory: VariableFactory): T = factory.from(this).local + +/** + * Getter from local scope. + * @param factory factory defining the variable. + */ +fun VariableScope.getLocalOptional(factory: VariableFactory): Optional = factory.from(this).localOptional /** * Fluent setter. @@ -131,7 +111,6 @@ fun VariableScope.setLocal(factory: VariableFactory, value: T, isTransien fun VariableScope.removeLocal(factory: VariableFactory) = this.apply { factory.on(this).removeLocal() } - /** * Fluent local updater. * @param factory factory defining the variable. diff --git a/extension/core/src/main/kotlin/VariableFactoryOperatorApi.kt b/extension/core/src/main/kotlin/VariableFactoryOperatorApi.kt new file mode 100644 index 00000000..bdceaae7 --- /dev/null +++ b/extension/core/src/main/kotlin/VariableFactoryOperatorApi.kt @@ -0,0 +1,18 @@ +package io.holunda.camunda.bpm.data + +import io.holunda.camunda.bpm.data.factory.VariableFactory +import org.camunda.bpm.engine.delegate.VariableScope +import org.camunda.bpm.engine.variable.VariableMap + +/** + * Operator getter from global scope. + * @param factory factory defining the variable. + */ +operator fun VariableMap.get(factory: VariableFactory): T = factory.from(this).get() + +/** + * Operator getter from global scope. + * @param factory factory defining the variable. + */ +operator fun VariableScope.get(factory: VariableFactory): T = factory.from(this).get() + diff --git a/extension/core/src/test/java/io/holunda/camunda/bpm/data/builder/VariableMapBuilderTest.java b/extension/core/src/test/java/io/holunda/camunda/bpm/data/builder/VariableMapBuilderTest.java index c20b6fbb..c4651401 100644 --- a/extension/core/src/test/java/io/holunda/camunda/bpm/data/builder/VariableMapBuilderTest.java +++ b/extension/core/src/test/java/io/holunda/camunda/bpm/data/builder/VariableMapBuilderTest.java @@ -1,14 +1,13 @@ package io.holunda.camunda.bpm.data.builder; -import static io.holunda.camunda.bpm.data.CamundaBpmData.stringVariable; -import static org.assertj.core.api.Assertions.assertThat; -import static org.camunda.bpm.engine.variable.Variables.createVariables; - import io.holunda.camunda.bpm.data.CamundaBpmData; import io.holunda.camunda.bpm.data.factory.VariableFactory; import org.camunda.bpm.engine.variable.VariableMap; import org.junit.Test; +import static io.holunda.camunda.bpm.data.CamundaBpmData.stringVariable; +import static org.assertj.core.api.Assertions.assertThat; + public class VariableMapBuilderTest { private static final VariableFactory FOO = stringVariable("foo"); diff --git a/extension/core/src/test/java/io/holunda/camunda/bpm/data/reader/ProcessExecutionVariableReaderTest.java b/extension/core/src/test/java/io/holunda/camunda/bpm/data/reader/ProcessExecutionVariableReaderTest.java index 59cebf4b..a2dcc684 100644 --- a/extension/core/src/test/java/io/holunda/camunda/bpm/data/reader/ProcessExecutionVariableReaderTest.java +++ b/extension/core/src/test/java/io/holunda/camunda/bpm/data/reader/ProcessExecutionVariableReaderTest.java @@ -1,18 +1,19 @@ package io.holunda.camunda.bpm.data.reader; -import static io.holunda.camunda.bpm.data.CamundaBpmData.stringVariable; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Mockito.when; - import io.holunda.camunda.bpm.data.CamundaBpmData; import io.holunda.camunda.bpm.data.factory.VariableFactory; -import java.util.UUID; import org.camunda.bpm.engine.RuntimeService; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; +import java.util.UUID; + +import static io.holunda.camunda.bpm.data.CamundaBpmData.stringVariable; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.when; + public class ProcessExecutionVariableReaderTest { private static final VariableFactory STRING = stringVariable("myString"); diff --git a/extension/core/src/test/kotlin/FluentApiTest.kt b/extension/core/src/test/kotlin/FluentApiTest.kt new file mode 100644 index 00000000..030b2d3c --- /dev/null +++ b/extension/core/src/test/kotlin/FluentApiTest.kt @@ -0,0 +1,109 @@ +package io.holunda.camunda.bpm.data + +import com.nhaarman.mockitokotlin2.mock +import io.holunda.camunda.bpm.data.CamundaBpmDataKotlin.stringVariable +import io.holunda.camunda.bpm.data.reader.CaseServiceVariableReader +import io.holunda.camunda.bpm.data.reader.RuntimeServiceVariableReader +import io.holunda.camunda.bpm.data.reader.TaskServiceVariableReader +import io.holunda.camunda.bpm.data.writer.CaseServiceVariableWriter +import io.holunda.camunda.bpm.data.writer.RuntimeServiceVariableWriter +import io.holunda.camunda.bpm.data.writer.TaskServiceVariableWriter +import org.assertj.core.api.Assertions.assertThat +import org.camunda.bpm.engine.CaseService +import org.camunda.bpm.engine.RuntimeService +import org.camunda.bpm.engine.TaskService +import org.camunda.bpm.engine.variable.Variables.createVariables +import org.camunda.bpm.engine.variable.Variables.stringValue +import org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake +import org.junit.Test +import java.util.* + +class FluentApiTest { + + companion object { + const val NAME = "myString" + const val VALUE = "some random value" + const val LOCAL_VALUE = "other local value" + val MY_VAR = stringVariable(NAME) + } + + @Test + fun `should read and write from variable map and variable scope`() { + val vars = createVariables().putValueTyped(NAME, stringValue(VALUE)) + val fake = DelegateExecutionFake("executionId").withVariables(vars) + + @Suppress("ReplaceGetOrSet") + assertThat(vars.get(MY_VAR)).isEqualTo(VALUE) + assertThat(vars[MY_VAR]).isEqualTo(VALUE) + assertThat(vars.getOptional(MY_VAR)).isEqualTo(Optional.of(VALUE)) + + @Suppress("ReplaceGetOrSet") + assertThat(fake.get(MY_VAR)).isEqualTo(VALUE) + assertThat(fake[MY_VAR]).isEqualTo(VALUE) + assertThat(fake.getOptional(MY_VAR)).isEqualTo(Optional.of(VALUE)) + + fake.set(MY_VAR, "new val") + assertThat(fake[MY_VAR]).isEqualTo("new val") + + fake.update(MY_VAR, { it.capitalize() }, false) + assertThat(fake[MY_VAR]).isEqualTo("New val") + + fake.remove(MY_VAR) + assertThat(fake.getOptional(MY_VAR)).isEqualTo(Optional.empty()) + } + + @Test + fun `should read local and write local from variable map and variable scope`() { + val localVars = createVariables().putValueTyped(NAME, stringValue(LOCAL_VALUE)) + val fake = DelegateExecutionFake("executionId").withVariablesLocal(localVars) + + // global reads local + @Suppress("ReplaceGetOrSet") + assertThat(fake.get(MY_VAR)).isEqualTo(LOCAL_VALUE) + assertThat(fake[MY_VAR]).isEqualTo(LOCAL_VALUE) + assertThat(fake.getOptional(MY_VAR)).isEqualTo(Optional.of(LOCAL_VALUE)) + + assertThat(fake.getLocal(MY_VAR)).isEqualTo(LOCAL_VALUE) + assertThat(fake.getLocalOptional(MY_VAR)).isEqualTo(Optional.of(LOCAL_VALUE)) + + fake.set(MY_VAR, "new val") + assertThat(fake[MY_VAR]).isEqualTo("new val") + + fake.update(MY_VAR, { it.capitalize() }, false) + assertThat(fake[MY_VAR]).isEqualTo("New val") + + fake.setLocal(MY_VAR, "another new local val") + assertThat(fake.getLocal(MY_VAR)).isEqualTo("another new local val") + + fake.updateLocal(MY_VAR, { it.capitalize() }, false) + assertThat(fake[MY_VAR]).isEqualTo("Another new local val") + + fake.removeLocal(MY_VAR) + assertThat(fake.getLocalOptional(MY_VAR)).isEqualTo(Optional.empty()) + + localVars.set(MY_VAR, "new val") + assertThat(localVars[MY_VAR]).isEqualTo("new val") + + localVars.update(MY_VAR, { it.capitalize() }, false) + assertThat(localVars[MY_VAR]).isEqualTo("New val") + + localVars.remove(MY_VAR) + assertThat(localVars.getOptional(MY_VAR)).isEqualTo(Optional.empty()) + } + + @Test + fun writer_and_reader() { + val case: CaseService = mock() + val runtime: RuntimeService = mock() + val task: TaskService = mock() + + assertThat(case.writer("case-id")).isEqualTo(CaseServiceVariableWriter(case, "case-id")) + assertThat(runtime.writer("id")).isEqualTo(RuntimeServiceVariableWriter(runtime, "id")) + assertThat(task.writer("task-id")).isEqualTo(TaskServiceVariableWriter(task, "task-id")) + + assertThat(case.reader("case-id")).isEqualTo(CaseServiceVariableReader(case, "case-id")) + assertThat(runtime.reader("id")).isEqualTo(RuntimeServiceVariableReader(runtime, "id")) + assertThat(task.reader("task-id")).isEqualTo(TaskServiceVariableReader(task, "task-id")) + + } +} diff --git a/extension/test/pom.xml b/extension/test/pom.xml index 7fc425ce..e2b7d228 100644 --- a/extension/test/pom.xml +++ b/extension/test/pom.xml @@ -58,6 +58,10 @@ org.jetbrains.kotlin kotlin-stdlib + + org.jetbrains.kotlin + kotlin-stdlib-common + org.jetbrains.kotlin kotlin-stdlib-jdk8 diff --git a/pom.xml b/pom.xml index 55354f4a..3cd6055f 100644 --- a/pom.xml +++ b/pom.xml @@ -19,19 +19,19 @@ ${java.version} ${java.version} - false - 7.12.0 - 7.12.1-ee + 7.13.0 + 7.13.1-ee + 7.13.0 - 2.2.4.RELEASE - 3.4.0 + 2.3.2.RELEASE 2.4.5 - 1.8.0 + 1.9.0 5.0.0 0.18.2 1.4.0 1.7.6 + 2.2.0 4.12.0 2.23.4 @@ -84,6 +84,17 @@ org.jetbrains.kotlin kotlin-stdlib ${kotlin.version} + + + org.jetbrains.kotlin + kotlin-stdlib-common + + + + + org.jetbrains.kotlin + kotlin-stdlib-common + ${kotlin.version} org.jetbrains.kotlin @@ -129,6 +140,12 @@ ${camunda-assert.version} test + + com.nhaarman.mockitokotlin2 + mockito-kotlin + ${mockito-kotlin.version} + test + @@ -560,7 +577,10 @@ !camunda-ee - + + + ${camunda.version.ce} + From 55917a610cd6f01b275abddec5d4063f98426da1 Mon Sep 17 00:00:00 2001 From: Simon Zambrovski Date: Tue, 25 Aug 2020 15:12:24 +0200 Subject: [PATCH 07/23] fix ee dependency --- example/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/pom.xml b/example/pom.xml index e00b7d10..264314a0 100644 --- a/example/pom.xml +++ b/example/pom.xml @@ -150,7 +150,7 @@ org.camunda.bpm.springboot - camunda-bpm-spring-boot-starter-webapp-ee + camunda-bpm-spring-boot-starter-webapp From 7ac05a5a42772524a8e8603ac7f679c4053d334c Mon Sep 17 00:00:00 2001 From: Simon Zambrovski Date: Tue, 25 Aug 2020 15:13:26 +0200 Subject: [PATCH 08/23] fixed codacy warning --- .../bpm/data/reader/ProcessExecutionVariableReaderTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/extension/core/src/test/java/io/holunda/camunda/bpm/data/reader/ProcessExecutionVariableReaderTest.java b/extension/core/src/test/java/io/holunda/camunda/bpm/data/reader/ProcessExecutionVariableReaderTest.java index a2dcc684..f425b1a0 100644 --- a/extension/core/src/test/java/io/holunda/camunda/bpm/data/reader/ProcessExecutionVariableReaderTest.java +++ b/extension/core/src/test/java/io/holunda/camunda/bpm/data/reader/ProcessExecutionVariableReaderTest.java @@ -53,7 +53,5 @@ public void shouldDelegateGetLocalOptional() { @Test public void shouldDelegateGetLocal() { assertThat(CamundaBpmData.reader(runtimeService, executionId).getLocal(STRING)).isEqualTo(valueLocal); - - VariableReader reader = CamundaBpmData.reader(runtimeService, executionId); } } From 48d63ec523a27e2e6b3c881cb16221613038ca95 Mon Sep 17 00:00:00 2001 From: Simon Zambrovski Date: Tue, 25 Aug 2020 15:25:56 +0200 Subject: [PATCH 09/23] removed import --- .../src/main/kotlin/CamundaBpmDataKotlinExample.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/example/example-kotlin/src/main/kotlin/CamundaBpmDataKotlinExample.kt b/example/example-kotlin/src/main/kotlin/CamundaBpmDataKotlinExample.kt index e8a4b708..a019091b 100644 --- a/example/example-kotlin/src/main/kotlin/CamundaBpmDataKotlinExample.kt +++ b/example/example-kotlin/src/main/kotlin/CamundaBpmDataKotlinExample.kt @@ -2,7 +2,6 @@ package io.holunda.camunda.bpm.data.example.kotlin import io.holunda.camunda.bpm.data.example.kotlin.process.OrderApprovalInstanceFactory import mu.KLogging -import org.camunda.bpm.engine.RepositoryService import org.camunda.bpm.spring.boot.starter.annotation.EnableProcessApplication import org.camunda.bpm.spring.boot.starter.event.PostDeployEvent import org.springframework.beans.factory.annotation.Autowired From f0ca96d8572c5c3880e30b453638d6debf0c90ae Mon Sep 17 00:00:00 2001 From: Simon Zambrovski Date: Tue, 25 Aug 2020 15:26:10 +0200 Subject: [PATCH 10/23] reorder --- example/example-kotlin/src/main/kotlin/process/OrderApproval.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/example-kotlin/src/main/kotlin/process/OrderApproval.kt b/example/example-kotlin/src/main/kotlin/process/OrderApproval.kt index 5797c4eb..06644700 100644 --- a/example/example-kotlin/src/main/kotlin/process/OrderApproval.kt +++ b/example/example-kotlin/src/main/kotlin/process/OrderApproval.kt @@ -5,11 +5,11 @@ import io.holunda.camunda.bpm.data.CamundaBpmData.stringVariable import io.holunda.camunda.bpm.data.CamundaBpmDataKotlin.customVariable import io.holunda.camunda.bpm.data.example.kotlin.domain.Order import io.holunda.camunda.bpm.data.example.kotlin.domain.OrderPosition +import io.holunda.camunda.bpm.data.example.kotlin.domain.OrderRepository import io.holunda.camunda.bpm.data.example.kotlin.process.OrderApproval.Variables.ORDER import io.holunda.camunda.bpm.data.example.kotlin.process.OrderApproval.Variables.ORDER_ID import io.holunda.camunda.bpm.data.example.kotlin.process.OrderApproval.Variables.ORDER_POSITION import io.holunda.camunda.bpm.data.example.kotlin.process.OrderApproval.Variables.ORDER_TOTAL -import io.holunda.camunda.bpm.data.example.kotlin.domain.OrderRepository import io.holunda.camunda.bpm.data.factory.VariableFactory import mu.KLogging import org.camunda.bpm.engine.delegate.DelegateExecution From 89b20acb1730606cd4685433fab360bfc28adb35 Mon Sep 17 00:00:00 2001 From: Simon Zambrovski Date: Tue, 25 Aug 2020 15:26:30 +0200 Subject: [PATCH 11/23] imports --- .../main/kotlin/process/OrderApprovalInstanceFactory.kt | 1 - .../src/test/kotlin/itest/RuntimeServiceAdapterITest.kt | 8 -------- 2 files changed, 9 deletions(-) diff --git a/example/example-kotlin/src/main/kotlin/process/OrderApprovalInstanceFactory.kt b/example/example-kotlin/src/main/kotlin/process/OrderApprovalInstanceFactory.kt index 642a6cc9..0f6bc63f 100644 --- a/example/example-kotlin/src/main/kotlin/process/OrderApprovalInstanceFactory.kt +++ b/example/example-kotlin/src/main/kotlin/process/OrderApprovalInstanceFactory.kt @@ -3,7 +3,6 @@ package io.holunda.camunda.bpm.data.example.kotlin.process import io.holunda.camunda.bpm.data.builder.VariableMapBuilder import io.holunda.camunda.bpm.data.example.kotlin.process.OrderApproval.Variables.ORDER_ID import org.camunda.bpm.engine.RuntimeService -import org.camunda.bpm.engine.variable.Variables.createVariables import org.springframework.stereotype.Component import java.util.* diff --git a/example/itest/src/test/kotlin/itest/RuntimeServiceAdapterITest.kt b/example/itest/src/test/kotlin/itest/RuntimeServiceAdapterITest.kt index a4721cff..bde2a330 100644 --- a/example/itest/src/test/kotlin/itest/RuntimeServiceAdapterITest.kt +++ b/example/itest/src/test/kotlin/itest/RuntimeServiceAdapterITest.kt @@ -1,6 +1,5 @@ package io.holunda.camunda.bpm.data.itest -import com.google.common.util.concurrent.ExecutionList import io.holunda.camunda.bpm.data.itest.CamundaBpmDataITestBase.Companion.Values.BOOLEAN import io.holunda.camunda.bpm.data.itest.CamundaBpmDataITestBase.Companion.Values.COMPLEX import io.holunda.camunda.bpm.data.itest.CamundaBpmDataITestBase.Companion.Values.COMPLEX_LIST @@ -15,16 +14,9 @@ import io.holunda.camunda.bpm.data.itest.CamundaBpmDataITestBase.Companion.Value import io.holunda.camunda.bpm.data.itest.CamundaBpmDataITestBase.Companion.Values.SET_STRING import io.holunda.camunda.bpm.data.itest.CamundaBpmDataITestBase.Companion.Values.SHORT import io.holunda.camunda.bpm.data.itest.CamundaBpmDataITestBase.Companion.Values.STRING -import org.camunda.bpm.engine.delegate.DelegateExecution -import org.camunda.bpm.engine.delegate.ExecutionListener -import org.camunda.bpm.engine.delegate.JavaDelegate import org.camunda.bpm.engine.variable.Variables.createVariables import org.junit.Test import org.springframework.beans.factory.annotation.Autowired -import org.springframework.beans.factory.annotation.Configurable -import org.springframework.context.annotation.Bean -import org.springframework.context.annotation.Configuration -import java.time.OffsetDateTime import java.util.* class RuntimeServiceAdapterITest : CamundaBpmDataITestBase() { From 5a0cbf967c08ed16a265bf517e95b0e3426cbb46 Mon Sep 17 00:00:00 2001 From: Simon Zambrovski Date: Tue, 25 Aug 2020 15:45:48 +0200 Subject: [PATCH 12/23] fixed codacy warns --- .../data/example/process/OrderApproval.java | 4 +++- .../rest/ApproveOrderTaskControllerTest.java | 4 +++- .../bpm/data/adapter/ValueWrapperUtil.java | 22 +++++++++++++++++-- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/example/example-java/src/main/java/io/holunda/camunda/bpm/data/example/process/OrderApproval.java b/example/example-java/src/main/java/io/holunda/camunda/bpm/data/example/process/OrderApproval.java index 2d288c2b..040fbeec 100644 --- a/example/example-java/src/main/java/io/holunda/camunda/bpm/data/example/process/OrderApproval.java +++ b/example/example-java/src/main/java/io/holunda/camunda/bpm/data/example/process/OrderApproval.java @@ -21,7 +21,9 @@ import java.math.BigDecimal; import static com.google.common.collect.Lists.newArrayList; -import static io.holunda.camunda.bpm.data.CamundaBpmData.*; +import static io.holunda.camunda.bpm.data.CamundaBpmData.booleanVariable; +import static io.holunda.camunda.bpm.data.CamundaBpmData.customVariable; +import static io.holunda.camunda.bpm.data.CamundaBpmData.stringVariable; import static io.holunda.camunda.bpm.data.guard.CamundaBpmDataGuards.exists; /** diff --git a/example/example-java/src/test/java/io/holunda/camunda/bpm/data/example/rest/ApproveOrderTaskControllerTest.java b/example/example-java/src/test/java/io/holunda/camunda/bpm/data/example/rest/ApproveOrderTaskControllerTest.java index de27a1fe..b0df1de0 100644 --- a/example/example-java/src/test/java/io/holunda/camunda/bpm/data/example/rest/ApproveOrderTaskControllerTest.java +++ b/example/example-java/src/test/java/io/holunda/camunda/bpm/data/example/rest/ApproveOrderTaskControllerTest.java @@ -14,7 +14,9 @@ import java.util.UUID; import static io.holunda.camunda.bpm.data.CamundaBpmData.builder; -import static io.holunda.camunda.bpm.data.example.process.OrderApproval.*; +import static io.holunda.camunda.bpm.data.example.process.OrderApproval.ORDER; +import static io.holunda.camunda.bpm.data.example.process.OrderApproval.ORDER_APPROVED; +import static io.holunda.camunda.bpm.data.example.process.OrderApproval.ORDER_TOTAL; import static io.holunda.camunda.bpm.data.mockito.CamundaBpmDataMockito.taskServiceMockVerifier; import static io.holunda.camunda.bpm.data.mockito.CamundaBpmDataMockito.taskServiceVariableMockBuilder; import static org.assertj.core.api.Assertions.assertThat; diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/ValueWrapperUtil.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/ValueWrapperUtil.java index be469f93..1d6c817a 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/ValueWrapperUtil.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/ValueWrapperUtil.java @@ -8,11 +8,23 @@ import org.camunda.bpm.engine.variable.value.ObjectValue; import org.camunda.bpm.engine.variable.value.TypedValue; +import java.io.File; import java.util.Collection; import java.util.Date; import java.util.Map; -import static org.camunda.bpm.engine.variable.Variables.*; +import static org.camunda.bpm.engine.variable.Variables.booleanValue; +import static org.camunda.bpm.engine.variable.Variables.dateValue; +import static org.camunda.bpm.engine.variable.Variables.doubleValue; +import static org.camunda.bpm.engine.variable.Variables.fileValue; +import static org.camunda.bpm.engine.variable.Variables.integerValue; +import static org.camunda.bpm.engine.variable.Variables.longValue; +import static org.camunda.bpm.engine.variable.Variables.objectValue; +import static org.camunda.bpm.engine.variable.Variables.shortValue; +import static org.camunda.bpm.engine.variable.Variables.stringValue; +import static org.camunda.bpm.engine.variable.Variables.untypedNullValue; +import static org.camunda.bpm.engine.variable.Variables.untypedValue; + /** * Static util methods. @@ -27,7 +39,8 @@ private ValueWrapperUtil() { } /** - * Delivers typed value for a given type and value. + * Delivers typed value for a given type and value.
+ * Supports every type except byteArray. * * @param clazz class of value. * @param value value to encapsulate. @@ -55,9 +68,14 @@ public static TypedValue getTypedValue(Class clazz, Object value, boolean return dateValue((Date) value, isTransient); } else if (Double.class.equals(clazz)) { return doubleValue((Double) value, isTransient); + } else if (File.class.equals(clazz)) { + return fileValue((File)value, isTransient); } else if (Object.class.equals(clazz)) { return objectValue(value, isTransient).create(); } else { + if (value == null) { + return untypedNullValue(isTransient); + } // fallback for unknown-type return untypedValue(value, isTransient); } From 2cd7558f4f9409e1b1e05f8be1ed6ce42eb94fb4 Mon Sep 17 00:00:00 2001 From: Simon Zambrovski Date: Tue, 25 Aug 2020 16:25:58 +0200 Subject: [PATCH 13/23] more tests --- .../test/kotlin/acl/apply/GlobalScopeReplaceStrategyTest.kt | 5 ++++- .../test/kotlin/acl/apply/LocalScopeReplaceStrategyTest.kt | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/extension/core/src/test/kotlin/acl/apply/GlobalScopeReplaceStrategyTest.kt b/extension/core/src/test/kotlin/acl/apply/GlobalScopeReplaceStrategyTest.kt index 320051e3..3e9b960f 100644 --- a/extension/core/src/test/kotlin/acl/apply/GlobalScopeReplaceStrategyTest.kt +++ b/extension/core/src/test/kotlin/acl/apply/GlobalScopeReplaceStrategyTest.kt @@ -2,6 +2,7 @@ package io.holunda.camunda.bpm.data.acl.apply import io.holunda.camunda.bpm.data.CamundaBpmData import io.holunda.camunda.bpm.data.CamundaBpmData.stringVariable +import org.assertj.core.api.Assertions.assertThat import org.camunda.bpm.engine.delegate.DelegateExecution import org.junit.Test import org.mockito.Mockito @@ -10,7 +11,7 @@ import org.mockito.Mockito.verifyNoMoreInteractions class GlobalScopeReplaceStrategyTest { - val FOO = stringVariable("foo") + private val FOO = stringVariable("foo") @Test fun `should apply global`() { @@ -22,5 +23,7 @@ class GlobalScopeReplaceStrategyTest { verify(executionMock, Mockito.never()).variablesLocal = Mockito.any() verify(executionMock).variables = variables verifyNoMoreInteractions(executionMock) + + assertThat(GlobalScopeReplaceStrategy.toString()).isEqualTo(GlobalScopeReplaceStrategy::class.java.canonicalName) } } diff --git a/extension/core/src/test/kotlin/acl/apply/LocalScopeReplaceStrategyTest.kt b/extension/core/src/test/kotlin/acl/apply/LocalScopeReplaceStrategyTest.kt index a01e9d2a..d5a424ff 100644 --- a/extension/core/src/test/kotlin/acl/apply/LocalScopeReplaceStrategyTest.kt +++ b/extension/core/src/test/kotlin/acl/apply/LocalScopeReplaceStrategyTest.kt @@ -2,13 +2,14 @@ package io.holunda.camunda.bpm.data.acl.apply import io.holunda.camunda.bpm.data.CamundaBpmData import io.holunda.camunda.bpm.data.CamundaBpmData.stringVariable +import org.assertj.core.api.Assertions import org.camunda.bpm.engine.delegate.DelegateExecution import org.junit.Test import org.mockito.Mockito.* class LocalScopeReplaceStrategyTest { - val FOO = stringVariable("foo") + private val FOO = stringVariable("foo") @Test fun `should apply local`() { @@ -20,5 +21,7 @@ class LocalScopeReplaceStrategyTest { verify(executionMock, never()).variables = any() verify(executionMock).variablesLocal = variables verifyNoMoreInteractions(executionMock) + + Assertions.assertThat(LocalScopeReplaceStrategy.toString()).isEqualTo(LocalScopeReplaceStrategy::class.java.canonicalName) } } From d8936ddf601010d9011c1f8d155bc8e87e529ed2 Mon Sep 17 00:00:00 2001 From: Simon Zambrovski Date: Tue, 25 Aug 2020 17:26:05 +0200 Subject: [PATCH 14/23] implement smart update, fix #64, add update to writers, fix #70 --- example/itest/pom.xml | 4 ++ .../itest/src/test/kotlin/SmartUpdateTest.kt | 41 +++++++++++++++++++ .../adapter/AbstractReadWriteAdapter.java | 14 ++++++- .../bpm/data/adapter/WriteAdapter.java | 4 ++ .../writer/CaseServiceVariableWriter.java | 24 +++++++++++ .../bpm/data/writer/GlobalVariableWriter.java | 24 +++++++++++ .../bpm/data/writer/LocalVariableWriter.java | 25 +++++++++++ .../writer/RuntimeServiceVariableWriter.java | 25 +++++++++++ .../writer/TaskServiceVariableWriter.java | 25 +++++++++++ .../bpm/data/writer/VariableMapWriter.java | 14 +++++++ .../bpm/data/writer/VariableScopeWriter.java | 25 +++++++++++ .../writer/CaseServiceVariableWriterTest.java | 24 +++++++++-- .../RuntimeServiceVariableWriterTest.java | 17 ++++++++ .../writer/TaskServiceVariableWriterTest.java | 17 ++++++++ 14 files changed, 277 insertions(+), 6 deletions(-) create mode 100644 example/itest/src/test/kotlin/SmartUpdateTest.kt diff --git a/example/itest/pom.xml b/example/itest/pom.xml index 5053b403..3211f860 100644 --- a/example/itest/pom.xml +++ b/example/itest/pom.xml @@ -169,6 +169,10 @@ spring-boot-starter-test test
+ + org.camunda.bpm.extension.mockito + camunda-bpm-mockito +
diff --git a/example/itest/src/test/kotlin/SmartUpdateTest.kt b/example/itest/src/test/kotlin/SmartUpdateTest.kt new file mode 100644 index 00000000..6e5ea08e --- /dev/null +++ b/example/itest/src/test/kotlin/SmartUpdateTest.kt @@ -0,0 +1,41 @@ +package io.holunda.camunda.bpm.data + +import com.nhaarman.mockito_kotlin.mock +import io.holunda.camunda.bpm.data.CamundaBpmDataKotlin.stringVariable +import io.holunda.camunda.bpm.data.mockito.RuntimeServiceMockVerifier +import io.holunda.camunda.bpm.data.mockito.RuntimeServiceVariableMockBuilder +import org.camunda.bpm.engine.RuntimeService +import org.junit.Test +import java.util.* + +/** + * Test to verify that update is not touching a variable is the value has not changed. + */ +class SmartUpdateTest { + + companion object { + val MY_VAR = stringVariable("myVar") + } + + @Test + fun should_not_touch_global() { + val execId = UUID.randomUUID().toString() + val runtime: RuntimeService = mock() + val verifier = RuntimeServiceMockVerifier(runtime) + RuntimeServiceVariableMockBuilder(runtime).initial(MY_VAR, "value").build() + MY_VAR.on(runtime, execId).update { _ -> "value" } + verifier.verifyGet(MY_VAR, execId) + verifier.verifyNoMoreInteractions() + } + + @Test + fun should_not_touch_local() { + val execId = UUID.randomUUID().toString() + val runtime: RuntimeService = mock() + val verifier = RuntimeServiceMockVerifier(runtime) + RuntimeServiceVariableMockBuilder(runtime).initialLocal(MY_VAR, "value").build() + MY_VAR.on(runtime, execId).updateLocal { _ -> "value" } + verifier.verifyGetLocal(MY_VAR, execId) + verifier.verifyNoMoreInteractions() + } +} diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/AbstractReadWriteAdapter.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/AbstractReadWriteAdapter.java index 180c961e..dc99cf9c 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/AbstractReadWriteAdapter.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/AbstractReadWriteAdapter.java @@ -45,12 +45,22 @@ public T getLocal() { @Override public void update(Function valueProcessor, boolean isTransient) { - set(valueProcessor.apply(get()), isTransient); + T oldValue = get(); + T newValue = valueProcessor.apply(oldValue); + if (!oldValue.equals(newValue)) { + // touch only if the value changes + set(newValue, isTransient); + } } @Override public void updateLocal(Function valueProcessor, boolean isTransient) { - setLocal(valueProcessor.apply(getLocal()), isTransient); + T oldValue = getLocal(); + T newValue = valueProcessor.apply(oldValue); + if (!oldValue.equals(newValue)) { + // touch only if the value changes + setLocal(newValue, isTransient); + } } @Override diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/WriteAdapter.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/WriteAdapter.java index 56d76550..1b1de0e8 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/WriteAdapter.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/adapter/WriteAdapter.java @@ -53,6 +53,7 @@ public interface WriteAdapter { /** * Updates a variable using provided value processor. + *
If the value is unchanged, the variable is not touched. * * @param valueProcessor function updating the value based on the old value. */ @@ -60,6 +61,7 @@ public interface WriteAdapter { /** * Updates a local variable using provided value processor. + *
If the value is unchanged, the variable is not touched. * * @param valueProcessor function updating the value based on the old value. */ @@ -67,6 +69,7 @@ public interface WriteAdapter { /** * Updates a variable using provided value processor. + *
If the value is unchanged, the variable is not touched. * * @param valueProcessor function updating the value based on the old value. * @param isTransient transient flag. @@ -75,6 +78,7 @@ public interface WriteAdapter { /** * Updates a local variable using provided value processor. + *
If the value is unchanged, the variable is not touched. * * @param valueProcessor function updating the value based on the old value. * @param isTransient transient flag. diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/CaseServiceVariableWriter.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/CaseServiceVariableWriter.java index 8d5844de..ec72f289 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/CaseServiceVariableWriter.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/CaseServiceVariableWriter.java @@ -6,6 +6,7 @@ import org.jetbrains.annotations.NotNull; import java.util.Objects; +import java.util.function.Function; /** * Process execution builder allowing for fluent variable setting. @@ -61,6 +62,17 @@ public CaseServiceVariableWriter setLocal(VariableFactory factory, T valu return this; } + @Override + public @NotNull CaseServiceVariableWriter updateLocal(VariableFactory factory, Function valueProcessor) { + return updateLocal(factory, valueProcessor, false); + } + + @Override + public @NotNull CaseServiceVariableWriter updateLocal(VariableFactory factory, Function valueProcessor, boolean isTransient) { + factory.on(this.caseService, this.caseExecutionId).updateLocal(valueProcessor, isTransient); + return this; + } + @Override @NotNull public CaseServiceVariableWriter remove(VariableFactory factory) { @@ -75,6 +87,18 @@ public CaseServiceVariableWriter removeLocal(VariableFactory factory) { return this; } + @Override + public @NotNull CaseServiceVariableWriter update(VariableFactory factory, Function valueProcessor) { + factory.on(this.caseService, this.caseExecutionId).update(valueProcessor); + return this; + } + + @Override + public @NotNull CaseServiceVariableWriter update(VariableFactory factory, Function valueProcessor, boolean isTransient) { + factory.on(this.caseService, this.caseExecutionId).updateLocal(valueProcessor, isTransient); + return this; + } + @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/GlobalVariableWriter.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/GlobalVariableWriter.java index 2f5ce747..4010fa7b 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/GlobalVariableWriter.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/GlobalVariableWriter.java @@ -5,6 +5,8 @@ import org.camunda.bpm.engine.variable.VariableMap; import org.jetbrains.annotations.NotNull; +import java.util.function.Function; + /** * Inverting calls to {@link io.holunda.camunda.bpm.data.adapter.WriteAdapter}. * @@ -35,6 +37,28 @@ public interface GlobalVariableWriter> { */ @NotNull S set(VariableFactory variableFactory, T value, boolean isTransient); + /** + * Sets the global value for the provided variable and returns the builder (fluently). + * + * @param variableFactory the variable + * @param valueProcessor function updating the value based on the old value. + * @param type of value + * @return current writer instance + * @see WriteAdapter#setLocal(Object) + */ + @NotNull S update(VariableFactory variableFactory, Function valueProcessor); + + /** + * Updates the global (transient) value for the provided variable and returns the builder (fluently). + * + * @param variableFactory the variable + * @param valueProcessor function updating the value based on the old value. + * @param isTransient if true, the variable is transient + * @param type of value + * @return current writer instance + * @see WriteAdapter#setLocal(Object, boolean) + */ + @NotNull S update(VariableFactory variableFactory, Function valueProcessor, boolean isTransient); /** * Removes the value for the provided variable and returns the builder (fluently). * diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/LocalVariableWriter.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/LocalVariableWriter.java index d5699943..39ef1373 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/LocalVariableWriter.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/LocalVariableWriter.java @@ -5,6 +5,8 @@ import org.camunda.bpm.engine.variable.VariableMap; import org.jetbrains.annotations.NotNull; +import java.util.function.Function; + /** * Inverting calls to {@link WriteAdapter}. * @@ -35,6 +37,29 @@ public interface LocalVariableWriter> { */ @NotNull S setLocal(VariableFactory variableFactory, T value, boolean isTransient); + /** + * Sets the local value for the provided variable and returns the builder (fluently). + * + * @param variableFactory the variable + * @param valueProcessor function updating the value based on the old value. + * @param type of value + * @return current writer instance + * @see WriteAdapter#setLocal(Object) + */ + @NotNull S updateLocal(VariableFactory variableFactory, Function valueProcessor); + + /** + * Updates the local (transient) value for the provided variable and returns the builder (fluently). + * + * @param variableFactory the variable + * @param valueProcessor function updating the value based on the old value. + * @param isTransient if true, the variable is transient + * @param type of value + * @return current writer instance + * @see WriteAdapter#setLocal(Object, boolean) + */ + @NotNull S updateLocal(VariableFactory variableFactory, Function valueProcessor, boolean isTransient); + /** * Removes the local value for the provided variable and returns the builder (fluently). * diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/RuntimeServiceVariableWriter.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/RuntimeServiceVariableWriter.java index 218d6585..3b24bb8f 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/RuntimeServiceVariableWriter.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/RuntimeServiceVariableWriter.java @@ -6,6 +6,7 @@ import org.jetbrains.annotations.NotNull; import java.util.Objects; +import java.util.function.Function; /** * Process execution builder allowing for fluent variable setting. @@ -75,6 +76,30 @@ public RuntimeServiceVariableWriter removeLocal(VariableFactory factory) return this; } + @Override + public @NotNull RuntimeServiceVariableWriter update(VariableFactory factory, Function valueProcessor) { + factory.on(this.runtimeService, this.executionId).update(valueProcessor); + return this; + } + + @Override + public @NotNull RuntimeServiceVariableWriter update(VariableFactory factory, Function valueProcessor, boolean isTransient) { + factory.on(this.runtimeService, this.executionId).update(valueProcessor, isTransient); + return this; + } + + @Override + public @NotNull RuntimeServiceVariableWriter updateLocal(VariableFactory factory, Function valueProcessor) { + factory.on(this.runtimeService, this.executionId).updateLocal(valueProcessor); + return this; + } + + @Override + public @NotNull RuntimeServiceVariableWriter updateLocal(VariableFactory factory, Function valueProcessor, boolean isTransient) { + factory.on(this.runtimeService, this.executionId).updateLocal(valueProcessor, isTransient); + return this; + } + @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/TaskServiceVariableWriter.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/TaskServiceVariableWriter.java index b57d8fb4..4e8ecd81 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/TaskServiceVariableWriter.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/TaskServiceVariableWriter.java @@ -6,6 +6,7 @@ import org.jetbrains.annotations.NotNull; import java.util.Objects; +import java.util.function.Function; /** * User task builder allowing for fluent variable setting. @@ -75,6 +76,30 @@ public TaskServiceVariableWriter removeLocal(VariableFactory factory) { return this; } + @Override + public @NotNull TaskServiceVariableWriter update(VariableFactory factory, Function valueProcessor) { + factory.on(this.taskService, this.taskId).update(valueProcessor); + return this; + } + + @Override + public @NotNull TaskServiceVariableWriter update(VariableFactory factory, Function valueProcessor, boolean isTransient) { + factory.on(this.taskService, this.taskId).update(valueProcessor, isTransient); + return this; + } + + @Override + public @NotNull TaskServiceVariableWriter updateLocal(VariableFactory factory, Function valueProcessor) { + factory.on(this.taskService, this.taskId).updateLocal(valueProcessor); + return this; + } + + @Override + public @NotNull TaskServiceVariableWriter updateLocal(VariableFactory factory, Function valueProcessor, boolean isTransient) { + factory.on(this.taskService, this.taskId).updateLocal(valueProcessor, isTransient); + return this; + } + @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/VariableMapWriter.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/VariableMapWriter.java index bd0004c5..bd31f8dc 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/VariableMapWriter.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/VariableMapWriter.java @@ -1,10 +1,12 @@ package io.holunda.camunda.bpm.data.writer; +import io.holunda.camunda.bpm.data.CamundaBpmData; import io.holunda.camunda.bpm.data.factory.VariableFactory; import org.camunda.bpm.engine.variable.VariableMap; import org.jetbrains.annotations.NotNull; import java.util.Objects; +import java.util.function.Function; /** * Variable map builder allowing for fluent variable setting. @@ -42,6 +44,18 @@ public VariableMapWriter remove(VariableFactory factory) { return this; } + @Override + public @NotNull VariableMapWriter update(VariableFactory factory, Function valueProcessor) { + factory.on(this.variables).update(valueProcessor); + return this; + } + + @Override + public @NotNull VariableMapWriter update(VariableFactory factory, Function valueProcessor, boolean isTransient) { + factory.on(this.variables).update(valueProcessor, isTransient); + return this; + } + @Override @NotNull public VariableMap variables() { diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/VariableScopeWriter.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/VariableScopeWriter.java index 6eb8cf2e..9db2bb7e 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/VariableScopeWriter.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/VariableScopeWriter.java @@ -6,6 +6,7 @@ import org.jetbrains.annotations.NotNull; import java.util.Objects; +import java.util.function.Function; /** * Variable scope builder allowing for fluent variable setting. @@ -50,6 +51,30 @@ public VariableScopeWriter setLocal(VariableFactory factory, T value, boo return this; } + @Override + public @NotNull VariableScopeWriter update(VariableFactory factory, Function valueProcessor) { + factory.on(this.scope).update(valueProcessor); + return this; + } + + @Override + public @NotNull VariableScopeWriter update(VariableFactory factory, Function valueProcessor, boolean isTransient) { + factory.on(this.scope).update(valueProcessor, isTransient); + return this; + } + + @Override + public @NotNull VariableScopeWriter updateLocal(VariableFactory factory, Function valueProcessor) { + factory.on(this.scope).updateLocal(valueProcessor); + return this; + } + + @Override + public @NotNull VariableScopeWriter updateLocal(VariableFactory factory, Function valueProcessor, boolean isTransient) { + factory.on(this.scope).updateLocal(valueProcessor, isTransient); + return this; + } + @Override @NotNull public VariableScopeWriter remove(VariableFactory factory) { diff --git a/extension/core/src/test/java/io/holunda/camunda/bpm/data/writer/CaseServiceVariableWriterTest.java b/extension/core/src/test/java/io/holunda/camunda/bpm/data/writer/CaseServiceVariableWriterTest.java index 8b4c93c9..62934949 100644 --- a/extension/core/src/test/java/io/holunda/camunda/bpm/data/writer/CaseServiceVariableWriterTest.java +++ b/extension/core/src/test/java/io/holunda/camunda/bpm/data/writer/CaseServiceVariableWriterTest.java @@ -12,8 +12,8 @@ import java.util.UUID; import static io.holunda.camunda.bpm.data.CamundaBpmData.stringVariable; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.camunda.bpm.engine.variable.Variables.stringValue; +import static org.mockito.Mockito.*; public class CaseServiceVariableWriterTest { @@ -39,14 +39,14 @@ public void after() { public void testSet() { CamundaBpmData.writer(caseService, CASE_EXECUTION_ID) .set(STRING, "value"); - verify(caseService).setVariable(CASE_EXECUTION_ID, STRING.getName(), Variables.stringValue("value")); + verify(caseService).setVariable(CASE_EXECUTION_ID, STRING.getName(), stringValue("value")); } @Test public void testSetLocal() { CamundaBpmData.writer(caseService, CASE_EXECUTION_ID) .setLocal(STRING, "value"); - verify(caseService).setVariableLocal(CASE_EXECUTION_ID, STRING.getName(), Variables.stringValue("value")); + verify(caseService).setVariableLocal(CASE_EXECUTION_ID, STRING.getName(), stringValue("value")); } @Test @@ -63,4 +63,20 @@ public void testRemoveLocal() { verify(caseService).removeVariableLocal(CASE_EXECUTION_ID, STRING.getName()); } + @Test + public void testUpdate() { + CamundaBpmData.writer(caseService, CASE_EXECUTION_ID) + .update(STRING, (old) -> "new value"); + verify(caseService).getVariable(CASE_EXECUTION_ID, STRING.getName()); + verify(caseService).setVariable(CASE_EXECUTION_ID, STRING.getName(), stringValue("new value")); + } + + @Test + public void testUpdateLocal() { + CamundaBpmData.writer(caseService, CASE_EXECUTION_ID) + .updateLocal(STRING, (old) -> "new value"); + verify(caseService).getVariableLocal(CASE_EXECUTION_ID, STRING.getName()); + verify(caseService).setVariableLocal(CASE_EXECUTION_ID, STRING.getName(), stringValue("new value")); + } + } diff --git a/extension/core/src/test/java/io/holunda/camunda/bpm/data/writer/RuntimeServiceVariableWriterTest.java b/extension/core/src/test/java/io/holunda/camunda/bpm/data/writer/RuntimeServiceVariableWriterTest.java index 7dc743c1..19ebab6c 100644 --- a/extension/core/src/test/java/io/holunda/camunda/bpm/data/writer/RuntimeServiceVariableWriterTest.java +++ b/extension/core/src/test/java/io/holunda/camunda/bpm/data/writer/RuntimeServiceVariableWriterTest.java @@ -12,6 +12,7 @@ import java.util.UUID; import static io.holunda.camunda.bpm.data.CamundaBpmData.stringVariable; +import static org.camunda.bpm.engine.variable.Variables.stringValue; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -63,4 +64,20 @@ public void testRemoveLocal() { verify(runtimeService).removeVariableLocal(EXECUTION_ID, STRING.getName()); } + @Test + public void testUpdate() { + CamundaBpmData.writer(runtimeService, EXECUTION_ID) + .update(STRING, (old) -> "new value"); + verify(runtimeService).getVariable(EXECUTION_ID, STRING.getName()); + verify(runtimeService).setVariable(EXECUTION_ID, STRING.getName(), stringValue("new value")); + } + + @Test + public void testUpdateLocal() { + CamundaBpmData.writer(runtimeService, EXECUTION_ID) + .updateLocal(STRING, (old) -> "new value"); + verify(runtimeService).getVariableLocal(EXECUTION_ID, STRING.getName()); + verify(runtimeService).setVariableLocal(EXECUTION_ID, STRING.getName(), stringValue("new value")); + } + } diff --git a/extension/core/src/test/java/io/holunda/camunda/bpm/data/writer/TaskServiceVariableWriterTest.java b/extension/core/src/test/java/io/holunda/camunda/bpm/data/writer/TaskServiceVariableWriterTest.java index b7c12a63..e11b18df 100644 --- a/extension/core/src/test/java/io/holunda/camunda/bpm/data/writer/TaskServiceVariableWriterTest.java +++ b/extension/core/src/test/java/io/holunda/camunda/bpm/data/writer/TaskServiceVariableWriterTest.java @@ -12,6 +12,7 @@ import java.util.UUID; import static io.holunda.camunda.bpm.data.CamundaBpmData.stringVariable; +import static org.camunda.bpm.engine.variable.Variables.stringValue; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -64,4 +65,20 @@ public void testRemoveLocal() { verify(taskService).removeVariableLocal(TASK_ID, STRING.getName()); } + @Test + public void testUpdate() { + CamundaBpmData.writer(taskService, TASK_ID) + .update(STRING, (old) -> "new value"); + verify(taskService).getVariable(TASK_ID, STRING.getName()); + verify(taskService).setVariable(TASK_ID, STRING.getName(), stringValue("new value")); + } + + @Test + public void testUpdateLocal() { + CamundaBpmData.writer(taskService, TASK_ID) + .updateLocal(STRING, (old) -> "new value"); + verify(taskService).getVariableLocal(TASK_ID, STRING.getName()); + verify(taskService).setVariableLocal(TASK_ID, STRING.getName(), stringValue("new value")); + } + } From 246c576116f4ce5e2505f0f816bf30dcfa3fd066 Mon Sep 17 00:00:00 2001 From: Simon Zambrovski Date: Tue, 25 Aug 2020 17:27:47 +0200 Subject: [PATCH 15/23] changelog --- docs/src/orchid/resources/changelog/1.1/1.1.0.ad | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/src/orchid/resources/changelog/1.1/1.1.0.ad b/docs/src/orchid/resources/changelog/1.1/1.1.0.ad index f6af1372..9d8fa55e 100644 --- a/docs/src/orchid/resources/changelog/1.1/1.1.0.ad +++ b/docs/src/orchid/resources/changelog/1.1/1.1.0.ad @@ -6,6 +6,8 @@ version: 1.1.0 * Improve Kotlin API with extension functions on `VariableMap` and `VariableScope`, see #58 * Provides Kotlin operators for read/write from/on `VariableMap` and `VariableScope`, see #65 +* Support smart update (set variable only if the value changed), see #65 +* Provide `update` and `updateLocal` methods in `Writer` interface, see #70 == Breaking Changes From 685ac895e6cab777b36e8f7a8146ee412fe2d239 Mon Sep 17 00:00:00 2001 From: Simon Zambrovski Date: Tue, 25 Aug 2020 17:34:34 +0200 Subject: [PATCH 16/23] fixed imports --- .../io/holunda/camunda/bpm/data/writer/VariableMapWriter.java | 1 - .../bpm/data/writer/CaseServiceVariableWriterTest.java | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/VariableMapWriter.java b/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/VariableMapWriter.java index bd31f8dc..b98cf3f6 100644 --- a/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/VariableMapWriter.java +++ b/extension/core/src/main/java/io/holunda/camunda/bpm/data/writer/VariableMapWriter.java @@ -1,6 +1,5 @@ package io.holunda.camunda.bpm.data.writer; -import io.holunda.camunda.bpm.data.CamundaBpmData; import io.holunda.camunda.bpm.data.factory.VariableFactory; import org.camunda.bpm.engine.variable.VariableMap; import org.jetbrains.annotations.NotNull; diff --git a/extension/core/src/test/java/io/holunda/camunda/bpm/data/writer/CaseServiceVariableWriterTest.java b/extension/core/src/test/java/io/holunda/camunda/bpm/data/writer/CaseServiceVariableWriterTest.java index 62934949..600b6f74 100644 --- a/extension/core/src/test/java/io/holunda/camunda/bpm/data/writer/CaseServiceVariableWriterTest.java +++ b/extension/core/src/test/java/io/holunda/camunda/bpm/data/writer/CaseServiceVariableWriterTest.java @@ -3,7 +3,6 @@ import io.holunda.camunda.bpm.data.CamundaBpmData; import io.holunda.camunda.bpm.data.factory.VariableFactory; import org.camunda.bpm.engine.CaseService; -import org.camunda.bpm.engine.variable.Variables; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -13,7 +12,8 @@ import static io.holunda.camunda.bpm.data.CamundaBpmData.stringVariable; import static org.camunda.bpm.engine.variable.Variables.stringValue; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; public class CaseServiceVariableWriterTest { From 931c5bee920cffa6d1b11cad302161f4153c920f Mon Sep 17 00:00:00 2001 From: Simon Zambrovski Date: Fri, 11 Sep 2020 14:40:03 +0200 Subject: [PATCH 17/23] uniform Guard API, fix #67, fix #72 --- .../main/kotlin/guard/CamundaBpmDataGuards.kt | 29 +++++++++---------- .../condition/VariableExistsGuardCondition.kt | 11 +++++-- .../VariableMatchesGuardCondition.kt | 10 +++++-- .../VariableNotExistsGuardCondition.kt | 8 +++-- .../condition/VariableValueGuardCondition.kt | 10 +++++-- .../VariableValueOneOfGuardCondition.kt | 10 +++++-- .../kotlin/guard/CamundaBpmDataGuardsTest.kt | 20 ++++++------- 7 files changed, 61 insertions(+), 37 deletions(-) diff --git a/extension/core/src/main/kotlin/guard/CamundaBpmDataGuards.kt b/extension/core/src/main/kotlin/guard/CamundaBpmDataGuards.kt index 4fa60239..d4973e77 100644 --- a/extension/core/src/main/kotlin/guard/CamundaBpmDataGuards.kt +++ b/extension/core/src/main/kotlin/guard/CamundaBpmDataGuards.kt @@ -16,22 +16,22 @@ object CamundaBpmDataGuards { * @param local flag indicating scope (global/local). */ @JvmStatic - fun exists(variableFactory: VariableFactory, local: Boolean = false) = variableFactory.exists(local) + fun exists(variableFactory: VariableFactory) = variableFactory.exists() /** - * Creates exists condition. + * Creates exists local condition. * @param variableFactory factory to work on. + * @param local flag indicating scope (global/local). */ @JvmStatic - fun exists(variableFactory: VariableFactory) = variableFactory.exists() + fun existsLocal(variableFactory: VariableFactory) = variableFactory.existsLocal() /** - * Creates not exists condition. + * Creates not exists local condition. * @param variableFactory factory to work on. - * @param local flag indicating scope (global/local). */ @JvmStatic - fun notExists(variableFactory: VariableFactory, local: Boolean = false) = variableFactory.notExists(local) + fun notExistsLocal(variableFactory: VariableFactory) = variableFactory.notExistsLocal() /** * Creates not exists condition. @@ -41,13 +41,12 @@ object CamundaBpmDataGuards { fun notExists(variableFactory: VariableFactory) = variableFactory.notExists() /** - * Creates has value condition. + * Creates has value local condition. * @param variableFactory factory to work on. - * @param local flag indicating scope (global/local). * @param value value that the variable must have. */ @JvmStatic - fun hasValue(variableFactory: VariableFactory, value: T, local: Boolean = false) = variableFactory.hasValue(value, local) + fun hasValueLocal(variableFactory: VariableFactory, value: T) = variableFactory.hasValueLocal(value) /** * Creates has value condition. @@ -58,13 +57,12 @@ object CamundaBpmDataGuards { fun hasValue(variableFactory: VariableFactory, value: T) = variableFactory.hasValue(value) /** - * Creates has value condition. + * Creates has value local condition. * @param variableFactory factory to work on. - * @param local flag indicating scope (global/local). * @param values set of values to compare with the variable value. */ @JvmStatic - fun hasOneOfValues(variableFactory: VariableFactory, values: Set, local: Boolean = false) = variableFactory.hasOneOfValues(values, local) + fun hasOneOfValuesLocal(variableFactory: VariableFactory, values: Set) = variableFactory.hasOneOfValuesLocal(values) /** * Creates has value condition. @@ -75,14 +73,13 @@ object CamundaBpmDataGuards { fun hasOneOfValues(variableFactory: VariableFactory, values: Set) = variableFactory.hasOneOfValues(values) /** - * Creates matches condition. + * Creates matches local condition. * @param variableFactory factory to work on. - * @param local flag indicating scope (global/local). * @param matcher a matcher function to check the variable value. */ @JvmStatic - fun matches(variableFactory: VariableFactory, - matcher: Function, local: Boolean = false) = variableFactory.matches(local) { matcher.apply(it) } + fun matchesLocal(variableFactory: VariableFactory, + matcher: Function) = variableFactory.matchesLocal { matcher.apply(it) } /** * Creates matches condition. diff --git a/extension/core/src/main/kotlin/guard/condition/VariableExistsGuardCondition.kt b/extension/core/src/main/kotlin/guard/condition/VariableExistsGuardCondition.kt index 1d81c0ca..ba5be980 100644 --- a/extension/core/src/main/kotlin/guard/condition/VariableExistsGuardCondition.kt +++ b/extension/core/src/main/kotlin/guard/condition/VariableExistsGuardCondition.kt @@ -32,8 +32,13 @@ class VariableExistsGuardCondition( } /** - * Creation extension for the condition. - * @param local is the variable should be local. + * Creates extension for the condition. * @return instance of [VariableExistsGuardCondition] on current factory. */ -fun VariableFactory.exists(local: Boolean = false) = VariableExistsGuardCondition(this, local) +fun VariableFactory.exists() = VariableExistsGuardCondition(this, false) + +/** + * Creates extension for the local condition. + * @return instance of [VariableExistsGuardCondition] on current factory. + */ +fun VariableFactory.existsLocal() = VariableExistsGuardCondition(this, true) diff --git a/extension/core/src/main/kotlin/guard/condition/VariableMatchesGuardCondition.kt b/extension/core/src/main/kotlin/guard/condition/VariableMatchesGuardCondition.kt index 40ae72ad..44824a3b 100644 --- a/extension/core/src/main/kotlin/guard/condition/VariableMatchesGuardCondition.kt +++ b/extension/core/src/main/kotlin/guard/condition/VariableMatchesGuardCondition.kt @@ -45,8 +45,14 @@ class VariableMatchesGuardCondition( /** * Creation extension for the condition. - * @param local is the variable should be local. * @param matcher function that must match the value. * @return instance of [VariableMatchesGuardCondition] on current factory. */ -fun VariableFactory.matches(local: Boolean = false, matcher: (value: T) -> Boolean) = VariableMatchesGuardCondition(this, local, matcher) +fun VariableFactory.matches(matcher: (value: T) -> Boolean) = VariableMatchesGuardCondition(this, false, matcher) + +/** + * Creation extension for the condition. + * @param matcher function that must match the value. + * @return instance of [VariableMatchesGuardCondition] on current factory. + */ +fun VariableFactory.matchesLocal(matcher: (value: T) -> Boolean) = VariableMatchesGuardCondition(this, true, matcher) diff --git a/extension/core/src/main/kotlin/guard/condition/VariableNotExistsGuardCondition.kt b/extension/core/src/main/kotlin/guard/condition/VariableNotExistsGuardCondition.kt index 1e2d2bda..877d539d 100644 --- a/extension/core/src/main/kotlin/guard/condition/VariableNotExistsGuardCondition.kt +++ b/extension/core/src/main/kotlin/guard/condition/VariableNotExistsGuardCondition.kt @@ -34,8 +34,12 @@ class VariableNotExistsGuardCondition( /** * Creation extension for the condition. - * @param local is the variable should be local. * @return instance of [VariableNotExistsGuardCondition] on current factory. */ -fun VariableFactory.notExists(local: Boolean = false) = VariableNotExistsGuardCondition(this, local) +fun VariableFactory.notExists() = VariableNotExistsGuardCondition(this, false) +/** + * Creation extension for the local condition. + * @return instance of [VariableNotExistsGuardCondition] on current factory. + */ +fun VariableFactory.notExistsLocal() = VariableNotExistsGuardCondition(this, true) diff --git a/extension/core/src/main/kotlin/guard/condition/VariableValueGuardCondition.kt b/extension/core/src/main/kotlin/guard/condition/VariableValueGuardCondition.kt index 25153756..74379927 100644 --- a/extension/core/src/main/kotlin/guard/condition/VariableValueGuardCondition.kt +++ b/extension/core/src/main/kotlin/guard/condition/VariableValueGuardCondition.kt @@ -44,8 +44,14 @@ class VariableValueGuardCondition( /** * Creation extension for the condition. * @param value value to check for. - * @param local if the variable should be local. * @return instance of [VariableValueGuardCondition] on current factory. */ -fun VariableFactory.hasValue(value: T, local: Boolean = false) = VariableValueGuardCondition(this, value, local) +fun VariableFactory.hasValue(value: T) = VariableValueGuardCondition(this, value, false) + +/** + * Creation extension for the condition. + * @param value value to check for. + * @return instance of [VariableValueGuardCondition] on current factory. + */ +fun VariableFactory.hasValueLocal(value: T) = VariableValueGuardCondition(this, value, true) diff --git a/extension/core/src/main/kotlin/guard/condition/VariableValueOneOfGuardCondition.kt b/extension/core/src/main/kotlin/guard/condition/VariableValueOneOfGuardCondition.kt index 7e3a851c..6876d817 100644 --- a/extension/core/src/main/kotlin/guard/condition/VariableValueOneOfGuardCondition.kt +++ b/extension/core/src/main/kotlin/guard/condition/VariableValueOneOfGuardCondition.kt @@ -44,8 +44,14 @@ class VariableValueOneOfGuardCondition( /** * Creation extension for the condition. - * @param local is the variable should be local. * @param values set of values which are allowed. * @return instance of [VariableValueOneOfGuardCondition] on current factory. */ -fun VariableFactory.hasOneOfValues(values: Set, local: Boolean = false) = VariableValueOneOfGuardCondition(this, values, local) +fun VariableFactory.hasOneOfValues(values: Set) = VariableValueOneOfGuardCondition(this, values, false) + +/** + * Creation extension for the local condition. + * @param values set of values which are allowed. + * @return instance of [VariableValueOneOfGuardCondition] on current factory. + */ +fun VariableFactory.hasOneOfValuesLocal(values: Set) = VariableValueOneOfGuardCondition(this, values, true) diff --git a/extension/core/src/test/kotlin/guard/CamundaBpmDataGuardsTest.kt b/extension/core/src/test/kotlin/guard/CamundaBpmDataGuardsTest.kt index 7362db26..e85831a5 100644 --- a/extension/core/src/test/kotlin/guard/CamundaBpmDataGuardsTest.kt +++ b/extension/core/src/test/kotlin/guard/CamundaBpmDataGuardsTest.kt @@ -21,7 +21,7 @@ class CamundaBpmDataGuardsTest { @Test fun `should construct exists local condition`() { - val condition = CamundaBpmDataGuards.exists(FOO, true) + val condition = CamundaBpmDataGuards.existsLocal(FOO) assertThat(condition).isInstanceOf(VariableExistsGuardCondition::class.java) assertThat(condition.variableFactory).isEqualTo(FOO) assertThat(condition.local).isEqualTo(true) @@ -37,7 +37,7 @@ class CamundaBpmDataGuardsTest { @Test fun `should construct notExists local condition`() { - val condition = CamundaBpmDataGuards.notExists(FOO, true) + val condition = CamundaBpmDataGuards.notExistsLocal(FOO) assertThat(condition).isInstanceOf(VariableNotExistsGuardCondition::class.java) assertThat(condition.variableFactory).isEqualTo(FOO) assertThat(condition.local).isEqualTo(true) @@ -54,7 +54,7 @@ class CamundaBpmDataGuardsTest { @Test fun `should construct hasValue local condition`() { - val condition = CamundaBpmDataGuards.hasValue(FOO, "valLocal", true) + val condition = CamundaBpmDataGuards.hasValueLocal(FOO, "valLocal") assertThat(condition).isInstanceOf(VariableValueGuardCondition::class.java) assertThat(condition.variableFactory).isEqualTo(FOO) assertThat(condition.local).isEqualTo(true) @@ -72,7 +72,7 @@ class CamundaBpmDataGuardsTest { @Test fun `should construct hasOneOfValues local condition`() { - val condition = CamundaBpmDataGuards.hasOneOfValues(FOO, setOf("valLocal1", "valLocal2"), true) + val condition = CamundaBpmDataGuards.hasOneOfValuesLocal(FOO, setOf("valLocal1", "valLocal2")) assertThat(condition).isInstanceOf(VariableValueOneOfGuardCondition::class.java) assertThat(condition.variableFactory).isEqualTo(FOO) assertThat(condition.local).isEqualTo(true) @@ -90,7 +90,7 @@ class CamundaBpmDataGuardsTest { @Test fun `should construct matches local condition`() { - val condition = CamundaBpmDataGuards.matches(FOO, Function { it == "special_val_local" }, true) + val condition = CamundaBpmDataGuards.matchesLocal(FOO, Function { it == "special_val_local" }) assertThat(condition).isInstanceOf(VariableMatchesGuardCondition::class.java) assertThat(condition.variableFactory).isEqualTo(FOO) assertThat(condition.local).isEqualTo(true) @@ -107,7 +107,7 @@ class CamundaBpmDataGuardsTest { @Test fun `kotlin should construct exists local condition`() { - val condition = FOO.exists(true) + val condition = FOO.existsLocal() assertThat(condition).isInstanceOf(VariableExistsGuardCondition::class.java) assertThat(condition.variableFactory).isEqualTo(FOO) assertThat(condition.local).isEqualTo(true) @@ -123,7 +123,7 @@ class CamundaBpmDataGuardsTest { @Test fun `kotlin should construct notExists local condition`() { - val condition = FOO.notExists(true) + val condition = FOO.notExistsLocal() assertThat(condition).isInstanceOf(VariableNotExistsGuardCondition::class.java) assertThat(condition.variableFactory).isEqualTo(FOO) assertThat(condition.local).isEqualTo(true) @@ -140,7 +140,7 @@ class CamundaBpmDataGuardsTest { @Test fun `kotlin should construct hasValue local condition`() { - val condition = FOO.hasValue("valLocal", true) + val condition = FOO.hasValueLocal("valLocal") assertThat(condition).isInstanceOf(VariableValueGuardCondition::class.java) assertThat(condition.variableFactory).isEqualTo(FOO) assertThat(condition.local).isEqualTo(true) @@ -158,7 +158,7 @@ class CamundaBpmDataGuardsTest { @Test fun `kotlin should construct hasOneOfValues local condition`() { - val condition = FOO.hasOneOfValues(setOf("valLocal1", "valLocal2"), true) + val condition = FOO.hasOneOfValuesLocal(setOf("valLocal1", "valLocal2")) assertThat(condition).isInstanceOf(VariableValueOneOfGuardCondition::class.java) assertThat(condition.variableFactory).isEqualTo(FOO) assertThat(condition.local).isEqualTo(true) @@ -176,7 +176,7 @@ class CamundaBpmDataGuardsTest { @Test fun `kotlin should construct matches local condition`() { - val condition = FOO.matches(true) { it == "special_val_local" } + val condition = FOO.matchesLocal { it == "special_val_local" } assertThat(condition).isInstanceOf(VariableMatchesGuardCondition::class.java) assertThat(condition.variableFactory).isEqualTo(FOO) assertThat(condition.local).isEqualTo(true) From 3425b65950098b6b5beac41e108e86fc2c6b374b Mon Sep 17 00:00:00 2001 From: Jan Galinski Date: Sat, 12 Sep 2020 12:52:43 +0200 Subject: [PATCH 18/23] Update README.adoc --- README.adoc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.adoc b/README.adoc index e65eb220..003a9f5c 100644 --- a/README.adoc +++ b/README.adoc @@ -51,20 +51,20 @@ If you just want to start using the library, put the following dependency into y io.holunda.data camunda-bpm-data - 1.0.1 + 1.0.2 ---- If you are using Gradle Kotlin DSL add to your `build.gradle.kts`: [source,kotlin] ---- -implementation("io.holunda.data:camunda-bpm-data:1.0.1") +implementation("io.holunda.data:camunda-bpm-data:1.0.2") ---- For Gradle Groovy DSL add to your `build.gradle`: [source,groovy] ---- -implementation 'io.holunda.data:camunda-bpm-data:1.0.1' +implementation 'io.holunda.data:camunda-bpm-data:1.0.2' ---- === Variable declaration From ff47d01d235ad4df8ca39fde88459792fc303f88 Mon Sep 17 00:00:00 2001 From: Simon Zambrovski Date: Tue, 15 Sep 2020 10:19:44 +0200 Subject: [PATCH 19/23] fixed name of GITHUB TOKEN secret --- .github/workflows/master.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index 3080fd22..3517c9fd 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -53,7 +53,7 @@ jobs: run: ./mvnw clean deploy -B -DskipTests -DskipExamples -Prelease -Dgpg.keyname=${{secrets.GPG_KEYNAME}} -Dgpg.passphrase=${{secrets.GPG_PASSPHRASE}} - name: Build and deploy site docs - run: ./mvnw -Pdeploy-docs -f docs -DgithubToken=${{secrets.GH_TOKEN}} + run: ./mvnw -Pdeploy-docs -f docs -DgithubToken=${{secrets.GITHUB_TOKEN}} - name: Upload coverage to Codecov uses: codecov/codecov-action@v1.0.2 From 905c40941194c2d63a894b4278721d9f13701702 Mon Sep 17 00:00:00 2001 From: Simon Zambrovski Date: Thu, 24 Sep 2020 01:02:00 +0200 Subject: [PATCH 20/23] improve docs, fixes #73, fixes #74, fixes #75 --- .github/workflows/default.yml | 6 +- .github/workflows/master.yml | 6 +- .../orchid/resources/changelog/1.1/1.1.0.ad | 10 +++ docs/src/orchid/resources/config.yml | 41 +++++------- docs/src/orchid/resources/config/theme.yml | 14 +++- .../src/orchid/resources/pages/quick-start.ad | 8 +-- extension/core/pom.xml | 1 + extension/test/pom.xml | 1 + extension/test/src/main/kotlin/packages.md | 6 ++ pom.xml | 67 +++++++++---------- 10 files changed, 87 insertions(+), 73 deletions(-) create mode 100644 extension/test/src/main/kotlin/packages.md diff --git a/.github/workflows/default.yml b/.github/workflows/default.yml index a10a27cb..a7feb030 100644 --- a/.github/workflows/default.yml +++ b/.github/workflows/default.yml @@ -14,12 +14,12 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v1 + uses: actions/checkout@v2 - - name: Set up JDK 1.8 + - name: Set up JDK 11 uses: actions/setup-java@v1 with: - java-version: 1.8 + java-version: 11 - name: Cache .m2 uses: actions/cache@v1 diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index 3517c9fd..07b2a97f 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -11,12 +11,12 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v1 + uses: actions/checkout@v2 - - name: Set up JDK 1.8 + - name: Set up JDK 11 uses: actions/setup-java@v1 with: - java-version: 1.8 + java-version: 11 - name: Cache .m2 uses: actions/cache@v1 diff --git a/docs/src/orchid/resources/changelog/1.1/1.1.0.ad b/docs/src/orchid/resources/changelog/1.1/1.1.0.ad index 9d8fa55e..c3d18aae 100644 --- a/docs/src/orchid/resources/changelog/1.1/1.1.0.ad +++ b/docs/src/orchid/resources/changelog/1.1/1.1.0.ad @@ -13,8 +13,18 @@ version: 1.1.0 * Guard API follows conventions of VariableFactory API (adding `Local` to method name for local scope), #67 +== Bugfix + +* Fix docs generation of quickstart, see #73 + +== Documentation + +* Include JavaDocs and KDocs into site, see #75 + == Chore +* Switch to JDK 11 +* Upgrade to Kotlin 1.4.10 and Dokka 1.4.10, see #74 * Upgrade to Kotlin 1.4.0, see #69 * Upgrade to Camunda BPM 7.13, see #69 * Upgrade to SpringBoot 2.3.2, see #69 diff --git a/docs/src/orchid/resources/config.yml b/docs/src/orchid/resources/config.yml index 589f1cdb..ab157bd6 100644 --- a/docs/src/orchid/resources/config.yml +++ b/docs/src/orchid/resources/config.yml @@ -24,37 +24,32 @@ allPages: - 'show-language' - 'copy-to-clipboard' -services: - publications: - stages: - - type: 'githubPages' - username: 'zambrovski' - repo: 'holunda-io/camunda-bpm-data' - -# -# FIXME: move to separate file after 0.19 release of orchid -# -javadoc: - modules: - - name: Camunda BPM Data - sourceDirs: - - '../../../../extension/src/main/java' +kotlindoc: + sourceDirs: + - './../../../../extension/core/src/main/kotlin' + - './../../../../extension/test/src/main/kotlin' + homePageOnly: false pages: menu: - type: 'sourcedocPageLinks' - moduleType: 'javadoc' + moduleType: 'kotlindoc' itemTitleType: 'SIGNATURE' includeItems: true -kotlindoc: - modules: - - name: Camunda BPM Data Kotlin - sourceDirs: - - '../../../../extension-kotlin/src/main/kotlin' +javadoc: + sourceDirs: + - './../../../../extension/core/src/main/java' pages: menu: - type: 'sourcedocPageLinks' - moduleType: 'kotlindoc' + moduleType: 'javadoc' + itemTitleType: 'SIGNATURE' includeItems: true - itemTitleType: 'NAME' + +services: + publications: + stages: + - type: 'githubPages' + username: 'holunda-io' + repo: 'holunda-io/camunda-bpm-data' diff --git a/docs/src/orchid/resources/config/theme.yml b/docs/src/orchid/resources/config/theme.yml index 89fffc3f..12137a46 100644 --- a/docs/src/orchid/resources/config/theme.yml +++ b/docs/src/orchid/resources/config/theme.yml @@ -40,9 +40,19 @@ menu: - type: 'page' title: 'License' itemId: 'License' - - type: 'sourcedocPages' - submenuTitle: 'JavaDoc All Packages' moduleType: 'javadoc' node: 'packages' asSubmenu: true + submenuTitle: 'Java Packages' + - type: 'sourcedocPages' + moduleType: 'kotlindoc' + node: 'packages' + asSubmenu: true + submenuTitle: 'Kotlin Packages' + +# - type: 'sourcedocModules' +# submenuTitle: 'JavaDoc All Packages' +# moduleType: 'javadoc' +# node: 'packages' + diff --git a/docs/src/orchid/resources/pages/quick-start.ad b/docs/src/orchid/resources/pages/quick-start.ad index aeb82222..d25e03ac 100644 --- a/docs/src/orchid/resources/pages/quick-start.ad +++ b/docs/src/orchid/resources/pages/quick-start.ad @@ -1,8 +1,6 @@ --- - title: Quick Start pageId: 'quick-start' - --- == {{ page.title }} @@ -16,20 +14,20 @@ In Apache Maven add to your `pom.xml`: io.holunda.data camunda-bpm-data - {{ site:version }} + ${camunda-bpm-data.version} ---- For Gradle Kotlin DSL add to your `build.gradle.kts`: [source,kotlin] ---- -implementation("io.holunda.data:camunda-bpm-data:{{ site:version }}") +implementation("io.holunda.data:camunda-bpm-data:${camunda-bpm-data.version}") ---- For Gradle Groovy DSL add to your `build.gradle`: [source,groovy] ---- -implementation 'io.holunda.data:camunda-bpm-data:{{ site:version }}' +implementation 'io.holunda.data:camunda-bpm-data:${camunda-bpm-data.version}' ---- === Declare process variable factories diff --git a/extension/core/pom.xml b/extension/core/pom.xml index 5fbc2460..afd8ed04 100644 --- a/extension/core/pom.xml +++ b/extension/core/pom.xml @@ -16,6 +16,7 @@ false + false diff --git a/extension/test/pom.xml b/extension/test/pom.xml index e2b7d228..4b0aaeb7 100644 --- a/extension/test/pom.xml +++ b/extension/test/pom.xml @@ -16,6 +16,7 @@ false + false 1.6.0 diff --git a/extension/test/src/main/kotlin/packages.md b/extension/test/src/main/kotlin/packages.md new file mode 100644 index 00000000..9c121b41 --- /dev/null +++ b/extension/test/src/main/kotlin/packages.md @@ -0,0 +1,6 @@ +# Package io.holunda.camunda.bpm.data.mockito + +Top-level package of the test library. + +check [io.holunda.camunda.bpm.data.mockito.CamundaBpmDataMockito] as entry point. +@since 0.0.2 diff --git a/pom.xml b/pom.xml index 3cd6055f..a940234e 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ UTF-8 UTF-8 - 1.8 + 11 ${java.version} ${java.version} ${java.version} @@ -29,7 +29,7 @@ 5.0.0 0.18.2 - 1.4.0 + 1.4.10 1.7.6 2.2.0 4.12.0 @@ -38,11 +38,10 @@ **/*ITest.* **/itest/**/*.* - false - - -Xdoclint:none true + + true @@ -230,7 +229,7 @@ - + org.apache.maven.plugins maven-compiler-plugin 3.8.1 @@ -268,7 +267,7 @@ - + kotlin-maven-plugin org.jetbrains.kotlin ${kotlin.version} @@ -337,7 +336,7 @@ maven-surefire-plugin - 2.20.1 + 2.22.2 false kill @@ -359,27 +358,36 @@ org.apache.maven.plugins maven-failsafe-plugin - 2.20.1 + 2.22.2 - + org.jetbrains.dokka dokka-maven-plugin - 0.10.1 + 1.4.10 attach-javadocs package + dokka javadocJar + ${dokka.skip} - packages.md + ${project.basedir}/src/main/kotlin/packages.md + + + ${project.basedir} + https://github.com/holunda-io/camunda-bpm-data/blob/master + #L + + 8 ${project.basedir}/src/main/kotlin @@ -387,22 +395,7 @@ - - org.apache.maven.plugins - maven-javadoc-plugin - 3.1.1 - - - attach-javadocs - package - - jar - - - - - - + org.codehaus.mojo build-helper-maven-plugin @@ -653,14 +646,6 @@ org.apache.maven.plugins maven-source-plugin - - org.apache.maven.plugins - maven-gpg-plugin - - - org.sonatype.plugins - nexus-staging-maven-plugin - org.jetbrains.dokka dokka-maven-plugin @@ -669,6 +654,14 @@ org.codehaus.mojo build-helper-maven-plugin + + org.apache.maven.plugins + maven-gpg-plugin + + + org.sonatype.plugins + nexus-staging-maven-plugin +
@@ -732,7 +725,7 @@ - + jcenter JCenter From 5cf42fec3b405882e2d4131dab43dbfaad50ff97 Mon Sep 17 00:00:00 2001 From: Simon Zambrovski Date: Mon, 28 Sep 2020 17:52:34 +0200 Subject: [PATCH 21/23] Update examples-kotlin.ad --- docs/src/orchid/resources/wiki/user-guide/examples-kotlin.ad | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/orchid/resources/wiki/user-guide/examples-kotlin.ad b/docs/src/orchid/resources/wiki/user-guide/examples-kotlin.ad index 38de79c7..bbf8027a 100644 --- a/docs/src/orchid/resources/wiki/user-guide/examples-kotlin.ad +++ b/docs/src/orchid/resources/wiki/user-guide/examples-kotlin.ad @@ -209,7 +209,7 @@ class SomeService { ); fun correlate() { - val variables = CamundaBpmData.writer() + val variables = CamundaBpmData.builder() .set(ORDER_ID, "4711") .set(ORDER_APPROVED, false) .build(); From de167d844a8108ec881d8241f4a84d31f20614c5 Mon Sep 17 00:00:00 2001 From: Simon Zambrovski Date: Tue, 6 Oct 2020 17:43:24 +0200 Subject: [PATCH 22/23] Update versions for release --- docs/pom.xml | 2 +- example/coverage-report-aggregator/pom.xml | 2 +- example/example-java/pom.xml | 2 +- example/example-kotlin/pom.xml | 2 +- example/itest/pom.xml | 2 +- example/pom.xml | 2 +- example/spin-type-detector/pom.xml | 2 +- extension/core/pom.xml | 2 +- extension/test/pom.xml | 2 +- pom.xml | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/pom.xml b/docs/pom.xml index e4275cb3..15e87bcb 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -6,7 +6,7 @@ io.holunda.data camunda-bpm-data-parent - 1.0.3-SNAPSHOT + 1.1.0-SNAPSHOT camunda-bpm-data-docs diff --git a/example/coverage-report-aggregator/pom.xml b/example/coverage-report-aggregator/pom.xml index b5d13e90..8d18d57b 100644 --- a/example/coverage-report-aggregator/pom.xml +++ b/example/coverage-report-aggregator/pom.xml @@ -6,7 +6,7 @@ io.holunda.data.example camunda-bpm-data-example-parent - 1.0.3-SNAPSHOT + 1.1.0-SNAPSHOT camunda-bpm-data-coverage-report diff --git a/example/example-java/pom.xml b/example/example-java/pom.xml index 496da041..12c8168c 100644 --- a/example/example-java/pom.xml +++ b/example/example-java/pom.xml @@ -6,7 +6,7 @@ io.holunda.data.example camunda-bpm-data-example-parent - 1.0.3-SNAPSHOT + 1.1.0-SNAPSHOT camunda-bpm-data-example-java diff --git a/example/example-kotlin/pom.xml b/example/example-kotlin/pom.xml index 6b1fee1c..697d5764 100644 --- a/example/example-kotlin/pom.xml +++ b/example/example-kotlin/pom.xml @@ -6,7 +6,7 @@ io.holunda.data.example camunda-bpm-data-example-parent - 1.0.3-SNAPSHOT + 1.1.0-SNAPSHOT camunda-bpm-data-example-kotlin diff --git a/example/itest/pom.xml b/example/itest/pom.xml index 3211f860..3b42aaf9 100644 --- a/example/itest/pom.xml +++ b/example/itest/pom.xml @@ -6,7 +6,7 @@ io.holunda.data.example camunda-bpm-data-example-parent - 1.0.3-SNAPSHOT + 1.1.0-SNAPSHOT camunda-bpm-data-integration-test diff --git a/example/pom.xml b/example/pom.xml index 264314a0..2a41feb2 100644 --- a/example/pom.xml +++ b/example/pom.xml @@ -6,7 +6,7 @@ io.holunda.data camunda-bpm-data-parent - 1.0.3-SNAPSHOT + 1.1.0-SNAPSHOT io.holunda.data.example diff --git a/example/spin-type-detector/pom.xml b/example/spin-type-detector/pom.xml index 17863377..b53a696c 100644 --- a/example/spin-type-detector/pom.xml +++ b/example/spin-type-detector/pom.xml @@ -6,7 +6,7 @@ io.holunda.data.example camunda-bpm-data-example-parent - 1.0.3-SNAPSHOT + 1.1.0-SNAPSHOT camunda-bpm-data-spin-type-detector diff --git a/extension/core/pom.xml b/extension/core/pom.xml index afd8ed04..8232a07d 100644 --- a/extension/core/pom.xml +++ b/extension/core/pom.xml @@ -6,7 +6,7 @@ io.holunda.data camunda-bpm-data-parent - 1.0.3-SNAPSHOT + 1.1.0-SNAPSHOT ../../pom.xml diff --git a/extension/test/pom.xml b/extension/test/pom.xml index 4b0aaeb7..fcae975b 100644 --- a/extension/test/pom.xml +++ b/extension/test/pom.xml @@ -6,7 +6,7 @@ io.holunda.data camunda-bpm-data-parent - 1.0.3-SNAPSHOT + 1.1.0-SNAPSHOT ../.. diff --git a/pom.xml b/pom.xml index a940234e..a6d79c68 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.holunda.data camunda-bpm-data-parent - 1.0.3-SNAPSHOT + 1.1.0-SNAPSHOT ${project.artifactId} Camunda BPM Data https://github.com/holunda-io/camunda-bpm-data/ From 333884b550172c3ebff00d1ad8467ae5d45b909b Mon Sep 17 00:00:00 2001 From: Simon Zambrovski Date: Tue, 6 Oct 2020 17:47:00 +0200 Subject: [PATCH 23/23] Update for next development version --- docs/pom.xml | 2 +- example/coverage-report-aggregator/pom.xml | 2 +- example/example-java/pom.xml | 2 +- example/example-kotlin/pom.xml | 2 +- example/itest/pom.xml | 2 +- example/pom.xml | 2 +- example/spin-type-detector/pom.xml | 2 +- extension/core/pom.xml | 2 +- extension/test/pom.xml | 2 +- pom.xml | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/pom.xml b/docs/pom.xml index 15e87bcb..40768a19 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -6,7 +6,7 @@ io.holunda.data camunda-bpm-data-parent - 1.1.0-SNAPSHOT + 1.1.0 camunda-bpm-data-docs diff --git a/example/coverage-report-aggregator/pom.xml b/example/coverage-report-aggregator/pom.xml index 8d18d57b..3d6ed4eb 100644 --- a/example/coverage-report-aggregator/pom.xml +++ b/example/coverage-report-aggregator/pom.xml @@ -6,7 +6,7 @@ io.holunda.data.example camunda-bpm-data-example-parent - 1.1.0-SNAPSHOT + 1.1.0 camunda-bpm-data-coverage-report diff --git a/example/example-java/pom.xml b/example/example-java/pom.xml index 12c8168c..9e87c0e6 100644 --- a/example/example-java/pom.xml +++ b/example/example-java/pom.xml @@ -6,7 +6,7 @@ io.holunda.data.example camunda-bpm-data-example-parent - 1.1.0-SNAPSHOT + 1.1.0 camunda-bpm-data-example-java diff --git a/example/example-kotlin/pom.xml b/example/example-kotlin/pom.xml index 697d5764..25b0cc8f 100644 --- a/example/example-kotlin/pom.xml +++ b/example/example-kotlin/pom.xml @@ -6,7 +6,7 @@ io.holunda.data.example camunda-bpm-data-example-parent - 1.1.0-SNAPSHOT + 1.1.0 camunda-bpm-data-example-kotlin diff --git a/example/itest/pom.xml b/example/itest/pom.xml index 3b42aaf9..f3ff115b 100644 --- a/example/itest/pom.xml +++ b/example/itest/pom.xml @@ -6,7 +6,7 @@ io.holunda.data.example camunda-bpm-data-example-parent - 1.1.0-SNAPSHOT + 1.1.0 camunda-bpm-data-integration-test diff --git a/example/pom.xml b/example/pom.xml index 2a41feb2..1f76ef13 100644 --- a/example/pom.xml +++ b/example/pom.xml @@ -6,7 +6,7 @@ io.holunda.data camunda-bpm-data-parent - 1.1.0-SNAPSHOT + 1.1.0 io.holunda.data.example diff --git a/example/spin-type-detector/pom.xml b/example/spin-type-detector/pom.xml index b53a696c..510cc6a0 100644 --- a/example/spin-type-detector/pom.xml +++ b/example/spin-type-detector/pom.xml @@ -6,7 +6,7 @@ io.holunda.data.example camunda-bpm-data-example-parent - 1.1.0-SNAPSHOT + 1.1.0 camunda-bpm-data-spin-type-detector diff --git a/extension/core/pom.xml b/extension/core/pom.xml index 8232a07d..a28f031f 100644 --- a/extension/core/pom.xml +++ b/extension/core/pom.xml @@ -6,7 +6,7 @@ io.holunda.data camunda-bpm-data-parent - 1.1.0-SNAPSHOT + 1.1.0 ../../pom.xml diff --git a/extension/test/pom.xml b/extension/test/pom.xml index fcae975b..bf592b01 100644 --- a/extension/test/pom.xml +++ b/extension/test/pom.xml @@ -6,7 +6,7 @@ io.holunda.data camunda-bpm-data-parent - 1.1.0-SNAPSHOT + 1.1.0 ../.. diff --git a/pom.xml b/pom.xml index a6d79c68..e93bae04 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ io.holunda.data camunda-bpm-data-parent - 1.1.0-SNAPSHOT + 1.1.0 ${project.artifactId} Camunda BPM Data https://github.com/holunda-io/camunda-bpm-data/