Oct 18 2009

Droid Does…

Category: MiscPhil @ 5:55 am

I like anything that gives Apple a little jab… and am looking forward to Verizon releasing some interesting new phones. Verizon just created a new sub-site, http://www.verizonwireless.com/droid. I think it is actually a pretty good campaign, “iDon’t”. I have been using Windows Mobile for many years, and I will be the first to say that it has be be considered a complete failure; but similar to the old Palm OS, there have always been a multitude of free applications with no Steve restrictions. My primary need for a Windows-based phone was the integration with Outlook, which allowed me to sync my calendar, contacts, email, etc; which did work flawlessly. I have never been into the whole Android thing, as I am no fan of “single” source solutions, such as that iThing. But, now that Verizon and several other carriers are planning to release phones, and even Acer has released a new Android-based netbook, I’m starting to get a little more interested!


Jun 14 2009

New Trees… Like we don’t have enough!

Category: MiscPhil @ 6:40 pm

Fortunately, we only lost a couple of trees last summer due to the drought.  Unfortunately, there were both relatively close to the house, so they really needed to be replaced. Amazingly, there were only two trees on our lot when we purchased it, now there are over two hundred! Call me crazy, I push mow around all of them before mowing with the big mower! I can’t believe how these trees have grown; we purchased about 150 Evergreens that were only 18 inches tall; many of them are over 10 fee tall now. Pretty cool!

We found a nice little nursery up in Frederick MD this weekend,  The Dutch Plant Farm. We live far enough to the west, that we can actually go up to Frederick, out to Winchester, or over to West Virginia; the distance is about the same any direction we go! The staff was very helpful and the prices were more reasonable than some of the big Northern Virginia nurseries.

One of the trees we lost was a six year old Japanese Maple. We wanted to replace it with another one, but were a little worried about their hardiness and cost. Between the hot, humid summers, too much rain, not enough rain, and the crazy amount of wind we get in the winter, we have some pretty tough tree growing conditions!  We ended up purchasing a different variety of Japanese Maple, one that was a little more tolerant of direct sunlight, a Red Dragon.  I obviously need to do some mulching, but it is a really pretty tree. The other tree we lost was a Harry Lauder Walking Stick; it was several years old too, but never really did that well.  We decided to replace it with a Raspberry Sundae Crapemyrtle. Living in the south, you see so many Crapemrytles, I think they are one of my favorites; especially when they start blooming. Hopefully, they will both survive the summer heat; I guess I will just have to keep up with my watering!


May 19 2009

How to customize your jUnit Behavior and Interaction

Category: Java, Misc, Testing, UbuntuPhil @ 8:17 pm

I have tried to walk through the jUnit source code a couple of times, trying to figure out how to implement my own behavior; only to give up in frustration (no I did not read the documentation, real developers don’t do that, they Google!) Why would I want to implement my own behavior? Well, it always seems to center around integrating with Spring. I usually want/need to do control the way the context is being created or do something immediately before the context is loaded or as the context is loading; something that might not be possible not possible using a @BeforeClass annotation.

This problem was actually related to my previous blog on Implementing Custom Scopes in Spring. Because I implemented some beans using the session scope, I kind of created a catch-22 scenario;  I have tried to capture the problem in bullet form:

  • Each jUnit test needs the ability to specify the specific test user (role, user info, etc.) that is relevant for that individual test
  • The test user profiles are configured and controlled by a Spring managed bean
  • All beans are lazy-init = true and injected into the unit test using the @Resource annotation
  • The session scope beans need to have the SecurityContextHolder configured with the appropriate principal (test user), before they are created
  • So, the problem is: How do you specify the test user, before the session scope beans are created and injected into the unit test class?

In a normal execution environment, using the Spring Security filters and a Servlet, the SecurityContextHolder would have been assigned using the authenticated principal, before creating any Spring dependencies. Because I created my own custom scopes for unit testing, the SecurityContextHolder was null and the session scope beans constructor was failing an assertion (principal != null). I could have easily fixed this by adding a pre-authenticated user to the SecurityContextHolder, using some static method approach,. However, because my mechanism for handling test users was itself a Spring bean, I had no possible way of specifying before the beans were injected into my unit test.

When jUnit 4.0 was released, it added several new constructs that make some very elegant solutions. I don’t think most developer’s ever look beyond the base jUnit functionality; fortunately it seems to solve 99% of the typical test scenarios. The new constructs are actually specified via annotations, they are the @RunWith and @TestExecutionListeners. My example code, can probably be made a little cleaner, but my main goal was to get the unit tests working. Because you don’t directly create any of these objects, you have to be aware of the timing; implement your customizations at  the correct point in the lifecycle. Another interesting problem, is that you don’t actually create the Spring Context, but you can interact with it via listeners.

First, we need a class which extends DependencyInjectionTestExecutionListener. This base class is required when using Spring and provides several override-able methods. I needed to configure the SecurityContextHolder, before any beans were injected into the unit test; I could accomplish this by utilizing the injectDependencies method. To support my testing needs, I added two (2) properties to the sub-class (this could have been cleaner); one to specify a user from a “user provider” factory, and a simpler one that used the user id of the person running the test. As you can see from the code, before an beans are injected into the unit test, I have access to the Spring context. This allows me to request the “user provider” factory and then request a specific test user. At this point, I can now assign the user to the SecurityContextHolder; all before any of the session scope beans are created.

public class AuthorizedTestExecutionListener extends DependencyInjectionTestExecutionListener {

    private TestUserAuthorization defaultAuthorization;
    private String                junitAuthorization;

    public void setJunitAuthorization(final String junitAuthorization) {
       this.junitAuthorization = junitAuthorization;
    }

    public void setDefaultAuthorization(final TestUserAuthorizationdefaultAuthorization) {
       this.defaultAuthorization = defaultAuthorization;
    }

    @Override
    @SuppressWarnings("PMD.SignatureDeclareThrowsException")
    protected voidinjectDependencies(final TestContext testContext) throws Exception {
       if (StringUtils.isNotBlank(junitAuthorization)) {
           final Authentication login = new UnitTestAuthenticationToken(this.getClass().getSimpleName());
           SecurityContextHolder.getContext().setAuthentication(login);
       }
       else if (defaultAuthorization != null) {
           finalTestUserModuleManager manager = (TestUserModuleManager) testContext.getApplicationContext()
                    .getBean(defaultAuthorization.testUserManager());
           final SecureUserInterface user = manager.find(defaultAuthorization.principal());
           final Authentication login = new UnitTestAuthenticationToken(user);
            SecurityContextHolder.getContext().setAuthentication(login);
        }

       super.injectDependencies(testContext);
    }
}

Next, we need to extend SpringJUnit4ClassRunner. This class is responsible for for creating the Spring test context and  DI listener class.  By over-ridding the  createTestContextManager, you have the opportunity to configure the test execution listeners.  I  also created two custom annotations, TestUserAuthentication and  JUnitAuthentication.  Using either one of these annotations, I could provide run-time meta-data  to my  custom AuthorizedSpringjUnit4ClassRunner; the meta data was then used to configure my custom  AuthorizedTestExecutionListner.

public class AuthorizedSpringjUnit4ClassRunner extends SpringJUnit4ClassRunner {

    public AuthorizedSpringjUnit4ClassRunner(final Class<?> clazz) throws InitializationError {
       super(clazz);
    }

    @Override
    @SuppressWarnings("PMD.ConfusingTernary")

    protected TestContextManager createTestContextManager(final Class<?> clazz) {

       final TestUserAuthorization defaultUser = clazz.getAnnotation(TestUserAuthorization.class);
       final JUnitAuthorization jUnitUser = clazz.getAnnotation(JUnitAuthorization.class);

       final TestContextManager context = super.createTestContextManager(clazz);

       for (final TestExecutionListener l : context.getTestExecutionListeners()) {
           if(AuthorizedTestExecutionListener.class.isAssignableFrom(l.getClass())) {
               if (defaultUser !=null) {
                    ((AuthorizedTestExecutionListener) l).setDefaultAuthorization(defaultUser);
                }
               else if (jUnitUser != null) {
                    ((AuthorizedTestExecutionListener) l).setJunitAuthorization(clazz.getSimpleName());
                }
            }
        }
       return context;
    }
}

Once you understand what all of the pieces do, they are super easy to customize to provide enhanced behavior. I think my solution provided a very clean, elegant solution for providing test specific user profiles, on a test by test basis.

@RunWith(AuthorizedSpringjUnit4ClassRunner.class)
@TestExecutionListeners(AuthorizedTestExecutionListener.class)
@ContextConfiguration(locations = {//
"/com/beilers/resources/spring/contexts/jUnitContext.xml" //
})

public class UnitTestHelper {
...
}


Jan 31 2009

Life on Pause….

Category: MiscPhil @ 11:08 am

Kind of amazing, I am almost recovered from a two week stint with pneumonia. I don’t know where the last two weeks went. Fortunately, I was not hospitalized, basically just confined to my house (my bed) for most of that time. The weird part is thinking about all of the stuff I have not done for a while:

  • I gave up reading, no RSS feeds, no books, minimal email. Most of the time, I had such a bad headache, it was practically impossible to think about anything, other than trying to stay warm and not induce coughing fits.
  • I have not worked out in two weeks. I guess I have a pretty good excuse, if you have no lung capacity and can’t breath, it is pretty hard to work out. The funny thing is that I lost 4 pounds towards my New Year Resolution goal. I guess you really don’t need to work out, just eat chicken soup and lots of water (Sprite in my case!)
  • I was listening to Pandora all of the time; I would crank up my “Nickelback Radio” every morning when I got to work. I guess I actually stopped listening to music all together; I would listen to music in the morning when I worked out too.
  • I listen to the Sports Junkies everyday on my way to work. I have only been in the car about thee times, and that was to drive to doctor’s appointments; not much car time! I should have saved some serious gas money this month! The Junkies are a pretty entertaining show, at least I will able to hear their Super Bowl recap on Monday morning, as that will be my first day back to work.
  • I don’t think I’ve been to church but one time this month. I think someone in our house has been sick every weekend this month. Hopefully, we can start February off on the right foot.

I guess we are all creatures of habit and have our little routines. I never thought much about my routine before, it was just automatic. So, just how routine should life be? This is not the kind of “spice” I wanted to break up my routine, but probably a good eye-opener. We should all work to find ways to break up the daily routine every so often. Life might get pretty dull when it is just work, doing laundry, mowing the grass, doing homework, making the kids practice their instruments… the list goes on an on! I don’t know what the right answer is, but it does give me more to think about!


Jan 04 2009

New Years Resolutions

Category: MiscPhil @ 11:14 am

I know it is a couple of days late, but it is hard to think about resolutions when you are traveling! On the way back from Ohio, I heard a statistic on the radio that said over 50% of people don’t even bother with New Years Resolutions anymore. The primary reason for not making a resolution was because they knew they would not succeed. That seems kind of sad, doesn’t it? Yet another old tradition that is going by the wayside, as society changes for the better(?). What bothers me most, is that I thought New Year’s resolutions were the one time a year where everyone had the chance to think about making some small changes in their lives for the better. Hopefully making them better or healthier people, or maybe even doing something that would make the world a better place.

Without resolutions, when does this happen? I don’t think the world is really into continuous improvement, something that I take very seriously in my professional life, but only recently have thought about from a personal level. I thought that I would use this opportunity to actually state my improvement goals in the form of some resolutions.

  • Be a better father, husband, and brother
    • This one is kind of hard to put in words, but my boys are getting older and I need to make sure that I “walk the talk”. They are great kids, but I need to keep re-enforcing my beliefs and morals, I only have a few more years before they are out on their own!
    • Be more thoughtful and supporting as a husband. It will be 17 years of marriage this year, I know there are lots of things I can to better for the next 17 years.
    • Talk to my sister more. We get along fine, but we just never seem to take the time to talk, this should be easy to fix!
  • Try to do better on my heath and fitness.
    • I actually want to lose 10 more pounds, based on the number of magazine, radio, and television commercials I’ve seen this past week, I’m not alone!
    • I have been running about 2.5 miles a day for about 18 months. I also do a few sets of sit-ups and push-ups… I plan to keep this up.
    • I should give up soda, but I don’ think I can do that!!! But, I will work on eating better, better foods and sticking to smaller portions.
  • Learn, Play, Blog
    • This sounds kind of funny, but I find blogging is actually very constructive and really helps build your writing skills. I created about a hundred plus entries on my work blog last year, which I will now start creating here instead.
    • Blogging about your experiences helps cement the concepts in your mind and also makes them available to others to lean from. It is a win-win situation!
    • I setup home.beilers.com in my office on an Ubuntu box last summer. It was a great learning experience and a lot of fun. I plan to move this blog to a hosted site so I don’t have to be so dependent on my box. I also would like to setup a real site for my wife’s company.
  • Read More
    • I am not much of a reader, it seems to take so much time. I have become an avid RSS reader, reading feeds on my cell phone is such a convenience and makes reading much more possible for me.
    • I finished a monster book last year, Atlas Shrugged, what a great book. I can’t wait for the movie! I need to start reading some smaller ones… stay tuned!
  • Update my resume
    • Kind of obvious!

I hope my goals (resolutions) spark something in you as well…. I pray that this year will be less negative (the financial crisis) than 2008, and that we can all get back on the road to recovery. Happy New Year!


Jan 02 2009

Wonderful Ohio Roads…

Category: MiscPhil @ 8:41 pm

We just got back from a week long vacation in Ohio with my parents. We had a really nice time with the family, but it never takes long to remember why I moved to Virginia…. winter! Check out the truck, can you say salt? It was amazing to see all of the cars and trucks from Michigan, Ohio, and Pennsylvania, coated in white. No wonder you see so many rusted out old cars and trucks! What a difference a little soap and water makes! The truck looks pretty good for being nine years old, it only has about 80 thousand miles on it. Now that gas is back to a reasonable price, we can actually afford to drive it again!

Fortunately, we only had one day of snow, but it was quite cold at the end of the week. I guess being so close to Lake Erie makes the air much damper, which makes it feel a lot colder. We did not even feel like going out side, the cold air felt like it cut right through you. There was a 30 degree temperature change, from the time we left to the time we arrived at home. Gas was also about 25 cents cheaper a gallon in Virginia too! Nice to be back home!


Nov 23 2008

XBox (Hardware) = Pathetic

Category: MiscPhil @ 1:40 pm

I’m no gamer, but when you have have two boys (13 and 11), you can avoid it!  We purchased an XBox 360 last year for Christmas… can you say “excited” kids?  Anyway, that XBox lasted about two (2) weeks and we were introduced the the “Red Ring of Death”… Sounds like a really cool video game, right? Unfortunately, it means your XBox is toast! We returned it and decided to buy another one from Best Buy, only because they offered an extended warranty. Normally, we do not buy the warranty, but if you do a Google search on XBox reliablity, and you will see thousands of pages of people with issues…. I hoped it would be money well spent, at least it  would make it easier on the kids.

Needless to say,  less that eleven months later, we had our second failure, this time it was an E74. When I take it back to Best Buy tomorrow, I will find out the real value of the warranty. Rather than boxing it up and mailing it off to Microsoft, I believe I just take it back to Best Buy and they give me a new one… That’s the way it is supposed to work… I think… I hope!

The XBox hardware might be a piece of junk, but I do think they have a pretty nice on-line environment. It is really cool all of the stuff the kids can do on line. We installed the XBox Live 2.0 upgrade last week; it looked really cool from the few minutes I watched. I will be very interested to hear how the Netflix integration works out… unfortunately, we don’t have Netfix!!!!


Oct 13 2008

Monday Morning Fun…

Category: MiscPhil @ 7:54 am

It’s 6AM, I am on my way to work, it is a beautiful fall Monday morning. I’m cruising down Route 7, flying along with all of the other early birds, listening to the Sports Junkies,  and they my luck changes…  I swear he was almost standing there, stupid deer!  He might have been walking into the road, but who knows, it was pitch black at that time of the day. I kind of glanced off to my right and I saw his glowing gold eye right there in front of me… Pretty freaky to hit a deer with a Miata! All I know is there were cars all around me, so I did not have any way of missing him. When I hit it, the car actually went sideways. I did this swervy little maneuver and was able to recover.  My legs were I little shaky, it scared the crap out of me!  It does not look that bad in the picture, but the hood will not open and my car is now a cyclops! That stupid deer went down the whole side of the car,  the door and front an real panels are all creased!

The thing I don’t understand, why me?  This is actually the 4th deer that I have hit (plus several other close calls)! The first one basically totaled my car; the car was un-drivable after t-boning it. The next two were just side swipes, just taking of my mirrors for fun! One was kind of funny, it was a huge deer that actually ran into me when I was driving thru Round Hill! Put a nice dent in my door!

Unfortunately, the car does not want to turn to the right anymore, it makes some pretty bad noises… I need to crawl under it and pull out some fiberglass.  Hopefully the insurance company will be friendly!