Skip to content

Commit

Permalink
Apply automatic changes
Browse files Browse the repository at this point in the history
  • Loading branch information
shsahahyland authored and github-actions[bot] committed Dec 2, 2024
1 parent 95dff0e commit a4c68b6
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@
import com.querydsl.jpa.JPQLQuery;
import com.querydsl.jpa.impl.JPAQueryFactory;
import jakarta.persistence.EntityManager;

import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import org.activiti.cloud.api.process.model.QueryCloudSubprocessInstance;
import org.activiti.cloud.services.query.model.ProcessInstanceEntity;
import org.activiti.cloud.services.query.model.QProcessInstanceEntity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

import java.util.*;

import com.querydsl.jpa.JPQLQuery;
import com.querydsl.jpa.impl.JPAQuery;
import com.querydsl.jpa.impl.JPAQueryFactory;
import jakarta.persistence.EntityManager;
import java.util.*;
import org.activiti.cloud.api.process.model.QueryCloudSubprocessInstance;
import org.activiti.cloud.services.query.app.repository.utils.ProcessInstanceHelper;
import org.activiti.cloud.services.query.model.ProcessInstanceEntity;
Expand All @@ -43,12 +42,16 @@ class CustomizedProcessInstanceRepositoryImplTest {

@Mock
private EntityManager entityManager;

@Mock
private JPAQueryFactory queryFactory;

@Mock
private JPAQuery<ProcessInstanceEntity> jpaQuery;

@Mock
private JPQLQuery<ProcessInstanceEntity> jpqlQuery;

@Mock
private Querydsl querydsl;

Expand All @@ -64,7 +67,8 @@ void setUp() {

@Test
void testGetQueryCloudSubprocessInstance() {
ProcessInstanceEntity subprocess = new ProcessInstanceHelper().createProcessInstance(UUID.randomUUID().toString());
ProcessInstanceEntity subprocess = new ProcessInstanceHelper()
.createProcessInstance(UUID.randomUUID().toString());
QueryCloudSubprocessInstance result = repository.getQueryCloudSubprocessInstance(subprocess);

assertNotNull(result);
Expand All @@ -88,7 +92,8 @@ void testGroupSubprocesses() {
List<ProcessInstanceEntity> processInstancesList = new ProcessInstanceHelper().createParentProcessInstances(4);
String parentIdOne = processInstancesList.getFirst().getId();
String parentIdTwo = processInstancesList.getLast().getId();
List<ProcessInstanceEntity> subprocessesList = new ProcessInstanceHelper().createSubprocessInstances(2, parentIdOne);
List<ProcessInstanceEntity> subprocessesList = new ProcessInstanceHelper()
.createSubprocessInstances(2, parentIdOne);
subprocessesList.addAll(new ProcessInstanceHelper().createSubprocessInstances(3, parentIdTwo));

Page<ProcessInstanceEntity> subprocesses = new PageImpl<>(subprocessesList);
Expand All @@ -106,7 +111,8 @@ void testGroupSubprocesses() {
@Test
void testFindSubprocessesByParentId() {
String parentId = UUID.randomUUID().toString();
List<ProcessInstanceEntity> expectedSubprocesses = new ProcessInstanceHelper().createSubprocessInstances(2, parentId);
List<ProcessInstanceEntity> expectedSubprocesses = new ProcessInstanceHelper()
.createSubprocessInstances(2, parentId);

QProcessInstanceEntity processInstanceEntity = QProcessInstanceEntity.processInstanceEntity;

Expand All @@ -131,7 +137,8 @@ void testFindSubprocessesByParentIds() {
List<String> parentIds = Arrays.asList("parent1", "parent2");
Pageable pageable = PageRequest.of(0, 10);

List<ProcessInstanceEntity> expectedSubprocesses = new ProcessInstanceHelper().createSubprocessInstances(2, "parent1");
List<ProcessInstanceEntity> expectedSubprocesses = new ProcessInstanceHelper()
.createSubprocessInstances(2, "parent1");
expectedSubprocesses.addAll(new ProcessInstanceHelper().createSubprocessInstances(3, "parent2"));

QProcessInstanceEntity processInstanceEntity = QProcessInstanceEntity.processInstanceEntity;
Expand All @@ -157,13 +164,18 @@ void testFindSubprocessesByParentIds() {
@Test
void testMapSubprocesses() {
List<ProcessInstanceEntity> processInstancesList = new ProcessInstanceHelper().createParentProcessInstances(2);
List<String> parentIds = Arrays.asList(processInstancesList.getFirst().getId(),processInstancesList.getLast().getId());
List<String> parentIds = Arrays.asList(
processInstancesList.getFirst().getId(),
processInstancesList.getLast().getId()
);
Page<ProcessInstanceEntity> processInstances = new PageImpl<>(processInstancesList);
Pageable pageable = PageRequest.of(0, 10);

List<ProcessInstanceEntity> subprocessesList = new ProcessInstanceHelper().createSubprocessInstances(2,
processInstancesList.get(0).getId());
subprocessesList.addAll(new ProcessInstanceHelper().createSubprocessInstances(3, processInstancesList.get(1).getId()));
List<ProcessInstanceEntity> subprocessesList = new ProcessInstanceHelper()
.createSubprocessInstances(2, processInstancesList.get(0).getId());
subprocessesList.addAll(
new ProcessInstanceHelper().createSubprocessInstances(3, processInstancesList.get(1).getId())
);

QProcessInstanceEntity processInstanceEntity = QProcessInstanceEntity.processInstanceEntity;

Expand All @@ -185,7 +197,8 @@ void testMapSubprocesses() {
void testMapSubprocessesForProcessInstance() {
ProcessInstanceEntity entity = new ProcessInstanceHelper().createProcessInstance("1");
String parentId = entity.getId();
List<ProcessInstanceEntity> expectedSubprocesses = new ProcessInstanceHelper().createSubprocessInstances(2, parentId);
List<ProcessInstanceEntity> expectedSubprocesses = new ProcessInstanceHelper()
.createSubprocessInstances(2, parentId);

QProcessInstanceEntity processInstanceEntity = QProcessInstanceEntity.processInstanceEntity;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
*/
package org.activiti.cloud.services.query.app.repository.utils;

import org.activiti.cloud.services.query.model.ProcessInstanceEntity;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.activiti.cloud.services.query.model.ProcessInstanceEntity;

public class ProcessInstanceHelper {

public ProcessInstanceEntity createProcessInstance(String parentId) {
ProcessInstanceEntity entity = new ProcessInstanceEntity();
entity.setId(UUID.randomUUID().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@

package org.activiti.cloud.repos;

import static org.junit.jupiter.api.Assertions.*;

import jakarta.persistence.EntityManager;
import java.util.ArrayList;
import java.util.List;
import org.activiti.QueryRestTestApplication;
import org.activiti.cloud.services.query.app.repository.CustomizedProcessInstanceRepositoryImpl;
import org.activiti.cloud.services.query.app.repository.ProcessInstanceRepository;
Expand All @@ -37,11 +41,6 @@
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;

import java.util.ArrayList;
import java.util.List;

import static org.junit.jupiter.api.Assertions.*;

@SpringBootTest(
classes = { QueryRestTestApplication.class },
properties = {
Expand All @@ -54,6 +53,7 @@
@Testcontainers
@Transactional
class CustomizedProcessInstanceRepositoryImplIT {

@Container
@ServiceConnection
static PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>("postgres:15-alpine");
Expand All @@ -78,34 +78,41 @@ void testMapSubprocessesForPage() {
List<ProcessInstanceEntity> processInstancesList = buildDefaultProcessInstances(3);
String parentId1 = processInstancesList.getFirst().getId();
List<ProcessInstanceEntity> subprocesses1 = buildDefaultProcessInstances(2);
setSubprocesses(subprocesses1,parentId1);
setSubprocesses(subprocesses1, parentId1);
String parentId2 = processInstancesList.getLast().getId();
List<ProcessInstanceEntity> subprocesses2 = buildDefaultProcessInstances(3);
setSubprocesses(subprocesses2,parentId2);
setSubprocesses(subprocesses2, parentId2);

entityManager.flush();

Page<ProcessInstanceEntity> processInstances = new PageImpl<>(processInstancesList, pageable, processInstancesList.size());
Page<ProcessInstanceEntity> processInstances = new PageImpl<>(
processInstancesList,
pageable,
processInstancesList.size()
);

Page<ProcessInstanceEntity> result = repository.mapSubprocesses(processInstances, pageable);

assertNotNull(result);
assertEquals(3, result.getTotalElements());

ProcessInstanceEntity parentInstance1 = result.getContent().stream()
ProcessInstanceEntity parentInstance1 = result
.getContent()
.stream()
.filter(instance -> instance.getId().equals(parentId1))
.findFirst()
.orElse(null);
assertNotNull(parentInstance1);
assertEquals(2, parentInstance1.getSubprocesses().size());

ProcessInstanceEntity parentInstance2 = result.getContent().stream()
ProcessInstanceEntity parentInstance2 = result
.getContent()
.stream()
.filter(instance -> instance.getId().equals(parentId2))
.findFirst()
.orElse(null);
assertNotNull(parentInstance2);
assertEquals(3, parentInstance2.getSubprocesses().size());

}

@Test
Expand All @@ -114,7 +121,7 @@ void testMapSubprocessesForProcessInstance() {
List<ProcessInstanceEntity> subprocesses = buildDefaultProcessInstances(2);
ProcessInstanceEntity entity = processInstances.getFirst();
String parentId = entity.getId();
setSubprocesses(subprocesses,parentId);
setSubprocesses(subprocesses, parentId);

ProcessInstanceEntity result = repository.mapSubprocesses(entity);

Expand All @@ -124,15 +131,15 @@ void testMapSubprocessesForProcessInstance() {

private List<ProcessInstanceEntity> buildDefaultProcessInstances(int count) {
List<ProcessInstanceEntity> entities = new ArrayList<>();
for(int i=1;i<=count;i++ ){
for (int i = 1; i <= count; i++) {
entities.add(new ProcessInstanceTestUtils().buildProcessInstanceEntity());
}
processInstanceRepository.saveAll(entities);
return entities;
}

private void setSubprocesses(List<ProcessInstanceEntity> subprocesses,String parentId){
for(ProcessInstanceEntity subprocess:subprocesses){
private void setSubprocesses(List<ProcessInstanceEntity> subprocesses, String parentId) {
for (ProcessInstanceEntity subprocess : subprocesses) {
subprocess.setParentId(parentId);
processInstanceRepository.save(subprocess);
}
Expand Down

0 comments on commit a4c68b6

Please sign in to comment.