|
|
@ -65,6 +65,7 @@ public class ResourceMapperTest { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* insert |
|
|
|
* insert |
|
|
|
|
|
|
|
* |
|
|
|
* @return Resource |
|
|
|
* @return Resource |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private Resource insertOne() { |
|
|
|
private Resource insertOne() { |
|
|
@ -76,12 +77,16 @@ public class ResourceMapperTest { |
|
|
|
resource.setDirectory(false); |
|
|
|
resource.setDirectory(false); |
|
|
|
resource.setType(ResourceType.FILE); |
|
|
|
resource.setType(ResourceType.FILE); |
|
|
|
resource.setUserId(111); |
|
|
|
resource.setUserId(111); |
|
|
|
resourceMapper.insert(resource); |
|
|
|
int status = resourceMapper.insert(resource); |
|
|
|
|
|
|
|
if (status != 1) { |
|
|
|
|
|
|
|
Assert.fail("insert data error"); |
|
|
|
|
|
|
|
} |
|
|
|
return resource; |
|
|
|
return resource; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* create resource by user |
|
|
|
* create resource by user |
|
|
|
|
|
|
|
* |
|
|
|
* @param user user |
|
|
|
* @param user user |
|
|
|
* @return Resource |
|
|
|
* @return Resource |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -93,12 +98,16 @@ public class ResourceMapperTest { |
|
|
|
resource.setAlias(alias); |
|
|
|
resource.setAlias(alias); |
|
|
|
resource.setFullName(fullName); |
|
|
|
resource.setFullName(fullName); |
|
|
|
resource.setUserId(user.getId()); |
|
|
|
resource.setUserId(user.getId()); |
|
|
|
resourceMapper.insert(resource); |
|
|
|
int status = resourceMapper.insert(resource); |
|
|
|
|
|
|
|
if (status != 1) { |
|
|
|
|
|
|
|
Assert.fail("insert data error"); |
|
|
|
|
|
|
|
} |
|
|
|
return resource; |
|
|
|
return resource; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* create resource by user |
|
|
|
* create resource by user |
|
|
|
|
|
|
|
* |
|
|
|
* @param user user |
|
|
|
* @param user user |
|
|
|
* @return Resource |
|
|
|
* @return Resource |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -113,6 +122,7 @@ public class ResourceMapperTest { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* create user |
|
|
|
* create user |
|
|
|
|
|
|
|
* |
|
|
|
* @return User |
|
|
|
* @return User |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private User createGeneralUser(String userName) { |
|
|
|
private User createGeneralUser(String userName) { |
|
|
@ -124,12 +134,17 @@ public class ResourceMapperTest { |
|
|
|
user.setCreateTime(new Date()); |
|
|
|
user.setCreateTime(new Date()); |
|
|
|
user.setTenantId(1); |
|
|
|
user.setTenantId(1); |
|
|
|
user.setUpdateTime(new Date()); |
|
|
|
user.setUpdateTime(new Date()); |
|
|
|
userMapper.insert(user); |
|
|
|
int status = userMapper.insert(user); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (status != 1) { |
|
|
|
|
|
|
|
Assert.fail("insert data error"); |
|
|
|
|
|
|
|
} |
|
|
|
return user; |
|
|
|
return user; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* create resource user |
|
|
|
* create resource user |
|
|
|
|
|
|
|
* |
|
|
|
* @return ResourcesUser |
|
|
|
* @return ResourcesUser |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private ResourcesUser createResourcesUser(Resource resource, User user) { |
|
|
|
private ResourcesUser createResourcesUser(Resource resource, User user) { |
|
|
@ -150,6 +165,7 @@ public class ResourceMapperTest { |
|
|
|
assertNotNull(resource.getId()); |
|
|
|
assertNotNull(resource.getId()); |
|
|
|
assertThat(resource.getId(), greaterThan(0)); |
|
|
|
assertThat(resource.getId(), greaterThan(0)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* test update |
|
|
|
* test update |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -294,16 +310,28 @@ public class ResourceMapperTest { |
|
|
|
Tenant tenant = new Tenant(); |
|
|
|
Tenant tenant = new Tenant(); |
|
|
|
tenant.setTenantName("ut tenant "); |
|
|
|
tenant.setTenantName("ut tenant "); |
|
|
|
tenant.setTenantCode("ut tenant code for resource"); |
|
|
|
tenant.setTenantCode("ut tenant code for resource"); |
|
|
|
tenantMapper.insert(tenant); |
|
|
|
int tenantInsertStatus = tenantMapper.insert(tenant); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (tenantInsertStatus != 1) { |
|
|
|
|
|
|
|
Assert.fail("insert tenant data error"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
User user = new User(); |
|
|
|
User user = new User(); |
|
|
|
user.setTenantId(tenant.getId()); |
|
|
|
user.setTenantId(tenant.getId()); |
|
|
|
user.setUserName("ut user"); |
|
|
|
user.setUserName("ut user"); |
|
|
|
userMapper.insert(user); |
|
|
|
int userInsertStatus = userMapper.insert(user); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (userInsertStatus != 1) { |
|
|
|
|
|
|
|
Assert.fail("insert user data error"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Resource resource = insertOne(); |
|
|
|
Resource resource = insertOne(); |
|
|
|
resource.setUserId(user.getId()); |
|
|
|
resource.setUserId(user.getId()); |
|
|
|
resourceMapper.updateById(resource); |
|
|
|
int userUpdateStatus = resourceMapper.updateById(resource); |
|
|
|
|
|
|
|
if (userUpdateStatus != 1) { |
|
|
|
|
|
|
|
Assert.fail("update user data error"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
String resource1 = resourceMapper.queryTenantCodeByResourceName( |
|
|
|
String resource1 = resourceMapper.queryTenantCodeByResourceName( |
|
|
|
resource.getFullName(), ResourceType.FILE.ordinal() |
|
|
|
resource.getFullName(), ResourceType.FILE.ordinal() |
|
|
@ -332,7 +360,6 @@ public class ResourceMapperTest { |
|
|
|
Assert.assertFalse(resources.stream().map(t -> t.getFullName()).collect(toList()).containsAll(Arrays.asList(resNames))); |
|
|
|
Assert.assertFalse(resources.stream().map(t -> t.getFullName()).collect(toList()).containsAll(Arrays.asList(resNames))); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// authorize object unauthorizedResource to generalUser
|
|
|
|
// authorize object unauthorizedResource to generalUser
|
|
|
|
createResourcesUser(unauthorizedResource, generalUser2); |
|
|
|
createResourcesUser(unauthorizedResource, generalUser2); |
|
|
|
List<Resource> authorizedResources = resourceMapper.listAuthorizedResource(generalUser2.getId(), resNames); |
|
|
|
List<Resource> authorizedResources = resourceMapper.listAuthorizedResource(generalUser2.getId(), resNames); |
|
|
@ -382,6 +409,8 @@ public class ResourceMapperTest { |
|
|
|
List<Resource> resourceList = new ArrayList<>(); |
|
|
|
List<Resource> resourceList = new ArrayList<>(); |
|
|
|
resourceList.add(resource); |
|
|
|
resourceList.add(resource); |
|
|
|
int result = resourceMapper.batchUpdateResource(resourceList); |
|
|
|
int result = resourceMapper.batchUpdateResource(resourceList); |
|
|
|
Assert.assertTrue(result>0); |
|
|
|
if (result != resourceList.size()) { |
|
|
|
|
|
|
|
Assert.fail("batch update resource data error"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |