Search in sources :

Example 1 with User

use of test.demo.config.User in project today-infrastructure by TAKETODAY.

the class DefaultUserRepository method initData.

@PostConstruct
public void initData() {
    log.info("init data: [{}]", this);
    users.put("666", new User(1, "Harry Yang", 20, "666", "666", "男", new Date()));
    users.put("6666", new User(2, "Harry Yang1", 20, "6666", "6666", "男", new Date()));
    users.put("66666", new User(3, "Harry Yang2", 20, "66666", "66666", "男", new Date()));
    users.put("666666", new User(4, "Harry Yang3", 20, "666666", "666666", "男", new Date()));
}
Also used : User(test.demo.config.User) Date(java.util.Date) PostConstruct(jakarta.annotation.PostConstruct)

Example 2 with User

use of test.demo.config.User in project today-framework by TAKETODAY.

the class DemoTests method testLogin.

@Test
void testLogin() throws NoSuchBeanDefinitionException, BeanDefinitionStoreException, IOException {
    try (StandardApplicationContext context = new StandardApplicationContext()) {
        ApplicationPropertySourcesProcessor processor = new ApplicationPropertySourcesProcessor(context);
        processor.setPropertiesLocation("info.properties");
        processor.postProcessEnvironment();
        context.scan("test.demo.service.impl", "test.demo.repository.impl");
        context.refresh();
        UserService userService = context.getBean(DefaultUserService.class);
        UserRepository userDao = context.getBean(UserRepository.class);
        DefaultUserRepository userDaoImpl = context.getBean(DefaultUserRepository.class);
        assert userDao != userDaoImpl;
        User login = userService.login(new User(1, "TODAY", 20, "666", "666", "男", new Date()));
        assert login != null : "Login failed";
    }
}
Also used : ApplicationPropertySourcesProcessor(cn.taketoday.context.support.ApplicationPropertySourcesProcessor) StandardApplicationContext(cn.taketoday.context.support.StandardApplicationContext) UserRepository(test.demo.repository.UserRepository) DefaultUserRepository(test.demo.repository.impl.DefaultUserRepository) User(test.demo.config.User) DefaultUserService(test.demo.service.impl.DefaultUserService) UserService(test.demo.service.UserService) DefaultUserRepository(test.demo.repository.impl.DefaultUserRepository) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 3 with User

use of test.demo.config.User in project today-framework by TAKETODAY.

the class ProfileTests method testProfile.

@Test
void testProfile() throws IOException {
    try (StandardApplicationContext context = new StandardApplicationContext()) {
        ApplicationPropertySourcesProcessor processor = new ApplicationPropertySourcesProcessor(context);
        processor.setPropertiesLocation("info.properties");
        processor.postProcessEnvironment();
        context.register(ProfileTestConfig.class);
        context.refresh();
        User user = context.getBean("user", User.class);
        assert "TEST".equals(user.getUserName());
    }
}
Also used : ApplicationPropertySourcesProcessor(cn.taketoday.context.support.ApplicationPropertySourcesProcessor) StandardApplicationContext(cn.taketoday.context.support.StandardApplicationContext) User(test.demo.config.User) Test(org.junit.jupiter.api.Test)

Example 4 with User

use of test.demo.config.User in project today-framework by TAKETODAY.

the class ApplicationContextTests method testLoadFromCollection.

@Test
void testLoadFromCollection() throws Exception {
    try (StandardApplicationContext applicationContext = new StandardApplicationContext()) {
        applicationContext.register(ConfigurationBean.class);
        applicationContext.refresh();
        User bean = applicationContext.getBean(User.class);
        bean.setAge(12);
        User user = applicationContext.getBean(User.class);
        assertThat(bean).isNotNull().isEqualTo(user);
    }
}
Also used : StandardApplicationContext(cn.taketoday.context.support.StandardApplicationContext) User(test.demo.config.User) Test(org.junit.jupiter.api.Test)

Example 5 with User

use of test.demo.config.User in project today-framework by TAKETODAY.

the class CachePutInterceptorTests method testInContext.

@Test
void testInContext() throws Exception {
    CacheExpressionOperations operations = new CacheExpressionOperations();
    try (StandardApplicationContext context = new StandardApplicationContext()) {
        context.register(CachePutConfig.class);
        context.refresh();
        CachePutInterceptor interceptor = context.getBean(CachePutInterceptor.class);
        Method save = CacheUserService.class.getDeclaredMethod("save", User.class);
        // CachePut
        MethodKey methodKey = new MethodKey(save, CachePut.class);
        interceptor.setExpressionOperations(operations);
        CacheConfiguration cachePut = operations.getConfig(methodKey);
        Cache users = interceptor.getCache("users", cachePut);
        User today = new User(1, "TODAY", 20, "666", "666", "男", new Date());
        CacheUserService userService = context.getBean(CacheUserService.class);
        userService.save(today);
        Object by_id_666 = users.get("by_id_666");
        assertThat(by_id_666).isEqualTo(today);
        User user = userService.getUser("666");
        assertThat(today).isEqualTo(user);
        user = userService.getUser("666");
        assertThat(today).isEqualTo(user);
        user = userService.getUser("666");
        assertThat(today).isEqualTo(user);
        user = userService.getUser("666");
        assertThat(today).isEqualTo(user);
        assertThat(today).isEqualTo(user).isEqualTo(by_id_666);
        // access time     no Cacheable Interceptor
        assertThat(userService.getAccessTime()).isEqualTo(4);
    }
}
Also used : StandardApplicationContext(cn.taketoday.context.support.StandardApplicationContext) User(test.demo.config.User) Method(java.lang.reflect.Method) CacheConfiguration(cn.taketoday.cache.annotation.CacheConfiguration) Date(java.util.Date) Cache(cn.taketoday.cache.Cache) Test(org.junit.jupiter.api.Test)

Aggregations

User (test.demo.config.User)9 StandardApplicationContext (cn.taketoday.context.support.StandardApplicationContext)7 Test (org.junit.jupiter.api.Test)7 Date (java.util.Date)6 Cache (cn.taketoday.cache.Cache)3 CacheConfiguration (cn.taketoday.cache.annotation.CacheConfiguration)3 ApplicationPropertySourcesProcessor (cn.taketoday.context.support.ApplicationPropertySourcesProcessor)3 Method (java.lang.reflect.Method)3 PostConstruct (jakarta.annotation.PostConstruct)2 CaffeineCache (cn.taketoday.cache.support.CaffeineCache)1 UserRepository (test.demo.repository.UserRepository)1 DefaultUserRepository (test.demo.repository.impl.DefaultUserRepository)1 UserService (test.demo.service.UserService)1 DefaultUserService (test.demo.service.impl.DefaultUserService)1