Exemplo n.º 1
0
 /**
  * Instantiates a new razor server, its services, and starts the scheduler. This can be replaced
  * by a dynamic handler manager but has the benefit of simplicity.
  */
 public RazorServer() {
   super();
   SERVICES.put(Service.ACCOUNT, AccountService.getInstance());
   SERVICES.put(Service.ALERT, AlertService.getInstance());
   SERVICES.put(Service.ASSET, AssetService.getInstance());
   SERVICES.put(Service.ATTRIBUTE, AttributeService.getInstance());
   SERVICES.put(Service.AUDIT, AuditService.getInstance());
   SERVICES.put(Service.CONTRACT, ContractService.getInstance());
   SERVICES.put(Service.FINANCE, FinanceService.getInstance());
   SERVICES.put(Service.JOURNAL, JournalService.getInstance());
   SERVICES.put(Service.IMAGE, ImageService.getInstance());
   SERVICES.put(Service.IMAGETEXT, ImageTextService.getInstance());
   SERVICES.put(Service.LICENSE, LicenseService.getInstance());
   SERVICES.put(Service.LOCATION, LocationService.getInstance());
   SERVICES.put(Service.MAIL, MailService.getInstance());
   SERVICES.put(Service.MONITOR, MonitorService.getInstance());
   SERVICES.put(Service.PARTNER, PartnerService.getInstance());
   SERVICES.put(Service.PARTY, PartyService.getInstance());
   SERVICES.put(Service.PRICE, PriceService.getInstance());
   SERVICES.put(Service.PRODUCT, ProductService.getInstance());
   SERVICES.put(Service.RATE, RateService.getInstance());
   SERVICES.put(Service.REPORT, ReportService.getInstance());
   SERVICES.put(Service.RESERVATION, ReservationService.getInstance());
   SERVICES.put(Service.SESSION, SessionService.getInstance());
   SERVICES.put(Service.SMS, SmsService.getInstance());
   SERVICES.put(Service.TASK, TaskService.getInstance());
   SERVICES.put(Service.TAX, TaxService.getInstance());
   SERVICES.put(Service.TEXT, TextService.getInstance());
   SERVICES.put(Service.WORKFLOW, WorkflowService.getInstance());
   //		startScheduler();
   //		PartnerService.startSchedulers();
 }
Exemplo n.º 2
0
 @Before
 public void setupMock() {
   productService = new ProductService();
   product = mock(Product.class);
   productDao = mock(ProductDao.class);
   productService.setProductDao(productDao);
 }
  private synchronized void addToBook(BookSide side, Tradable trd) throws Exception {
    if (ProductService.getInstance().getMarketState().equals(MarketState.PREOPEN)) {
      switch (side) {
        case BUY:
          buySide.addToBook(trd);
          break;
        case SELL:
          sellSide.addToBook(trd);
          break;
      }
    } else {
      HashMap<String, FillMessage> allFills = null;

      switch (side) {
        case BUY:
          allFills = sellSide.tryTrade(trd);
          break;
        case SELL:
          allFills = buySide.tryTrade(trd);
          break;
      }

      if (allFills != null && !allFills.isEmpty()) {
        this.updateCurrentMarket();
        int difference = trd.getOriginalVolume() - trd.getRemainingVolume();
        Price lastSalePrice = this.determineLastSalePrice(allFills);
        LastSalePublisher.getInstance()
            .publishLastSale(this.productSymbol, lastSalePrice, difference);
      }

      if (trd.getRemainingVolume() > 0) {
        if (trd.getPrice().isMarket()) {
          CancelMessage cm =
              new CancelMessage(
                  trd.getUser(),
                  trd.getProduct(),
                  trd.getPrice(),
                  trd.getRemainingVolume(),
                  "Cancelled",
                  trd.getSide(),
                  trd.getId());

          MessagePublisher.getInstance().publishCancel(cm);
        } else {
          switch (side) {
            case BUY:
              buySide.addToBook(trd);
              break;
            case SELL:
              sellSide.addToBook(trd);
              break;
          }
        }
      }
    }
  }
 public void testGetCategoriesByProduct() {
   int count =
       jdbcTemplate.queryForInt(
           "select count(0) from product_category " + "where product_id=1000");
   Product product = productSevice.getProductById(1000);
   List categories = (List) categoryService.getCategoriesByProduct(product);
   assertEquals("Product should belong to one category", count, categories.size());
   assertEquals(
       "Category name does not match", "Adventure", ((Category) categories.get(0)).getName());
 }
  @Test
  public void testAddingProductsToCart() throws Exception {

    Customer customer = customerService.createCustomer("A", "Customer");

    Purchase purchase = customerOrderService.createPurchase(customer.getId());

    Product product1 =
        productService.createProduct("Widget1", "a widget that slices (but not dices)", 12.0);
    Product product2 =
        productService.createProduct("Widget2", "a widget that dices (but not slices)", 7.5);

    LineItem one = customerOrderService.addProductToPurchase(purchase.getId(), product1.getId());
    LineItem two = customerOrderService.addProductToPurchase(purchase.getId(), product2.getId());

    purchase = customerOrderService.getPurchaseById(purchase.getId());
    assertTrue(purchase.getTotal() == (product1.getPrice() + product2.getPrice()));

    assertEquals(one.getPurchase().getId(), purchase.getId());
    assertEquals(two.getPurchase().getId(), purchase.getId());

    // this part requires XA to work correctly
    customerOrderService.checkout(purchase.getId());
  }
  public void testAddProductCategory() {
    Category category = categoryService.getCategoryById(2);
    //    int count = category.getProductCategories().size();
    int count =
        jdbcTemplate.queryForInt("select count(0) from product_category where category_id=2");
    Product product = productSevice.getProductById(1005);
    ProductCategory productCategory = new ProductCategory(category, product);
    categoryService.saveProductCategory(productCategory);
    category.getProductCategories().add(productCategory);
    Category cat = categoryService.saveCategory(category);
    category = categoryService.getCategoryById(cat.getCategoryId());

    assertEquals(
        "The new product category mapping was not added",
        count + 1,
        category.getProductCategories().size());
  }
Exemplo n.º 7
0
 @Test
 public void testBuy() throws InsufficientProductsException {
   int availableQuantity = 30;
   System.out.println("Stubbing getAvailableProducts(product) to return " + availableQuantity);
   when(productDao.getAvailableProducts(product)).thenReturn(availableQuantity);
   System.out.println("Calling ProductService.buy(product," + purchaseQuantity + ")");
   productService.buy(product, purchaseQuantity);
   System.out.println("Verifying ProductDao(product, " + purchaseQuantity + ") is called");
   verify(productDao).orderProduct(product, purchaseQuantity);
   System.out.println("Verifying getAvailableProducts(product) is called at least once");
   verify(productDao, atLeastOnce()).getAvailableProducts(product);
   System.out.println(
       "Verifying order of method calls on ProductDao: First call getAvailableProducts() followed by orderProduct()");
   InOrder order = inOrder(productDao);
   order.verify(productDao).getAvailableProducts(product);
   order.verify(productDao).orderProduct(product, purchaseQuantity);
 }
Exemplo n.º 8
0
  @Test
  public void testAddTrialEnvironment() throws Exception {
    loginTestUser();
    List<TrialEnvironment> environments = trialService.getEnvironments(1L);
    int enviroSize = environments.size();

    User user = new User();
    user.setUsername("*****@*****.**");
    user.setFirstName("Test");
    user.setLastName("Test");
    user.setCreatedAt(new Date());
    user.getRoles().add(Role.ROLE_EXTERNAL);
    user.setPassword(securityService.encodePassword("test", user.getCreatedAt()));
    userDao.save(user);

    Product product = new Product();
    product.setShortName("Test");
    product.setName("Test Long");

    productService.addProduct(product);

    ProductVersion productVersion = new ProductVersion();
    productVersion.setName("Test-version");
    productVersion.setCreatedAt(new Date());
    productVersion.setProduct(product);
    productVersion.setIeOnly(true);
    productVersionDao.save(productVersion);
    product.getProductVersions().add(productVersion);
    productDao.save(product);

    emService.flush();

    TrialDto trial = new TrialDto();
    trial.setProductId(product.getId());
    trial.setProductVersionId(productVersion.getId());
    trial.setUserId(user.getId());
    trial.setUrl("http://test/hahahaha");
    trial.setUsername("test");
    trial.setPassword("haha");
    trialService.createTrialEnvironment(trial);
    emService.flush();

    environments = trialService.getEnvironments(product.getId());
    assertEquals(enviroSize + 1, environments.size());
  }
Exemplo n.º 9
0
 @Test(expected = InsufficientProductsException.class)
 public void purchaseWithInsufficientAvailableQuantity() throws InsufficientProductsException {
   int availableQuantity = 3;
   System.out.println("Stubbing getAvailableProducts(product) to return " + availableQuantity);
   when(productDao.getAvailableProducts(product)).thenReturn(availableQuantity);
   try {
     System.out.println(
         "productService.buy(product"
             + purchaseQuantity
             + ") should throw InsufficientProductsException");
     productService.buy(product, purchaseQuantity);
   } catch (InsufficientProductsException e) {
     System.out.println("InsufficientProductsException has been thrown");
     verify(productDao, times(0)).orderProduct(product, purchaseQuantity);
     System.out.println("Verified orderProduct(product, " + purchaseQuantity + ") is not called");
     throw e;
   }
 }
Exemplo n.º 10
0
  /** 插入某订单的退货仓库费 */
  public void insertStoreMoney(int orderId) {
    Order order = orderService.getOrderById(orderId);
    FinanceUnit unit = new FinanceUnit(order);
    unit.setFinanceType(FinanceType.Store);
    float money = 0f;

    List<OrderItem> orderItems = order.getOrderItems();
    for (OrderItem orderItem : orderItems) {
      int productId = orderItem.getProductId();
      Product product = productService.getSimpleProductById(productId);
      String size = product.getSizeWithPackage();
      float moneyTmp = computeStoreFee(size);
      money += (moneyTmp * orderItem.getNum());
    }
    int coinage = order.getCoinage();
    money = Coinage.convertToAimCoinage(coinage, money, Coinage.Dollar);
    unit.setMoney(money);
    unit.setSender(UserType.SELLER + "-" + order.getSellerId());
    unit.setReceiver(UserType.ADMIN);
    insert(unit);
  }
Exemplo n.º 11
0
  public void testGetAwardCategoryForProduct() {
    Product product = productSevice.getProductById(1005);
    Collection awardCategories = categoryService.getAwardCategoriesForProduct(product);

    assertEquals("List should be empty", 0, awardCategories.size());
  }
Exemplo n.º 12
0
 public List<Product> listProducts() {
   return productService.listAll();
 }