Repository navigation
Expand file tree
/
Copy pathClassTest.java
More file actions
111 lines (81 loc) · 3.14 KB
/
Copy pathClassTest.java
File metadata and controls
111 lines (81 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package test;
import java.sql.SQLException;
import database.bean.Admin;
import database.bean.ModularClass;
import database.managers.ConnectionManager;
import database.managers.DatabaseManager;
import database.managers.ModularClassManager;
import exception.InvalidAdminException;
import utils.BeanType;
import utils.ValidationType;
public class ClassTest
{
public static void main(String[] args)
{
// First and very important step is to specify the Admin that is
// making the change as follows
Admin currentAdmin = new Admin("Chidi", "OguejioforTheGreat" );
DatabaseManager.setCurrentAdmin(currentAdmin);
// Rest of the code
try
{
TestUtils.displayBean(BeanType.MODULAR_CLASS , 0 );
System.out.println("---------------CREATING A NEW CLASS TEST--------------");
String name = TestUtils.getStringInput("Enter the new class name: ");
ModularClass modClass = new ModularClass(name );
if( ModularClassManager.createNewClass(modClass) ) {
System.out.println("Successfully created a new class and "
+ "also gave updated the dateCreated attribute.");
TestUtils.displayBean(BeanType.MODULAR_CLASS , 0 );
}
else
{
System.out.println("Was Unsuccessful for unknown reasons!!!");
}
System.out.println("---------------REMOVING AN EXISTING CLASS TEST--------------");
name = TestUtils.getStringInput("Enter the new class name: ");
modClass = new ModularClass(name );
if( ModularClassManager.removeClass(modClass ) ){
System.out.println( "Class was removed succcessfullly!!!");
TestUtils.displayBean(BeanType.MODULAR_CLASS , 0 );
}
else
{
System.out.println("Nothing was removed! "
+ "Maybe the class name you inputed is not in the database");
}
System.out.println("---------------UPDATING AN EXISTING CLASS TEST--------------");
name = TestUtils.getStringInput("Enter the existing class name: ");
String newName = TestUtils.getStringInput("Enter the new class name: ");
modClass = new ModularClass(name );
System.out.println("Validation Result:: "+ modClass.isValid(ValidationType.EXISTING_BEAN ));
ModularClass newClass = new ModularClass( newName);
if( ModularClassManager.update(modClass, newClass) ){
System.out.println( "Class was updated succcessfullly!!!");
TestUtils.displayBean(BeanType.MODULAR_CLASS , 0 );
}
else if( !(modClass.isValid(ValidationType.EXISTING_BEAN ) &&
newClass.isValid(ValidationType.NEW_BEAN))){
System.err.println("Invalid Bean format");
}
else
{
System.out.println("Nothing was removed! "
+ "Maybe the class name you inputed is not in the database");
}
}
catch ( InvalidAdminException e)
{
System.err.println( e );
System.err.println("The Admin was invalid");
}
catch (SQLException e)
{
e.printStackTrace();
}
finally{
// This is also very important. Close the ConnectionManager
ConnectionManager.close();
}
}
}