@Test
public void test26createPolicy() throws Exception {

	setup();
	XXServiceDefDao xServiceDefDao = Mockito.mock(XXServiceDefDao.class);
	XXPolicy xPolicy = Mockito.mock(XXPolicy.class);
	XXPolicyDao xPolicyDao = Mockito.mock(XXPolicyDao.class);
	XXServiceDao xServiceDao = Mockito.mock(XXServiceDao.class);
	XXService xService = Mockito.mock(XXService.class);
	XXServiceDef xServiceDef = serviceDef();
	Map<String, String> configs = new HashMap<String, String>();
	configs.put("username", "servicemgr");
	configs.put("password", "servicemgr");
	configs.put("namenode", "servicemgr");
	configs.put("hadoop.security.authorization", "No");
	configs.put("hadoop.security.authentication", "Simple");
	configs.put("hadoop.security.auth_to_local", "");
	configs.put("dfs.datanode.kerberos.principal", "");
	configs.put("dfs.namenode.kerberos.principal", "");
	configs.put("dfs.secondary.namenode.kerberos.principal", "");
	configs.put("hadoop.rpc.protection", "Privacy");
	configs.put("commonNameForCertificate", "");
	RangerService rangerService = new RangerService();
	rangerService.setId(Id);
	rangerService.setConfigs(configs);
	rangerService.setCreateTime(new Date());
	rangerService.setDescription("service policy");
	rangerService.setGuid("1427365526516_835_0");
	rangerService.setIsEnabled(true);
	rangerService.setName("HDFS_1");
	rangerService.setPolicyUpdateTime(new Date());
	rangerService.setType("1");
	rangerService.setUpdatedBy("Admin");
	String policyName = "HDFS_1-1-20150316062345";
	String name = "HDFS_1-1-20150316062453";
	List<RangerPolicyItemAccess> accessesList = new ArrayList<RangerPolicyItemAccess>();
	RangerPolicyItemAccess policyItemAccess = new RangerPolicyItemAccess();
	policyItemAccess.setIsAllowed(true);
	policyItemAccess.setType("1");
	List<String> usersList = new ArrayList<String>();
	List<String> groupsList = new ArrayList<String>();
	List<String> rolesList = new ArrayList<String>();
               List<String> policyLabels = new ArrayList<String>();
	List<RangerPolicyItemCondition> conditionsList = new ArrayList<RangerPolicyItemCondition>();
	RangerPolicyItemCondition policyItemCondition = new RangerPolicyItemCondition();
	policyItemCondition.setType("1");
	policyItemCondition.setValues(usersList);
	conditionsList.add(policyItemCondition);
	List<RangerPolicyItem> policyItems = new ArrayList<RangerPolicy.RangerPolicyItem>();
	RangerPolicyItem rangerPolicyItem = new RangerPolicyItem();
	rangerPolicyItem.setDelegateAdmin(false);
	rangerPolicyItem.setAccesses(accessesList);
	rangerPolicyItem.setConditions(conditionsList);
	rangerPolicyItem.setGroups(groupsList);
	rangerPolicyItem.setUsers(usersList);
	policyItems.add(rangerPolicyItem);
	List<RangerPolicyItem> policyItemsSet = new ArrayList<RangerPolicy.RangerPolicyItem>();
	RangerPolicyItem paramPolicyItem = new RangerPolicyItem(accessesList,
			usersList, groupsList, rolesList, conditionsList, false);
	paramPolicyItem.setDelegateAdmin(false);
	paramPolicyItem.setAccesses(accessesList);
	paramPolicyItem.setConditions(conditionsList);
	paramPolicyItem.setGroups(groupsList);
	rangerPolicyItem.setUsers(usersList);
	policyItemsSet.add(paramPolicyItem);
	XXPolicyItem xPolicyItem = new XXPolicyItem();
	xPolicyItem.setDelegateAdmin(false);
	xPolicyItem.setAddedByUserId(null);
	xPolicyItem.setCreateTime(new Date());
	xPolicyItem.setGUID(null);
	xPolicyItem.setId(Id);
	xPolicyItem.setOrder(null);
	xPolicyItem.setPolicyId(Id);
	xPolicyItem.setUpdatedByUserId(null);
	xPolicyItem.setUpdateTime(new Date());
	XXPolicy xxPolicy = new XXPolicy();
	xxPolicy.setId(Id);
	xxPolicy.setName(name);
	xxPolicy.setAddedByUserId(Id);
	xxPolicy.setCreateTime(new Date());
	xxPolicy.setDescription("test");
	xxPolicy.setIsAuditEnabled(true);
	xxPolicy.setIsEnabled(true);
	xxPolicy.setService(1L);
	xxPolicy.setUpdatedByUserId(Id);
	xxPolicy.setUpdateTime(new Date());
	List<XXServiceConfigDef> xServiceConfigDefList = new ArrayList<XXServiceConfigDef>();
	XXServiceConfigDef serviceConfigDefObj = new XXServiceConfigDef();
	serviceConfigDefObj.setId(Id);
	xServiceConfigDefList.add(serviceConfigDefObj);
	List<XXServiceConfigMap> xConfMapList = new ArrayList<XXServiceConfigMap>();
	XXServiceConfigMap xConfMap = new XXServiceConfigMap();
	xConfMap.setAddedByUserId(null);
	xConfMap.setConfigkey(name);
	xConfMap.setConfigvalue(name);
	xConfMap.setCreateTime(new Date());
	xConfMap.setServiceId(null);
	xConfMap.setId(Id);
	xConfMap.setUpdatedByUserId(null);
	xConfMap.setUpdateTime(new Date());
	xConfMapList.add(xConfMap);
	List<String> users = new ArrayList<String>();
	RangerPolicyResource rangerPolicyResource = new RangerPolicyResource();
	rangerPolicyResource.setIsExcludes(true);
	rangerPolicyResource.setIsRecursive(true);
	rangerPolicyResource.setValue("1");
	rangerPolicyResource.setValues(users);
	Map<String, RangerPolicyResource> policyResource = new HashMap<String, RangerPolicyResource>();
	policyResource.put(name, rangerPolicyResource);
	policyResource.put(policyName, rangerPolicyResource);
	RangerPolicy rangerPolicy = new RangerPolicy();
	rangerPolicy.setId(Id);
	rangerPolicy.setCreateTime(new Date());
	rangerPolicy.setDescription("policy");
	rangerPolicy.setGuid("policyguid");
	rangerPolicy.setIsEnabled(true);
	rangerPolicy.setName("HDFS_1-1-20150316062453");
	rangerPolicy.setUpdatedBy("Admin");
	rangerPolicy.setUpdateTime(new Date());
	rangerPolicy.setService("HDFS_1-1-20150316062453");
	rangerPolicy.setIsAuditEnabled(true);
	rangerPolicy.setPolicyItems(policyItems);
	rangerPolicy.setResources(policyResource);
               rangerPolicy.setPolicyLabels(policyLabels);
	XXPolicyResource xPolicyResource = new XXPolicyResource();
	xPolicyResource.setAddedByUserId(Id);
	xPolicyResource.setCreateTime(new Date());
	xPolicyResource.setId(Id);
	xPolicyResource.setIsExcludes(true);
	xPolicyResource.setIsRecursive(true);
	xPolicyResource.setPolicyId(Id);
	xPolicyResource.setResDefId(Id);
	xPolicyResource.setUpdatedByUserId(Id);
	xPolicyResource.setUpdateTime(new Date());
	List<XXPolicyConditionDef> policyConditionDefList = new ArrayList<XXPolicyConditionDef>();
	XXPolicyConditionDef policyConditionDefObj = new XXPolicyConditionDef();
	policyConditionDefObj.setAddedByUserId(Id);
	policyConditionDefObj.setCreateTime(new Date());
	policyConditionDefObj.setDefid(Id);
	policyConditionDefObj.setDescription("policy");
	policyConditionDefObj.setId(Id);
	policyConditionDefObj.setName("country");
	policyConditionDefObj.setOrder(0);
	policyConditionDefObj.setUpdatedByUserId(Id);
	policyConditionDefObj.setUpdateTime(new Date());
	policyConditionDefList.add(policyConditionDefObj);
	Mockito.when(daoManager.getXXService()).thenReturn(xServiceDao);
	Mockito.when(xServiceDao.findByName(name)).thenReturn(xService);
	Mockito.when(svcService.getPopulatedViewObject(xService)).thenReturn(
			rangerService);
	Mockito.when(daoManager.getXXServiceDef()).thenReturn(xServiceDefDao);
	Mockito.when(xServiceDefDao.findByName(rangerService.getType()))
			.thenReturn(xServiceDef);
	Mockito.when(daoManager.getXXPolicy()).thenReturn(xPolicyDao);
	Mockito.when(policyService.create(rangerPolicy, true)).thenReturn(
			rangerPolicy);
	Mockito.when(daoManager.getXXPolicy()).thenReturn(xPolicyDao);
	Mockito.when(xPolicyDao.getById(Id)).thenReturn(xPolicy);
	Mockito.doNothing().when(policyRefUpdater).createNewPolMappingForRefTable(rangerPolicy, xPolicy, xServiceDef);
	Mockito.when(policyService.getPopulatedViewObject(xPolicy)).thenReturn(rangerPolicy);
	Mockito.when(daoManager.getXXService()).thenReturn(xServiceDao);
	Mockito.when(xServiceDao.getById(Id)).thenReturn(xService);
	Mockito.when(daoManager.getXXService()).thenReturn(xServiceDao);
	Mockito.when(xServiceDao.getById(Id)).thenReturn(xService);
	RangerPolicyResourceSignature signature = Mockito
			.mock(RangerPolicyResourceSignature.class);
	Mockito.when(factory.createPolicyResourceSignature(rangerPolicy))
			.thenReturn(signature);
	Mockito.when(!bizUtil.hasAccess(xService, null)).thenReturn(true);
	RangerPolicy dbRangerPolicy = serviceDBStore.createPolicy(rangerPolicy);
	Assert.assertNotNull(dbRangerPolicy);
	Assert.assertEquals(Id, dbRangerPolicy.getId());
}