IntelliJ Databases for Easy DBUnit Configurations

I use DBUnit for integration tests – It’s the biggest bang for my buck in terms of test coverage and ease. For the unitiated, DBUnit uses an XML schema to populate your database with test data, and can provide cleanup and assertions for the state of your database. Nifty. My only hangup is writing out verbose XML schemas. Given that your workflow surely involves a database already initiated with data for testing and developing against, why not just pull out that data to use for your test cases?

IntelliJ Ultimate – well worth the money – has a database access tool that will allow you to pull out records in various formats. The XML option unhelpfully pulls out each column as an XML element, and most surprisingly does not name the encompassing element for the database table where applicable. To easily convert a dozen rows into a flat XML schema for DBUnit’s consumption, select the JSON Data Extractor, then select and copy whatever records you need into your clipboard.

json-data-extractor

From here you can pretty easily convert the JSON documents into XML, but for the lazy, I’ve written some plan Javascript to be run in your browser’s developer console.

function createXmlElement(table, json) {
	var element = document.createElement(table);

	for (key in json) {
		element.setAttribute(key, json[key]);
	}
	
	return element.outerHTML.replace("></" + table + ">", " />");
}

function createXml(table, documents) {
	return documents.map(function(json) {
		return createXmlElement(table, json);
	}).join("\r\n\t");	
}

So just paste that into Chrome, and invoke it with your documents for a pretty-printed output. Tabs > Space, suckas!

createXml("norms", [{
  "norm_id": "2b6c0392-1841-4237-899d-2fe88ac47c7c",
  "attribute_id": "233bc966-4fcd-4b46-88e6-3e07090f322d",
  "lower_bound": 0.00,
  "ordering": 1
 },
 {
  "norm_id": "2b6c0392-1841-4237-899d-2fe88ac47c7c",
  "attribute_id": "233bc966-4fcd-4b46-88e6-3e07090f322d",
  "lower_bound": 0.00,
  "ordering": 2
 }
])

"<norms norm_id="2b6c0392-1841-4237-899d-2fe88ac47c7c" attribute_id="233bc966-4fcd-4b46-88e6-3e07090f322d" lower_bound="0" ordering="1" />
	<norms norm_id="2b6c0392-1841-4237-899d-2fe88ac47c7c" attribute_id="233bc966-4fcd-4b46-88e6-3e07090f322d" lower_bound="0" ordering="2" />"

Play! & IntelliJ Configurations

These are just some notes I’ve thrown together for setting up a new Play! framework project with IntelliJ. There are a few minor “gotchas” or minor details that I did not find up to snuff. The built-in command play idea works pretty-damned well at setting everything one would need, but it gets some little details wrong. Some of the following is general to Play’s generation of a new application, while the latter portion is specific to it’s integration with IntelliJ. Do note that I have written this guide against version Play! 2.2.1 and sbt 0.13.0 so things could be different depending on where you are.

Continue reading Play! & IntelliJ Configurations

Removing DD-WRT from Netgear WNDR3700

As luck would have it, my Netgear WNDR3700 crapped out in fun way: my download speed became 0.01Mbps. After trying everything I could think of, including getting an RMA from Netgear, I decided to give DD-WRT a shot to see if it might help fix the problem. Did it? Nope.

So I’m going to be returning the router to Netgear and hopefully will be getting a shiny new router back, but I don’t quite think having non-factory firmware looks good, so I needed to flash the original firmware back onto the router. Despite simply uploading a CHK file into the Netgear’s web based UI to switch to DD-WRT, it is a real pain in the ass to switch back.

Continue reading Removing DD-WRT from Netgear WNDR3700

Android Annotations & IntelliJ

So after reading skimming Pro Android 4 and concluding that the default Android way of doing things is pretty asinine (though I get why it is the way it is) and doesn’t belong in the year 2013, I too a look into libraries and tools to make things nicer. Long story short, I found Android Annotations and fell in love with it. Combine that with the Android app we have at work using it, thus giving me a nice example of everything I could need, I got to work. However setting things up in IntelliJ was a bit more of a pain than I bargained for.

Continue reading Android Annotations & IntelliJ

Genymotion with IntelliJ

So there is this great tool out there called Genymotion, which provides an extremely fast Android emulator. I started to learn Android development about a month ago and quit as soon as I fired up the emulator. Having seen Genymotion on Hacker News, I decided to try it out and dayyyyuuumm does it solve the speed issue. My only hangup was getting things working with IntelliJ. Given that it doesn’t use a traditional AVD, you have to do some configuration to use Genymotion. Down the rabbit hole we go…

Continue reading Genymotion with IntelliJ

Response Headers and Chrome Extensions

So I just got around to releasing the Header Editor version 2.0.0 Chrome extension. It’s fancy! Somehow I missed the fact that there are request and response headers to be modified, so after a little hacking around you can now edit the response headers as well.

Now for those of you like me, who check everything in the Chrome request inspector, you’ll notice that the response headers do not show up in the list of response headers. You probably think “Well shit, that’s a bug there ain’t it?”, and you’d be right.

Continue reading Response Headers and Chrome Extensions

Travis CI and Tabs

I caught the NodeJS bug a few days ago, and have started working on my first module. Being the good software “engineer” that I am, I decided to add testing to my module to give anyone using it that warm tingly feeling because they know the software is high quality shit. Since I’ve already started down the hipster path, I decided to try out that Travis CI thing I keep seeing over on good ol’ GitHub.

So setting up a basic .travis.yml file for Node is pretty simple. It basically looks like this:

language: node_js
node_js:
	- "0.11"
	- "0.10"
	- "0.8"
	- "0.6"

Continue reading Travis CI and Tabs

Switching WordPress Themes by Name (or Anything, Maybe)

I’m going to preface this one with this: I HATE WordPress. Kinda. From a user’s standpoint it’s not really all that bad. I’ll go out on a limb and say it’s marginally nice. From a programmer’s standpoint? I’d like to see the WordPress developers strung up by their thumbs. Ouch.┬áTo quote myself on Twitter

“Every time I work with WordPress, I reaffirm my belief that the WP devs really just are a programming troll collective.”

From time to time I’ll run into fun little things like WordPress inserting <p> and <br /> tags into my code text (apparently it’s text now, whatever WordPress…).

Continue reading Switching WordPress Themes by Name (or Anything, Maybe)

Chrome Extension Library

If you’re working on a Chrome Extension inside of one of those fancy IDEs, you may just want to be able to get those nifty features such as auto-completion and error checking. Luckily, the folks working on Google’s Closure Compiler are kind enough to have a mock library, chrome_extension.js. Just add this file to your IDE of choice as a library, and you’re good to go.

“object scala not found”

Don’t ask me why, but I decided that it would be convenient to develop on my main home computer, a beast with a hex-core processor, 16 GB or RAM, and more that will just make my computer seem like overkill. Regardless, I was trying to setup a Play Framework project on Windows 7 with a fresh install of everything (meaning Java, Scala, Play Framework, etc.) but I kept getting a very cryptic error message while tying to compile my project.

Caused by: scala.tools.nsc.MissingRequirementError: object scala not found.
        at scala.tools.nsc.symtab.Definitions$definitions$.getModuleOrClass(Definitions.scala:655)
        at scala.tools.nsc.symtab.Definitions$definitions$.getModule(Definitions.scala:605)
        at scala.tools.nsc.symtab.Definitions$definitions$.ScalaPackage(Definitions.scala:145)
        at scala.tools.nsc.symtab.Definitions$definitions$.ScalaPackageClass(Definitions.scala:146)
        at scala.tools.nsc.symtab.Definitions$definitions$.AnyClass(Definitions.scala:176)
        at scala.tools.nsc.symtab.Definitions$definitions$.init(Definitions.scala:814)
        at scala.tools.nsc.Global$Run.(Global.scala:697)
        at scala.tools.nsc.interactive.Global$TyperRun.(Global.scala:1036)
        at scala.tools.nsc.interactive.Global.newTyperRun(Global.scala:1059)
        at scala.tools.nsc.interactive.Global.(Global.scala:191)

Continue reading “object scala not found”