Added a customized checkstyle configuration file to tame the Maven 2 checkstyle report to the extent that it gives some useful infomation. Tidied up comments, excessively long lines, use of tabs etc. to match.

This commit is contained in:
Luke Taylor
2007-02-24 21:00:24 +00:00
parent bd2d4b013a
commit fabca162a7
189 changed files with 2207 additions and 1789 deletions

View File

@@ -8,80 +8,80 @@ import sample.dms.DocumentDao;
/**
* Basic integration test for DMS sample.
*
*
* @author Ben Alex
* @version $Id$
*
*/
public class DmsIntegrationTests extends AbstractTransactionalDataSourceSpringContextTests {
protected DocumentDao documentDao;
protected String[] getConfigLocations() {
return new String[] {"classpath:applicationContext-dms-shared.xml", "classpath:applicationContext-dms-insecure.xml"};
}
protected DocumentDao documentDao;
public void setDocumentDao(DocumentDao documentDao) {
this.documentDao = documentDao;
}
protected String[] getConfigLocations() {
return new String[] {"classpath:applicationContext-dms-shared.xml", "classpath:applicationContext-dms-insecure.xml"};
}
public void testBasePopulation() {
assertEquals(9, jdbcTemplate.queryForInt("select count(id) from DIRECTORY"));
assertEquals(90, jdbcTemplate.queryForInt("select count(id) from FILE"));
assertEquals(3, documentDao.findElements(Directory.ROOT_DIRECTORY).length);
}
public void testMarissaRetrieval() {
process("marissa", "koala", false);
}
public void testScottRetrieval() {
process("scott", "wombat", false);
}
public void testDianneRetrieval() {
process("dianne", "emu", false);
}
public void setDocumentDao(DocumentDao documentDao) {
this.documentDao = documentDao;
}
protected void process(String username, String password, boolean shouldBeFiltered) {
SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken(username, password));
System.out.println("------ Test for username: " + username + " ------");
AbstractElement[] rootElements = documentDao.findElements(Directory.ROOT_DIRECTORY);
assertEquals(3, rootElements.length);
Directory homeDir = null;
Directory nonHomeDir = null;
for (int i = 0; i < rootElements.length; i++) {
if (rootElements[i].getName().equals(username)) {
homeDir = (Directory) rootElements[i];
} else {
nonHomeDir = (Directory) rootElements[i];
}
}
System.out.println("Home directory......: " + homeDir.getFullName());
System.out.println("Non-home directory..: " + nonHomeDir.getFullName());
AbstractElement[] homeElements = documentDao.findElements(homeDir);
assertEquals(12, homeElements.length); // confidential and shared directories, plus 10 files
public void testBasePopulation() {
assertEquals(9, jdbcTemplate.queryForInt("select count(id) from DIRECTORY"));
assertEquals(90, jdbcTemplate.queryForInt("select count(id) from FILE"));
assertEquals(3, documentDao.findElements(Directory.ROOT_DIRECTORY).length);
}
public void testMarissaRetrieval() {
process("marissa", "koala", false);
}
public void testScottRetrieval() {
process("scott", "wombat", false);
}
public void testDianneRetrieval() {
process("dianne", "emu", false);
}
protected void process(String username, String password, boolean shouldBeFiltered) {
SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken(username, password));
System.out.println("------ Test for username: " + username + " ------");
AbstractElement[] rootElements = documentDao.findElements(Directory.ROOT_DIRECTORY);
assertEquals(3, rootElements.length);
Directory homeDir = null;
Directory nonHomeDir = null;
for (int i = 0; i < rootElements.length; i++) {
if (rootElements[i].getName().equals(username)) {
homeDir = (Directory) rootElements[i];
} else {
nonHomeDir = (Directory) rootElements[i];
}
}
System.out.println("Home directory......: " + homeDir.getFullName());
System.out.println("Non-home directory..: " + nonHomeDir.getFullName());
AbstractElement[] homeElements = documentDao.findElements(homeDir);
assertEquals(12, homeElements.length); // confidential and shared directories, plus 10 files
AbstractElement[] nonHomeElements = documentDao.findElements(nonHomeDir);
assertEquals(shouldBeFiltered ? 11 : 12, nonHomeElements.length); // cannot see the user's "confidential" sub-directory when filtering
// Attempt to read the other user's confidential directory from the returned results
// Of course, we shouldn't find a "confidential" directory in the results if we're filtering
Directory nonHomeConfidentialDir = null;
for (int i = 0; i < nonHomeElements.length; i++) {
if (nonHomeElements[i].getName().equals("confidential")) {
nonHomeConfidentialDir = (Directory) nonHomeElements[i];
}
}
if (shouldBeFiltered) {
assertNull("Found confidential directory when we should not have", nonHomeConfidentialDir);
} else {
System.out.println("Inaccessible dir....: " + nonHomeConfidentialDir.getFullName());
assertEquals(10, documentDao.findElements(nonHomeConfidentialDir).length); // 10 files (no sub-directories)
}
SecurityContextHolder.clearContext();
}
AbstractElement[] nonHomeElements = documentDao.findElements(nonHomeDir);
assertEquals(shouldBeFiltered ? 11 : 12, nonHomeElements.length); // cannot see the user's "confidential" sub-directory when filtering
// Attempt to read the other user's confidential directory from the returned results
// Of course, we shouldn't find a "confidential" directory in the results if we're filtering
Directory nonHomeConfidentialDir = null;
for (int i = 0; i < nonHomeElements.length; i++) {
if (nonHomeElements[i].getName().equals("confidential")) {
nonHomeConfidentialDir = (Directory) nonHomeElements[i];
}
}
if (shouldBeFiltered) {
assertNull("Found confidential directory when we should not have", nonHomeConfidentialDir);
} else {
System.out.println("Inaccessible dir....: " + nonHomeConfidentialDir.getFullName());
assertEquals(10, documentDao.findElements(nonHomeConfidentialDir).length); // 10 files (no sub-directories)
}
SecurityContextHolder.clearContext();
}
}

View File

@@ -14,54 +14,54 @@ import sample.dms.Directory;
/**
* Basic integration test for DMS sample when security has been added.
*
*
* @author Ben Alex
* @version $Id$
*
*/
public class SecureDmsIntegrationTests extends DmsIntegrationTests {
private AclService aclService;
public void setAclService(AclService aclService) {
this.aclService = aclService;
}
private AclService aclService;
protected String[] getConfigLocations() {
return new String[] {"classpath:applicationContext-dms-shared.xml", "classpath:applicationContext-dms-secure.xml"};
}
public void setAclService(AclService aclService) {
this.aclService = aclService;
}
public void testBasePopulation() {
assertEquals(9, jdbcTemplate.queryForInt("select count(id) from DIRECTORY"));
assertEquals(90, jdbcTemplate.queryForInt("select count(id) from FILE"));
assertEquals(4, jdbcTemplate.queryForInt("select count(id) from ACL_SID")); // 3 users + 1 role
assertEquals(2, jdbcTemplate.queryForInt("select count(id) from ACL_CLASS")); // Directory and File
assertEquals(100, jdbcTemplate.queryForInt("select count(id) from ACL_OBJECT_IDENTITY"));
assertEquals(115, jdbcTemplate.queryForInt("select count(id) from ACL_ENTRY"));
}
/*
public void testItOut() {
SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken("marissa", "password", new GrantedAuthority[] {new GrantedAuthorityImpl("ROLE_SUPERVISOR")}));
AbstractElement[] elements = documentDao.findElements(Directory.ROOT_DIRECTORY);
ObjectIdentity oid = new ObjectIdentityImpl(elements[0]);
//ObjectIdentity oid = new ObjectIdentityImpl(Directory.class, new Long(3));
Acl acl = aclService.readAclById(oid);
System.out.println(acl);
}*/
public void testMarissaRetrieval() {
process("marissa", "koala", true);
}
protected String[] getConfigLocations() {
return new String[] {"classpath:applicationContext-dms-shared.xml", "classpath:applicationContext-dms-secure.xml"};
}
public void testScottRetrieval() {
process("scott", "wombat", true);
}
public void testDianneRetrieval() {
process("dianne", "emu", true);
}
public void testBasePopulation() {
assertEquals(9, jdbcTemplate.queryForInt("select count(id) from DIRECTORY"));
assertEquals(90, jdbcTemplate.queryForInt("select count(id) from FILE"));
assertEquals(4, jdbcTemplate.queryForInt("select count(id) from ACL_SID")); // 3 users + 1 role
assertEquals(2, jdbcTemplate.queryForInt("select count(id) from ACL_CLASS")); // Directory and File
assertEquals(100, jdbcTemplate.queryForInt("select count(id) from ACL_OBJECT_IDENTITY"));
assertEquals(115, jdbcTemplate.queryForInt("select count(id) from ACL_ENTRY"));
}
/*
public void testItOut() {
SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken("marissa", "password", new GrantedAuthority[] {new GrantedAuthorityImpl("ROLE_SUPERVISOR")}));
AbstractElement[] elements = documentDao.findElements(Directory.ROOT_DIRECTORY);
ObjectIdentity oid = new ObjectIdentityImpl(elements[0]);
//ObjectIdentity oid = new ObjectIdentityImpl(Directory.class, new Long(3));
Acl acl = aclService.readAclById(oid);
System.out.println(acl);
}*/
public void testMarissaRetrieval() {
process("marissa", "koala", true);
}
public void testScottRetrieval() {
process("scott", "wombat", true);
}
public void testDianneRetrieval() {
process("dianne", "emu", true);
}
}