単体テストでは、正しく機能したふりをするための認証メソッドが必要です。私の場合は何もしないので、メソッド自体が期待どおりの動作をするかどうかをテストできます(認証は単体テストの原則に従って他の場所でテストされますが、認証が必要です。そのメソッド内で呼び出されます)
これは、認証用のモックオブジェクトを作成する必要がある私のTestNGクラスです。
package in.hexgen.api.facade;
import javax.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.Authentication;
import org.testng.annotations.Test;
import com.hexgen.api.facade.security.HexGenPermissionEvaluator;
public class HexGenPermissionEvaluatorTest {
private static final Logger logger = LoggerFactory.getLogger(HexGenPermissionEvaluatorTest.class);
Object name="akash";
Object permission="CREATE_REQUISITION";
Authentication authentication;
//@Resource(name = "permissionEval")
private HexGenPermissionEvaluator permissionEval;
@Test
public void hasPermission() {
//authentication.setAuthenticated(true);
logger.debug("HexGenPermissionEvaluator Generate - starting ...");
permissionEval.hasPermission(authentication,name, permission);
logger.debug("HexGenPermissionEvaluator Generate - completed ...");
}
}
これを行う方法。
よろしくお願いします