@Test public void testSendHtmlMail() { Map<String, Object> map = new HashMap<String, Object>(); Flow flow = new Flow(); flow.setPaticipants("wangyue10-zhanglihui-记文清qa-向海龙alb"); flow.setNotstandardreason("KA外部特殊政策"); map.put("flowid", flow.getId()); List<Flowtask> flowTask = new ArrayList<Flowtask>(); Flowtask task1 = new Flowtask(); task1.setErpCustomerName("wangyue10"); task1.setEndtime(new Date()); task1.setOperatorName("wangyue10"); task1.setFlowtaskstatusName("审核通过"); task1.setMsg("1"); flowTask.add(task1); Flowtask task2 = new Flowtask(); task2.setErpCustomerName("zhanglihui"); task2.setEndtime(new Date()); task2.setOperatorName("zhanglihui"); task2.setFlowtaskstatusName("审核通过"); task2.setMsg("2"); flowTask.add(task2); Flowtask task3 = new Flowtask(); task3.setErpCustomerName("记文清qa"); task3.setEndtime(new Date()); task3.setOperatorName("记文清qa"); task3.setFlowtaskstatusName("审核中"); task3.setMsg("3"); flowTask.add(task3); map.put("contractName", "新签"); Contractinapprove contract = new Contractinapprove(); contract.setContractid(105L); map.put("contractId", contract.getContractid()); Flowtask task = new Flowtask(); task.setErpCustomerName("zhanglihui"); map.put("prePerson", task.getErpCustomerName()); map.put("nextPerson", flowTask.get(flowTask.size() - 1).getErpCustomerName()); map.put("flow", flow); map.put("flowTask", flowTask); // 发起人信息 Useracct useracct = new Useracct(); useracct.setUsername("陈刚"); map.put("addUserName", useracct.getUsername()); StringBuilder sb = new StringBuilder("您的【"); sb.append("新签"); sb.append("】合同【"); sb.append(contract.getContractid()); sb.append("】已经通过【"); sb.append(task.getErpCustomerName()); sb.append("】审批,当前待【"); sb.append(flowTask.get(flowTask.size() - 1).getErpCustomerName()); sb.append("】审批"); String content = VelocityUtils.getInstance().parse("contract_approved_node_notice.vm", map); // MailHtmlUtils.sendHtmlMail("*****@*****.**", sb.toString(), content, // "1", "*****@*****.**"); }
@Test public void demonstrateASimplerOneToManyStage() throws Exception { // tests: Graph<FlowShape<Integer, Integer>, NotUsed> duplicator = Flow.fromGraph(new Duplicator2<Integer>()); CompletionStage<Integer> result = Source.from(Arrays.asList(1, 2, 3)).via(duplicator).runFold(0, (n, sum) -> n + sum, mat); assertEquals(new Integer(12), result.toCompletableFuture().get(3, TimeUnit.SECONDS)); }
@Test public void mustBeAbleToUseQueue() throws Exception { final Pair<SourceQueueWithComplete<String>, CompletionStage<List<String>>> x = Flow.of(String.class) .runWith(Source.queue(2, OverflowStrategy.fail()), Sink.seq(), materializer); final SourceQueueWithComplete<String> source = x.first(); final CompletionStage<List<String>> result = x.second(); source.offer("hello"); source.offer("world"); source.complete(); assertEquals( result.toCompletableFuture().get(3, TimeUnit.SECONDS), Arrays.asList("hello", "world")); }
@Test public void demonstrateAManyToOneElementGraphStage() throws Exception { // tests: Graph<FlowShape<Integer, Integer>, NotUsed> evenFilter = Flow.fromGraph(new Filter<Integer>(n -> n % 2 == 0)); CompletionStage<Integer> result = Source.from(Arrays.asList(1, 2, 3, 4, 5, 6)) .via(evenFilter) .runFold(0, (elem, sum) -> sum + elem, mat); assertEquals(new Integer(12), result.toCompletableFuture().get(3, TimeUnit.SECONDS)); }
@Test public void demonstrateOneToOne() throws Exception { // tests: final Graph<FlowShape<String, Integer>, NotUsed> stringLength = Flow.fromGraph( new Map<String, Integer>( new Function<String, Integer>() { @Override public Integer apply(String str) { return str.length(); } })); CompletionStage<Integer> result = Source.from(Arrays.asList("one", "two", "three")) .via(stringLength) .runFold(0, (sum, n) -> sum + n, mat); assertEquals(new Integer(11), result.toCompletableFuture().get(3, TimeUnit.SECONDS)); }
@Test public void mustBeAbleToUseConflate() throws Exception { final JavaTestKit probe = new JavaTestKit(system); final List<String> input = Arrays.asList("A", "B", "C"); CompletionStage<String> future = Source.from(input) .conflateWithSeed(s -> s, (aggr, in) -> aggr + in) .runFold("", (aggr, in) -> aggr + in, materializer); String result = future.toCompletableFuture().get(3, TimeUnit.SECONDS); assertEquals("ABC", result); final Flow<String, String, NotUsed> flow2 = Flow.of(String.class).conflate((a, b) -> a + b); CompletionStage<String> future2 = Source.from(input) .conflate((String a, String b) -> a + b) .runFold("", (a, b) -> a + b, materializer); String result2 = future2.toCompletableFuture().get(3, TimeUnit.SECONDS); assertEquals("ABC", result2); }
@Test public void mustWorksForTwoStreams() throws Exception { final Flow<Integer, Integer, NotUsed> sharedThrottle = Flow.of(Integer.class) .throttle(1, FiniteDuration.create(1, TimeUnit.DAYS), 1, ThrottleMode.enforcing()); CompletionStage<List<Integer>> result1 = Source.single(1).via(sharedThrottle).via(sharedThrottle).runWith(Sink.seq(), materializer); // If there is accidental shared state then we would not be able to pass through the single // element assertEquals( result1.toCompletableFuture().get(3, TimeUnit.SECONDS), Collections.singletonList(1)); // It works with a new stream, too CompletionStage<List<Integer>> result2 = Source.single(1).via(sharedThrottle).via(sharedThrottle).runWith(Sink.seq(), materializer); assertEquals( result2.toCompletableFuture().get(3, TimeUnit.SECONDS), Collections.singletonList(1)); }
@Test public void demonstrateAnAsynchronousSideChannel() throws Exception { // tests: CompletableFuture<Done> switchF = new CompletableFuture<>(); Graph<FlowShape<Integer, Integer>, NotUsed> killSwitch = Flow.fromGraph(new KillSwitch<>(switchF)); ExecutionContext ec = system.dispatcher(); CompletionStage<Integer> valueAfterKill = switchF.thenApply(in -> 4); CompletionStage<Integer> result = Source.from(Arrays.asList(1, 2, 3)) .concat(Source.fromCompletionStage(valueAfterKill)) .via(killSwitch) .runFold(0, (n, sum) -> n + sum, mat); switchF.complete(Done.getInstance()); assertEquals(new Integer(6), result.toCompletableFuture().get(3, TimeUnit.SECONDS)); }