use of org.springframework.integration.service.CoffeeService in project spring-integration-samples by spring-projects.
the class Main method executeSample2.
private static void executeSample2() {
final Scanner scanner = new Scanner(System.in);
final GenericXmlApplicationContext context = new GenericXmlApplicationContext();
context.load("classpath:META-INF/spring/integration/spring-integration-sample2-context.xml");
context.registerShutdownHook();
context.refresh();
final CoffeeService service = context.getBean(CoffeeService.class);
final String message = "\n\n" + "* Please enter 'list' and press <enter> to get a list of coffees.\n" + "* Enter a coffee id, e.g. '1' and press <enter> to get a description.\n" + "* Please press 'q + Enter' to quit the application.\n";
System.out.println(message);
while (!scanner.hasNext("q")) {
String input = scanner.nextLine();
if ("list".equalsIgnoreCase(input)) {
List<CoffeeBeverage> coffeeBeverages = service.findAllCoffeeBeverages();
for (CoffeeBeverage coffeeBeverage : coffeeBeverages) {
System.out.println(String.format("%s - %s", coffeeBeverage.getId(), coffeeBeverage.getName()));
}
} else {
System.out.println("Retrieving coffee information...");
String coffeeDescription = service.findCoffeeBeverage(Integer.valueOf(input));
System.out.println(String.format("Searched for '%s' - Found: '%s'.", input, coffeeDescription));
System.out.print("To try again, please enter another coffee beverage and press <enter>:\n\n");
}
}
scanner.close();
context.close();
System.out.println("Back to main menu.");
}
use of org.springframework.integration.service.CoffeeService in project spring-integration-samples by spring-projects.
the class CoffeeServiceFindAllTest method testFindCoffee.
@Test
public void testFindCoffee() {
final ApplicationContext context = new ClassPathXmlApplicationContext("/META-INF/spring/integration/spring-integration-context.xml", CoffeeServiceFindAllTest.class);
final CoffeeService service = context.getBean(CoffeeService.class);
List<CoffeeBeverage> coffeeBeverages = service.findAllCoffeeBeverages();
assertTrue(coffeeBeverages.size() == 4);
}
use of org.springframework.integration.service.CoffeeService in project spring-integration-samples by spring-projects.
the class CoffeeServiceFindCoffeeTest method testFindCoffee.
@Test
public void testFindCoffee() {
final ApplicationContext context = new ClassPathXmlApplicationContext("/META-INF/spring/integration/spring-integration-context.xml", CoffeeServiceFindCoffeeTest.class);
final CoffeeService service = context.getBean(CoffeeService.class);
String description = service.findCoffeeBeverage(3);
assertEquals("Mmmmh, chocolate.", description);
}
use of org.springframework.integration.service.CoffeeService in project spring-integration-samples by spring-projects.
the class Main method main.
/**
* Load the Spring Integration Application Context
*
* @param args - command line arguments
*/
public static void main(final String... args) {
LOGGER.info(LINE + LINE + "\n Welcome to Spring Integration Coffee Database! " + NEWLINE + "\n For more information please visit: " + "\n http://www.springsource.org/spring-integration " + NEWLINE + LINE);
final AbstractApplicationContext context = new ClassPathXmlApplicationContext("classpath:META-INF/spring/integration/*-context.xml");
context.registerShutdownHook();
final Scanner scanner = new Scanner(System.in);
final CoffeeService service = context.getBean(CoffeeService.class);
LOGGER.info(LINE + NEWLINE + "\n Please press 'q + Enter' to quit the application. " + NEWLINE + LINE);
System.out.print("Please enter 'list' and press <enter> to get a list of coffees.");
System.out.print("Enter a coffee id, e.g. '1' and press <enter> to get a description.\n\n");
while (!scanner.hasNext("q")) {
String input = scanner.nextLine();
if ("list".equalsIgnoreCase(input)) {
List<CoffeeBeverage> coffeeBeverages = service.findAllCoffeeBeverages();
for (CoffeeBeverage coffeeBeverage : coffeeBeverages) {
System.out.println(String.format("%s - %s", coffeeBeverage.getId(), coffeeBeverage.getName()));
}
} else {
System.out.println("Retrieving coffee information...");
String coffeeDescription = service.findCoffeeBeverage(Integer.valueOf(input));
System.out.println(String.format("Searched for '%s' - Found: '%s'.", input, coffeeDescription));
System.out.print("To try again, please enter another coffee beaverage and press <enter>:\n\n");
}
}
LOGGER.info("Exiting application...bye.");
scanner.close();
context.close();
}
Aggregations