Search in sources :

Example 26 with SQLDatabaseConnection

use of SQLDatabase.SQLDatabaseConnection in project SmartCity-Market by TechnionYP5777.

the class SQLDatabaseConnectionTest method testSimpleAddMoveToCartRemovePakage.

@Test
public void testSimpleAddMoveToCartRemovePakage() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    ProductPackage productPackage = new ProductPackage(new SmartCode(barcodeDebug, date112000), 5, locationWarehouse);
    int cartSession = 0;
    try {
        cartSession = sqlConnection.loginCustomer(ClientServerDefs.anonymousCustomerUsername, ClientServerDefs.anonymousCustomerPassword);
        sqlConnection.addProductPackageToWarehouse(null, productPackage);
        sqlConnection.placeProductPackageOnShelves(null, productPackage);
        assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
        assertEquals("5", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
        sqlConnection.addProductToGroceryList(cartSession, productPackage);
        assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
        assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
        sqlConnection.removeProductFromGroceryList(cartSession, productPackage);
        assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
        assertEquals("5", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
        sqlConnection.removeProductPackageFromShelves(null, productPackage);
        assertEquals("0", sqlConnection.getProductPackageAmonutInWarehouse(null, productPackage));
        assertEquals("0", sqlConnection.getProductPackageAmonutOnShelves(null, productPackage));
    } catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch | ProductPackageNotExist | AuthenticationError | ClientAlreadyConnected | NumberOfConnectionsExceeded e) {
        fail();
    }
    try {
        sqlConnection.removeProductFromGroceryList(cartSession, productPackage);
        fail();
    } catch (ProductPackageNotExist e) {
    } catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch e) {
        fail();
    }
    try {
        sqlConnection.removeProductPackageFromShelves(null, productPackage);
        fail();
    } catch (ProductPackageNotExist e) {
    } catch (CriticalError | ClientNotConnected | ProductNotExistInCatalog | ProductPackageAmountNotMatch e) {
        fail();
    }
    try {
        sqlConnection.logout(cartSession, ClientServerDefs.anonymousCustomerUsername);
    } catch (ClientNotConnected | CriticalError e) {
        fail();
    }
}
Also used : AuthenticationError(SQLDatabase.SQLDatabaseException.AuthenticationError) SmartCode(BasicCommonClasses.SmartCode) ProductNotExistInCatalog(SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog) ProductPackageAmountNotMatch(SQLDatabase.SQLDatabaseException.ProductPackageAmountNotMatch) SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) ProductPackage(BasicCommonClasses.ProductPackage) ProductPackageNotExist(SQLDatabase.SQLDatabaseException.ProductPackageNotExist) NumberOfConnectionsExceeded(SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded) ClientAlreadyConnected(SQLDatabase.SQLDatabaseException.ClientAlreadyConnected) Test(org.junit.Test)

Example 27 with SQLDatabaseConnection

use of SQLDatabase.SQLDatabaseConnection in project SmartCity-Market by TechnionYP5777.

the class Main method main.

public static void main(String[] args) {
    if (!parseArguments(args))
        return;
    /* Setting log properties */
    PropertyConfigurator.configure("../log4j.properties");
    log.setLevel(verbosity);
    CommandProcess commandProcess = new CommandProcess();
    ThreadPooledServer server = null;
    try {
        server = new ThreadPooledServer(port, numOfThreads, commandProcess, serverIP);
    } catch (UnknownHostException e1) {
        log.fatal("Server IP address leads to unknown host, server won't start.");
        return;
    }
    SQLDatabaseConnection connection = new SQLDatabaseConnection();
    log.info("Disconnect from all clients");
    try {
        connection.logoutAllUsers();
        connection.close();
    } catch (CriticalError e1) {
        log.fatal("Disconnect failed");
        return;
    }
    log.info("Starting Server.");
    new Thread(server).start();
    try {
        Thread.sleep(1000 * timeout);
    } catch (InterruptedException e) {
        /* Get interrupt to stop server */
        log.info("Server Got interrupted.");
    }
    log.info("Stopping server.");
    server.stop();
}
Also used : CommandProcess(CommandHandler.CommandProcess) SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) UnknownHostException(java.net.UnknownHostException) ThreadPooledServer(ClientServerCommunication.ThreadPooledServer)

Example 28 with SQLDatabaseConnection

use of SQLDatabase.SQLDatabaseConnection in project SmartCity-Market by TechnionYP5777.

the class SQLDatabaseConnectionTest method testCantGetSecurityQusetionOfNotExistedWorker.

@Test
public void testCantGetSecurityQusetionOfNotExistedWorker() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    try {
        sqlConnection.getSecurityQuestionWorker(workerName);
        fail();
    } catch (CriticalError e1) {
        fail();
    } catch (ClientNotExist e2) {
    }
}
Also used : SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotExist(SQLDatabase.SQLDatabaseException.ClientNotExist) Test(org.junit.Test)

Example 29 with SQLDatabaseConnection

use of SQLDatabase.SQLDatabaseConnection in project SmartCity-Market by TechnionYP5777.

the class SQLDatabaseConnectionTest method testWorkerCanSetSecurityQA.

@Test
public void testWorkerCanSetSecurityQA() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    ForgotPasswordData p = new ForgotPasswordData("question", "answer");
    String result = null;
    try {
        sqlConnection.addWorker(null, new Login(workerName, workerName), new ForgotPasswordData("", ""));
    } catch (CriticalError | ClientAlreadyExist | ClientNotConnected e) {
        fail();
    }
    try {
        sqlConnection.setSecurityQAWorker(workerName, p);
        result = sqlConnection.getSecurityQuestionWorker(workerName);
        assertTrue(sqlConnection.verifySecurityAnswerWorker(workerName, "answer"));
        assertEquals("question", result);
    } catch (CriticalError | ClientNotExist e1) {
        fail();
    } finally {
        try {
            sqlConnection.removeWorker(null, workerName);
        } catch (CriticalError | ClientNotExist | ClientNotConnected e) {
            e.printStackTrace();
        }
    }
}
Also used : SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) ClientAlreadyExist(SQLDatabase.SQLDatabaseException.ClientAlreadyExist) ForgotPasswordData(BasicCommonClasses.ForgotPasswordData) Login(BasicCommonClasses.Login) ClientNotExist(SQLDatabase.SQLDatabaseException.ClientNotExist) Test(org.junit.Test)

Example 30 with SQLDatabaseConnection

use of SQLDatabase.SQLDatabaseConnection in project SmartCity-Market by TechnionYP5777.

the class SQLDatabaseConnectionTest method testWorkerCanLoginWithNewPassword.

@Test
public void testWorkerCanLoginWithNewPassword() {
    SQLDatabaseConnection sqlConnection = new SQLDatabaseConnection();
    try {
        sqlConnection.addWorker(null, new Login(workerName, workerName), new ForgotPasswordData("", ""));
    } catch (CriticalError | ClientAlreadyExist | ClientNotConnected e) {
        fail();
    }
    try {
        sqlConnection.setPasswordWorker(workerName, "newPass");
        //try to login with new password
        int sessionID = sqlConnection.loginWorker(workerName, "newPass");
        sqlConnection.logout(sessionID, workerName);
    } catch (CriticalError | ClientNotExist | AuthenticationError | ClientAlreadyConnected | NumberOfConnectionsExceeded | ClientNotConnected e1) {
        fail();
    } finally {
        try {
            sqlConnection.removeWorker(null, workerName);
        } catch (CriticalError | ClientNotExist | ClientNotConnected e) {
            e.printStackTrace();
        }
    }
}
Also used : AuthenticationError(SQLDatabase.SQLDatabaseException.AuthenticationError) SQLDatabaseConnection(SQLDatabase.SQLDatabaseConnection) CriticalError(SQLDatabase.SQLDatabaseException.CriticalError) ClientNotConnected(SQLDatabase.SQLDatabaseException.ClientNotConnected) ForgotPasswordData(BasicCommonClasses.ForgotPasswordData) Login(BasicCommonClasses.Login) ClientNotExist(SQLDatabase.SQLDatabaseException.ClientNotExist) ClientAlreadyExist(SQLDatabase.SQLDatabaseException.ClientAlreadyExist) NumberOfConnectionsExceeded(SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded) ClientAlreadyConnected(SQLDatabase.SQLDatabaseException.ClientAlreadyConnected) Test(org.junit.Test)

Aggregations

SQLDatabaseConnection (SQLDatabase.SQLDatabaseConnection)62 CriticalError (SQLDatabase.SQLDatabaseException.CriticalError)61 Test (org.junit.Test)58 ClientNotConnected (SQLDatabase.SQLDatabaseException.ClientNotConnected)48 ProductNotExistInCatalog (SQLDatabase.SQLDatabaseException.ProductNotExistInCatalog)24 SmartCode (BasicCommonClasses.SmartCode)20 AuthenticationError (SQLDatabase.SQLDatabaseException.AuthenticationError)19 ClientAlreadyConnected (SQLDatabase.SQLDatabaseException.ClientAlreadyConnected)19 NumberOfConnectionsExceeded (SQLDatabase.SQLDatabaseException.NumberOfConnectionsExceeded)19 ProductPackage (BasicCommonClasses.ProductPackage)18 ClientNotExist (SQLDatabase.SQLDatabaseException.ClientNotExist)17 ProductPackageAmountNotMatch (SQLDatabase.SQLDatabaseException.ProductPackageAmountNotMatch)16 ProductPackageNotExist (SQLDatabase.SQLDatabaseException.ProductPackageNotExist)16 ForgotPasswordData (BasicCommonClasses.ForgotPasswordData)9 Manufacturer (BasicCommonClasses.Manufacturer)9 Ingredient (BasicCommonClasses.Ingredient)8 ClientAlreadyExist (SQLDatabase.SQLDatabaseException.ClientAlreadyExist)8 IngredientNotExist (SQLDatabase.SQLDatabaseException.IngredientNotExist)6 Gson (com.google.gson.Gson)6 CatalogProduct (BasicCommonClasses.CatalogProduct)5