Search in sources :

Example 6 with ApplicationContext

use of com.tvd12.ezyhttp.server.core.ApplicationContext in project ezyhttp by youngmonkeys.

the class EzyHttpApplicationTest method test.

@Test
public void test() throws Exception {
    // given
    EzyHttpApplication sut = EzyHttpApplication.start(EzyHttpApplicationTest.class);
    ApplicationContext applicationContext = sut.getApplicationContext();
    EzyBeanContext beanContext = applicationContext.getBeanContext();
    // when
    int actualOneProp = beanContext.getProperty("one", int.class);
    boolean managementEnable = beanContext.getProperty("management.enable", boolean.class);
    UserService userService = beanContext.getSingleton(UserService.class);
    ViewContextBuilder viewContextBuilder = beanContext.getSingleton(ViewContextBuilder.class);
    ResourceResolver resourceResolver = beanContext.getSingleton(ResourceResolver.class);
    ResourceDownloadManager resourceDownloadManager = beanContext.getSingleton(ResourceDownloadManager.class);
    // then
    Asserts.assertEquals(1, actualOneProp);
    Asserts.assertTrue(managementEnable);
    Asserts.assertNotNull(userService);
    Asserts.assertNotNull(viewContextBuilder);
    Asserts.assertNotNull(resourceDownloadManager);
    Asserts.assertEquals(4, resourceResolver.getResources().size());
    sut.stop();
}
Also used : ApplicationContext(com.tvd12.ezyhttp.server.core.ApplicationContext) ResourceDownloadManager(com.tvd12.ezyhttp.core.resources.ResourceDownloadManager) EzyHttpApplication(com.tvd12.ezyhttp.server.core.EzyHttpApplication) EzyBeanContext(com.tvd12.ezyfox.bean.EzyBeanContext) UserService(com.tvd12.ezyhttp.server.core.test.service.UserService) ResourceResolver(com.tvd12.ezyhttp.server.core.resources.ResourceResolver) ViewContextBuilder(com.tvd12.ezyhttp.server.core.view.ViewContextBuilder) Test(org.testng.annotations.Test)

Example 7 with ApplicationContext

use of com.tvd12.ezyhttp.server.core.ApplicationContext in project ezyhttp by youngmonkeys.

the class EzyHttpApplicationTest method testFailedDueToNoApplicationEntry.

@Test
public void testFailedDueToNoApplicationEntry() {
    // given
    ApplicationContext context = mock(ApplicationContext.class);
    EzyHttpApplication sut = new EzyHttpApplication(context);
    // when
    Throwable e = Asserts.assertThrows(sut::start);
    // then
    Asserts.assertThat(e).isEqualsType(IllegalStateException.class);
    verify(context, times(1)).getAnnotatedSingleton(ApplicationBootstrap.class);
}
Also used : ApplicationContext(com.tvd12.ezyhttp.server.core.ApplicationContext) EzyHttpApplication(com.tvd12.ezyhttp.server.core.EzyHttpApplication) Test(org.testng.annotations.Test)

Example 8 with ApplicationContext

use of com.tvd12.ezyhttp.server.core.ApplicationContext in project java-examples by tvd12.

the class MyApplicationStartup method main.

public static void main(String[] args) {
    ApplicationContext appContext = SpringApplication.run(MyApplicationStartup.class, args);
    BookService bookService = appContext.getBean(BookService.class);
    bookService.saveBook(new Book(1, "youngmonkeys.org"));
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) Book(com.tvd12.example.spring_boot.entity.Book) BookService(com.tvd12.example.spring_boot.service.BookService)

Aggregations

EzyBeanContext (com.tvd12.ezyfox.bean.EzyBeanContext)6 ApplicationContext (com.tvd12.ezyhttp.server.core.ApplicationContext)6 Test (org.testng.annotations.Test)6 ResourceDownloadManager (com.tvd12.ezyhttp.core.resources.ResourceDownloadManager)4 EzyHttpApplication (com.tvd12.ezyhttp.server.core.EzyHttpApplication)4 ResourceResolver (com.tvd12.ezyhttp.server.core.resources.ResourceResolver)4 UserService (com.tvd12.ezyhttp.server.core.test.service.UserService)3 ViewContextBuilder (com.tvd12.ezyhttp.server.core.view.ViewContextBuilder)3 ApplicationContextBuilder (com.tvd12.ezyhttp.server.core.ApplicationContextBuilder)2 Book (com.tvd12.example.spring_boot.entity.Book)1 BookService (com.tvd12.example.spring_boot.service.BookService)1 ComponentManager (com.tvd12.ezyhttp.server.core.manager.ComponentManager)1 EventService (com.tvd12.ezyhttp.server.core.test.event.EventService)1 SourceService (com.tvd12.ezyhttp.server.core.test.event.SourceService)1 UserService0 (com.tvd12.ezyhttp.server.core.test.service.UserService0)1 Properties (java.util.Properties)1 ApplicationContext (org.springframework.context.ApplicationContext)1