Search in sources :

Example 46 with SmartCode

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

the class AddProductPackageToWarehouseTest method addProductPackageToWarehouseIllegalProductPackageTest.

@Test
public void addProductPackageToWarehouseIllegalProductPackageTest() {
    assertEquals(ResultDescriptor.SM_ERR, (new CommandExecuter(new CommandWrapper(1, CommandDescriptor.ADD_PRODUCT_PACKAGE_TO_WAREHOUSE, new Gson().toJson("", String.class)).serialize())).execute(sqlDatabaseConnection).getResultDescriptor());
    assertEquals(ResultDescriptor.SM_INVALID_PARAMETER, (new CommandExecuter(new CommandWrapper(1, CommandDescriptor.ADD_PRODUCT_PACKAGE_TO_WAREHOUSE, new Gson().toJson(new ProductPackage(new SmartCode(1, null), -1, new Location(0, 0, PlaceInMarket.WAREHOUSE)), ProductPackage.class)).serialize())).execute(sqlDatabaseConnection).getResultDescriptor());
}
Also used : SmartCode(BasicCommonClasses.SmartCode) ProductPackage(BasicCommonClasses.ProductPackage) Gson(com.google.gson.Gson) CommandWrapper(ClientServerApi.CommandWrapper) CommandExecuter(CommandHandler.CommandExecuter) Location(BasicCommonClasses.Location) Test(org.junit.Test)

Example 47 with SmartCode

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

the class AddProductPackageToWarehouseTest method addProductPackageToWarehouseClientNotConnectedTest.

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

Example 48 with SmartCode

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

the class AddProductPackageToWarehouseTest method addProductPackageToWarehouseProductNotExistInCatalogTest.

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

Example 49 with SmartCode

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

the class SQLDatabaseConnection method editProductInCatalog.

/*
	 * (non-Javadoc)
	 * 
	 * @see SQLDatabase.ISQLDatabaseConnection#UpdateProductInCatalog(java.lang.
	 * Integer, java.lang.Long, BasicCommonClasses.CatalogProduct)
	 */
@Override
public void editProductInCatalog(Integer sessionID, CatalogProduct productToUpdate) throws CriticalError, ClientNotConnected, ProductNotExistInCatalog, IngredientNotExist, ManufacturerNotExist {
    log.debug("SQL Public editProductInCatalog: Trying to edit to: " + productToUpdate + " (SESSION: " + sessionID + " )");
    validateSessionEstablished(sessionID);
    try {
        // START transaction
        connectionStartTransaction();
        // READ part of transaction
        if (!isProductExistInCatalog(productToUpdate.getBarcode()))
            throw new ProductNotExistInCatalog();
        // check if manufacturer exist
        if (isManufacturerExist((int) productToUpdate.getManufacturer().getId()))
            throw new ManufacturerNotExist();
        checkAllIngredientsExist(productToUpdate.getIngredients());
        // WRITE part of transaction
        // do update = remove product and adds it again
        removeCatalogProduct(new SmartCode(productToUpdate.getBarcode(), null));
        addCatalogProduct(productToUpdate);
        // END transaction
        connectionCommitTransaction();
    } catch (CriticalError | SQLException e) {
        connectionRollbackTransaction();
        throw new CriticalError();
    } finally {
        connectionEndTransaction();
    }
}
Also used : SmartCode(BasicCommonClasses.SmartCode) SQLException(java.sql.SQLException)

Example 50 with SmartCode

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

the class ViewProductFromCatalogTest method ViewProductFromCatalogSuccessfulTest.

@Test
public void ViewProductFromCatalogSuccessfulTest() {
    CatalogProduct testCatalogProduct = null, catalogProduct = new CatalogProduct(1234567890, "name", null, new Manufacturer(1, "Manufacturer"), "description", 22.0, null, null);
    CommandWrapper commandWrapper = new CommandWrapper(ResultDescriptor.SM_OK, Serialization.serialize(catalogProduct));
    try {
        Mockito.when(clientRequestHandler.sendRequestWithRespond(new CommandWrapper(WorkerDefs.loginCommandSenderId, CommandDescriptor.VIEW_PRODUCT_FROM_CATALOG, Serialization.serialize(new SmartCode(1234567890, null))).serialize())).thenReturn(commandWrapper.serialize());
    } catch (IOException ¢) {
        fail();
    }
    try {
        testCatalogProduct = worker.viewProductFromCatalog(1234567890);
    } catch (InvalidParameter | CriticalError | EmployeeNotConnected | ProductNotExistInCatalog | ConnectionFailure ¢) {
        fail();
    }
    assertEquals(testCatalogProduct.getBarcode(), 1234567890);
    assertEquals(testCatalogProduct.getManufacturer().getId(), 1);
    assertEquals(testCatalogProduct.getManufacturer().getName(), "Manufacturer");
    assertEquals(testCatalogProduct.getName(), "name");
}
Also used : SmartCode(BasicCommonClasses.SmartCode) ProductNotExistInCatalog(EmployeeDefs.AEmployeeException.ProductNotExistInCatalog) InvalidParameter(EmployeeDefs.AEmployeeException.InvalidParameter) CriticalError(SMExceptions.CommonExceptions.CriticalError) ConnectionFailure(EmployeeDefs.AEmployeeException.ConnectionFailure) Manufacturer(BasicCommonClasses.Manufacturer) CatalogProduct(BasicCommonClasses.CatalogProduct) CommandWrapper(ClientServerApi.CommandWrapper) IOException(java.io.IOException) EmployeeNotConnected(EmployeeDefs.AEmployeeException.EmployeeNotConnected) 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