* @throws StorageException
* @throws UserNotFoundException
*/
@Test
public final void testDeleteScript() throws ScriptNotFoundException, IsActiveException, AuthenticationRequiredException, UserNotFoundException, StorageException, QuotaExceededException {
MockSession session = new MockSession();
SieveRepository repository = new MockSieveRepository();
CoreProcessor core = new CoreProcessor(session, repository, new MockSieveParser());
// Unauthorised
boolean success = false;
session.setAuthentication(false);
try {
core.deleteScript("script");
} catch (AuthenticationRequiredException ex) {
success = true;
}
assertTrue("Expected AuthenticationRequiredException", success);
// Authorised - non-existent script
success = false;
session.setAuthentication(true);
session.setUser("test");
try {
core.deleteScript("script");
} catch (ScriptNotFoundException ex) {
success = true;
}
assertTrue("Expected ScriptNotFoundException", success);
// Authorised - existent script
session.setAuthentication(true);
session.setUser("test");
repository.putScript("test", "script", "content");
core.deleteScript("script");
success = false;
try {
repository.getScript("test", "script");
} catch (ScriptNotFoundException ex) {
success = true;
}
assertTrue("Expected ScriptNotFoundException", success);
// Authorised - active script
success = false;
session.setAuthentication(true);
session.setUser("test");
repository.putScript("test", "script", "content");
repository.setActive("test", "script");
try {
core.deleteScript("script");
} catch (IsActiveException ex) {