Created
May 7, 2017 04:18
-
-
Save barorion/5fff2020f89da9841c9cb29e4122995c to your computer and use it in GitHub Desktop.
Spring integration tests: code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package springit; | |
| import org.springframework.boot.SpringApplication; | |
| import org.springframework.boot.autoconfigure.SpringBootApplication; | |
| import org.springframework.context.ApplicationContext; | |
| @SpringBootApplication | |
| public class Application { | |
| public static void main(String[] args) throws Exception { | |
| ApplicationContext applicationContext = SpringApplication.run(Application.class, args); | |
| FinancialReporter financialReporter = applicationContext.getBean(FinancialReporter.class); | |
| System.out.println("report: " + financialReporter.produceReport()); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package springit; | |
| import javax.inject.Named; | |
| @Named | |
| public class DataSource { | |
| private final int cycles = 10; | |
| public String runQuery(String query) { | |
| try { | |
| for (int i = 0; i < cycles; i++) { | |
| System.out.println("################# running query for [" + query + "]... (" + i + "/" + cycles + ") ######################"); | |
| Thread.sleep(1_000); | |
| } | |
| } catch (InterruptedException e) { | |
| e.printStackTrace(); | |
| } | |
| return "results for : " + query; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package springit; | |
| import javax.inject.Named; | |
| import java.util.Arrays; | |
| import java.util.Map; | |
| import java.util.stream.Collectors; | |
| @Named | |
| public class FinancialReporter { | |
| private final DataSource dataSource; | |
| private final String[] reportCategories = new String[]{"revenue", "income", "profit"}; | |
| public FinancialReporter(DataSource dataSource) { | |
| this.dataSource = dataSource; | |
| } | |
| public Map<String, String> produceReport() { | |
| return Arrays.stream(reportCategories).collect(Collectors.toMap(category -> category, category -> dataSource.runQuery(category))); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment