Search in sources :

Example 1 with CoffeeService

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.");
}
Also used : Scanner(java.util.Scanner) CoffeeBeverage(org.springframework.integration.model.CoffeeBeverage) GenericXmlApplicationContext(org.springframework.context.support.GenericXmlApplicationContext) CoffeeService(org.springframework.integration.service.CoffeeService)

Example 2 with CoffeeService

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);
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) CoffeeBeverage(org.springframework.integration.model.CoffeeBeverage) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) CoffeeService(org.springframework.integration.service.CoffeeService) Test(org.junit.Test)

Example 3 with CoffeeService

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);
}
Also used : ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) CoffeeService(org.springframework.integration.service.CoffeeService) Test(org.junit.Test)

Example 4 with CoffeeService

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();
}
Also used : Scanner(java.util.Scanner) AbstractApplicationContext(org.springframework.context.support.AbstractApplicationContext) CoffeeBeverage(org.springframework.integration.model.CoffeeBeverage) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) CoffeeService(org.springframework.integration.service.CoffeeService)

Aggregations

CoffeeService (org.springframework.integration.service.CoffeeService)4 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)3 CoffeeBeverage (org.springframework.integration.model.CoffeeBeverage)3 Scanner (java.util.Scanner)2 Test (org.junit.Test)2 ApplicationContext (org.springframework.context.ApplicationContext)2 AbstractApplicationContext (org.springframework.context.support.AbstractApplicationContext)1 GenericXmlApplicationContext (org.springframework.context.support.GenericXmlApplicationContext)1