@Test
  public void testDelete() {
    try {
      setUpProducts();
      Product product = pdt.setUpProduct1();

      ProductXml productXml =
          new ProductXml.ProductBuilder()
              .author(product.getAuthor())
              .imageURL(product.getImageURL())
              .imageLargeURL(product.getImageLargeURL())
              .manufacturer(product.getManufacturer())
              .productIndex(product.getProductIndex())
              .productgroup(product.getProductgroup())
              .productId(product.getProductId())
              .productidtype(product.getProductidtype())
              .source(product.getSource())
              .sourceid(product.getSourceid())
              .title(product.getTitle())
              .build();

      ProductMsgXml productMsg = new ProductMsgXml(productXml);
      ProductDaoSql productDaoSql = new ProductDaoSql(productMsg);
      productMsg = (ProductMsgXml) productDaoSql.delete();
      System.out.println(productMsg.getSuccess());
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
 private void setUpProducts() {
   try {
     Product product = pdt.setUpProduct1();
     mysqlProduct.create(product);
     product = pdt.setUpProduct2();
     mysqlProduct.create(product);
     product = pdt.setUpProduct3();
     mysqlProduct.create(product);
     product = pdt.setUpProduct4();
     mysqlProduct.create(product);
     product = pdt.setUpProduct5();
     mysqlProduct.create(product);
     product = pdt.setUpProduct6();
     mysqlProduct.create(product);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Exemple #3
0
  public void createTables() throws Exception {
    System.out.println("SetUpTables createTables");
    mySqlProduct = TableFactory.getTable(TableEnum.PRODUCT);
    mySqlRegisteredUser = TableFactory.getTable(TableEnum.REGISTERED_USER);
    mySqlUserToProduct = TableFactory.getTable(TableEnum.USER_TO_PRODUCT);
    try {
      mySqlProduct.dropTable();
      mySqlRegisteredUser.dropTable();
      mySqlUserToProduct.dropTable();
    } catch (Exception e) {
      // ignore if no table found
    }
    mySqlProduct.createTable();
    mySqlRegisteredUser.createTable();
    mySqlUserToProduct.createTable();

    System.out.println("SetUpTables set up product");

    Product product = ptd.setUpProduct1();
    mySqlProduct.create(product);
    product = ptd.setUpProduct2();
    mySqlProduct.create(product);
    product = ptd.setUpProduct3();
    mySqlProduct.create(product);
    product = ptd.setUpProduct4();
    mySqlProduct.create(product);
    product = ptd.setUpProduct5();
    mySqlProduct.create(product);
    product = ptd.setUpProduct6();
    mySqlProduct.create(product);

    System.out.println("SetUpTables set up registered user");

    RegisteredUser registeredUser = rutd.setUpRegisteredUser1();
    mySqlRegisteredUser.create(registeredUser);
    registeredUser = rutd.setUpRegisteredUser2();
    mySqlRegisteredUser.create(registeredUser);
    registeredUser = rutd.setUpRegisteredUser3();
    mySqlRegisteredUser.create(registeredUser);
    registeredUser = rutd.setUpRegisteredUser4();
    mySqlRegisteredUser.create(registeredUser);
    registeredUser = rutd.setUpRegisteredUser5();
    mySqlRegisteredUser.create(registeredUser);
    registeredUser = rutd.setUpRegisteredUser6();
    mySqlRegisteredUser.create(registeredUser);
    registeredUser = rutd.setUpRegisteredUser7();
    mySqlRegisteredUser.create(registeredUser);
    registeredUser = rutd.setUpRegisteredUser8();
    mySqlRegisteredUser.create(registeredUser);
    registeredUser = rutd.setUpRegisteredUser9();
    mySqlRegisteredUser.create(registeredUser);

    System.out.println("SetUpTables set up user to product");

    UserToProduct UserToProduct = utptd.insertUserToProductTable1();
    mySqlUserToProduct.create(UserToProduct);
    UserToProduct = utptd.insertUserToProductTable2();
    mySqlUserToProduct.create(UserToProduct);
    UserToProduct = utptd.insertUserToProductTable3();
    mySqlUserToProduct.create(UserToProduct);
    UserToProduct = utptd.insertUserToProductTable4();
    mySqlUserToProduct.create(UserToProduct);
    UserToProduct = utptd.insertUserToProductTable5();
    mySqlUserToProduct.create(UserToProduct);
    UserToProduct = utptd.insertUserToProductTable6();
    mySqlUserToProduct.create(UserToProduct);
    UserToProduct = utptd.insertUserToProductTable7();
    mySqlUserToProduct.create(UserToProduct);
    UserToProduct = utptd.insertUserToProductTable8();
    mySqlUserToProduct.create(UserToProduct);
    UserToProduct = utptd.insertUserToProductTable9();
    mySqlUserToProduct.create(UserToProduct);
  }
  @Test
  public void testUpdateSourceID() {
    try {
      setUpProducts();
      Product product = pdt.setUpProduct6();
      ProductXml productXml =
          new ProductXml.ProductBuilder()
              .author("")
              .imageURL("")
              .imageLargeURL("")
              .manufacturer("")
              .productIndex("")
              .productgroup("")
              .productId(product.getProductId())
              .productidtype("")
              .source("")
              .sourceid("999999")
              .title("")
              .build();
      ProductMsgXml productMsg = new ProductMsgXml(productXml);

      ProductDaoSql productDaoSql = new ProductDaoSql(productMsg);
      productDaoSql.update();
      productXml = new ProductXml();
      productXml.setProductId("9780789799999");
      productMsg = new ProductMsgXml(productXml);
      productDaoSql = new ProductDaoSql(productMsg);
      productMsg = (ProductMsgXml) productDaoSql.read();
      System.out.println(productMsg.getSuccess());

      productXml = productMsg.getLOfProducts().get(0);

      assertEquals(
          "getProduct failed Incorrect author returned ", "Willy wonka", productXml.getAuthor());
      assertEquals(
          "getProduct failed Incorrect image URL returned ",
          "http://ecx.images-amazon.com/images/I/51TW6S55A4L._SL75_.jpg",
          productXml.getImageURL());
      assertEquals(
          "getProduct failed Incorrect image large URL returned ",
          "http://ecx.images-amazon.com/images/I/51TW6S55A4L._SL75_.jpg",
          productXml.getImageLargeURL());
      assertEquals(
          "getProduct failed Incorrect manufacturer returned ",
          "QUE",
          productXml.getManufacturer());
      assertEquals(
          "getProduct failed Incorrect product index returned ", "0", productXml.getProductIndex());
      assertEquals(
          "getProduct failed Incorrect product group returned ",
          "DVD",
          productXml.getProductgroup());
      assertEquals(
          "getProduct failed Incorrect product id returned ",
          "9780789799999",
          productXml.getProductId());
      assertEquals(
          "getProduct failed Incorrect id product type returned ",
          "EAN",
          productXml.getProductidtype());
      assertEquals(
          "getProduct failed Incorrect source returned ", "Amazon", productXml.getSource());
      assertEquals(
          "actualProduct failed Incorrect source id returned ", "999999", productXml.getSourceid());
      assertEquals(
          "getProduct failed Incorrect title returned ",
          "The Choocolate Factory",
          productXml.getTitle());
      assertTrue("getProduct failed crDate is null", null != productXml.getCrDate());
      assertTrue("getProduct failed updDate is null", null != productXml.getUpdDate());
    } catch (Exception e) {
      e.printStackTrace();
    }
  }