Package org.apache.abdera.protocol.client

Examples of org.apache.abdera.protocol.client.AbderaClient


                NodeFactory.newInstance().createNode("org/apache/tuscany/sca/binding/atom/ReceiptProvider.composite",
                                                     new Contribution("provider", contribution));
            scaProviderNode.start();

            abdera = new Abdera();
            client = new AbderaClient(abdera);
            abderaParser = Abdera.getNewParser();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
View Full Code Here


        scaProviderNode = NodeFactory.newInstance().createNode("org/apache/tuscany/sca/binding/atom/Provider.composite", new Contribution("provider", contribution));
        scaProviderNode.start();

        abdera = new Abdera();
        client = new AbderaClient(abdera);
        abderaParser = Abdera.getNewParser();
    }
View Full Code Here

            scaProviderNode = NodeFactory.newInstance().createNode("org/apache/tuscany/sca/binding/atom/Provider.composite", new Contribution("provider", contribution));
            scaProviderNode.start();

            abdera = new Abdera();
            client = new AbderaClient(abdera);
            abderaParser = Abdera.getNewParser();
        } catch(Exception e) {
            e.printStackTrace();
        }
    }
View Full Code Here

  public void testJCRAdapter() throws Exception {
    Abdera abdera = new Abdera();
    Factory factory = abdera.getFactory();

    AbderaClient client = new AbderaClient(abdera);

    String base = "http://localhost:9002/";

    // Testing of entry creation
    IRI colUri = new IRI(base).resolve("feed");
    Entry entry = factory.newEntry();
    entry.setTitle("Some Entry");
    entry.setUpdated(new Date());
    entry.addAuthor("Dan Diephouse");
    entry.setId(factory.newUuidUri());
    entry.setSummary("This is my entry.");
    entry.setContent("This is my entry. It's swell.");

    RequestOptions opts = new RequestOptions();
    opts.setContentType("application/atom+xml;type=entry");
    ClientResponse res = client.post(colUri.toString(), entry, opts);
    assertEquals(201, res.getStatus());

    //prettyPrint(abdera, res.getDocument());

    IRI location = res.getLocation();
    assertEquals(base + "feed/Some_Entry", location.toString());

    // GET the entry
    res = client.get(location.toString());
    assertEquals(200, res.getStatus());

    //prettyPrint(abdera, res.getDocument());
    org.apache.abdera.model.Document<Entry> entry_doc = res.getDocument();
    Entry entry2 = entry_doc.getRoot();

    assertEquals(entry.getTitle(), entry2.getTitle());
    assertEquals(entry.getSummary(), entry2.getSummary());
    assertEquals(entry.getContent(), entry2.getContent());

    List<Person> authors = entry2.getAuthors();
    assertEquals(1, authors.size());

    entry = entry2;
    entry.setSummary("New Summary");
    entry.setContent("New Content");

    res = client.put(location.toString(), entry, opts);
    assertEquals(204, res.getStatus());

    res = client.get(colUri.toString());
    org.apache.abdera.model.Document<Feed> feed_doc = res.getDocument();
    Feed feed = feed_doc.getRoot();

    assertEquals(1, feed.getEntries().size());
    //prettyPrint(abdera, feed_doc);

    // test 404 not found
    res = client.get(location.toString() + "Invalid");
    assertEquals(404, res.getStatus());
  }
View Full Code Here

        this.server.stop();
    }

    @Test
    public void testProcessSuccessfully() throws Exception {
        AbderaClient client = new AbderaClient();
        ClientResponse response = null;
        // Test with first adapter:
        response = client.get("http://localhost:9002/search1?q=test1&c=1");
        assertEquals(200, response.getStatus());
        // Test with second adapter:
        client.get("http://localhost:9002/search2?q=test2&c=1");
        assertEquals(200, response.getStatus());
    }
View Full Code Here

        assertEquals(200, response.getStatus());
    }
   
    @Test
    public void testProcessFailsBecauseOfNoAdapterFound() throws Exception {
        AbderaClient client = new AbderaClient();
        ClientResponse response = null;
        // No adapter found for this Open Search url:
        response = client.get("http://localhost:9002/search3?q=test1&c=1");
        assertEquals(404, response.getStatus());
    }
View Full Code Here

        this.server.stop();
    }

    @Test
    public void testOpenSearchDescriptionRequestProcessorOutput() throws Exception {
        AbderaClient client = new AbderaClient();
        ClientResponse resp = client.get("http://localhost:9002/search");

        assertNotNull(resp);
        assertEquals(ResponseType.SUCCESS, resp.getType());
        assertTrue(MimeTypeHelper.isMatch(resp.getContentType().toString(), OpenSearchConstants.OPENSEARCH_DESCRIPTION_CONTENT_TYPE));
View Full Code Here

        this.server.stop();
    }
   
    @Test
    public void testOpenSearchFeedResponse() throws Exception {
        AbderaClient client = new AbderaClient();
        ClientResponse response = client.get("http://localhost:9002/search1?q=test1&c=1");
        assertEquals(200, response.getStatus());
       
        Document<Feed> feedDoc = response.getDocument();
        Feed feed = feedDoc.getRoot();
        assertEquals(TestingOpenSearchUrlAdapter.OS_FEED_ID, feed.getId().toString());
View Full Code Here

  private void runTests(String base) throws IOException {
    Abdera abdera = new Abdera();
    Factory factory = abdera.getFactory();

    AbderaClient client = new AbderaClient(abdera);

    String uri = "http://localhost:9002" + base;

    // Service document test.

    ClientResponse res = client.get(uri);
    assertNotNull(res);
    try {
      assertEquals(200, res.getStatus());
      assertEquals(ResponseType.SUCCESS, res.getType());
      assertTrue(MimeTypeHelper.isMatch(res.getContentType().toString(), Constants.APP_MEDIA_TYPE));

      Document<Service> doc = res.getDocument();
      Service service = doc.getRoot();
      assertEquals(1, service.getWorkspaces().size());

      Workspace workspace = service.getWorkspaces().get(0);
      assertEquals(1, workspace.getCollections().size());

      // Keep the loop in case we add other collections to the test.

      for (Collection collection : workspace.getCollections()) {
        if (collection.getTitle().equals("Acme Customer Database")) {
          String expected = uri + "customers";
          String actual = collection.getResolvedHref().toString();
          assertEquals(expected, actual);
        }
      }
    } finally {
      res.release();
    }

    // Testing of entry creation
    IRI colUri = new IRI(uri).resolve("customers");

    Entry entry = factory.newEntry();
    entry.setTitle("This is ignored right now");
    entry.setUpdated(new Date());
    entry.addAuthor("Acme Industries");
    entry.setId(factory.newUuidUri());
    entry.setSummary("Customer document");

    Element customerEl = factory.newElement(new QName("customer"));
    customerEl.setAttributeValue(new QName("name"), "Dan Diephouse");
    entry.setContent(customerEl);

    RequestOptions opts = new RequestOptions();
    opts.setContentType("application/atom+xml;type=entry");
    res = client.post(colUri.toString() + "?test=foo", entry, opts);
    assertEquals(201, res.getStatus());

    //prettyPrint(abdera, res.getDocument());

    IRI location = res.getLocation();
    assertEquals(uri + "customers/1001-Dan_Diephouse", location.toString());

    // GET the entry
    res = client.get(location.toString());
    assertEquals(200, res.getStatus());
    res.release();

    // prettyPrint(abdera, res.getDocument());
    org.apache.abdera.model.Document<Entry> entry_doc = res.getDocument();
    //prettyPrint(abdera, entry_doc);
    entry = entry_doc.getRoot();
    assertEquals(uri + "customers/1001-Dan_Diephouse", entry_doc.getRoot().getEditLinkResolvedHref().toString());

    // HEAD
    res = client.head(location.toString());
    assertEquals(200, res.getStatus());
    assertEquals(0, res.getContentLength());
    res.release();

    // Try invalid resources
    res = client.get(colUri + "/foobar");
    assertEquals(404, res.getStatus());
    res.release();

    res = client.head(colUri + "/foobar");
    assertEquals(404, res.getStatus());
    assertEquals(0, res.getContentLength());
    res.release();
   
    IRI badColUri = new IRI(uri).resolve("customersbad");
    // GET the service doc
    res = client.get(colUri.toString());
    assertEquals(200, res.getStatus());
    res.release();
    res = client.get(badColUri.toString());
    assertEquals(404, res.getStatus());
    res.release();
  }
View Full Code Here

//    assertEquals(resp1, "5");
  }
 
  @Test
  public void testResponseMustRevalidate() throws Exception {
    AbderaClient abderaClient = new AbderaClient();
    RequestOptions options = abderaClient.getDefaultRequestOptions();
    options.setHeader("Connection", "close");
    options.setHeader("x-reqnum", "1");
    ClientResponse response = abderaClient.get(CHECK_MUST_REVALIDATE, options);
 
    String resp1 = getResponse(response);
    assertEquals(resp1, "1");
   
    // Should be revalidated and use the cache
    options.setHeader("x-reqnum", "2");
    response = abderaClient.get(CHECK_MUST_REVALIDATE, options);
    assertTrue(response instanceof CachedResponse);
   
    String resp2 = getResponse(response);
    assertEquals(resp2, "1");
   
    // Should be revalidated and return a 404
    options.setHeader("x-reqnum", "3");
    response = abderaClient.get(CHECK_MUST_REVALIDATE, options)
    assertEquals(response.getStatus(), 404);
    response.release();

  }
View Full Code Here

TOP

Related Classes of org.apache.abdera.protocol.client.AbderaClient

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.