コード例 #1
0
  public void testCreateAndLoadCar() throws Exception {
    Database database = _category.getDatabase();

    database.begin();
    Order order = new Order();
    order.setId(11);
    order.setName("order 11");
    database.create(order);
    database.commit();

    database.begin();
    ProductDetail detail = new ProductDetail();
    detail.setId(11);
    detail.setCategory("category 11");
    detail.setLocation("location 11");
    database.create(detail);
    database.commit();

    database.begin();
    Truck truck = new Truck();
    truck.setId(11);
    truck.setName("truck 11");
    truck.setKw(112);
    truck.setMake("Fiat");
    truck.setMaxWeight(3750);
    truck.setDetail((ProductDetail) database.load(ProductDetail.class, new Integer(11)));
    database.create(truck);
    Collection orders = new LinkedList();
    orders.add(database.load(Order.class, new Integer(11)));
    truck.setOrders(orders);
    database.commit();

    database.begin();
    Object object = database.load(Car.class, new Integer(11));
    assertNotNull(object);
    assertEquals("ctf.jdo.tc9x.Truck", object.getClass().getName());
    Truck loadedTruck = (Truck) object;
    database.commit();

    assertNotNull(loadedTruck);
    assertEquals(11, loadedTruck.getId());

    database.begin();
    database.remove(database.load(Car.class, new Integer(11)));
    database.remove(database.load(ProductDetail.class, new Integer(11)));
    database.remove(database.load(Order.class, new Integer(11)));
    database.commit();

    database.close();
  }
コード例 #2
0
  public void testCreateAndLoadComputer() throws Exception {
    Database database = _category.getDatabase();

    database.begin();
    Order order = new Order();
    order.setId(12);
    order.setName("order 12");
    database.create(order);
    database.commit();

    database.begin();
    ProductDetail detail = new ProductDetail();
    detail.setId(12);
    detail.setCategory("category 12");
    detail.setLocation("location 12");
    database.create(detail);
    database.commit();

    database.begin();
    Laptop laptop = new Laptop();
    laptop.setId(12);
    laptop.setName("laptop 12");
    laptop.setCpu("centrino");
    laptop.setResolution("1600");
    laptop.setWeight(2450);
    laptop.setDetail((ProductDetail) database.load(ProductDetail.class, new Integer(12)));
    database.create(laptop);
    Collection orders = new LinkedList();
    orders.add(database.load(Order.class, new Integer(12)));
    laptop.setOrders(orders);
    database.commit();

    database.begin();
    Computer computer = (Computer) database.load(Computer.class, new Integer(12));
    database.commit();

    assertNotNull(computer);
    assertEquals("ctf.jdo.tc9x.Laptop", computer.getClass().getName());
    assertEquals(12, computer.getId());
    assertEquals("laptop 12", computer.getName());

    database.begin();
    computer = (Computer) database.load(Computer.class, new Integer(12));
    database.remove(computer);
    database.remove(database.load(ProductDetail.class, new Integer(12)));
    database.remove(database.load(Order.class, new Integer(12)));
    database.commit();

    database.close();
  }
コード例 #3
0
ファイル: SelectorTest.java プロジェクト: nebnagrom/hornetq
  @Test
  public void testPull() throws Exception {
    ClientRequest request = new ClientRequest(generateURL("/topics/" + topicName));

    ClientResponse<?> response = request.head();
    response.releaseConnection();
    Assert.assertEquals(200, response.getStatus());
    Link consumers =
        MessageTestBase.getLinkByTitle(
            manager.getQueueManager().getLinkStrategy(), response, "pull-subscriptions");
    System.out.println("pull: " + consumers);
    response =
        consumers
            .request()
            .formParameter("autoAck", "true")
            .formParameter("selector", "MyTag = '1'")
            .post();
    response.releaseConnection();

    Link consumeOne =
        MessageTestBase.getLinkByTitle(
            manager.getQueueManager().getLinkStrategy(), response, "consume-next");
    System.out.println("consumeOne: " + consumeOne);
    response =
        consumers
            .request()
            .formParameter("autoAck", "true")
            .formParameter("selector", "MyTag = '2'")
            .post();
    response.releaseConnection();
    Link consumeTwo =
        MessageTestBase.getLinkByTitle(
            manager.getQueueManager().getLinkStrategy(), response, "consume-next");
    System.out.println("consumeTwo: " + consumeTwo);

    // test that Accept header is used to set content-type
    {
      Order order = new Order();
      order.setName("1");
      order.setAmount("$5.00");
      publish(topicName, order, null, "1");
      order.setName("2");
      publish(topicName, order, null, "2");
      order.setName("3");
      publish(topicName, order, null, "2");
      order.setName("4");
      publish(topicName, order, null, "1");
      order.setName("5");
      publish(topicName, order, null, "1");
      order.setName("6");
      publish(topicName, order, null, "1");

      {
        order.setName("1");
        consumeOne = consumeOrder(order, consumeOne);
        order.setName("2");
        consumeTwo = consumeOrder(order, consumeTwo);
        order.setName("3");
        consumeTwo = consumeOrder(order, consumeTwo);
        order.setName("4");
        consumeOne = consumeOrder(order, consumeOne);
        order.setName("5");
        consumeOne = consumeOrder(order, consumeOne);
        order.setName("6");
        consumeOne = consumeOrder(order, consumeOne);
      }
    }
  }
コード例 #4
0
ファイル: SelectorTest.java プロジェクト: nebnagrom/hornetq
  @Test
  public void testPush() throws Exception {
    server.getJaxrsServer().getDeployment().getRegistry().addPerRequestResource(PushReceiver.class);
    ClientRequest request = new ClientRequest(generateURL("/topics/" + topicName));

    ClientResponse<?> response = request.head();
    response.releaseConnection();
    Assert.assertEquals(200, response.getStatus());
    Link consumers =
        MessageTestBase.getLinkByTitle(
            manager.getQueueManager().getLinkStrategy(), response, "push-subscriptions");
    System.out.println("push: " + consumers);

    PushTopicRegistration oneReg = new PushTopicRegistration();
    oneReg.setDurable(false);
    XmlLink target = new XmlLink();
    target.setMethod("post");
    target.setHref(generateURL("/push/one"));
    target.setType("application/xml");
    oneReg.setTarget(target);
    oneReg.setSelector("MyTag = '1'");
    response = consumers.request().body("application/xml", oneReg).post();
    response.releaseConnection();
    Link oneSubscription = response.getLocation();

    PushTopicRegistration twoReg = new PushTopicRegistration();
    twoReg.setDurable(false);
    target = new XmlLink();
    target.setMethod("post");
    target.setHref(generateURL("/push/two"));
    target.setType("application/xml");
    twoReg.setTarget(target);
    twoReg.setSelector("MyTag = '2'");
    response = consumers.request().body("application/xml", twoReg).post();
    response.releaseConnection();
    Link twoSubscription = response.getLocation();

    Order order = new Order();
    order.setName("1");
    order.setAmount("$5.00");
    publish(topicName, order, null, "1");
    Thread.sleep(200);
    Assert.assertEquals(order, PushReceiver.oneOrder);

    order.setName("2");
    publish(topicName, order, null, "2");
    Thread.sleep(200);
    Assert.assertEquals(order, PushReceiver.twoOrder);

    order.setName("3");
    publish(topicName, order, null, "2");
    Thread.sleep(200);
    Assert.assertEquals(order, PushReceiver.twoOrder);

    order.setName("4");
    publish(topicName, order, null, "1");
    Thread.sleep(200);
    Assert.assertEquals(order, PushReceiver.oneOrder);

    order.setName("5");
    publish(topicName, order, null, "1");
    Thread.sleep(200);
    Assert.assertEquals(order, PushReceiver.oneOrder);

    order.setName("6");
    publish(topicName, order, null, "1");
    Thread.sleep(200);
    Assert.assertEquals(order, PushReceiver.oneOrder);

    response = oneSubscription.request().delete();
    response.releaseConnection();
    response = twoSubscription.request().delete();
    response.releaseConnection();
  }