Search in sources :

Example 31 with SmartCode

use of BasicCommonClasses.SmartCode in project SmartCity-Market by TechnionYP5777.

the class ProductPackageTest method ProductPackageTestMethod.

@Test
public void ProductPackageTestMethod() {
    LocalDate ld = LocalDate.of(2016, 12, 11);
    SmartCode sc = new SmartCode(123, ld);
    Location lo = new Location(1, 1, PlaceInMarket.WAREHOUSE);
    ProductPackage pp = new ProductPackage(sc, 2, lo);
    if (!sc.equals(pp.getSmartCode()) || pp.getAmount() != 2 || !lo.equals(pp.getLocation()))
        fail();
    sc.setBarcode(111);
    lo.setX(2);
    pp.setSmartCode(sc);
    pp.setAmount(1);
    pp.setLocation(lo);
    if (!sc.equals(pp.getSmartCode()) || pp.getAmount() != 1 || !lo.equals(pp.getLocation()))
        fail();
    LocalDate ld2 = LocalDate.of(2015, 12, 12);
    SmartCode sc2 = new SmartCode(111, ld2);
    ProductPackage pp2 = new ProductPackage(sc2, 1, lo);
    if (pp2.equals(pp))
        fail();
    sc2.setExpirationDate(sc.getExpirationDate());
    pp.setSmartCode(sc2);
    if (!pp2.equals(pp))
        fail();
}
Also used : SmartCode(BasicCommonClasses.SmartCode) ProductPackage(BasicCommonClasses.ProductPackage) LocalDate(java.time.LocalDate) Location(BasicCommonClasses.Location) Test(org.junit.Test)

Example 32 with SmartCode

use of BasicCommonClasses.SmartCode in project SmartCity-Market by TechnionYP5777.

the class SmartCodeTest method SmartCodeTestMethod.

@Test
public void SmartCodeTestMethod() {
    LocalDate ld = LocalDate.of(2016, 12, 11);
    SmartCode sc = new SmartCode(123, ld);
    if (sc.getBarcode() != 123 || !sc.getExpirationDate().equals(ld))
        fail();
    sc.setBarcode(111);
    ld.plusDays(1);
    sc.setExpirationDate(ld);
    if (sc.getBarcode() != 111 || !sc.getExpirationDate().equals(ld))
        fail();
    LocalDate ld2 = LocalDate.of(2015, 12, 12);
    SmartCode sc2 = new SmartCode(111, ld2);
    if (sc2.equals(sc))
        fail();
    sc2.setExpirationDate(sc.getExpirationDate());
    if (!sc2.equals(sc))
        fail();
}
Also used : SmartCode(BasicCommonClasses.SmartCode) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 33 with SmartCode

use of BasicCommonClasses.SmartCode in project SmartCity-Market by TechnionYP5777.

the class CustomerMainScreen method smartcodeScanned.

@Subscribe
public void smartcodeScanned(SmartcodeScanEvent ¢) {
    SmartCode smartCode = ¢.getSmarCode();
    scannedSmartCode = smartCode;
    smartcodeScannedHandler();
}
Also used : SmartCode(BasicCommonClasses.SmartCode) Subscribe(com.google.common.eventbus.Subscribe)

Example 34 with SmartCode

use of BasicCommonClasses.SmartCode in project SmartCity-Market by TechnionYP5777.

the class RemoveProductFromCatalogTest method removeCatalogProductNotExistInCatalogTest.

@Test
public void removeCatalogProductNotExistInCatalogTest() {
    int senderID = 1;
    SmartCode smartCode = new SmartCode(1, null);
    String command = new CommandWrapper(senderID, CommandDescriptor.REMOVE_PRODUCT_FROM_CATALOG, new Gson().toJson(smartCode, SmartCode.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doThrow(new ProductNotExistInCatalog()).when(sqlDatabaseConnection).removeProductFromCatalog(senderID, smartCode);
    } catch (CriticalError | ClientNotConnected | ProductStillForSale e) {
        fail();
    } catch (ProductNotExistInCatalog e) {
    /* success */
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_CATALOG_PRODUCT_DOES_NOT_EXIST, out.getResultDescriptor());
}
Also used : SmartCode(BasicCommonClasses.SmartCode) ProductNotExistInCatalog(SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog) ProductStillForSale(SQLDatabase.SQLDatabaseException.ProductStillForSale) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) CommandExecuter(CommandHandler.CommandExecuter) Test(org.junit.Test)

Example 35 with SmartCode

use of BasicCommonClasses.SmartCode in project SmartCity-Market by TechnionYP5777.

the class RemoveProductPackageFromGroceryListTest method removeProductPackageFromGroceryListCriticalErrorTest.

@Test
public void removeProductPackageFromGroceryListCriticalErrorTest() {
    int cartID = 1;
    ProductPackage productPackage = new ProductPackage(new SmartCode(1, null), 1, new Location(0, 0, PlaceInMarket.WAREHOUSE));
    String command = new CommandWrapper(cartID, CommandDescriptor.REMOVE_PRODUCT_FROM_GROCERY_LIST, new Gson().toJson(productPackage, ProductPackage.class)).serialize();
    CommandExecuter commandExecuter = new CommandExecuter(command);
    CommandWrapper out;
    try {
        Mockito.doThrow(new CriticalError()).when(sqlDatabaseConnection).removeProductFromGroceryList(cartID, productPackage);
    } catch (ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist e) {
        fail();
    } catch (CriticalError __) {
    /* Successful */
    }
    out = commandExecuter.execute(sqlDatabaseConnection);
    assertEquals(ResultDescriptor.SM_ERR, out.getResultDescriptor());
}
Also used : SmartCode(BasicCommonClasses.SmartCode) ProductNotExistInCatalog(SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog) ProductPackageAmountNotMatch(SQLDatabase.SQLDatabaseException.ProductPackageAmountNotMatch) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) ProductPackage(BasicCommonClasses.ProductPackage) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) ProductPackageNotExist(SQLDatabase.SQLDatabaseException.ProductPackageNotExist) CommandExecuter(CommandHandler.CommandExecuter) Location(BasicCommonClasses.Location) Test(org.junit.Test)

Aggregations

SmartCode (BasicCommonClasses.SmartCode)82 Test (org.junit.Test)71 ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)63 CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)63 ProductNotExistInCatalog (SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog)63 ProductPackage (BasicCommonClasses.ProductPackage)58 CommandWrapper (ClientServerApi.CommandWrapper)51 Gson (com.google.gson.Gson)50 CommandExecuter (CommandHandler.CommandExecuter)47 Location (BasicCommonClasses.Location)41 ProductPackageAmountNotMatch (SQLDatabase.SQLDatabaseException.ProductPackageAmountNotMatch)39 ProductPackageNotExist (SQLDatabase.SQLDatabaseException.ProductPackageNotExist)39 SQLDatabaseConnection (SQLDatabase.SQLDatabaseConnection)20 AuthenticationError (SQLDatabase.SQLDatabaseException.AuthenticationError)8 ClientAlreadyConnected (SQLDatabase.SQLDatabaseException.ClientAlreadyConnected)8 NumberOfConnectionsExceeded (SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded)8 ProductStillForSale (SQLDatabase.SQLDatabaseException.ProductStillForSale)8 CatalogProduct (BasicCommonClasses.CatalogProduct)5 Manufacturer (BasicCommonClasses.Manufacturer)3 SMException (SMExceptions.SMException)3