Package com.volantis.shared.net.http

Examples of com.volantis.shared.net.http.SimpleHTTPMessageEntities


    /**
     * Test that put puts a HTTPMessageEntity into the ..Entities. In
     * doing so this test also tests contains and retrieve as a side-effect.
     */
    public void testPutContainsRetreive() {
        SimpleHTTPMessageEntities entities =
                new SimpleHTTPMessageEntities();
        String headerName = "header";

        HeaderImpl header = new HeaderImpl(headerName);

        entities.put(header);

        assertTrue("The header that was put is not contained in this entities",
                entities.containsIdentity(header.getIdentity()));


        HTTPMessageEntity retrieved [] =
                entities.retrieve(header.getIdentity());

        assertEquals("There can be only one", 1, retrieved.length);

        assertEquals("The retreived HTTPMessageEntity is not equal to the" +
                " entity that was put", header, retrieved[0]);
View Full Code Here


    /**
     * Test that the put method replaces an existing entity in the entities
     * with the same name.
     */
    public void testPutDoesReplace() {
        SimpleHTTPMessageEntities entities =
                new SimpleHTTPMessageEntities();

        String headerName = "header";

        String value1 = "value1";
        String value2 = "value2";

        HeaderImpl header1 = new HeaderImpl(headerName);
        header1.setValue(value1);

        entities.put(header1);

        HTTPMessageEntity retrieved [] = entities.retrieve(header1.getIdentity());

        assertEquals(value1, retrieved[0].getValue());

        HeaderImpl header2 = new HeaderImpl(headerName);
        header2.setValue(value2);

        entities.put(header2);

        retrieved = entities.retrieve(header1.getIdentity());

        assertEquals("There can be only one", 1, retrieved.length);

        assertEquals("The previous entry should have been replaced", value2,
                retrieved[0].getValue());
View Full Code Here

     * Test array put i.e. the put that takes an array of entities to
     * put.
     */
    public void testArrayPut() throws Exception {

        SimpleHTTPMessageEntities entities =
                new SimpleHTTPMessageEntities();

        String name1 = "name1";
        String name2 = "name2";
        String name3 = "name3";

        HeaderImpl header1 = new HeaderImpl(name1);
        HeaderImpl header2 = new HeaderImpl(name1);
        HeaderImpl header3 = new HeaderImpl(name2);
        HeaderImpl header4 = new HeaderImpl(name3);

        entities.add(header1);
        header1.setValue("value1");
        entities.add(header2);
        header2.setValue("value2");
        entities.add(header3);
        entities.add(header4);

        Header headers [] = new Header[3];
        headers[0] = new HeaderImpl(name1);
        headers[1] = new HeaderImpl(name1);
        headers[2] = new HeaderImpl(name2);

        // Putting the headers array should replace header1, header2 and
        // header3 and return these three replaced entities. In addition
        // entities should consist of the three headers in the headers array
        // and header4.

        HTTPMessageEntity replaced [] = entities.put(headers);

        assertEquals("Expected 3 replaced entities", 3, replaced.length);

        assertEquals("Expected there to be 4 entities in entities", 4,
                entities.size());

        // Check the replaced entities.
        List replacedList = Arrays.asList(replaced);
        List expectedList = new ArrayList();
        expectedList.add(header1);
View Full Code Here

    /**
     * Test remove.
     */
    public void testRemove() {
        SimpleHTTPMessageEntities entities =
                new SimpleHTTPMessageEntities();

        String name1 = "name1";
        String name2 = "name2";

        HeaderImpl header1 = new HeaderImpl(name1);
        HeaderImpl header2 = new HeaderImpl(name1);
        HeaderImpl header3 = new HeaderImpl(name2);

        entities.add(header1);
        header1.setValue("value1");
        entities.add(header2);
        header2.setValue("value2");
        entities.add(header3);

        // Removing name1 headers should remove header1 and header2
        // leaving only header3.

        HTTPMessageEntity removed [] = entities.remove(header1.getIdentity());

        assertEquals("Two entities should have been removed", 2,
                removed.length);

        assertEquals("One entity should remain", 1, entities.size());

        // Use identityHashCode in case equals changes later.
        if (System.identityHashCode(removed[0]) ==
                System.identityHashCode(header1)) {
            assertEquals("Expected to find header2",
View Full Code Here

    /**
     * Test remove.
     */
    public void testRetrieve() {
        SimpleHTTPMessageEntities entities =
                new SimpleHTTPMessageEntities();

        String name1 = "name1";
        String name2 = "name2";

        HeaderImpl header1 = new HeaderImpl(name1);
        HeaderImpl header2 = new HeaderImpl(name1);
        HeaderImpl header3 = new HeaderImpl(name2);

        entities.add(header1);
        header1.setValue("value1");
        entities.add(header2);
        header2.setValue("value2");
        entities.add(header3);

        HTTPMessageEntity retrieved [] =
                entities.retrieve(header1.getIdentity());

        assertEquals("Two entities should have been retrieved", 2,
                retrieved.length);

        assertEquals("Three entities should remain", 3, entities.size());

        // Use identityHashCode in case equals changes later.
        if (System.identityHashCode(retrieved[0]) ==
                System.identityHashCode(header1)) {
            assertEquals("Expected to find header2",
View Full Code Here

    /**
     * Test contains.
     */
    public void testContainsPositive() {
        SimpleHTTPMessageEntities entities =
                new SimpleHTTPMessageEntities();

        String name1 = "name1";
        String name2 = "name2";

        HeaderImpl header1 = new HeaderImpl(name1);
        HeaderImpl header2 = new HeaderImpl(name1);
        HeaderImpl header3 = new HeaderImpl(name2);

        entities.put(header1);
        entities.put(header2);
        entities.put(header3);

        assertTrue("Expected a name1 entity to be contained in entities",
                entities.containsIdentity(header1.getIdentity()));

        assertFalse("Did not expect an entity named bibble to be contained " +
                "in entities",
                entities.containsIdentity(new HeaderImpl("bibble").getIdentity()));
    }
View Full Code Here

    /**
     * Test clear.
     */
    public void testClear() {
        SimpleHTTPMessageEntities entities =
                new SimpleHTTPMessageEntities();

        String name1 = "name1";
        String name2 = "name2";

        HeaderImpl header1 = new HeaderImpl(name1);
        header1.setValue("value1");
        HeaderImpl header2 = new HeaderImpl(name1);
        header2.setValue("value2");
        HeaderImpl header3 = new HeaderImpl(name2);

        entities.add(header1);
        entities.add(header2);
        entities.add(header3);

        assertEquals(3, entities.size());
        entities.clear();
        assertEquals(0, entities.size());
    }
View Full Code Here

     * Test add.
     * @throws java.lang.Exception
     */
    public void testAdd() throws Exception {

        SimpleHTTPMessageEntities entities =
                new SimpleHTTPMessageEntities();

        String name1 = "name1";
        String name2 = "name2";

        HeaderImpl header1 = new HeaderImpl(name1);
        header1.setValue("value1");
        HeaderImpl header2 = new HeaderImpl(name1);
        header2.setValue("value2");
        HeaderImpl header3 = new HeaderImpl(name1);
        header3.setValue("value2");
        HeaderImpl header4 = new HeaderImpl(name2);

        entities.add(header1);
        entities.add(header2);
        entities.add(header3);
        entities.add(header4);

        assertEquals(3, entities.size());


        // Check that entities is as expected.
        Collection entityCollection = (Collection)
                PrivateAccessor.getField(entities, "entities");
View Full Code Here

        // =====================================================================
        //   Create Mocks
        // =====================================================================

        WebRequestCookie cookie = new WebRequestCookie();
        HTTPMessageEntities entities = new SimpleHTTPMessageEntities();

        // =====================================================================
        //   Set Expectations
        // =====================================================================
View Full Code Here

        //   Set Expectations
        // =====================================================================

        WebRequestParameter parameter = new WebRequestParameter();
        entityFactoryMock.expects.createParameter().returns(parameter);
        HTTPMessageEntities entities = new SimpleHTTPMessageEntities();
        entityFactoryMock.expects.createHTTPMessageEntities().returns(entities);

        expectAddSimpleElementProcess(parameter);

        contextMock.expects.getProperty(WebRequestParameter.class).returns(
View Full Code Here

TOP

Related Classes of com.volantis.shared.net.http.SimpleHTTPMessageEntities

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.