Examples of ShoppingCart


Examples of org.jboss.as.quickstarts.sfsb.ShoppingCart

        final String viewClassName = ShoppingCart.class.getName();

        /* Lookup the remote interface of the shopping cart */
        String lookupName = "ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName
                + "?stateful";
        final ShoppingCart cart = (ShoppingCart) context.lookup(lookupName);

        System.out.println("\n&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&");
        System.out.println("Obtained the remote interface to the shopping cart");

        /* invoke on the remote interface */
        System.out.println("Buying a \"" + EAP + "\"");
        cart.buy(EAP, 1);
        System.out.println("Buying another \"" + EAP + "\"");
        cart.buy(EAP, 1);

        System.out.println("Buying a \"" + SOAP + "\"");
        cart.buy(SOAP, 1);

        System.out.println("\nPrint cart:");
        HashMap<String, Integer> cartContents = cart.getCartContents();
        for (String product : cartContents.keySet()) {
            System.out.println(cartContents.get(product) + "     " + product);
        }

        System.out.println("\nCheckout");
        cart.checkout();

        /* Try to access the cart after checkout */
        try {
            cart.getCartContents();
            System.err.println("ERROR: The cart should not be available after Checkout!");
        } catch (NoSuchEJBException e) {
            System.out.println("Cart was correctly removed, as expected, after Checkout and is no longer available!");
        }
        System.out.println("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\n");
View Full Code Here

Examples of org.jboss.mobicents.seam.ShoppingCart

                invokeAction("#{search.addToCart}");
            }
           
            @Override
            protected void renderResponse() throws Exception {
                ShoppingCart cart = (ShoppingCart) getValue("#{cart}");
                assert cart != null;
                assert cart.getCart().size() == 1;
            }
        }.run();
       
        new FacesRequest("/dvd.xhtml", id) {
            @Override
            protected void beforeRequest() {
                setParameter("id", "42");
            }         
        }.run();
       
        new FacesRequest("/dvd.xhtml", id) {
            @Override
            protected void invokeApplication() throws Exception {
                invokeAction("#{search.addToCart}");
            }
           
            @Override
            protected void renderResponse() throws Exception {
                ShoppingCart cart = (ShoppingCart) getValue("#{cart}");
                assert cart != null;
                assert cart.getCart().size() == 2;
            }
        }.run();
       
        new FacesRequest("/dvd.xhtml", id) {
            @Override
            protected void beforeRequest() {
                setParameter("id", "41");
            }        
        }.run();
       
        new FacesRequest("/dvd.xhtml", id) {
            @Override
            protected void invokeApplication() throws Exception {
                invokeAction("#{search.addToCart}");
            }
           
            @Override
            protected void renderResponse() throws Exception {
                ShoppingCart cart = (ShoppingCart) getValue("#{cart}");
                assert cart != null;
                assert cart.getCart().size() == 2;
            }
        }.run();
       
       
        new FacesRequest("/dvd.xhtml", id) {
            @Override
            protected void beforeRequest() {
                setParameter("id", "43");
            }          
        }.run();
       
        new FacesRequest("/dvd.xhtml", id) {
            @Override
            protected void invokeApplication() throws Exception {
                invokeAction("#{search.addToCart}");
            }
           
            @Override
            protected void renderResponse() throws Exception {
                ShoppingCart cart = (ShoppingCart) getValue("#{cart}");
                assert cart != null;
                assert cart.getCart().size() == 3;
            }
        }.run();
       
    }
View Full Code Here

Examples of org.jboss.test.cluster.ejb3.stateful.nested.base.xpc.ShoppingCart

   }

   public void testBasic() throws Exception
   {
      BeanSet beanSet = getBeanSet();
      ShoppingCart cart = beanSet.cart;
      NestedXPCMonitor monitor = beanSet.monitor;
     
      Customer customer;

      long id = cart.createCustomer();   
      customer = monitor.find(id);
      Assert.assertEquals("Stateless has proper initial name",
                          "William", customer.getName());
      customer = cart.find(id);
      Assert.assertEquals("ShoppingCart has proper initial name",
                          "William", customer.getName());
     
      cart.update();
      customer = monitor.find(id);
      Assert.assertEquals("Stateless has proper updated name",
                           "Bill", customer.getName());
      customer = cart.find(id);
      Assert.assertEquals("ShoppingCart has proper updated name",
                          "Bill", customer.getName());
     
      cart.update2();
      customer = monitor.find(id);
      Assert.assertEquals("Stateless has proper update2() name",
                          "Billy", customer.getName());
      customer = cart.find(id);
      Assert.assertEquals("ShoppingCart has proper update2() name",
                          "Billy", customer.getName());
     
      cart.update3();
      customer = monitor.find(id);
      Assert.assertEquals("Stateless has proper update3() name",
                          "Bill Jr.", customer.getName());
      customer = cart.find(id);
      Assert.assertEquals("ShoppingCart has proper update3() name",
                          "Bill Jr.", customer.getName());
     
      removeBean(cart);
      removeBean(monitor);
View Full Code Here

Examples of org.jboss.test.cluster.ejb3.stateful.nested.base.xpc.ShoppingCart

   {
      getLog().debug("Running testXPCSharing()");
      getLog().debug("==================================");
     
      BeanSet beanSet = getBeanSet();
      ShoppingCart parent = beanSet.cart;
      NestedXPCMonitor monitor = beanSet.monitor;
     
      // Confirm the nested beans are there
      String deepId = monitor.getDeepNestedId();
      Assert.assertNotNull("Got a deepId", deepId);
      Assert.assertFalse("Got a non-ERROR deepId", "ERROR".equals(deepId));
      String localDeepId = monitor.getLocalDeepNestedId();
      Assert.assertNotNull("Got a localDeepId", localDeepId);
      Assert.assertFalse("Got a non-ERROR localDeepId", "ERROR".equals(localDeepId));
     
      long id = parent.createCustomer()
      Customer customer = parent.find(id);
      Assert.assertNotNull("Customer created and found on parent", customer);
     
      parent.setContainedCustomer();
      Assert.assertTrue("Parent and local contained share customer", parent.checkContainedCustomer());
     
      Assert.assertTrue("Parent and remote nested do not share ref",
                        monitor.compareTopToNested(id));
      Assert.assertTrue("Parent and local nested do share ref",
                         monitor.compareTopToLocalNested(id));
      Assert.assertTrue("Remote nested and local nested do not share a ref",
                        monitor.compareNestedToLocalNested(id));
      Assert.assertTrue("Remote nested and deepNested share a ref",
                        monitor.compareNestedToDeepNested(id));
      Assert.assertTrue("Local nested and localDeepNested share a ref",
                        monitor.compareLocalNestedToLocalDeepNested(id));
     
      // Confirm this survives passivation/activation
     
      parent.reset();
     
      sleep(getSleepTime());
     
      // DeepContained beans ignore replication in their
      // activation/passivation counters, so we can test them
View Full Code Here

Examples of org.jboss.test.cluster.ejb3.stateful.nested.base.xpc.ShoppingCart

   {
      getLog().debug("Running testDependentLifecycle()");
      getLog().debug("==================================");
     
      BeanSet beanSet = getBeanSet();
      ShoppingCart parent = beanSet.cart;
      NestedXPCMonitor monitor = beanSet.monitor;
     
      // Confirm the nested beans are there
      String deepId = monitor.getDeepNestedId();
      Assert.assertNotNull("Got a deepId", deepId);
      Assert.assertFalse("Got a non-ERROR deepId", "ERROR".equals(deepId));
      String localDeepId = monitor.getLocalDeepNestedId();
      Assert.assertNotNull("Got a localDeepId", localDeepId);
      Assert.assertFalse("Got a non-ERROR localDeepId", "ERROR".equals(localDeepId));
     
      long id = parent.createCustomer()
      Customer customer = parent.find(id);
      Assert.assertNotNull("Customer created and found on parent", customer);
     
      Assert.assertTrue("Parent and remote nested do not share ref",
                        monitor.compareTopToNested(id));
      Assert.assertTrue("Parent and local nested do share ref",
View Full Code Here

Examples of org.jboss.test.cluster.ejb3.stateful.nested.base.xpc.ShoppingCart

   }

   public void testPassivation() throws Exception
   {
      BeanSet beanSet = getBeanSet();
      ShoppingCart cart = beanSet.cart;
      NestedXPCMonitor monitor = beanSet.monitor;
     
      Customer customer;
     
      long id = cart.createCustomer();     
      customer = monitor.find(id);
      Assert.assertEquals("Stateless has proper initial name",
                          "William", customer.getName());
      customer = cart.find(id);
      Assert.assertEquals("ShoppingCart has proper initial name",
                          "William", customer.getName());
     
      cart.update();
      customer = monitor.find(id);
      Assert.assertEquals("Stateless has proper updated name",
                           "Bill", customer.getName());
      customer = cart.find(id);
      Assert.assertEquals("ShoppingCart has proper updated name",
                          "Bill", customer.getName());
     
      cart.update2();
      customer = monitor.find(id);
      Assert.assertEquals("Stateless has proper update2() name",
                          "Billy", customer.getName());
      customer = cart.find(id);
      Assert.assertEquals("ShoppingCart has proper update2() name",
                          "Billy", customer.getName());
     
      cart.update3();
      customer = monitor.find(id);
      Assert.assertEquals("Stateless has proper update3() name",
                          "Bill Jr.", customer.getName());
      customer = cart.find(id);
      Assert.assertEquals("ShoppingCart has proper update3() name",
                          "Bill Jr.", customer.getName());
     
      // Tell the contained bean to get the customer
      cart.setContainedCustomer();
     
      // Clear the passivation counts
      cart.reset();
     
      sleep(getSleepTime()); // passivation  
     
      Assert.assertEquals("Contained bean was passivated", 1, monitor.getLocalNestedPassivations());
     
      Assert.assertTrue("Parent and local contained share customer", cart.checkContainedCustomer());
     
      Assert.assertTrue("Contained bean was activated", monitor.getLocalNestedActivations() > 0)
     
      cart.findAndUpdateStateless();
      cart.updateContained();
     
      customer = monitor.find(id);
      Assert.assertEquals("contained modified", customer.getName());
      customer = cart.find(id);
      Assert.assertEquals("contained modified", customer.getName());
         
      removeBean(monitor);
      removeBean(cart);
   }
View Full Code Here

Examples of org.jboss.test.cluster.ejb3.stateful.nested.base.xpc.ShoppingCart

      // we can keep creating SFSBs until we get one we want
      NestedXPCMonitor monitor = (NestedXPCMonitor) getInitialContext().lookup("NestedXPCMonitorBean/remote");
      VMID statelessVM = monitor.getVMID();
      addRemovable(monitor);

      ShoppingCart cart = null;     
      boolean vmMatch = false;
      for (int i = 0; i < 10 && !vmMatch; i++)
      {
         cart = (ShoppingCart) getInitialContext().lookup("testShoppingCart/remote");
        
         vmMatch = statelessVM.equals(cart.getVMID());
         addRemovable(cart);
         if (!vmMatch)
            removeBean(cart);
      }
     
      Assert.assertTrue("Monitor and SFSB in same VM", vmMatch);
     
      // Reset the parent to initialize all the beans
      cart.reset();
     
      // Monitor the parent
      monitor.monitor(cart);
     
      // Reset the parent to clean things up
      cart.reset();
     
      BeanSet result = new BeanSet();
      result.cart = cart;
      result.monitor = monitor;
     
View Full Code Here

Examples of org.jboss.test.cluster.ejb3.stateful.nested.base.xpc.ShoppingCart

  
   private void failoverTest(boolean passivate, boolean passivateAgain, boolean repeated)
   throws Exception
   {
      BeanSet beanSet = runner.getBeanSet();
      ShoppingCart parent = beanSet.cart;
      NestedXPCMonitor monitor = beanSet.monitor;
     
      // Confirm the nested beans are there
      String deepId = monitor.getDeepNestedId();
      Assert.assertNotNull("Got a deepId", deepId);
      Assert.assertFalse("Got a non-ERROR deepId", "ERROR".equals(deepId));
      String localDeepId = monitor.getLocalDeepNestedId();
      Assert.assertNotNull("Got a localDeepId", localDeepId);
      Assert.assertFalse("Got a non-ERROR localDeepId", "ERROR".equals(localDeepId));
     
      VMID origId = parent.getVMID();
      Assert.assertNotNull("Got a VMID", origId);
     
      long id = parent.createCustomer()
      Customer customer = parent.find(id);
      Assert.assertNotNull("Customer created and found on parent", customer);
     
      parent.setContainedCustomer();
      Assert.assertTrue("Parent and contained share customer", parent.checkContainedCustomer());
     
      Assert.assertTrue("Parent and remote nested do not share ref",
                        monitor.compareTopToNested(id));
      Assert.assertTrue("Parent and local nested do share ref",
                         monitor.compareTopToLocalNested(id));
      Assert.assertTrue("Remote nested and local nested do not share a ref",
                        monitor.compareNestedToLocalNested(id));
      Assert.assertTrue("Remote nested and deepNested share a ref",
                        monitor.compareNestedToDeepNested(id));
      Assert.assertTrue("Local nested and localDeepNested share a ref",
                        monitor.compareLocalNestedToLocalDeepNested(id));
     
      VMID newId = parent.getVMID();
      Assert.assertTrue("VMID remained the same", origId.equals(newId));
     
      if (passivate)
      {
         runner.sleep();
      }
     
      parent.setUpFailover("once");
     
      newId = parent.getVMID();
      assertNotNull("Got a new VMID", newId);
      assertFalse("Failover has occurred", origId.equals(newId));
     
      InitialContext[] ctxs = new InitialContext[2];
      ctxs[0] = getInitialContext(1);
      ctxs[1] = getInitialContext(0);
      monitor = runner.getXPCMonitor(ctxs, newId);     
     
      monitor.monitor(parent);
     
      Assert.assertTrue("Parent and remote nested do not share ref",
                        monitor.compareTopToNested(id));
      Assert.assertTrue("Parent and local nested do share ref",
                         monitor.compareTopToLocalNested(id));
      Assert.assertTrue("Remote nested and local nested do not share a ref",
                        monitor.compareNestedToLocalNested(id));
      Assert.assertTrue("Remote nested and deepNested share a ref",
                        monitor.compareNestedToDeepNested(id));
      Assert.assertTrue("Local nested and localDeepNested share a ref",
                        monitor.compareLocalNestedToLocalDeepNested(id));
     
      if (repeated)
      {
         if (passivateAgain)
         {
            runner.sleep();
         }
         origId = newId;
        
         parent.setUpFailover("once");
        
         newId = parent.getVMID();
         assertNotNull("Got a new VMID", newId);
         assertFalse("Failover has occurred", origId.equals(newId));
        
         // Swap the contexts so we try node0 first
         InitialContext ctx = ctxs[1];
View Full Code Here

Examples of org.jboss.tutorial.entity.bean.ShoppingCart

public class Client
{
   public static void main(String[] args) throws Exception
   {
      InitialContext ctx = new InitialContext();
      ShoppingCart cart = (ShoppingCart) ctx.lookup("ShoppingCartBean/remote");

      System.out.println("Buying 2 memory sticks");
      cart.buy("Memory stick", 2, 500.00);
      System.out.println("Buying a laptop");
      cart.buy("Laptop", 1, 2000.00);

      System.out.println("Print cart:");
      Order order = cart.getOrder();
      System.out.println("Total: $" + order.getTotal());
      for (LineItem item : order.getLineItems())
      {
         System.out.println(item.getQuantity() + "     " + item.getProduct() + "     " + item.getSubtotal());
      }

      System.out.println("Checkout");
      cart.checkout();

   }
View Full Code Here

Examples of org.jboss.tutorial.extended.bean.ShoppingCart

      return new InitialContext();
   }

   public static void testLongLivedSession() throws Exception
   {
      ShoppingCart test = (ShoppingCart) getInitialContext().lookup("ShoppingCartBean/remote");
      StatelessRemote remote = (StatelessRemote) getInitialContext().lookup("StatelessSessionBean/remote");
      Customer c;

      long id = test.createCustomer();
      c = remote.find(id);
      System.out.println("Created customer: " + c.getName());

      test.update();
      c = remote.find(id);
      System.out.println("ShoppingCartBean.customer should stay managed because we're in an extended PC: Customer.getName() == " + c.getName());

      test.update3();
      c = remote.find(id);
      System.out.println("Extended persistence contexts are propagated to nested EJB calls: Customer.getName() == " + c.getName());
      test.checkout();
   }
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.