Esempio n. 1
0
  @Test
  public void testWorkflow() throws Exception {

    GenericXmlApplicationContext ctx =
        new GenericXmlApplicationContext("/org/springframework/data/hadoop/batch/in-do-out.xml");

    ctx.registerShutdownHook();

    FileSystem fs = FileSystem.get(ctx.getBean(Configuration.class));
    System.out.println("FS is " + fs.getClass().getName());
    HdfsResourceLoader hrl = ctx.getBean(HdfsResourceLoader.class);
    Resource resource = hrl.getResource("/ide-test/output/word/");

    assertTrue(ctx.isPrototype("script-tasklet"));

    fs.delete(new Path(resource.getURI().toString()), true);

    JobsTrigger.startJobs(ctx);

    Path p = new Path("/ide-test/output/word/");
    Job job = (Job) ctx.getBean("mr-job");
    Configuration c = job.getConfiguration();
    FileSystem fs2 = p.getFileSystem(c);
    System.out.println("FS is " + fs2.getClass().getName());

    fs2.exists(p);

    ctx.close();
  }
 @Test
 public void testLifecycleInEndpointWithMessageSource() throws Exception {
   context = new GenericXmlApplicationContext(getClass(), "lifecycle-source.xml");
   messageChannelsMonitor = context.getBean(IntegrationMBeanExporter.class);
   assertNotNull(messageChannelsMonitor);
   MBeanServer server = context.getBean(MBeanServer.class);
   Set<ObjectName> names =
       server.queryNames(
           ObjectName.getInstance("org.springframework.integration:type=ManagedEndpoint,*"), null);
   assertEquals(0, names.size());
   names =
       server.queryNames(
           ObjectName.getInstance("org.springframework.integration:name=explicit,*"), null);
   assertEquals(1, names.size());
   MBeanOperationInfo[] operations = server.getMBeanInfo(names.iterator().next()).getOperations();
   String startName = null;
   for (MBeanOperationInfo info : operations) {
     String name = info.getName();
     if (name.startsWith("start")) {
       startName = name;
     }
   }
   // Lifecycle method name
   assertEquals("start", startName);
   assertTrue((Boolean) server.invoke(names.iterator().next(), "isRunning", null, null));
   messageChannelsMonitor.stopActiveComponents(false, 3000);
   assertFalse((Boolean) server.invoke(names.iterator().next(), "isRunning", null, null));
   ActiveChannel activeChannel = context.getBean("activeChannel", ActiveChannel.class);
   assertTrue(activeChannel.isStopCalled());
   OtherActiveComponent otherActiveComponent = context.getBean(OtherActiveComponent.class);
   assertTrue(otherActiveComponent.isBeforeCalled());
   assertTrue(otherActiveComponent.isAfterCalled());
 }
 @Test
 public void testLifecycleInEndpointWithoutMessageSource() throws Exception {
   context = new GenericXmlApplicationContext(getClass(), "lifecycle-no-source.xml");
   messageChannelsMonitor = context.getBean(IntegrationMBeanExporter.class);
   assertNotNull(messageChannelsMonitor);
   MBeanServer server = context.getBean(MBeanServer.class);
   Set<ObjectName> names =
       server.queryNames(
           ObjectName.getInstance("org.springframework.integration:type=ManagedEndpoint,*"), null);
   assertEquals(1, names.size());
   names =
       server.queryNames(
           ObjectName.getInstance("org.springframework.integration:name=gateway,*"), null);
   assertEquals(1, names.size());
   MBeanOperationInfo[] operations = server.getMBeanInfo(names.iterator().next()).getOperations();
   String startName = null;
   for (MBeanOperationInfo info : operations) {
     String name = info.getName();
     if (name.startsWith("start")) {
       startName = name;
     }
   }
   // Lifecycle method name
   assertEquals("start", startName);
 }
 @Test
 public void testDuplicateComponentNames() throws Exception {
   context = new GenericXmlApplicationContext(getClass(), "duplicate-components.xml");
   messageChannelsMonitor = context.getBean(IntegrationMBeanExporter.class);
   assertNotNull(messageChannelsMonitor);
   MBeanServer server = context.getBean(MBeanServer.class);
   Set<ObjectName> names =
       server.queryNames(
           ObjectName.getInstance("org.springframework.integration:type=ManagedEndpoint,*"), null);
   assertEquals(2, names.size());
 }
Esempio n. 5
0
  @Test
  public void test01() {
    GenericXmlApplicationContext context = new GenericXmlApplicationContext();
    context.load(TestIocBean.class, new String[] {"app-context-xml.xml"});
    context.refresh();

    MessageProvider messageProvider = context.getBean("messageProvider", MessageProvider.class);
    System.out.println(messageProvider.getMessage());

    MessageRender messageRender = context.getBean("messageRender", MessageRender.class);
    messageRender.render();
  }
Esempio n. 6
0
  @Test
  public void test02() {
    GenericXmlApplicationContext context = new GenericXmlApplicationContext();
    // context.load("classpath:app-context-annotation.xml");
    context.load(TestIocBean.class, "app-context-xml.xml");
    context.refresh();

    MessageProvider messageProvider = context.getBean("messageProvider", MessageProvider.class);
    System.out.println(messageProvider.getMessage());

    MessageRender messageRender = context.getBean("messageRender", MessageRender.class);
    messageRender.render();
  }
  @Test
  public void should_read_properties_file_from_profile_a() {

    context.getEnvironment().setDefaultProfiles("default");
    context.getEnvironment().setActiveProfiles("a");
    context.load(
        "classpath:/com/github/jcgay/example/spring/ConfigureBeansWithPropertiesInProfileTest.xml");
    context.refresh();

    BeanWithProperties bean = context.getBean(BeanWithProperties.class);
    BeanWithPropertiesAnnotated annotated = context.getBean(BeanWithPropertiesAnnotated.class);

    assertThat(bean.getTest()).isEqualTo("a");
    assertThat(annotated.getTest()).isEqualTo("a");
  }
 @Test
 public void testCircularReferenceWithChannelInFactoryBean() throws Exception {
   context = new GenericXmlApplicationContext(getClass(), "oref-factory-channel.xml");
   messageChannelsMonitor = context.getBean(IntegrationMBeanExporter.class);
   assertNotNull(messageChannelsMonitor);
   assertTrue(Arrays.asList(messageChannelsMonitor.getChannelNames()).contains("anonymous"));
   MBeanServer server = context.getBean(MBeanServer.class);
   assertEquals(1, server.queryNames(ObjectName.getInstance("com.foo:*"), null).size());
   assertEquals(
       1,
       server
           .queryNames(
               ObjectName.getInstance("org.springframework.integration:name=anonymous,*"), null)
           .size());
 }
  public static void main(String[] args) {
    logger.info("TestClient started");

    // [ Aufgabe 1.6
    GenericXmlApplicationContext context = new GenericXmlApplicationContext();
    context.getEnvironment().setActiveProfiles("mysql");
    context.load("/app/server/bean-definitions.xml");
    context.refresh();
    // ] Aufgabe 1.6  Define application context

    // [ Aufgabe 1.7
    IBookService bean = context.getBean("bookService", IBookService.class);
    // ] Aufgabe 1.7  Receive the bookService from the application context

    BookSearchCriteria criteria = new BookSearchCriteria();
    criteria.setPublicationYear(2007);
    // [ Aufgabe 1.8
    List<Book> books = bean.findBySearchCriteria(criteria);
    // ] Aufgabe 1.8  Read books - List<Book> books = null;

    if (books != null) {
      logger.info("The following books have been found:");
      for (Book book : books) {
        logger.info(book.getAuthor() + ": \"" + book.getTitle() + "\"");
      }
    }
  }
  public static void main(String[] args) {

    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
    ctx.load("classpath:app-context-annotation.xml");
    ctx.refresh();

    ContactDao contactDao = ctx.getBean("contactDao", ContactDao.class);

    // Find and list all contacts
    List<Contact> contacts = contactDao.findAll();
    listContacts(contacts);

    // Find and list all contacts
    /*		contacts = contactDao.findAllWithDetail();
    listContacts(contacts);	*/

    // Find contacts by first name
    contacts = contactDao.findByFirstName("Clarence");
    listContacts(contacts);

    Contact contact;

    // Update contact
    contact = new Contact();
    contact.setId(1l);
    contact.setFirstName("Clarence");
    contact.setLastName("Peter");
    contact.setBirthDate(new Date((new GregorianCalendar(1977, 10, 1)).getTime().getTime()));
    contactDao.update(contact);
    contacts = contactDao.findAll();
    listContacts(contacts);

    // Insert contact
    contact = new Contact();
    contact.setFirstName("Rod");
    contact.setLastName("Johnson");
    contact.setBirthDate(new Date((new GregorianCalendar(2001, 10, 1)).getTime().getTime()));
    contactDao.insert(contact);
    contacts = contactDao.findAll();
    listContacts(contacts);

    // Insert contact with details
    contact = new Contact();
    contact.setFirstName("Michael");
    contact.setLastName("Jackson");
    contact.setBirthDate(new Date((new GregorianCalendar(1964, 10, 1)).getTime().getTime()));
    List<ContactTelDetail> contactTelDetails = new ArrayList<ContactTelDetail>();
    ContactTelDetail contactTelDetail = new ContactTelDetail();
    contactTelDetail.setTelType("Home");
    contactTelDetail.setTelNumber("11111111");
    contactTelDetails.add(contactTelDetail);
    contactTelDetail = new ContactTelDetail();
    contactTelDetail.setTelType("Mobile");
    contactTelDetail.setTelNumber("22222222");
    contactTelDetails.add(contactTelDetail);
    contact.setContactTelDetails(contactTelDetails);
    contactDao.insertWithDetail(contact);
    contacts = contactDao.findAllWithDetail();
    listContacts(contacts);
  }
Esempio n. 11
0
  public static void main(String[] args) {

    GenericXmlApplicationContext ctx = null;

    ctx = new GenericXmlApplicationContext("spring/beans_dao.xml");

    CityMapper cityMapper = ctx.getBean(CityMapper.class);

    //		List<City> list = cityMapper.selectAll();

    List<City> list = cityMapper.selectByCountryCode("KOR");

    list.forEach(
        new Consumer<City>() {

          @Override
          public void accept(City c) {

            log.info(c.getCountryCode() + "\t" + c.getName());
          }
        });

    //		for(City c : list){
    //
    //			log.info(c.getCountryCode());
    //
    //		}

    ctx.close();
  }
Esempio n. 12
0
  public static void main(String[] args) {
    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
    ctx.load("classpath:META-INF/spring/app-context-xml.xml");
    ctx.refresh();

    Target t = null;

    System.out.println("Using byName:\n");
    t = (Target) ctx.getBean("targetByName");

    System.out.println("\nUsing byType:\n");
    t = (Target) ctx.getBean("targetByType");

    System.out.println("\nUsing constructor:\n");
    t = (Target) ctx.getBean("targetConstructor");
  }
 public static void main(String[] args) throws Exception {
   GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
   ctx.load("classpath:META-INF/aop-2.xml");
   ctx.refresh();
   MyBean myBean = (MyBean) ctx.getBean("myBean");
   myBean.execute();
 }
 @Test
 public void testComponentNames() throws Exception {
   context = new GenericXmlApplicationContext(getClass(), "excluded-components.xml");
   messageChannelsMonitor = context.getBean(IntegrationMBeanExporter.class);
   assertNotNull(messageChannelsMonitor);
   MBeanServer server = context.getBean(MBeanServer.class);
   Set<ObjectName> names =
       server.queryNames(
           ObjectName.getInstance("org.springframework.integration:type=MessageChannel,*"), null);
   // Only one registered (out of >2 available)
   assertEquals(1, names.size());
   names =
       server.queryNames(
           ObjectName.getInstance("org.springframework.integration:type=MessageHandler,*"), null);
   assertEquals(0, names.size());
 }
 public static void main(String[] args) {
   GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
   ctx.load("classpath:factorybean/app-context-with-attribute.xml");
   ctx.refresh();
   MessageDigester digester = (MessageDigester) ctx.getBean("digester");
   digester.digest("Hello World!");
 }
  public static void main(String[] args) {
    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
    ctx.load("classpath:META-INF/spring/app-context-annotation.xml");
    ctx.refresh();

    ConstructorConfusion cc = (ConstructorConfusion) ctx.getBean("constructorConfusion");
    System.out.println(cc);
  }
  public static void main(String[] args) {
    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
    ctx.load("classpath:META-INF/spring/app-context-xml.xml");
    ctx.refresh();

    MyBean myBean = (MyBean) ctx.getBean("myBean");
    myBean.execute();
  }
  public static void main(String[] args) {
    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
    ctx.load("classpath:META-INF/spring/app-context-annotation.xml");
    ctx.refresh();

    ContactDao contactDao = ctx.getBean("contactDao", ContactDao.class);

    System.out.println(contactDao.findFirstNameById(1L));
  }
  public static void main(String[] args) {
    GenericXmlApplicationContext parent = new GenericXmlApplicationContext();
    parent.load("classpath:META-INF/spring/parent.xml");
    parent.refresh();

    GenericXmlApplicationContext child = new GenericXmlApplicationContext();
    child.load("classpath:META-INF/spring/app-context-xml.xml");
    child.setParent(parent);
    child.refresh();

    SimpleTarget target1 = (SimpleTarget) child.getBean("target1");
    SimpleTarget target2 = (SimpleTarget) child.getBean("target2");
    SimpleTarget target3 = (SimpleTarget) child.getBean("target3");

    System.out.println(target1.getVal());
    System.out.println(target2.getVal());
    System.out.println(target3.getVal());
  }
Esempio n. 20
0
 public static void main(String[] args) {
   GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
   ctx.load("classpath:/jms-sender-app-context.xml", "classpath:/jms-listener-app-context.xml");
   ctx.refresh();
   MessageSender messageSender = ctx.getBean("messageSender", MessageSender.class);
   for (int i = 0; i < 10; i++) {
     messageSender.sendMessage("Test message: " + i);
   }
 }
  public static void main(String[] args) {

    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
    ctx.load("classpath:app-context-sf.xml");
    ctx.refresh();

    ContactSfDao contactSfDao = ctx.getBean("contactSfDao", ContactSfDao.class);

    System.out.println(contactSfDao.getFirstNameById(1l));
  }
 public static void main(String[] args) {
   GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
   ctx.load("classpath:app-context.xml");
   ctx.refresh();
   ContactService contactService = ctx.getBean("contactService", ContactService.class);
   List<Contact> contacts;
   // Find all contacts
   contacts = contactService.findAll();
   listContacts(contacts);
 }
  public static void main(String[] args) {

    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
    // ctx.load("classpath:app-context-xml.xml");
    ctx.load("classpath:com/shamrov/spring/ioc/annotation/constructor/app-context-annotation.xml");
    ctx.refresh();

    MessageProvider messageProvider = ctx.getBean("messageProvider", MessageProvider.class);

    System.out.println(messageProvider.getMessage());
  }
 @Test
 public void testSelfDestruction() throws Exception {
   context = new GenericXmlApplicationContext(getClass(), "self-destruction-context.xml");
   SourcePollingChannelAdapter adapter = context.getBean(SourcePollingChannelAdapter.class);
   adapter.start();
   int n = 0;
   while (adapter.isRunning()) {
     n += 10;
     if (n > 10000) {
       fail("Adapter failed to stop");
     }
     Thread.sleep(10);
   }
 }
Esempio n. 25
0
  @Test
  public void testWorkflowNS() throws Exception {
    GenericXmlApplicationContext ctx =
        new GenericXmlApplicationContext("/org/springframework/data/hadoop/batch/in-do-out-ns.xml");

    ctx.registerShutdownHook();

    FileSystem fs = FileSystem.get(ctx.getBean(Configuration.class));
    fs.delete(new Path("/ide-test/output/word/"), true);

    assertTrue(ctx.isPrototype("hadoop-tasklet"));

    JobsTrigger.startJobs(ctx);
    ctx.close();
  }
public class LanguageTest {
  GenericXmlApplicationContext ctx = new GenericXmlApplicationContext("Config.xml");
  LanguageService scategory = ctx.getBean("lservice", LanguageService.class);

  @Test
  public void searchByLanguageSuccess() throws Exception {
    assertTrue(scategory.findByLanguage("English").size() > 1);
  }

  @Test(expected = LanguageNotFound.class)
  public void searchByLanguageIfLanguageIsNull() throws Exception {
    scategory.findByLanguage(null);
  }

  @Test(expected = LanguageNotFound.class)
  public void searchByLanguageIfLanguageIsNotFound() throws Exception {
    scategory.findByLanguage("Animation");
  }
}
Esempio n. 27
0
 public <T> T getBean(String beanName, Class<T> clazz) {
   return ctx.getBean(beanName, clazz);
 }
 @Test
 public void testCircularReferenceWithChannelInFactoryBeanAutodetected() throws Exception {
   context = new GenericXmlApplicationContext(getClass(), "oref-factory-channel-autodetect.xml");
   messageChannelsMonitor = context.getBean(IntegrationMBeanExporter.class);
   assertNotNull(messageChannelsMonitor);
 }
 @Test
 public void testCircularReferenceNoChannel() throws Exception {
   context = new GenericXmlApplicationContext(getClass(), "oref-nonchannel.xml");
   messageChannelsMonitor = context.getBean(IntegrationMBeanExporter.class);
   assertNotNull(messageChannelsMonitor);
 }
 @Test
 public void control() {
   GenericXmlApplicationContext ctx =
       new GenericXmlApplicationContext(getClass(), "EnableLoadTimeWeavingTests-context.xml");
   ctx.getBean("loadTimeWeaver", LoadTimeWeaver.class);
 }