net.kamhon.ieagle.function.user.service.UserDetailsServiceTest.java Source code

Java tutorial

Introduction

Here is the source code for net.kamhon.ieagle.function.user.service.UserDetailsServiceTest.java

Source

/*
 * Copyright 2012 Eng Kam Hon (kamhon@gmail.com)
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.kamhon.ieagle.function.user.service;

import net.kamhon.ieagle.FrameworkConst;
import net.kamhon.ieagle.aop.AppDetailsBaseAdvice;
import net.kamhon.ieagle.application.Application;
import net.kamhon.ieagle.function.user.vo.User;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

public class UserDetailsServiceTest {
    private static final Log log = LogFactory.getLog(UserDetailsServiceTest.class);

    protected UserDetailsService userDetailsService;

    @Before
    public void init() {
        Application.reset();
        userDetailsService = (UserDetailsService) Application.lookupBean(UserDetailsService.BEAN_NAME);
    }

    @Test
    @Ignore
    public void testOnSaveAdminUser() {
        if (!userDetailsService.isUsernameAvailable(null, "admin")) {
            log.debug("the user admin already exists");

            return;
        }

        User user = new User(true);

        user.setUserId(AppDetailsBaseAdvice.SYSTEM_USER_ID);
        user.setStaffCode("staffcode");
        user.setCompId(FrameworkConst.DEFAULT_COMPANY);

        user.setUsername("admin");

        // user.setDeptId(1L);

        user.setRootLocId(1L);
        user.setLocId(1L);

        user.setFullname("Admin");
        user.setPassword("123456");

        try {
            userDetailsService.saveUser(user, null);
        } catch (Exception ex) {
            log.debug(ex, ex.fillInStackTrace());
        }
    }
}