Testing Our Service and DAO5:08 with Chris Ramacciotti
In this video we boot our application to see our category service and DAO in action.
Git Command to Sync Your Code to the Start of this Video
git checkout -f s2v6
Using Github With This Course
You can complete this course entirely using code created by you on your local machine. However, if you choose to use the code I've made available to you, you have two options:
- Use the project files linked at the bottom of this page, or
- Use the Github repository I've made available (recommended)
If you choose the recommended option of using the Github repository, it can be found at
To utilize Github with this course, you can download the Github desktop client for your system or use the command line interface provided with Git.
Clone this repository to your machine using the Github desktop client, or using the following command:
git clone firstname.lastname@example.org:treehouse/giflib-hibernate.git
To update your local repository to match a video's starting point, you can use the
git checkout command in combination with the stage and video number. For example, to update your local repository to match the starting point of Stage 5, Video 4, you'd use the following:
git checkout -f s5v4
Notice the use of the -f option. This forces Git to override all local changes, so be aware: this will cause any changes you made to be lost.
Hey, great work over those last few videos. 0:00 You now have three application layers, 0:03 and hopefully a working implementation of those layers for category. 0:05 We have plenty of work left to do in giflib, but 0:09 we should fire it up now to make sure we're on the right path. 0:11 With our interfaces and implementations for category DAO and 0:16 service in place, and with our auto wired service in the category controller, 0:19 let's fire up our application. 0:23 Now, I'm assuming that your database server is still running, and 0:25 you've already inserted a row into the category table. 0:29 If not, we'll insert a second row in just a moment. 0:32 With that said, I'm gonna go ahead and run my boot run task. 0:34 If your server is still running, go ahead and hit the Stop button and 0:38 then you can rerun the task and let's see what happens here. 0:42 To make sure that everything compiles successfully and 0:47 that the spring application boots successfully without exceptions. 0:50 Looks like my application did indeed start successfully. 0:55 So let's switch to the browser. 1:00 Let me refresh this categories view to see if I still get my one category to display. 1:04 When I refresh and looks like I still successfully 1:09 grab that category using my new service DAO pattern. 1:14 Now, how about we switch to that H2 web console and 1:18 see what happens if we insert another row into the category table. 1:21 So I will go back here. 1:25 And let's do insert into category (name, 1:26 colorcode), we'll insert the values. 1:31 I'll put Java, remember that's a string. 1:36 Don't forget the single quotes as well as the hexadecimal code for 1:38 this color or whatever color you like, 35986. 1:44 Let's insert that, we'll run that. 1:49 If you get this message that simply means that your session has expired and 1:53 all you have to do is log in again. 1:57 Of course, you're gonna have to run that query again. 1:59 insert into category (name, 2:02 colorcode) values). 2:07 Get my codes in their first ('Java' 2:11 #b35986, let's try that one more time. 2:15 Cool. 2:21 Update count is one which means my row was inserted. 2:22 Now, what should happen is that when I flip back here and refresh my page, 2:26 I should see both of those categories technology and Java. 2:30 There it is. 2:34 Now, you might be wondering why the colors are the same since we 2:36 definitely chose different color codes for these categories. 2:39 Well, it's all about how the HTML and CSS is coded in this case. 2:43 And for this particular piece, the color is specified in the time leaf template. 2:48 And just so that we don't go too far in this course before interacting with our 2:52 timely views, let's open that now to prove that we can make noticeable changes. 2:56 So I'll switch back to IntelliJ, and I'm going to open the category Index Template. 3:02 So under templates, and category, let's open that index template. 3:09 Now, if we scroll down here, you'll eventually see a div 3:14 with a static background color set in its style attribute. 3:19 Now, you may have learned the rule of keeping your styling in your CSS files and 3:25 out of your HTML if you've done any front-end work. 3:29 But as with any rule, there are certainly exceptions. 3:32 If there is user data that's used to add custom styling to a page, 3:35 such as is the case here with a user specified color, this may be one of 3:39 those few scenarios where it's common practice to place that within the HTML. 3:44 In this case, we can prefix the style attribute with th or like this. 3:49 So that timely for process this attribute. 3:54 And you sometime leave concatenation to combine the background color with this 3:56 category objects color code field value. 4:01 So to trigger concatenation, we can use the vertical bars or the pipe symbol. 4:06 And instead of this statically set code we can place this expression, 4:13 cat.colorcode. 4:18 Now, let's save this template and reboot our application. 4:22 So I'll stop this spring app. 4:26 Let me trash that output there. 4:29 And I will rerun the boot run task. 4:32 And give it a moment to compile and to boot. 4:36 And let's switch back to the browser and refresh so I'm back here and 4:42 I'm going to refresh. 4:46 All right. 4:49 Look at those colors, pretty cool. 4:50 We've now touched all the layers of the apple both in the MVC architecture 4:52 as well as within the service DAO pattern. 4:56 In the next stage, we'll add a whole bunch of features to our app, allowing our 4:59 users to interact with the underlying data via our nicely designed user interface. 5:03
You need to sign up for Treehouse in order to download course files.Sign up