|
|
@ -65,9 +65,10 @@ public class ResourceMapperTest { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* insert |
|
|
|
* insert |
|
|
|
|
|
|
|
* |
|
|
|
* @return Resource |
|
|
|
* @return Resource |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private Resource insertOne(){ |
|
|
|
private Resource insertOne() { |
|
|
|
//insertOne
|
|
|
|
//insertOne
|
|
|
|
Resource resource = new Resource(); |
|
|
|
Resource resource = new Resource(); |
|
|
|
resource.setAlias("ut-resource"); |
|
|
|
resource.setAlias("ut-resource"); |
|
|
@ -76,16 +77,20 @@ 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 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private Resource createResource(User user,boolean isDirectory,ResourceType resourceType,int pid,String alias,String fullName){ |
|
|
|
private Resource createResource(User user, boolean isDirectory, ResourceType resourceType, int pid, String alias, String fullName) { |
|
|
|
//insertOne
|
|
|
|
//insertOne
|
|
|
|
Resource resource = new Resource(); |
|
|
|
Resource resource = new Resource(); |
|
|
|
resource.setDirectory(isDirectory); |
|
|
|
resource.setDirectory(isDirectory); |
|
|
@ -93,19 +98,23 @@ 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 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private Resource createResource(User user){ |
|
|
|
private Resource createResource(User user) { |
|
|
|
//insertOne
|
|
|
|
//insertOne
|
|
|
|
String alias = String.format("ut-resource-%s",user.getUserName()); |
|
|
|
String alias = String.format("ut-resource-%s", user.getUserName()); |
|
|
|
String fullName = String.format("/%s",alias); |
|
|
|
String fullName = String.format("/%s", alias); |
|
|
|
|
|
|
|
|
|
|
|
Resource resource = createResource(user, false, ResourceType.FILE, -1, alias, fullName); |
|
|
|
Resource resource = createResource(user, false, ResourceType.FILE, -1, alias, fullName); |
|
|
|
return resource; |
|
|
|
return resource; |
|
|
@ -113,9 +122,10 @@ public class ResourceMapperTest { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* create user |
|
|
|
* create user |
|
|
|
|
|
|
|
* |
|
|
|
* @return User |
|
|
|
* @return User |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private User createGeneralUser(String userName){ |
|
|
|
private User createGeneralUser(String userName) { |
|
|
|
User user = new User(); |
|
|
|
User user = new User(); |
|
|
|
user.setUserName(userName); |
|
|
|
user.setUserName(userName); |
|
|
|
user.setUserPassword("1"); |
|
|
|
user.setUserPassword("1"); |
|
|
@ -124,15 +134,20 @@ 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) { |
|
|
|
//insertOne
|
|
|
|
//insertOne
|
|
|
|
ResourcesUser resourcesUser = new ResourcesUser(); |
|
|
|
ResourcesUser resourcesUser = new ResourcesUser(); |
|
|
|
resourcesUser.setCreateTime(new Date()); |
|
|
|
resourcesUser.setCreateTime(new Date()); |
|
|
@ -145,16 +160,17 @@ public class ResourceMapperTest { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testInsert(){ |
|
|
|
public void testInsert() { |
|
|
|
Resource resource = insertOne(); |
|
|
|
Resource resource = insertOne(); |
|
|
|
assertNotNull(resource.getId()); |
|
|
|
assertNotNull(resource.getId()); |
|
|
|
assertThat(resource.getId(),greaterThan(0)); |
|
|
|
assertThat(resource.getId(), greaterThan(0)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* test update |
|
|
|
* test update |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testUpdate(){ |
|
|
|
public void testUpdate() { |
|
|
|
//insertOne
|
|
|
|
//insertOne
|
|
|
|
Resource resource = insertOne(); |
|
|
|
Resource resource = insertOne(); |
|
|
|
resource.setCreateTime(new Date()); |
|
|
|
resource.setCreateTime(new Date()); |
|
|
@ -167,7 +183,7 @@ public class ResourceMapperTest { |
|
|
|
* test delete |
|
|
|
* test delete |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testDelete(){ |
|
|
|
public void testDelete() { |
|
|
|
Resource resourceMap = insertOne(); |
|
|
|
Resource resourceMap = insertOne(); |
|
|
|
int delete = resourceMapper.deleteById(resourceMap.getId()); |
|
|
|
int delete = resourceMapper.deleteById(resourceMap.getId()); |
|
|
|
Assert.assertEquals(1, delete); |
|
|
|
Assert.assertEquals(1, delete); |
|
|
@ -294,19 +310,31 @@ 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() |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -315,7 +343,7 @@ public class ResourceMapperTest { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testListAuthorizedResource(){ |
|
|
|
public void testListAuthorizedResource() { |
|
|
|
// create a general user
|
|
|
|
// create a general user
|
|
|
|
User generalUser1 = createGeneralUser("user1"); |
|
|
|
User generalUser1 = createGeneralUser("user1"); |
|
|
|
User generalUser2 = createGeneralUser("user2"); |
|
|
|
User generalUser2 = createGeneralUser("user2"); |
|
|
@ -328,20 +356,19 @@ public class ResourceMapperTest { |
|
|
|
|
|
|
|
|
|
|
|
List<Resource> resources = resourceMapper.listAuthorizedResource(generalUser2.getId(), resNames); |
|
|
|
List<Resource> resources = resourceMapper.listAuthorizedResource(generalUser2.getId(), resNames); |
|
|
|
|
|
|
|
|
|
|
|
Assert.assertEquals(generalUser2.getId(),resource.getUserId()); |
|
|
|
Assert.assertEquals(generalUser2.getId(), resource.getUserId()); |
|
|
|
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); |
|
|
|
Assert.assertTrue(authorizedResources.stream().map(t -> t.getFullName()).collect(toList()).containsAll(Arrays.asList(resNames))); |
|
|
|
Assert.assertTrue(authorizedResources.stream().map(t -> t.getFullName()).collect(toList()).containsAll(Arrays.asList(resNames))); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void deleteIdsTest(){ |
|
|
|
public void deleteIdsTest() { |
|
|
|
// create a general user
|
|
|
|
// create a general user
|
|
|
|
User generalUser1 = createGeneralUser("user1"); |
|
|
|
User generalUser1 = createGeneralUser("user1"); |
|
|
|
|
|
|
|
|
|
|
@ -352,11 +379,11 @@ public class ResourceMapperTest { |
|
|
|
resourceList.add(resource.getId()); |
|
|
|
resourceList.add(resource.getId()); |
|
|
|
resourceList.add(resource1.getId()); |
|
|
|
resourceList.add(resource1.getId()); |
|
|
|
int result = resourceMapper.deleteIds(resourceList.toArray(new Integer[resourceList.size()])); |
|
|
|
int result = resourceMapper.deleteIds(resourceList.toArray(new Integer[resourceList.size()])); |
|
|
|
Assert.assertEquals(result,2); |
|
|
|
Assert.assertEquals(result, 2); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void queryResourceListAuthoredTest(){ |
|
|
|
public void queryResourceListAuthoredTest() { |
|
|
|
// create a general user
|
|
|
|
// create a general user
|
|
|
|
User generalUser1 = createGeneralUser("user1"); |
|
|
|
User generalUser1 = createGeneralUser("user1"); |
|
|
|
User generalUser2 = createGeneralUser("user2"); |
|
|
|
User generalUser2 = createGeneralUser("user2"); |
|
|
@ -372,16 +399,18 @@ public class ResourceMapperTest { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void batchUpdateResourceTest(){ |
|
|
|
public void batchUpdateResourceTest() { |
|
|
|
// create a general user
|
|
|
|
// create a general user
|
|
|
|
User generalUser1 = createGeneralUser("user1"); |
|
|
|
User generalUser1 = createGeneralUser("user1"); |
|
|
|
// create resource
|
|
|
|
// create resource
|
|
|
|
Resource resource = createResource(generalUser1); |
|
|
|
Resource resource = createResource(generalUser1); |
|
|
|
resource.setFullName(String.format("%s-update",resource.getFullName())); |
|
|
|
resource.setFullName(String.format("%s-update", resource.getFullName())); |
|
|
|
resource.setUpdateTime(new Date()); |
|
|
|
resource.setUpdateTime(new Date()); |
|
|
|
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"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |