StartProcessHelper { public static String findLatestProcessByName(KieBase kbase, final String processName) { if (kbase == null) { return null; } return findLatestProcessByName(kbase.getProcesses(), processName); }  static ProcessInstance startProcessByName( KieRuntime kruntime, String name, Map<String, Object> parameters ); static ProcessInstance startProcessByName(KieRuntime kruntime, String name, Map<String, Object> parameters, Comparator<Process> comparator); static String findLatestProcessByName(KieBase kbase, final String processName); static String findLatestProcessByName(KieBase kbase, final String processName, Comparator<Process> comparator); static String findLatestProcessByName(Collection<Process> processes, final String processName); static String findLatestProcessByName(Collection<Process> processes, final String processName, Comparator<Process> comparator); static Comparator<Process> getComparator(String name); static final String PROCESS_COMPARATOR_CLASS_KEY; }
@Test public void testFindLatestProcessByNameNoInput() { String foundProcessId = StartProcessHelper.findLatestProcessByName((KieBase)null, "Hello"); assertNull(foundProcessId); }
@Test public void testFindLatestProcessByNameNoExisting() { List<Process> processes = buildProcessCollection("Hello", 5); String foundProcessId = StartProcessHelper.findLatestProcessByName(processes, "NoSuchProcess"); assertNull(foundProcessId); }
@Test public void testFindLatestProcessByName() { List<Process> processes = buildProcessCollection("Hello", 5); String foundProcessId = StartProcessHelper.findLatestProcessByName(processes, "Hello"); assertNotNull(foundProcessId); assertEquals("5", foundProcessId); }
@Test public void testFindLatestProcessByNameMultipleProcesses() { List<Process> processes = buildProcessCollection("Hello", 5); processes.addAll(buildProcessCollection("DifferentProcess", 10)); processes.addAll(buildProcessCollection("DifferentProcess1", 10)); processes.addAll(buildProcessCollection("DifferentProcess2", 30)); processes.addAll(buildProcessCollection("Process", 10)); processes.addAll(buildProcessCollection("Diffeocess1", 10)); processes.addAll(buildProcessCollection("Differs2", 30)); processes.addAll(buildProcessCollection("zDifferentProcess", 10)); processes.addAll(buildProcessCollection("xDifferentProcess1", 10)); processes.addAll(buildProcessCollection("cDifferentProcess2", 30)); processes.addAll(buildProcessCollection("vProcess", 10)); processes.addAll(buildProcessCollection("bDiffeocess1", 10)); processes.addAll(buildProcessCollection("nDiffers2", 30)); Collections.shuffle(processes); String foundProcessId = StartProcessHelper.findLatestProcessByName(processes, "Hello"); assertNotNull(foundProcessId); assertEquals("5", foundProcessId); foundProcessId = StartProcessHelper.findLatestProcessByName(processes, "DifferentProcess"); assertNotNull(foundProcessId); assertEquals("10", foundProcessId); }
@Test public void testFindLatestProcessByNameDoubleAsVersion() { List<Process> processes = new ArrayList<Process>(); ProcessImpl process = new ProcessImpl(); process.setName("Hello"); process.setId("1"); process.setVersion("0.1"); processes.add(process); process = new ProcessImpl(); process.setName("Hello"); process.setId("2"); process.setVersion("0.2"); processes.add(process); String foundProcessId = StartProcessHelper.findLatestProcessByName(processes, "Hello"); assertNotNull(foundProcessId); assertEquals("2", foundProcessId); }