classical geek

Cialis OnlineBuy CialisGeneric CialisCheap CialisBuy Cialis OnlineWww.cialis.comViagra CialisCialis ProfessionalDiscount CialisCialis SampleCialis CanadaOrder CialisCialis GenericCialis CheapOnline CialisCialis On LineCialis No PrescriptionCanadian CialisCialis DosageCialis Without PrescriptionPurchase CialisCialis Side EffectsCialis For SaleCialis Or ViagraCheapest CialisCialis DiscountBuy-cialis.htmOrder Cialis OnlineCialis BuyCialis Soft TabsSoft CialisCialis UkCialis 20mgCialis PriceNo Prescription CialisCialis PurchaseCialis Levitra ViagraCialis SamplesCanada CialisCialis ViagraCialis PillsLevitra Cialis ViagraBuy Generic CialisCialis LevitraCialis TadalafilViagra Vs CialisCialisisCialis SalesCanadian Pharmacy CialisCialis By MailFree CialisCialis TabletsWhere To Buy CialisCialis SaleCialis PricesBuy Cialis Without PrescriptionCialis Vs ViagraCialis Canadian PharmacyCheap Cialis OnlineCialis Overnight DeliveryOrdering CialisBuy Cheap CialisCialis OvernightBuying Cialis OnlineCialis IndiaCialis OrderCialis PharmacyCialis ProCialis SoftGeneric Cialis OnlineCheap Generic CialisPurchase Cialis OnlineCialis From CanadaCialis PrescriptionOrder Cialis Without PrescriptionCialis Buy OnlineCialis Online PharmacyViagra Versus CialisCialis Rug Side EffectsViagra Cialis LevitraBuy Cialis Online CanadaLiquid CialisCialis And ViagraCialis 20 MgTadalafil CialisCialis Super ActiveNon Prescription CialisCialis Free SampleSuper CialisCialis DrugBuy CialisonlineGeneric Cialis CanadaCialis Online PurchaseCialis On-lineOvernight CialisBuy Cialis On LineCialis DoseCialis Online CanadaCialis Without PerscriptionDiscount Generic CialisCialis MastercardCialis Online PrescriptionCialis PrescriptionsCialis Order OnlineBuying CialisCialis Online No PrescriptionCialis To BuyGeneric Viagra CialisCialis WikipediaBuy Cialis CanadaFast Delivery CialisCialis CostProfessional CialisGeneric Cialis TadalafilOnline Pharmacy CialisCialis Professional PillsCialis PaypalCialis SuppliersFemale CialisCialis 20Cialis ForumDiscount Cialis OnlineCialis For WomenCialis AustraliaAchat CialisBuy Generic Cialis OnlineViagra And CialisCialis FreeCialis ComCialis RxCialis Versus ViagraCheap Cialis CanadaMail Order CialisCialis SofttabsCialis TabletSide Effects Of CialisDaily CialisCialis CanadianCialis For CheapCialis Once DailyGeneric Cialis Soft TabsWhat Is CialisBuy Cialis ProfessionalLow Cost CialisCialis EuropeCialis Online Without PrescriptionCialis DailyPrescription CialisHow To Order CialisCialis Online OrderingBest Price CialisCialis On SaleCialis Online OrderGet Cialis OnlineCialis In CanadaGeneric Cialis No PrescriptionCialis InformationCialis Best PriceViagra Or CialisFind Cheap CialisCialis, CheapViagra Vs Cialis Vs LevitraOn Line CialisCialis 5mgViagra Cialis GenericCialis 10 MgLevitra Vs Viagra Vs CialisBuy Cialis OnlieCialis Mail OrderCialis Purchase OnlineOrder Cialis In CanadaSafe CialisWholesale CialisIs Cialis Better Than ViagraViagra And Cialis Rush DeliveryCheap Canadian CialisGeneric Cialis ProPurchase Cialis Without A PrescriptionBuy Cialis CheapCialis Overnight ShippingBuy Cialis Online Without A PrescriptionCialis Next DayCialis From UkBuy Cialis No PrescriptionBuying Cialis On Line2.5 Mg CialisBuycialisBuy Discount CialisBuy Cialis 20mgCialis CouponCheap Cialis ViagraCialis DiscountedCialis IngredientsCialis SuperBuy ViagraGeneric ViagraCheap ViagraViagra OnlineBuy Viagra OnlineViagra For SaleViagra Side EffectsPfizer ViagraFree ViagraDiscount ViagraViagra CanadaOnline ViagraOrder ViagraCanadian ViagraViagra On LineViagra AlternativeViagra SalesPurchase ViagraViagra CheapViagra PillsViagra ProfessionalCheapest ViagraViagra No PrescriptionCanadian Pharmacy ViagraViagra BuyFemale ViagraViagra GenericViagra Without PrescriptionViagra SampleViagra UkHerbal Alternative To ViagraCanada ViagraOrder Viagra OnlineViagra SaleViagra SamplesViagra Online Without PrescriptionBuying ViagraViagra PurchaseViagra Super ActiveViagra Soft TabsWhere To Buy ViagraGeneric Viagra OnlineBuy Viagra On LineViagra OrderHerbal ViagraFree Viagra SamplesBuy Cheap ViagraNo Prescription ViagraViagra DiscountCheap Generic ViagraBuy Generic ViagraViagra Without A PrescriptionLow Cost ViagraViagra DoseBuying Viagra OnlineViagra For WomenViagra DosageGeneric ViagrasViagra OvernightViagra PricesViagra By MailPurchase Viagra OnlineViagra Canadian PharmacyViagra Free SampleViagra From CanadaViagra AustraliaMail Order ViagraViagra IndiaViagra Online CanadaFree Viagra SampleCheap Viagra OnlineViagra SubstituteBuy Viagra Without PrescriptionViagra CanadianOver The Counter ViagraBuy Viagra CheapViagra PrescriptionHow To Get ViagraGet ViagraViagra Online PharmacyOvernight ViagraSuper ViagraFree Sample ViagraGenericviagraGeneric Viagra PillsSoft ViagraOrdering ViagraViagra PharmacyViagra How It WorksNatural ViagraViagra PrescriptionsGeneric Viagra CanadaViagra On SaleViagra StoreViagra PfizerFree Samples Of ViagraGeneric Viagra For SaleViagra DirectionsViagra LevitraViagra UseViagra Order OnlineOrdering Viagra OnlineViagra PillViagra Free SamplesViagra SoftCheapviagraViagra DosesViagra DrugOn Line ViagraBuy Viagra No PrescriptionCheep ViagraBuy Generic Viagra OnlineFree ViagrasamplesMexican ViagraBest Price ViagraViagra Next Day DeliveryViagra AlternativesNon Prescription ViagraBuy Viagra In CanadaFree Sample Of ViagraViagra In CanadaViagra Online UkViagra RxViagra Online PrescriptionViagra Best PriceViagra Prescription OnlineBuy Viagra CanadaCheap Viagra No PrescriptionOnline Pharmacy ViagraWholesale ViagraViagra PaypalOrder Viagra Without PrescriptionSample ViagraViagra Mail OrderViagra IrelandFree Trial ViagraViagra Rug Side EffectsViagra For Sale OnlineViagra No RxViagra 25mgViagra 50mgViagra For LessViagra CostLiquid ViagraViagra In AustraliaViagra GenericsSildenafil ViagraOnline Viagra SalesViagra PriceViagraonlineViagra InfoViagra Sales OnlineViagra Free TrialViagra FactsBuy Cheap ViagrasViagra Online SalesViagra TabletsViagra Online PurchaseViagra 100mgViagra For SellBuy Viagra Online No PrescriptionCheap Online ViagraBuy Online ViagraViagra Fast ShippingBest Herbal ViagraBuy Real ViagraViagra.caViagra Sales UkViagra Online AustraliaBuy Viagra Without A PrescriptionHow To Buy ViagraGeneric Viagra IndiaViagra Without A PerscriptionLowest Price ViagraCheap ViagrasViagra InformationViagra Pills For SaleGenaric ViagraCheapest Generic ViagraCheapest Viagra OnlineLow Price ViagraBuy Viagra UsaIndian ViagraGeneric Viagra No PrescriptionFree Trial Of ViagraOtc Viagra

Mocking the Server Side

No, I’m not talking about making fun of a popular Java developer web site here. I just want to describe a process that I’ve found myself using in my Ajax develoment, and wondering what other people think about it.

A typical Ajax application is split across two layers. The client-side code is written in JavaScript, and the server-side code in PHP, Java, .Net, Ruby or whatever else (which is itself split into layers, but we don’t need to worry about that today). The job of the server code is to generate data feeds to the Ajax app, most commonly written in XML. The xml returned by the server can then be read by the XmlHttpRequest object as a JavaScript Document object using xhr.responseXML. (Or, yes, you could just use responseText if you’re returning JSON, say, or another form of text-based markup.)

I tend to write my client code by hand, and serve it as static .html and .js files from the server, so the server-side code has no involvement in the process beyond supplying the data feeds. I know that this isn’t everyone’s style, and I’m intrigued by the frameworks such as Backbase, Guise and some JSF implementations, that claim to relieve you of the burden of hand-coding JavaScript. But let’s stick to my way of doing things for now, because I realised that it offers an interesting advantage, the ability to mock the entire server layer.

A Mock Object is a stand-in for the real thing. Few modern programs are really standalone, and enterprise apps require a very complex context in order to operate; containers, databases, directories, web services, etc. This can make testing difficult, because to set up the test and run it, one neds to provide all the necessary context. Mock objects can be thought of as really dumb implementations of a contextual element, one that would never be useful in production, but provides the predictability and ease of setup required for a test. A mock database might always return the same four rows of data, whatever the WHERE clause. A mock web sevice might always serve up the same XML document. You get the idea? If not, there’s much more about mock objects here.

I’ve found myself using the file system as a mock server side. Granted, my position is probably as bit unusual at the moment, with final reviews of server-side code written in four different languages flying across my desk for the Ajax book. I don’t have the time to fire up a J2EE container, .Net server and a PHP system all at once, but I can test out client-side code by mocking the output of a script.

Let’s take an example, have a look at the following bit of code, written for ASP.NET using C#:

Response.ContentType="text/xml";
StringBuilder builder=new StringBuilder("<results>");
string query=Request.Params("q").ToString();
string sql="SELECT name,address FROM people WHERE name LIKE '%"+query+"%'";

//...run database query...

foreach (DataRow row in results.Rows){
builder.append("<match name='"+row["name"].ToString()+"'>");
builder.append("<address>");
builder.append(row["address"].ToString());
builder.append("</address>");
builder.append("</match>");
}
builder.append("</results>");
Response.Write(builder.ToString());

This is about as simple as things can get - I pull some data out of a table, format it as XML and write the result to the response. Getting it off the ground requires me to fire up a .Net server, and populate a database table, however.

Alternatively, I can create a mock implementation in two simple steps:

  • Read the aspx file, and figure out what the XML should look like, then write a little bit by hand.
  • Drop it onto a plain old web server, and modify my client code to point to the appropriate URL.

In this case, the mock XML might look like this:

<results>
<match name="dave">
<address>Stroud, UK</address>
</match>
<match name="somebody else">
<address>world</address>
</match>
</results>

I can’t test the business flow of my application using Mocks, but if I just want to see how the user interface looks or responds, or do a quick test to see how things render across a number of browsers, then I can save myself the bother of setting the server up, and just drop the client code and the mock XML into the Apache server that quietly hums away in the background on my development box.

So, my general question is, then, who else is doing this right now? Does it save you time? Does it even enforce good separation between client and server? Or is it a dangerous practice to be discouraged?

5 Comments

  1. In the “old days” (even older than what people nowadays tend to think of as “the old days”..) we used to refer to this practice as “stubbing out the code”.

    Anywhere that “real” code wasn’t available to “take a call”, we would fake it by writing a throwaway component to act like the missing code. Today, the missing code is more likely a missing service (database, HTTP, etc.) than just some unwritten logic, but I think that the idea and purpose are much the same.

    These days I use this technique more often to stand in for HL7 responders than XML responders, since real HL7 servers are generally not accessible, being critical medical systems well hidden behind hospital firewalls.

    So, generally speaking, I think that it is a useful and safe way to “move along” whenever you wouldn’t otherwise be able to for lack of access to a real or simulated deployment environment to test in.

    Comment by Thomas J Lukasik — October 18, 2005 @ 8:07 pm

  2. Seems entirely sensible to me. I’ve used the same technique and anything that allows you to develop and test a component in isolation before coming up against the problems of integrating it into a wider system has to be helpful.

    Comment by Phil Wills — October 19, 2005 @ 12:52 pm

  3. […] e, Needs Feedback October 19, 2005 on 5:21 pm | In AJAX Programming | Dave talks about his AJAX programming ways and says: So, my general questi […]

    Pingback by AJAX » Dave Talks About Client/Server Side Code, Needs Feedback — October 20, 2005 @ 12:23 am

  4. […] “mock” the server - so we were particularly interested in David Crane’s Mocking the Server Side blog. BTW, congrats on the book!) Despite th […]

    Pingback by ntschutta.com » Blog Archive » More Foundations of Ajax — November 1, 2005 @ 2:55 am

  5. This is exactly what I do…Mock the server side results with a file in the file system. This way it would be easy too to debug the issues with some part of the code.

    Pavan keely

    Comment by Pavan Keely — February 4, 2006 @ 12:39 am

RSS feed for comments on this post. TrackBack URI

Sorry, the comment form is closed at this time.

Powered by WordPress, Supported by SaveOnRefinance.com