Package pygmy.nntp

Examples of pygmy.nntp.NntpRequest


        buffer.append( "." );
        buffer.append( Http.CRLF );
        buffer.append("ihave <blkdu9$pd8$1@hood.uits.indiana.edu>");
        buffer.append(Http.CRLF);

        NntpRequest request = new NntpRequest( null, new Properties(), new ByteArrayInputStream( buffer.toString().getBytes() ) );
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        NntpResponse response = new NntpResponse( baos );
        forum.createNewsgroup("comp.lang.java.programmer");

        request.nextCommand();
        NewsHandler handler = new NewsHandler( forum );
        assertTrue( "Assert that the handler handled the request.", handler.handleNntp( request, response ) );
//        System.out.println( baos.toString() );
        assertTrue( "Assert the response asked to send the article", baos.toString().startsWith("335 send article to be transferred.  End with <CR-LF>.<CR-LF>") );
        assertEquals( "Assert the forum size has increased by one.", 1, forum.getNewsgroup( "comp.lang.java.programmer" ).size() );
        assertTrue( "Assert the response received the article.", baos.toString().indexOf( "235 article transferred ok" ) >= 0 );

        request.nextCommand();
        baos.reset();
        assertTrue( "Assert that the handler handled the request.", handler.handleNntp( request, response ) );
        assertTrue( "Assert the response denied the article", baos.toString().startsWith("435 article not wanted - do not send i") );

        forum.addArticle( NntpTestUtil.createArticle("test.eml"), "localhost" );
View Full Code Here


        buffer.append( Http.CRLF );
        buffer.append("article <foo>");
        buffer.append( Http.CRLF );
        buffer.append("foo bar baz");
        buffer.append( Http.CRLF );
        NntpRequest request = createNntpRequest(buffer);
        request.nextCommand();
        assertEquals( "list", request.getCommand() );
        assertEquals( 0, request.parameterLength() );
        assertNull( request.getParameter(0) );

        request.nextCommand();
        assertEquals( "article", request.getCommand() );
        assertEquals( 1, request.parameterLength() );
        assertEquals( "<foo>", request.getParameter(0) );

        request.nextCommand();
        assertEquals( "foo", request.getCommand() );
        assertEquals( 2, request.parameterLength() );
        assertEquals( "bar", request.getParameter(0) );
        assertEquals( "baz", request.getParameter(1) );
    }
View Full Code Here

    public void testIsDone() throws IOException {
        StringBuffer buffer = new StringBuffer();
        buffer.append("quit");
        buffer.append( Http.CRLF );
        NntpRequest request = createNntpRequest(buffer);
        request.nextCommand();
        assertEquals( "quit", request.getCommand() );
        assertTrue( request.isDone() );
    }
View Full Code Here

    public void testGetCurrentNewsgroup() throws IOException, NoCurrentNewsgroupException, NoCurrentArticleException {
        StringBuffer buffer = new StringBuffer();
        buffer.append("list");
        buffer.append( Http.CRLF );
        NntpRequest request = createNntpRequest(buffer);

        try {
            request.getCurrentNewsgroup();
            fail("Assert NntpRequest throws an exception when there is no current group.");
        } catch( NoCurrentNewsgroupException e ) {
            assertTrue( true );
        }

        try {
            request.getCurrentArticle();
            fail("Assert NntpRequest throws an exception when there is no current article.");
        } catch (NoCurrentArticleException e) {
            assertTrue(true);
        }

        String newsgroup = "comp.lang.java";
        request.setCurrentNewsgroup(newsgroup);
        assertEquals( "Assert current news group is " + newsgroup, newsgroup, request.getCurrentNewsgroup() );

        String articlePointer = "1";
        request.setCurrentArticle(articlePointer);
        assertEquals( "Assert current article pointer is " + articlePointer, articlePointer, request.getCurrentArticle() );
    }
View Full Code Here

        assertEquals( "Assert current article pointer is " + articlePointer, articlePointer, request.getCurrentArticle() );
    }

    private NntpRequest createNntpRequest(StringBuffer buffer) throws IOException {
        ByteArrayInputStream bais = new ByteArrayInputStream( buffer.toString().getBytes() );
        NntpRequest request = new NntpRequest( null, new Properties(), bais );
        return request;
    }
View Full Code Here

        buffer.append(Http.CRLF);
        buffer.append("group comp.lang.java");
        buffer.append(Http.CRLF);
        buffer.append("group foo.bar.baz");
        buffer.append(Http.CRLF);
        NntpRequest request = new NntpRequest( null, new Properties(), new ByteArrayInputStream( buffer.toString().getBytes() ) );
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        NntpResponse response = new NntpResponse( baos );

        request.nextCommand();
        GroupHandler handler = new GroupHandler( forum );
        assertTrue( "Assert that the handler handled the request.", handler.handleNntp( request, response ) );
        assertTrue( baos.toString().indexOf("215 list of newsgroups follows" + Http.CRLF + ".") >= 0 );

        forum.createNewsgroup("comp.lang.java");
        forum.createNewsgroup("comp.lang.ada").addArticle( NntpTestUtil.createArticle("test.eml"), "localhost" );
        forum.createNewsgroup("rec.music.makers").addArticle( NntpTestUtil.createArticle("test.eml"), "localhost" );
        request.nextCommand();
        assertTrue( "Assert that the handler handled the request.", handler.handleNntp( request, response ) );
        assertTrue( baos.toString().indexOf("215 list of newsgroups follows") >= 0 );

        baos.reset();
        request.nextCommand();
        assertTrue( "Assert that the handler handled the request.", handler.handleNntp( request, response ) );
        assertTrue( baos.toString().indexOf("211 0 2147483647 0 comp.lang.java") >= 0 );

        baos.reset();
        request.nextCommand();
        assertTrue( "Assert that the handler handled the request.", handler.handleNntp( request, response ) );
        assertTrue( baos.toString().indexOf("411 no such news group") >= 0 );
    }
View Full Code Here

TOP

Related Classes of pygmy.nntp.NntpRequest

Copyright © 2018 www.massapicom. 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.