The following page is a set of FAQs that have been put together by past and present CSC 326 TAs and students. Some of these ought to be considered advice, which we encourage you to use with appropriate discernment. If you have something you would like to add or modify, please contact your current TA or an iTrust project admin.
The Eclipse Debugger tutorial provides a step-by-step explanation of how to use the debugger.
For more information on how to perform debugging in general, see Using the Eclipse Debugger tutorial.
There is a possibility that you are only using local databases for your semester. If your TA never gave you remote database information, then don't worry about this part.
Your TA should give you a username, password, URL, and database name (sometimes the database name is combined with the URL). Here's how you connect:
username="astudent" password="astudentspassword" url="jdbc:mysql://theserver.csc.ncsu.edu:3306/astudentsdatabase" ... other stuff that needs no modification ... />
If you still cannot connect:
You will have to be running a local instance of MySQL, and it should be started. Check that these items are true.
username="astudent" password="astudentspassword" url="jdbc:mysql://localhost:3306/astudentsdatabase" ... other stuff that needs no modification ... />
If you still cannot connect:
Please make sure that the CREATE TABLE statement generally matches the format and structure of the other tables in createTables.sql. Use similar column types and table options, rather than simply copying straight from some auto-generated code. Please keep the engine as MyISAM.
First, decide who will have access to the JSP. If it's any user, then you can place it in /WebRoot, but pages which require certain authentication levels should go in the appropriate subfolder of /WebRoot/auth. For example, a page which is accessible only to administrators should go in /WebRoot/auth/admin. Right click in the appropriate folder and go to New → File. The figure below shows the creation of a new file which is accessible only to administrators.
On the box that comes up, type in the filename followed by .jsp. This will create your file as a new JSP page.
Every page in iTrust must start with <%@include file=”/global.jsp” %> This includes the global resources and variables that an iTrust JSP will typically use.
If you would like to set a title (in the browser title bar) for the page, you can include the following line:
<%
pageTitle = “iTrust - ER Home”;
%>
Next, every JSP in iTrust must contain <%@include file=”/header.jsp” %> and end with <%@include file=”/footer.jsp” %>. These JSP fragments contain the HTML rendered for the appropriate user which have the context-appropriate menu and typical layout for an iTrust page.
The contents of the page go in between these lines. Thus, the whole body of the page will something like the following figure:
Most pages in iTrust should contain a structure resembling the one in the following figure.
If you want to catch and handle exceptions which come from iTrust classes (such as an Action class or a DAO) in the JSP, you will need to add the following line to the top of the JSP:
<%@page errorPage=”/auth/exceptionHandler.jsp” %>
This is the simplest way to catch any exception which may come from the methods in iTrust classes you may call. This setup will not catch certain types of exceptions, however, and the safest way to ensure that your code fails gracefully is to catch any exceptions which may occur in the method you call and throw it as an iTrustException. If you desire more control over how exceptions are handled, read on.
If you wish to place your specific error messages within a certain segment of the page, consider the example provided by /WebRoot/auth/staff/editMyDemographics.jsp presented in the figure below.
The call to the action class is placed in a try block, and the code following the successful call returns an informational message telling the user that the action was successful. This result goes in a iTrustMessage span, which is green and indicative of a positive result. In the case of an exception, the catch block returns the error message (with e.getMessage()) and presents it to the user in a well-formatted iTrustError span. Note that not all errors received by this example will be of type FormValidationException– for example, the database could go out. This is why editMyDemographics.jsp also includes the exception handler as mentioned above at the top of the page with the line:
<%@page errorPage=”/auth/exceptionHandler.jsp” %>
Also, note that DBExceptions are formed from SQLException, printed out the console, and then a really vague error is shown to the user. This is intentional. For security reasons, database information should not become available to users. Note that you should alway print this out to the console so that you can trace your exception.
This is best practice for handling other types of exceptions which may occur.
Use a Validator. Make sure that you validate input so that all errors are reported at once. This usually takes the form of:
ErrorList errorList = new ErrorList(); errorList.addIfNotNull( ... ); //bunch of these if (errorList.hasErrors()) throw new FormValidationException(errorList);
There's a whole host of regex's and other utility methods that can be used. If you have trouble generating the correct regex, look at some of the other examples and compare them to the requirements of how th
A good example of a validator is PersonnelValidator.
We recommend using the built-in launch configuration, which will reset the database (via DBBuilder) prior to your unit tests.
If this is your first time running the iTrust unit tests, there are two ways to start them. The easiest is to right-click the file iTrust Unit Tests.launch in the package explore and go to Run As → iTrust Unit Tests as in the figure below.
Another way is to go to Run > Run Configurations… at the top menu. Within the Run Configurations dialog, select iTrust Unit Tests and run that.
If you have executed your unit tests before, they should be in your recent runtime configurations. Click the arrow to the right of the “Play” arrow and select “iTrust Unit Tests” from the menu that appears, as in the following figure.
If you cannot find the .launch file, you can also right-click the unittests source folder and go to Run As → JUnit Test, as in the following figure. Note: this will effectively run your unit tests twice, as this method considers the AllTests.java suite as a single test. We do not recommend this approach.
JUnit will allow any of these execution units if you specify it in the package explorer when right-clicking. The following figures show executing a package of tests and then a single JUnit test case (method), respectively.
If you have executed your HTTP tests before, they should be in your recent runtime configurations. Click the arrow to the right of the “Play” arrow and select “iTrust HTTP Tests” from the menu that appears, as in the following figure.
If this is your first time running the iTrust HTTP tests, there are two ways to start them. The easiest is to right-click the file iTrust HTTP Tests.launch in the package explore and go to Run As → iTrust HTTP Tests as in the figure below.
If you cannot find the .launch file, you can also right-click the httptests source folder and go to Run As → JUnit Test, as in the following figure.
NOTE: These instructions are for dropping and re-creating the table definitions (“database schema”). Most times, you probably just want to reset the test data, for which there are instructions in the next section.
There are two ways to reset the database: using the saved launch configuration or manually finding and executing the Java application.
To reset the database using the saved launch configuration, just right click the file DBBuilder.launch and go to Run As → Java Application as in the figure below.
To reset the database by manually finding the Java application, execute the file DBBuilder, which can be found in src → unittests → DBBuilder.java as in the following figure.
NOTE: You can reset the data that is used for manual testing by these instructions. However, if you feel (or know) that you would like to drop and recreate all the iTrust tables in your database, you should see the other section on “reset the database”.
To reset the test data, execute the file TestDataGenerator.java as a Java application, which is located in unittests → edu.ncsu.csc.itrust → datagenerators → TestDataGenerator.java. The following two figures show how to execute the existing saved launch configuration, and how to execute this file manually, respectively.
In the JUnit setUp() method, insert a call to
TestDataGenerator.clearAllTables() TestDataGenerator.standardData()
See the existing unit tests for an example of the convention for best practice in iTrust tests.
When it comes to using TestDataGenerator, we follow a few conventions:
See above.
Fixing a bunch of broken tests can be painful, as re-running the whole unit tests suite (or HTTP test suite) can be slow. Here's a tip:
Here's a shot of your JUnit history:
(clear the tables, use the stacktraces, make sure expected values are correct, try the test by itself)
BeanBuilder is a utility that transfers parameter maps given by the JSP pages into a bean. BeanBuilder is intended to be used in the JSP, and the returning bean be passed to the Action class. The utility works by introspecting the bean, looking for all “setters”. If a setter exists, then the utility will look up the name of the setter property in the parameter map, and then put the value into the setter. For example, if a bean has “setName”, then the property name is “name”.
Make SURE you get this right in your JSP by naming your HTML fields correctly, otherwise your parameter will not be passed into the Action class. Also, don't overload a setter - just name them differently. For example, use setDateOfBirthStr(String str), instead of overloading setDateOfBirth with both a string and date type. If BeanBuilder is used on a bean that is overloaded, then an exception will be thrown.
See /WebRoot/auth/getPatientID.jsp for an example. Include the getUserScript.jspf, then make sure you pass the name of your hidden HTML value correctly.
See /WebRoot/auth/hcp-uap/editPHR.jsp for an example. Send a forward to getPatientID.jsp, passing your current URL as the parameter “forward”.
See /WebRoot/auth/hcp-uap/editPatient.jsp for an example. Include the DatePicker.js, which is located at: /WebRoot/js/DatePicker.js For a button (or any js event), call the function: displayDatePicker('PARAM'), where PARAM is the name of your HTML field
DAOFactory is a triple-singleton (tripleton?). It has exactly three instances…
Also note that when in a DAO, you should use the “factory” variable to call other DAOs - since you don't know which instance is currently being used.
The Patient Navigation tag (ie <itrust:patientNav /> ) is supposed to be used to navigate from patient pages. To use it, you need to include the library at the top of your JSP: And then use it in your code with the following attributes
This is to be used to make the State select tag easier.
For example:
<itrust:state name="icState" value=""/>
(Will describe more in-depth, but: work iteratively, prioritize well, test a lot, test along the way, start early, ask questions, listen to the TA)
(Will describe more in-depth, but: set deadlines, alert TA as early as possible, start early, we do look at PairEval, be polite but firm)
We have a tutorial which illustrates how to execute this task.
We have a tutorial which illustrates how to execute this task.
(work iteratively, make a to-do list, better to have a half-working feature than half the code to work)
(polite, constructive - you'd be surprised how much we've improved this class from student feedback)
x