The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

ukari (7) [Avatar] Offline
#1
import org.mule.api.MuleMessage;
import org.mule.api.client.MuleClient;
import org.mule.tck.junit4.FunctionalTestCase;
import org.mule.transport.NullPayload;


import org.junit.Test;
import org.skyscreamer.jsonassert.*;
/*
<dependency>
<groupId>org.skyscreamer</groupId>
<artifactId>jsonassert</artifactId>
<version>1.2.1</version>
</dependency>
*/

import static org.junit.Assert.*;


//<start id="lis_02_product_test"/>


public class ProductServiceFunctionalTestCase extends FunctionalTestCase {
protected String getConfigResources() {
return "./src/main/app/product_registration.xml";
}


@Test
public void productservice() throws Exception {
MuleClient client = muleContext.getClient();


String productAsJson = "{'name':'Widget', 'price': 9.99, 'weight': 1.0, 'sku': 'abcd-12345'}"; //<co id="lis_02_product_test-1"/>


client.dispatch("http://localhost:8080/products", productAsJson, null); //<co id="lis_02_product_test-2"/>




MuleMessage result = client.request("jms://products",
RECEIVE_TIMEOUT); //<co id="lis_02_product_test-3"/>
assertNotNull(result); //<co id="lis_02_product_test-4"/>
assertNull(result.getExceptionPayload());
assertFalse(result.getPayload() instanceof NullPayload);
/*
/////////////////////////////////////////////////////////////////////////////////////////////////
/// with out this enhancement getting errors like (likely Windows encoding??)

// org.junit.ComparisonFailure: expected:<{['name':'Widget', 'price': 9.99, 'weight': 1.0, 'sku': 'abcd-12345']}> but was:<{["name":"Widget","price":9.99]}>

// org.junit.ComparisonFailure: expected:<{['name':'Widget', 'price': 9.99, 'weight': 1.0, 'sku': 'abcd-12345']}> but was:<{["name":"Widget", "price": 9.99, "weight": 1.0, "sku": "abcd-12345"]}>

*/

JSONAssert.assertEquals(productAsJson, result.getPayloadAsString(), false); //<co id="lis_02_product_test-5"/>
}
}
David Dossot (233) [Avatar] Offline
#2
Re: ProductRegistrationFunctionalTestCase works only after adding JSONAssert
Thanks. Please run "mvn version" and post the information so we can know the specifics of your environment and try to understand why it fails for you.
ukari (7) [Avatar] Offline
#3
Re: ProductRegistrationFunctionalTestCase works only after adding JSONAssert
C:Usersukari>mvn -version
Apache Maven 3.1.1 (0728685237757ffbf44136acec0402957f723d9a; 2013-09-17 05:22:22-1000)
Maven home: C:maven3.1.1
Java version: 1.7.0_40, vendor: Oracle Corporation
Java home: C:jdk1.7.0_40jre
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"
David Dossot (233) [Avatar] Offline
#4
Re: ProductRegistrationFunctionalTestCase works only after adding JSONAssert
Thank you.

As explained in the README, the build only works with Oracle JDK 6 (because it depends on DevKit 3.4.0 that requires Oracle JDK 6).

This said, the issue you're facing is different, I suspect that it only shows up on Windows (none of the authors are using Windows so the build has never been tested on this particular OS).

Using JSONAssert as you suggest seems like a great suggestion, thanks again!

BTW Pull requests are welcome at https://github.com/ddossot/mule-in-action-2e
David Dossot (233) [Avatar] Offline
#5
Re: ProductRegistrationFunctionalTestCase works only after adding JSONAssert
Wait... actually the issue is even worse than that.

In ProductRegistrationFunctionalTestCase, productAsJson is not valid JSON!

"{'name':'Widget' ... is not JSON!

Thanks for attracting our attention to the issue.