Examples of MockSession


Examples of org.apache.james.managesieve.mock.MockSession

    /**
     * Test method for {@link org.apache.james.managesieve.core.CoreProcessor#capability()}.
     */
    @Test
    public final void testCapability() {
        MockSession session = new MockSession();
        MockSieveParser parser = new MockSieveParser();
        CoreProcessor core = new CoreProcessor(session, new MockSieveRepository(), parser);

        // Unauthenticated
        session.setAuthentication(false);
        parser.setExtensions(Arrays.asList(new String[]{"a","b","c"}));
        Map<Capabilities, String> capabilities = core.capability();
        assertEquals(CoreProcessor.IMPLEMENTATION_DESCRIPTION, capabilities.get(Capabilities.IMPLEMENTATION));
        assertEquals(CoreProcessor.MANAGE_SIEVE_VERSION, capabilities.get(Capabilities.VERSION));
        assertEquals("a b c", capabilities.get(Capabilities.SIEVE));
        assertFalse(capabilities.containsKey(Capabilities.OWNER));
        assertTrue(capabilities.containsKey(Capabilities.GETACTIVE));
       
        // Authenticated
        session.setAuthentication(true);
        parser.setExtensions(Arrays.asList(new String[]{"a","b","c"}));
        session.setUser("test");
        capabilities = core.capability();
        assertEquals(CoreProcessor.IMPLEMENTATION_DESCRIPTION, capabilities.get(Capabilities.IMPLEMENTATION));
        assertEquals(CoreProcessor.MANAGE_SIEVE_VERSION, capabilities.get(Capabilities.VERSION));
        assertEquals("a b c", capabilities.get(Capabilities.SIEVE));
        assertEquals("test", capabilities.get(Capabilities.OWNER));
View Full Code Here

Examples of org.apache.james.managesieve.mock.MockSession

     * @throws SyntaxException
     * @throws AuthenticationRequiredException
     */
    @Test
    public final void testCheckScript() throws AuthenticationRequiredException, SyntaxException {
        MockSession session = new MockSession();
        CoreProcessor core = new CoreProcessor(session, new MockSieveRepository(), new MockSieveParser());

        // Unauthorised
        boolean success = false;
        session.setAuthentication(false);
        try {
            core.checkScript("warning");
        } catch (AuthenticationRequiredException ex) {
            success = true;
        }
        assertTrue("Expected AuthenticationRequiredException", success);

        // Authorised
        session.setAuthentication(true);
        session.setUser("test");
        List<String> warnings = core.checkScript("warning");
        assertEquals(2, warnings.size());
        assertEquals("warning1", warnings.get(0));
        assertEquals("warning2", warnings.get(1));

        // Syntax
        success = false;
        session.setAuthentication(true);
        session.setUser("test");
        try {
            core.checkScript("SyntaxException");
        } catch (SyntaxException ex) {
            success = true;
        }
View Full Code Here

Examples of org.apache.james.managesieve.mock.MockSession

     * @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) {
View Full Code Here

Examples of org.apache.james.managesieve.mock.MockSession

     * @throws StorageException
     * @throws UserNotFoundException
     */
    @Test
    public final void testGetScript() throws ScriptNotFoundException, 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.getScript("script");
        } catch (AuthenticationRequiredException ex) {
            success = true;
        }
        assertTrue("Expected AuthenticationRequiredException", success);

        // Authorised - non-existent script
        success = false;
        session.setAuthentication(true);
        session.setUser("test");
        try {
            core.getScript("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.getScript("script");
    }
View Full Code Here

Examples of org.apache.james.managesieve.mock.MockSession

     * @throws QuotaExceededException
     * @throws AuthenticationRequiredException
     */
    @Test
    public final void testHaveSpace() throws QuotaExceededException, AuthenticationRequiredException {
        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.haveSpace("script", Long.MAX_VALUE);
        } catch (AuthenticationRequiredException ex) {
            success = true;
        }
        assertTrue("Expected AuthenticationRequiredException", success);
       
        // Authorised - existent script
        session.setAuthentication(true);
        session.setUser("test");
        core.haveSpace("script", Long.MAX_VALUE);
    }
View Full Code Here

Examples of org.apache.james.managesieve.mock.MockSession

     * @throws StorageException
     * @throws UserNotFoundException
     */
    @Test
    public final void testListScripts() throws 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.listScripts();
        } catch (AuthenticationRequiredException ex) {
            success = true;
        }
        assertTrue("Expected AuthenticationRequiredException", success);

        // Authorised - non-existent script
        success = false;
        session.setAuthentication(true);
        session.setUser("test");
        List<ScriptSummary> summaries = core.listScripts();
        assertTrue(summaries.isEmpty());
       
        // Authorised - existent script
        session.setAuthentication(true);
        session.setUser("test");
        repository.putScript("test", "script", "content");
        summaries = core.listScripts();
        assertEquals(1, summaries.size());
    }
View Full Code Here

Examples of org.apache.james.managesieve.mock.MockSession

     * @throws ScriptNotFoundException
     * @throws UserNotFoundException
     */
    @Test
    public final void testPutScript() throws SyntaxException, QuotaExceededException, AuthenticationRequiredException, UserNotFoundException, ScriptNotFoundException {
        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.putScript("script", "content");
        } catch (AuthenticationRequiredException ex) {
            success = true;
        }
        assertTrue("Expected AuthenticationRequiredException", success);

        // Authorised
        success = false;
        session.setAuthentication(true);
        session.setUser("test");
        core.putScript("script", "content");
        assertEquals("content", repository.getScript("test", "script"));
       
        // Syntax
        success = false;
        session.setAuthentication(true);
        session.setUser("test");
        try {
            core.putScript("script", "SyntaxException");
        } catch (SyntaxException ex) {
            success = true;
        }
View Full Code Here

Examples of org.apache.james.managesieve.mock.MockSession

     * @throws StorageException
     * @throws UserNotFoundException
     */
    @Test
    public final void testRenameScript() throws ScriptNotFoundException, IsActiveException, DuplicateException, AuthenticationRequiredException, SyntaxException, QuotaExceededException, UserNotFoundException, StorageException {
        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.renameScript("oldName", "newName");
        } catch (AuthenticationRequiredException ex) {
            success = true;
        }
        assertTrue("Expected AuthenticationRequiredException", success);

        // Authorised
        success = false;
        session.setAuthentication(true);
        session.setUser("test");
        repository.putScript("test", "oldName", "content");
        core.renameScript("oldName", "newName");
        assertEquals("content", repository.getScript("test", "oldName"));
    }
View Full Code Here

Examples of org.apache.james.managesieve.mock.MockSession

     * @throws StorageException
     * @throws UserNotFoundException
     */
    @Test
    public final void testSetActive() throws ScriptNotFoundException, 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.setActive("script");
        } catch (AuthenticationRequiredException ex) {
            success = true;
        }
        assertTrue("Expected AuthenticationRequiredException", success);

        // Authorised
        success = false;
        session.setAuthentication(true);
        session.setUser("test");
        repository.putScript("test", "script", "content");
        core.setActive("script");
        assertEquals("content", repository.getActive("test"));
    }
View Full Code Here

Examples of org.apache.james.managesieve.mock.MockSession

     */
    @Test
    public final void testGetActive() throws ScriptNotFoundException,
            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.getActive();
        } catch (AuthenticationRequiredException ex) {
            success = true;
        }
        assertTrue("Expected AuthenticationRequiredException", success);

        // Authorised - non-existent script
        success = false;
        session.setAuthentication(true);
        session.setUser("test");
        try {
            core.getActive();
        } catch (ScriptNotFoundException ex) {
            success = true;
        }
        assertTrue("Expected ScriptNotFoundException", success);

        // Authorised - existent script, inactive
        session.setAuthentication(true);
        session.setUser("test");
        repository.putScript("test", "script", "content");
        try {
            core.getActive();
        } catch (ScriptNotFoundException ex) {
            success = true;
        }
        assertTrue("Expected ScriptNotFoundException", success);

        // Authorised - existent script, active
        session.setAuthentication(true);
        session.setUser("test");
        repository.setActive("test", "script");
        core.getActive();
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.