there could of been a valid reason for the immigration official to go this far. any number of things could of set off a red flag that warranted further investigation which led to the testing. would need more first hand knowledge of the encounter to make a proper decision.
while i don't agree with random testing of urine. ignorance to the laws used by adults is no excuse.