Search in sources :

Example 1 with MidnightLiteral

use of org.b3log.latke.ioc.speaker.annotation.MidnightLiteral in project latke by b3log.

the class SpeakerUnitTest method beforeTest.

@BeforeTest
@SuppressWarnings("unchecked")
public void beforeTest() throws Exception {
    System.out.println("before SpeakerUnitTest");
    Latkes.initRuntimeEnv();
    beanManager = LatkeBeanManagerImpl.getInstance();
    Lifecycle.startApplication(speakerPackageClasses);
    final Configurator configurator = beanManager.getConfigurator();
    // Create beans by APIs approach
    configurator.createBean(HelloSpeaker.class).qualified(new HelloLiteral());
    configurator.createBean(NightSpeaker.class).qualified(new NightLiteral());
    configurator.createBean(MidnightSpeaker.class).qualified(new MidnightLiteral());
    final Set<Annotation> helloSpeakerQualifiers = new HashSet<Annotation>();
    helloSpeakerQualifiers.add(new HelloLiteral());
    helloSpeakerQualifiers.add(new NamedLiteral("helloSpeaker"));
    final LatkeBean<?> helloSpeakerBean = beanManager.getBean(Speaker.class, helloSpeakerQualifiers);
    helloSpeaker = (HelloSpeaker) beanManager.getReference(helloSpeakerBean);
    assertNotNull(helloSpeaker);
    configurator.validate();
    final Set<Annotation> morningSpeakerQualifiers = new HashSet<Annotation>();
    morningSpeakerQualifiers.add(new MorningLiteral());
    morningSpeakerQualifiers.add(new NamedLiteral("morningSpeaker"));
    final LatkeBean<?> morningSpeakerBean = beanManager.getBean(Speaker.class, morningSpeakerQualifiers);
    morningSpeaker = (MorningSpeaker) beanManager.getReference(morningSpeakerBean);
    assertNotNull(morningSpeaker);
    final Set<Annotation> speakerQualifiers = new HashSet<Annotation>();
    speakerQualifiers.add(new NamedLiteral("speakerService"));
    final LatkeBean<?> speakerProviderBean = beanManager.getBean(SpeakerService.class, speakerQualifiers);
    speakerProvider = (SpeakerService) beanManager.getReference(speakerProviderBean);
    assertNotNull(speakerProvider);
}
Also used : Configurator(org.b3log.latke.ioc.config.Configurator) NamedLiteral(org.b3log.latke.ioc.literal.NamedLiteral) Annotation(java.lang.annotation.Annotation) MorningLiteral(org.b3log.latke.ioc.speaker.annotation.MorningLiteral) HelloLiteral(org.b3log.latke.ioc.speaker.annotation.HelloLiteral) MidnightLiteral(org.b3log.latke.ioc.speaker.annotation.MidnightLiteral) NightLiteral(org.b3log.latke.ioc.speaker.annotation.NightLiteral) HashSet(java.util.HashSet) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

Annotation (java.lang.annotation.Annotation)1 HashSet (java.util.HashSet)1 Configurator (org.b3log.latke.ioc.config.Configurator)1 NamedLiteral (org.b3log.latke.ioc.literal.NamedLiteral)1 HelloLiteral (org.b3log.latke.ioc.speaker.annotation.HelloLiteral)1 MidnightLiteral (org.b3log.latke.ioc.speaker.annotation.MidnightLiteral)1 MorningLiteral (org.b3log.latke.ioc.speaker.annotation.MorningLiteral)1 NightLiteral (org.b3log.latke.ioc.speaker.annotation.NightLiteral)1 BeforeTest (org.testng.annotations.BeforeTest)1