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