Example usage for org.springframework.context.support GenericApplicationContext getBean

List of usage examples for org.springframework.context.support GenericApplicationContext getBean

Introduction

In this page you can find the example usage for org.springframework.context.support GenericApplicationContext getBean.

Prototype

@Override
    public Object getBean(String name) throws BeansException 

Source Link

Usage

From source file:edu.internet2.middleware.psp.shibboleth.AllMemberSubjectIdsDataConnectorTest.java

/**
 * Test get all identifiers.//from  w ww. ja va2  s.  c om
 */
public void testGetAllIdentifiers() {

    try {
        GenericApplicationContext gContext = BaseDataConnectorTest.createSpringContext(RESOLVER_CONFIG);
        AllMemberSubjectIdsDataConnector mdc = (AllMemberSubjectIdsDataConnector) gContext
                .getBean("testIdOnly");
        AttributeMap currentMap = new AttributeMap(
                mdc.resolve(getShibContext(BulkProvisioningRequest.BULK_REQUEST_ID)));

        List<String> values = new ArrayList<String>();
        values.add(SubjectTestHelper.SUBJ0_ID);
        values.add(SubjectTestHelper.SUBJ1_ID);
        values.add(SubjectTestHelper.SUBJ2_ID);
        values.add(SubjectTestHelper.SUBJ3_ID);

        AttributeMap correctMap = new AttributeMap();
        correctMap.setAttribute(AllMemberSubjectIdsDataConnector.ALL_IDENTIFIERS_ATTRIBUTE_ID,
                values.toArray(new String[] {}));

        assertEquals(correctMap, currentMap);

    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}

From source file:com.textocat.textokit.eval.EvaluationLauncher.java

public static void runUsingProperties(Properties configProperties) throws Exception {
    GenericApplicationContext appCtx = new GenericApplicationContext();

    appCtx.getEnvironment().getPropertySources()
            .addLast(new PropertiesPropertySource("configFile", configProperties));

    XmlBeanDefinitionReader xmlBDReader = new XmlBeanDefinitionReader(appCtx);
    xmlBDReader.loadBeanDefinitions(APP_CONTEXT_LOCATION);

    // register listeners
    Map<String, String> listenerImpls = getPrefixedKeyPairs(configProperties, PREFIX_LISTENER_ID);
    for (String listenerId : listenerImpls.keySet()) {
        String listenerClass = listenerImpls.get(listenerId);
        BeanDefinitionBuilder bb = genericBeanDefinition(listenerClass);
        Map<String, String> listenerProperties = getPrefixedKeyPairs(configProperties,
                PREFIX_LISTENER_PROPERTY + listenerId + ".");
        for (String propName : listenerProperties.keySet()) {
            bb.addPropertyValue(propName, listenerProperties.get(propName));
        }//from   w  w  w  .ja va  2s .com
        appCtx.registerBeanDefinition(listenerId, bb.getBeanDefinition());
    }

    appCtx.refresh();

    appCtx.registerShutdownHook();

    GoldStandardBasedEvaluation eval = appCtx.getBean(GoldStandardBasedEvaluation.class);
    eval.run();
}

From source file:nz.co.senanque.madura.bundle.BundleRootTest.java

@Test
@Ignore // fails because of parent bean which is undefined.
public void testGetApplicationContext() {
    GenericApplicationContext ctx = new GenericApplicationContext();
    XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(ctx);
    xmlReader.loadBeanDefinitions(new ClassPathResource("/bundle-spring.xml"));
    ctx.refresh();/*from ww  w.j  a va 2 s .com*/
    Object bundleName = ctx.getBean("bundleName");
    bundleName.toString();
}

From source file:com.acmemotors.batch.LoadJobConfigurationTests.java

@Test
public void integrationTest() throws Exception {
    GenericApplicationContext context = new AnnotationConfigApplicationContext(TestJobConfiguration.class);

    JobLauncher launcher = context.getBean(JobLauncher.class);
    Job job = context.getBean(Job.class);

    JobParameters jobParameters = new JobParametersBuilder().addLong("delay", 50l)
            .addString("inputFile",
                    new ClassPathResource("/data/sampleJourney.json").getFile().getAbsolutePath())
            .toJobParameters();/*from w  w w  . ja v  a 2  s.c  o  m*/
    JobExecution execution = launcher.run(job, jobParameters);
    assertEquals(execution.getStatus(), BatchStatus.COMPLETED);
    verify(writer, times(3)).write(anyListOf(String.class));
}

From source file:org.megam.deccanplato.provider.crm.test.MaluubaAdapterTest.java

@Test
public void maluubaTest() {
    GenericApplicationContext ctx = new GenericApplicationContext();
    XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(ctx);
    xmlReader.loadBeanDefinitions(new ClassPathResource("applicationContext.xml"));
    ctx.refresh();//from  ww  w . j av  a2 s. c o  m
    ProviderRegistry registry = (ProviderRegistry) ctx.getBean("registry");
    List<String> busiMethod = new ArrayList<String>();
    busiMethod.add("normalize");
    //busiMethod.add("interpret");
    List<String> busiActivity = new ArrayList<String>();
    busiActivity.add("norm");

    for (String function : busiMethod) {
        for (String activity : busiActivity) {
            CommonTest ctest = new CommonTest();
            RequestData reqData;
            reqData = ctest.commonTest(function, activity, MALUUBA);

            testAdapterAccess(reqData);

            ctest.testBusinessImpl();
        }
    }
}

From source file:org.megam.deccanplato.provider.crm.test.XeroAdapterTest.java

@Test
public void xeroTest() {
    GenericApplicationContext ctx = new GenericApplicationContext();
    XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(ctx);
    xmlReader.loadBeanDefinitions(new ClassPathResource("applicationContext.xml"));
    ctx.refresh();/*from w ww.j a  v a  2s  .  c o  m*/
    ProviderRegistry registry = (ProviderRegistry) ctx.getBean("registry");

    List<String> oauth = new ArrayList<String>();
    //oauth.add("invoice");
    //oauth.add("account");
    //oauth.add("payment");
    //oauth.add("contact");
    //oauth.add("item");
    //oauth.add("user");
    //oauth.add("receipt");
    oauth.add("employee");
    List<String> oauthList = new ArrayList<String>();
    //oauthList.add("list");
    //oauthList.add("view");
    //oauthList.add("create");
    oauthList.add("update");
    for (String activity : oauth) {
        for (String function : oauthList) {

            CommonTest ctest = new CommonTest();
            RequestData reqData;
            reqData = ctest.commonTest(activity, function, XERO);
            if (function.equalsIgnoreCase("list") && activity.equalsIgnoreCase("invoice")) {
                testAdapterAccess(reqData);
            }
            ctest.testBusinessImpl();

        }
    }
}

From source file:org.apache.zeppelin.lens.LensBootstrap.java

public LensJLineShellComponent getLensJLineShellComponent() {
    GenericApplicationContext ctx = (GenericApplicationContext) getApplicationContext();
    RootBeanDefinition rbd = new RootBeanDefinition();
    rbd.setBeanClass(LensJLineShellComponent.class);
    DefaultListableBeanFactory bf = (DefaultListableBeanFactory) ctx.getBeanFactory();
    bf.registerBeanDefinition(LensJLineShellComponent.class.getSimpleName(), rbd);
    return ctx.getBean(LensJLineShellComponent.class);
}

From source file:fi.okm.mpass.shibboleth.profile.metadata.DataSourceMetadataResolverTest.java

@SuppressWarnings("unchecked")
protected <Type> Type getBean(String fileName, Class<Type> claz, GenericApplicationContext context,
        boolean supressValid) {
    context.setDisplayName("ApplicationContext: " + claz);
    loadFile(fileName, context, supressValid);
    context.refresh();//w w w  . j  av a  2 s  .  co  m
    return (Type) ((RelyingPartyMetadataProvider) context.getBean("dataSourceEntity")).getEmbeddedResolver();
}

From source file:net.cpollet.jixture.spring.TestConfiguration.java

@Test
public void springConfigurationIsWorking() {
    GenericApplicationContext applicationContext = new GenericApplicationContext( //
            new ClassPathXmlApplicationContext("classpath:/spring/jpa2-unit-test-context.xml"));

    for (String beanName : applicationContext.getBeanDefinitionNames()) {
        if (!applicationContext.getBeanDefinition(beanName).isAbstract()) {
            logger.info("Requesting bean {}", beanName);
            applicationContext.getBean(beanName);
        }/*from w w w  .j  a v a2s.com*/
    }
}

From source file:org.megam.deccanplato.provider.crm.test.BoxAdapterTest.java

@Test
public void boxAdapterTest() {
    GenericApplicationContext ctx = new GenericApplicationContext();
    XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(ctx);
    xmlReader.loadBeanDefinitions(new ClassPathResource("applicationContext.xml"));
    ctx.refresh();/*from   w  w w.  j a v a  2s  .  c o m*/
    ProviderRegistry registry = (ProviderRegistry) ctx.getBean("registry");

    final String file = "file";
    final String folder = "folder";
    final String user = "user";

    List<String> busiActivity = new ArrayList<String>();
    busiActivity.add("upload");
    //busiActivity.add("download");
    //busiActivity.add("delete");
    //busiActivity.add("share");
    //busiActivity.add("view");

    List<String> folderList = new ArrayList<>();
    folderList.add("retrive");

    List<String> userList = new ArrayList<>();
    //userList.add("create");
    userList.add("list");
    //userList.add("delete");

    for (String activity : busiActivity) {
        CommonTest ctest = new CommonTest();
        RequestData reqData;
        reqData = ctest.commonTest(file, activity, BOX);
        if (file.equalsIgnoreCase("file") & activity.equalsIgnoreCase("upload")) {
            testAdapterAccess(reqData);
            System.out.println("REQDATA:" + reqData);
        }
        ctest.testBusinessImpl();
    }

    /*for(String activity: folderList) {
         CommonTest ctest=new CommonTest();
         RequestData reqData;
         reqData=ctest.commonTest(folder, activity, BOX);
         if(folder.equalsIgnoreCase("folder")&activity.equalsIgnoreCase("retrive")) {
            testAdapterAccess(reqData);           
         }
         ctest.testBusinessImpl();
       }
    /*for(String activity: userList) {
         CommonTest ctest=new CommonTest();
         RequestData reqData;
         reqData=ctest.commonTest(user, activity, BOX);
         if(folder.equalsIgnoreCase("user")&activity.equalsIgnoreCase("create")) {
            testAdapterAccess(reqData);           
         }
         ctest.testBusinessImpl();
       }*/
}