Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //public class DBModel {
- //
- // private String mDBName;
- // private String mTableName;
- // private String[] mFieldNames;
- // private String[] mFieldTypes;
- // public DBModel(String dbName, String tableName, String[] fieldNames, String[] fieldTypes)
- // throws SQLException {
- // super();
- // mDBName = dbName;
- // mTableName = tableName;
- // mFieldNames = fieldNames;
- // mFieldTypes = fieldTypes;
- // if (mFieldNames == null || mFieldTypes == null || mFieldNames.length == 0 || mFieldNames.length != mFieldTypes.length)
- // throw new SQLException("Database field names and types must exist and have the same number of elements.");
- // createTable();
- // }
- //
- // private void createTable() throws SQLException
- // {
- // try (Connection connection = connectToDB();
- // Statement stmt = connection.createStatement();) {
- // StringBuilder createSQL = new StringBuilder("CREATE TABLE IF NOT EXISTS ");
- // createSQL.append(mTableName).append("(");
- // for (int i = 0; i < mFieldNames.length; i++)
- // createSQL.append(mFieldNames[i]).append(" ").append(mFieldTypes[i]).append((i < mFieldNames.length -1) ? "," : ")");
- // stmt.executeUpdate(createSQL.toString());
- // }
- //
- // }
- //
- // public ArrayList<ArrayList<String>> getAllRecords() throws SQLException {
- // try (Connection connection = connectToDB();
- // Statement stmt = connection.createStatement();
- // ResultSet rs = stmt.executeQuery("SELECT * FROM " + mTableName);) {
- // ArrayList<ArrayList<String>> resultsList = new ArrayList<>();
- // while (rs.next()) {
- // // Let's loop through each of the fields and add each value to the ArrayList
- // ArrayList<String> values = new ArrayList<>(mFieldNames.length);
- // for (String fieldName : mFieldNames)
- // values.add(rs.getString(fieldName));
- // // Now add the values to the 2D ArrayList
- // resultsList.add(values);
- // }
- // return resultsList;
- // }
- // }
- //
- // public ArrayList<ArrayList<String>> getRecord(String key) throws SQLException
- // {
- // try (Connection connection = connectToDB();
- // Statement stmt = connection.createStatement();
- // ResultSet rs = stmt.executeQuery("SELECT * FROM " + mTableName + " WHERE " + mFieldNames[0] + " = " + key);) {
- // ArrayList<ArrayList<String>> resultsList = new ArrayList<>();
- // while (rs.next()) {
- // // Let's loop through each of the fields and add each value to the ArrayList
- // ArrayList<String> values = new ArrayList<>(mFieldNames.length);
- // for (String fieldName : mFieldNames)
- // values.add(rs.getString(fieldName));
- // // Now add the values to the 2D ArrayList
- // resultsList.add(values);
- // }
- // return resultsList;
- // }
- // }
- //
- // public int getRecordCount() throws SQLException {
- // return getAllRecords().size();
- // }
- //
- // public int createRecord(String[] fields, String[] values) throws SQLException {
- // try (Connection connection = connectToDB();
- // Statement stmt = connection.createStatement();) {
- // if(fields == null || values == null || fields.length == 0 || fields.length != values.length)
- // return -1;
- //
- // StringBuilder insertSQL = new StringBuilder("INSERT INTO ");
- // insertSQL.append(mTableName).append("(");
- // for(int i = 0; i < fields.length; i++)
- // insertSQL.append(fields[i]).append((i < fields.length - 1) ? "," : ") VALUES(");
- // for(int i = 0; i < values.length; i++)
- // insertSQL.append(convertToSQLText(fields[i], values[i])).append((i < values.length - 1) ? "," : ")");
- //
- // stmt.executeUpdate(insertSQL.toString());
- // return stmt.getGeneratedKeys().getInt(1);
- // }
- // }
- //
- // public boolean updateRecord(String key, String[] fields, String[] values) throws SQLException
- // {
- //
- // if (fields == null || values == null || fields.length == 0 || fields.length != values.length)
- // return false;
- // StringBuilder updateSQL = new StringBuilder("UPDATE ");
- // updateSQL.append(mTableName).append(" SET ");
- // for (int i = 0; i < fields.length; i++)
- // updateSQL.append(fields[i]).append("=").append(convertToSQLText(fields[i], values[i])).append((i < fields.length - 1) ? ", " : " ");
- // try (Connection connection = connectToDB();
- // Statement stmt = connection.createStatement();) {
- // updateSQL.append("WHERE ").append(mFieldNames[0]).append("=").append(key);
- // stmt.executeUpdate(updateSQL.toString());
- // return true;
- // }
- // }
- //
- // public void deleteAllRecords() throws SQLException {
- // try (Connection connection = connectToDB();
- // Statement stmt = connection.createStatement();) {
- // stmt.executeUpdate("DELETE FROM " + mTableName);
- // }
- // }
- //
- // public void deleteRecord(String key) throws SQLException
- // {
- // try (Connection connection = connectToDB();
- // Statement stmt = connection.createStatement();) {
- // stmt.executeUpdate("DELETE FROM " + mTableName + " WHERE " + mFieldNames[0] + " = " + key);
- // }
- // }
- //
- // private String convertToSQLText(String field, String value) {
- // // Lookup the field in field names, if found, check to see if the type is TEXT (if so, append ' ' around value)
- // for (int i = 0; i < mFieldNames.length; i++) {
- // if (mFieldNames[i].equals(field)) {
- // if (mFieldTypes[i].toUpperCase().startsWith("TEXT"))
- // return "'" + value + "'";
- // break;
- // }
- // }
- // return value;
- // }
- //
- // private Connection connectToDB() throws SQLException {
- // // Load SQLite database classes
- // try {
- // Class.forName("org.sqlite.JDBC");
- // } catch (ClassNotFoundException e) {
- // e.printStackTrace();
- // }
- // // Establish a connection to the database and return that connection
- // Connection connection = DriverManager.getConnection("jdbc:sqlite:" + mDBName);
- // return connection;
- // }
- //}
- //
- //public class Controller {
- //
- // private static Controller theOne;
- //
- // private static final String DB_NAME = "vg_inventory.db";
- //
- // private static final String USER_TABLE_NAME = "user";
- // private static final String[] USER_FIELD_NAMES = { "id", "name", "email", "role", "password"};
- // private static final String[] USER_FIELD_TYPES = { "INTEGER PRIMARY KEY", "TEXT", "TEXT", "TEXT", "TEXT"};
- //
- // private static final String VIDEO_GAME_TABLE_NAME = "video_game";
- // private static final String[] VIDEO_GAME_FIELD_NAMES = { "id", "name", "platform", "year", "genre", "publisher"};
- // private static final String[] VIDEO_GAME_FIELD_TYPES = { "INTEGER PRIMARY KEY", "TEXT", "TEXT", "INTEGER", "TEXT", "TEXT"};
- // private static final String VIDEO_GAME_DATA_FILE = "videogames_lite.csv";
- //
- // private static final String USER_GAMES_TABLE_NAME = "user_games";
- // private static final String[] USER_GAMES_FIELD_NAMES = { "user_id", "game_id"};
- // private static final String[] USER_GAMES_FIELD_TYPES = { "INTEGER", "INTEGER"};
- //
- // private User mCurrentUser;
- // private DBModel mUserDB;
- // private DBModel mVideoGameDB;
- // private DBModel mUserGamesDB;
- //
- // private ObservableList<User> mAllUsersList;
- // private ObservableList<VideoGame> mAllGamesList;
- //
- // private Controller() {
- // }
- //
- // public static Controller getInstance() {
- // if (theOne == null) {
- // theOne = new Controller();
- // theOne.mAllUsersList = FXCollections.observableArrayList();
- // theOne.mAllGamesList = FXCollections.observableArrayList();
- //
- // try {
- // theOne.mUserDB = new DBModel(DB_NAME, USER_TABLE_NAME, USER_FIELD_NAMES, USER_FIELD_TYPES);
- //
- // ArrayList<ArrayList<String>> resultsList = theOne.mUserDB.getAllRecords();
- //
- // for (ArrayList<String> values : resultsList) {
- // int id = Integer.parseInt(values.get(0));
- // String name = values.get(1);
- // String email = values.get(2);
- // String role = values.get(3);
- // theOne.mAllUsersList.add(new User(id, name, email, role));
- // }
- //
- // theOne.mVideoGameDB = new DBModel(DB_NAME, VIDEO_GAME_TABLE_NAME, VIDEO_GAME_FIELD_NAMES, VIDEO_GAME_FIELD_TYPES);
- // theOne.initializeVideoGameDBFromFile();
- // resultsList = theOne.mVideoGameDB.getAllRecords();
- // for (ArrayList<String> values : resultsList)
- // {
- // int id = Integer.parseInt(values.get(0));
- // String name = values.get(1);
- // String platform = values.get(2);
- // int year = Integer.parseInt(values.get(3));
- // String genre = values.get(4);
- // String publisher = values.get(5);
- // theOne.mAllGamesList.add(new VideoGame(id, name, platform, year, genre, publisher));
- // }
- //
- // theOne.mUserGamesDB= new DBModel(DB_NAME, USER_GAMES_TABLE_NAME, USER_GAMES_FIELD_NAMES, USER_GAMES_FIELD_TYPES);
- //
- // } catch (SQLException e) {
- // e.printStackTrace();
- // }
- // }
- // return theOne;
- // }
- //
- // public boolean isValidPassword(String password)
- // {
- // // Valid password must contain (see regex below):
- // // At least one lower case letter
- // // At least one digit
- // // At least one special character (@, #, $, %, !)
- // // At least one upper case letter
- // // At least 8 characters long, but no more than 16
- // return password.matches("((?=.*[a-z])(?=.*d)(?=.*[@#$%!])(?=.*[A-Z]).{8,16})");
- // }
- //
- // public boolean isValidEmail(String email)
- // {
- // return email.matches(
- // "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
- // + "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$");
- // }
- //
- // public String signUpUser(String name, String email, String password)
- // {
- // if (!isValidEmail(email))
- // return "Email address is not valid. Please use different address.";
- //
- // for (User u : theOne.mAllUsersList)
- // if (u.getEmail().equalsIgnoreCase(email))
- // return "Email address already used. Please sign in or use different email.";
- //
- // if (!isValidPassword(password))
- // return "Password must be at least 8 characters, including 1 upper case letter, 1 lower case letter, 1 digit and one symbol.";
- //
- // try {
- // // In practice, passwords should always be encrypted before storing in database:
- // // See http://www.jasypt.org/howtoencryptuserpasswords.html for a useful tutorial
- // String[] values = {name, email, "STANDARD", password};
- // int id = theOne.mUserDB.createRecord(Arrays.copyOfRange(USER_FIELD_NAMES, 1, USER_FIELD_NAMES.length), values);
- // mCurrentUser = new User(id, name, email, "STANDARD");
- // theOne.mAllUsersList.add(mCurrentUser);
- // } catch (Exception e) {
- // e.printStackTrace();
- // return "Error creating user, please try again.";
- // }
- // return "SUCCESS";
- // }
- //
- // public String signInUser(String email, String password) {
- // for (User u : theOne.mAllUsersList)
- // if (u.getEmail().equalsIgnoreCase(email))
- // {
- // try {
- // ArrayList<ArrayList<String>> resultsList = theOne.mUserDB.getRecord(String.valueOf(u.getId()));
- // String storedPassword = resultsList.get(0).get(4);
- // if (password.equals(storedPassword))
- // {
- // mCurrentUser = u;
- // return "SUCCESS";
- // }
- //
- //
- // } catch (Exception e) {}
- // return "Incorrect password. Please try again.";
- // }
- // return "Email address not found. Please try again.";
- // }
- //
- // public User getCurrentUser()
- // {
- // return mCurrentUser;
- // }
- //
- // public ObservableList<User> getAllUsers() {
- // return theOne.mAllUsersList;
- // }
- //
- // public ObservableList<VideoGame> getAllVideoGames() {
- // return theOne.mAllGamesList;
- // }
- //
- // public ObservableList<String> getDistinctPlatforms() {
- // ObservableList<String> platforms = FXCollections.observableArrayList();
- // platforms.add("");
- // for (VideoGame vg : theOne.mAllGamesList)
- // if (!platforms.contains(vg.getPlatform()))
- // platforms.add(vg.getPlatform());
- // FXCollections.sort(platforms);
- // return platforms;
- // }
- //
- // public ObservableList<String> getDistinctPublishers() {
- // ObservableList<String> publishers = FXCollections.observableArrayList();
- // publishers.add("");
- // for (VideoGame vg : theOne.mAllGamesList)
- // if (!publishers.contains(vg.getPublisher()))
- // publishers.add(vg.getPublisher());
- // FXCollections.sort(publishers);
- // return publishers;
- // }
- //
- // public ObservableList<VideoGame> getGamesForCurrentUser()
- // {
- // ObservableList<VideoGame> userGamesList = FXCollections.observableArrayList();
- // if (mCurrentUser != null)
- // {
- // try {
- // ArrayList<ArrayList<String>> resultsList= theOne.mUserGamesDB.getRecord(String.valueOf(mCurrentUser.getId()));
- // for (ArrayList<String> values : resultsList)
- // {
- // int gameId = Integer.parseInt(values.get(1));
- // for (VideoGame vg : theOne.mAllGamesList)
- // if (vg.getId() == gameId)
- // userGamesList.add(vg);
- // }
- //
- // } catch (SQLException e) {
- // e.printStackTrace();
- // }
- //
- // }
- //
- // return userGamesList;
- // }
- //
- // public boolean addGameToInventory(VideoGame selectedGame) {
- // ObservableList<VideoGame> userGamesList = theOne.getGamesForCurrentUser();
- // if (userGamesList.contains(selectedGame))
- // return false;
- // String[] values = {String.valueOf(mCurrentUser.getId()), String.valueOf(selectedGame.getId())};
- // try {
- // this.mUserGamesDB.createRecord(USER_GAMES_FIELD_NAMES, values);
- // } catch (SQLException e) {
- // e.printStackTrace();
- // return false;
- // }
- // return true;
- // }
- //
- // private int initializeVideoGameDBFromFile() throws SQLException {
- // int recordsCreated = 0;
- //
- // // If the result set contains results, database table already has
- // // records, no need to populate from file (so return false)
- // if (theOne.mUserDB.getRecordCount() > 0)
- // return 0;
- //
- // try {
- // // Otherwise, open the file (CSV file) and insert user data
- // // into database
- // Scanner fileScanner = new Scanner(new File(VIDEO_GAME_DATA_FILE));
- // // First read is for headings:
- // fileScanner.nextLine();
- // // All subsequent reads are for user data
- // while (fileScanner.hasNextLine()) {
- // String[] data = fileScanner.nextLine().split(",");
- // // Length of values is one less than field names because values
- // // does not have id (DB will assign one)
- // String[] values = new String[VIDEO_GAME_FIELD_NAMES.length - 1];
- // values[0] = data[1].replaceAll("'", "''");
- // values[1] = data[2];
- // values[2] = data[3];
- // values[3] = data[4];
- // values[4] = data[5];
- // theOne.mVideoGameDB.createRecord(Arrays.copyOfRange(VIDEO_GAME_FIELD_NAMES, 1, VIDEO_GAME_FIELD_NAMES.length), values);
- // recordsCreated++;
- // }
- //
- // // All done with the CSV file, close the connection
- // fileScanner.close();
- // } catch (FileNotFoundException e) {
- // return 0;
- // }
- // return recordsCreated;
- // }
- //
- // public ObservableList<VideoGame> filter(String publisher, String platform, double year) {
- // ObservableList<VideoGame> filteredVideoGamesList = FXCollections.observableArrayList();
- // for (VideoGame vg : theOne.mAllGamesList) {
- // if ((publisher == null || vg.getPublisher().equals(publisher) || publisher.isEmpty()) && (platform == null || vg.getPlatform().equals(platform) || platform.isEmpty())
- // && (vg.getYear() >= year))
- // filteredVideoGamesList.add(vg);
- // }
- // return filteredVideoGamesList;
- // }
- //
- //}
- //
- //public class ViewNavigator {
- //
- // public static final String SIGN_UP_SCENE = "SignUpScene.fxml";
- //
- //
- // public static final String SIGN_IN_SCENE = "SignInScene.fxml";
- //
- // public static final String VIDEO_GAME_LIST_SCENE = "VideoGamesListScene.fxml";
- //
- // public static final String VIEW_INVENTORY_SCENE = "ViewInventoryScene.fxml";
- //
- // public static Stage mainStage;
- //
- // public static void setStage(Stage stage) {
- // mainStage = stage;
- // }
- //
- // public static void loadScene(String title, String sceneFXML) {
- //
- // try {
- // mainStage.setTitle(title);
- // Scene scene = new Scene(FXMLLoader.load(ViewNavigator.class.getResource(sceneFXML)));
- // mainStage.setScene(scene);
- // mainStage.show();
- // } catch (IOException e) {
- // System.err.println("Error loading: " + sceneFXML + "\n" + e.getMessage());
- // e.printStackTrace();
- // }
- // }
- //
- //}
- //public class MainView extends Application {
- //
- // @Override
- // public void start(Stage primaryStage) throws Exception {
- // // Set stage only needs to be called once for the view navigator
- // ViewNavigator.setStage(primaryStage);
- // ViewNavigator.loadScene("Welcome to VG in.vent.ory", ViewNavigator.SIGN_IN_SCENE);
- // }
- //
- // public static void main(String[] args) {
- // launch(args);
- // }
- //
- //}
- //public class VideoGamesListScene implements Initializable {
- //
- // private static Controller controller = Controller.getInstance();
- //
- // @FXML
- // private ListView<VideoGame> allVideoGamesLV;
- // @FXML
- // private ComboBox<String> publishersCB;
- // @FXML
- // private ComboBox<String> platformsCB;
- // @FXML
- // private Slider yearSlider;
- //
- // @Override
- // public void initialize(URL location, ResourceBundle resources) {
- // allVideoGamesLV.setItems(controller.getAllVideoGames());
- // platformsCB.setItems(controller.getDistinctPlatforms());
- // publishersCB.setItems(controller.getDistinctPublishers());
- // }
- //
- // @FXML
- // public Object addGameToInventory()
- // {
- // VideoGame selectedGame = allVideoGamesLV.getSelectionModel().getSelectedItem();
- // if (controller.addGameToInventory(selectedGame))
- // System.out.println("SUCCESS");
- // else
- // System.out.println("Could not add game.");
- // return this;
- // }
- //
- // @FXML
- // public Object viewInventory()
- // {
- // ViewNavigator.loadScene("User's Video Games", ViewNavigator.VIEW_INVENTORY_SCENE);
- // return this;
- // }
- //
- // @FXML
- // private void filter() {
- // ObservableList<VideoGame> gamesList;
- // gamesList = controller.filter(publishersCB.getSelectionModel().getSelectedItem(), platformsCB.getSelectionModel().getSelectedItem(), yearSlider.getValue());
- // allVideoGamesLV.setItems(gamesList);
- // }
- //}
- //<?xml version="1.0" encoding="UTF-8"?>
- //
- //<?import javafx.geometry.Insets?>
- //<?import javafx.scene.control.Button?>
- //<?import javafx.scene.control.ComboBox?>
- //<?import javafx.scene.control.Label?>
- //<?import javafx.scene.control.ListView?>
- //<?import javafx.scene.control.Slider?>
- //<?import javafx.scene.layout.BorderPane?>
- //<?import javafx.scene.layout.ColumnConstraints?>
- //<?import javafx.scene.layout.GridPane?>
- //<?import javafx.scene.layout.HBox?>
- //<?import javafx.scene.layout.RowConstraints?>
- //
- //<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="480.0" prefWidth="640.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="edu.orangecoastcollege.cs272.ic14.view.VideoGamesListScene">
- // <top>
- // <GridPane vgap="10.0" BorderPane.alignment="CENTER">
- // <columnConstraints>
- // <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
- // <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
- // </columnConstraints>
- // <rowConstraints>
- // <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
- // <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
- // <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
- // </rowConstraints>
- // <children>
- // <Label text="Select Platform:" />
- // <Label text="Select Publisher:" GridPane.rowIndex="1" />
- // <Label text="Filter Year:" GridPane.rowIndex="2" />
- // <Slider fx:id="yearSlider" blockIncrement="5.0" majorTickUnit="11.0" max="2015.0" min="1982.0" minorTickCount="2" onMouseDragged="#filter" showTickLabels="true" showTickMarks="true" GridPane.columnIndex="1" GridPane.rowIndex="2" />
- // <ComboBox fx:id="platformsCB" onAction="#filter" prefWidth="200.0" GridPane.columnIndex="1" />
- // <ComboBox fx:id="publishersCB" onAction="#filter" prefWidth="200.0" GridPane.columnIndex="1" GridPane.rowIndex="1" />
- // </children>
- // <BorderPane.margin>
- // <Insets bottom="10.0" left="10.0" right="10.0" top="10.0" />
- // </BorderPane.margin>
- // </GridPane>
- // </top>
- // <center>
- // <ListView fx:id="allVideoGamesLV" prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER" />
- // </center>
- // <bottom>
- // <HBox alignment="CENTER" prefHeight="40.0" prefWidth="200.0" spacing="50.0" BorderPane.alignment="CENTER">
- // <children>
- // <Button mnemonicParsing="false" onAction="#addGameToInventory" text="Add Game to Inventory" />
- // <Button mnemonicParsing="false" onAction="#viewInventory" text="View Inventory" />
- // </children>
- // </HBox>
- // </bottom>
- //</BorderPane>
- //public class TestDBModel
- //{
- //
- // private static final String DB_NAME = "cs272_test.db";
- // private static final String TABLE_NAME = "car";
- // private static final String[] FIELD_NAMES = { "id", "make", "description", "horsepower", "fuelType", "cityMPG", "hwyMPG", "hybrid" };
- // private static final String[] FIELD_TYPES = { "INTEGER PRIMARY KEY", "TEXT", "TEXT", "INTEGER", "TEXT", "INTEGER", "INTEGER", "INTEGER" };
- //
- // private static DBModel db;
- //
- // private String[] values;
- //
- // // Set up before class defines variables, resources, etc
- // // Static method, so only executes once before all testing begins
- // // Anything you need to setup before testing, do it here
- // @BeforeClass
- // public static void setUpBeforeClass() throws Exception
- // {
- // // Instantiate our database
- // db = new DBModel(DB_NAME, TABLE_NAME, FIELD_NAMES, FIELD_TYPES);
- // }
- //
- // // Tear down after class cleans up any open resources
- // // Static method, only executes once at the end of all testing
- // @AfterClass
- // public static void tearDownAfterClass() throws Exception
- // {
- // db.close();
- // }
- //
- // // set up is executed before each individual test
- // @Before
- // public void setUp() throws Exception
- // {
- // values = new String[] { "1", "BMW", "2018 M3 Manual", "300", "Gas", "25", "45", "0" };
- //
- // }
- //
- // // tear down is executed after each individual test
- // @After
- // public void tearDown() throws Exception
- // {
- // db.deleteAllRecords();
- // }
- //
- // @Test
- // public void testGetAllRecords()
- // {
- // try
- // {
- // db.getAllRecords();
- // }
- // catch (SQLException e)
- // {
- // fail("Getting all records on empty database should not generate SQLException");
- // }
- // }
- //
- // @Test
- // public void testGetRecord()
- // {
- // try
- // {
- // db.createRecord(Arrays.copyOfRange(FIELD_NAMES, 1, FIELD_NAMES.length), Arrays.copyOfRange(values, 1, values.length));
- // assertTrue("Before deletion, count should be positive", db.getRecordCount() > 0);
- // db.getRecord(FIELD_NAMES[1]);
- // }
- // catch (SQLException e)
- // {
- // fail("Getting record on empty database should not generate SQLException");
- // }
- // }
- //
- // @Test
- // public void testGetRecordCount()
- // {
- // try
- // {
- // db.createRecord(Arrays.copyOfRange(FIELD_NAMES, 1, FIELD_NAMES.length), Arrays.copyOfRange(values, 1, values.length));
- // assertEquals("Testing to see if record count is 1 after creating a record.", 1, db.getRecordCount());
- // db.createRecord(Arrays.copyOfRange(FIELD_NAMES, 1, FIELD_NAMES.length), Arrays.copyOfRange(values, 1, values.length));
- // assertEquals("Testing to see if record count is 2 after creating a record.", 2, db.getRecordCount());
- // db.deleteRecord("1");
- // assertEquals("Testing to see if record count is 1 after deleting a record.", 1, db.getRecordCount());
- // db.deleteRecord("2");
- // assertEquals("Testing to see if record count is 0 after deleting a record.", 0, db.getRecordCount());
- // }
- // catch(SQLException e)
- // {
- // fail("Getting record count should not generate SQLException");
- // }
- // }
- //
- // @Test
- // public void testCreateRecord()
- // {
- // try
- // {
- // assertEquals("Testing creation of car with id provided", 1, db.createRecord(FIELD_NAMES, values));
- // assertEquals("Testing the count of records", 1, db.getRecordCount());
- // assertEquals("Testing creation of car, no id provided", 2, db.createRecord(Arrays.copyOfRange(FIELD_NAMES, 1, FIELD_NAMES.length), Arrays.copyOfRange(values, 1, values.length)));
- // assertEquals("Testing the count of records", 2, db.getRecordCount());
- // }
- // catch (SQLException e)
- // {
- // e.printStackTrace();
- // fail("Creation of records should not generate SQLException");
- // }
- //
- // try
- // {
- // db.createRecord(FIELD_NAMES, values);
- // fail("Creating a record with a duplicate id should generate a SQLException.");
- // }
- // catch (SQLException e)
- // {
- // // Expected
- // }
- // }
- //
- // @Test
- // public void testUpdateRecord()
- // {
- // try
- // {
- // db.createRecord(Arrays.copyOfRange(FIELD_NAMES, 1, FIELD_NAMES.length), Arrays.copyOfRange(values, 1, values.length));
- // assertTrue("Update should be successful", db.updateRecord("1", Arrays.copyOfRange(FIELD_NAMES, 1, FIELD_NAMES.length), Arrays.copyOfRange(values, 1, values.length)));
- // assertFalse("Update should be successful", db.updateRecord("1", FIELD_NAMES, Arrays.copyOfRange(values, 1, values.length)));
- // assertTrue("Update of id that does not exist should return true", db.updateRecord("10", Arrays.copyOfRange(FIELD_NAMES, 1, FIELD_NAMES.length), Arrays.copyOfRange(values, 1, values.length)));
- // }
- // catch (SQLException e)
- // {
- // fail("Update of records should not generate SQLException");
- // }
- // }
- //
- // @Test
- // public void testDeleteAllRecords()
- // {
- // try
- // {
- // db.createRecord(Arrays.copyOfRange(FIELD_NAMES, 1, FIELD_NAMES.length), Arrays.copyOfRange(values, 1, values.length));
- // assertTrue("Before deletion, count should be positive", db.getRecordCount() > 0);
- // db.deleteAllRecords();
- // assertEquals("Count after deletion should be 0.", 0, db.getRecordCount());
- // }
- // catch (SQLException e)
- // {
- // fail("Deletion should not generate an SQLException.");
- // }
- // }
- //
- // @Test
- // public void testDeleteRecord()
- // {
- // try
- // {
- // db.createRecord(Arrays.copyOfRange(FIELD_NAMES, 1, FIELD_NAMES.length), Arrays.copyOfRange(values, 1, values.length));
- // assertTrue("Before deletion, count should be positive", db.getRecordCount() > 0);
- // db.deleteRecord("1");
- // assertEquals("Count after deletion should be 0.", 0, db.getRecordCount());
- // }
- // catch (SQLException e)
- // {
- // fail("Deletion should not generate an SQLException.");
- // }
- // }
- //
- //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement