Skip to content

Commit

Permalink
[SHRINKWRAP-290] Check for resource existence
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Pazmino committed Jun 26, 2011
1 parent 29439bc commit 0e78c56
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1504,10 +1504,19 @@ protected Class<T> getActualClass()
return this.actualType;
}

private File fileFromResource(final String resourceName)
/**
* Gets a resource from the TCCL and returns its file path.
*
* @param resourceName is the name of the resource in the classpath
* @return the file path for resourceName @see {@link java.net.URL#getFile()}
* @throws IllegalArgumentException if resourceName doesn't exist in the classpath or privileges are not granted
*/
private File fileFromResource(final String resourceName) throws IllegalArgumentException
{
final String resourcePath = AccessController.doPrivileged(GetTcclAction.INSTANCE).getResource(resourceName)
.getFile();
final URL resourceUrl = AccessController.doPrivileged(GetTcclAction.INSTANCE).getResource(resourceName);
Validate.notNull(resourceUrl, resourceName + " doesn't exist or can't be accessed");

final String resourcePath = resourceUrl.getFile();
return new File(resourcePath);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,15 @@ public void testAddManifestResource() throws Exception {
"Archive should contain " + testPath,
getArchive().contains(testPath));
}

@Test(expected = IllegalArgumentException.class)
@ArchiveType(ManifestContainer.class)
public void testAddNonExistentManifestResource() throws Exception {
final String nonExistentResourceName = "ejb/security/ejb-jar.xml";

//Since the resource doesn't exist the ManifestContainer implementation throws the expected exception
getManifestContainer().addAsManifestResource(nonExistentResourceName);
}

@Test
@ArchiveType(ManifestContainer.class)
Expand Down

0 comments on commit 0e78c56

Please sign in to comment.