Java tutorial
package com.webbfontaine.valuewebb.action.tt.dataimporter; import com.webbfontaine.valuewebb.model.Pd; import com.webbfontaine.valuewebb.model.TtGen; import com.webbfontaine.valuewebb.model.TtInv; import com.webbfontaine.valuewebb.utils.Doc2Bytes; import org.apache.commons.lang3.RandomStringUtils; import org.apache.http.HttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.impl.client.DefaultHttpClient; import org.testng.annotations.Test; import java.math.BigDecimal; /** * Copyrights 2002-2013 Webb Fontaine * This software is the proprietary information of Webb Fontaine. * Its use is subject to License terms. * Developer: nigiyan * Date: 17/06/2013 */ @Test(groups = { "unit" }) public class TTMergeTest { @Test(parameters = "daiTTURL") public void testTTMerge(String daiTTURL) throws Exception { DefaultHttpClient httpClient = new DefaultHttpClient(); HttpUriRequest httpGet = new HttpGet(daiTTURL); HttpResponse response = httpClient.execute(httpGet); assert response.getStatusLine().getStatusCode() == 200; TtGen daiTT = (TtGen) Doc2Bytes.unmarshal(response.getEntity().getContent(), TtGen.class); assert daiTT != null; TtGen ttGen = getTT(); MergeLoadedTT.merge(daiTT, ttGen); assert ttGen.getAppTin().equals(daiTT.getAppTin()); assert !ttGen.getAppAdr().isEmpty(); // keep original assert ttGen.getFirstTtInvs().getInvCur().equals(daiTT.getFirstTtInvs().getInvCur()); assert ttGen.getFirstTtInvs().getInsuranceF() != null; // keep original Pd pd = ttGen.getFirstTtInvs().getPds().get(0); Pd daiPD = daiTT.getFirstTtInvs().getPds().get(0); assert pd.getCtyOrig().equals(daiPD.getCtyOrig()); assert pd.getHsCodeD().equals(daiPD.getHsCodeD()); } private static TtGen getTT() { TtGen ttGen = new TtGen(); ttGen.setAppTin(RandomStringUtils.random(5)); ttGen.setAppAdr(RandomStringUtils.random(5)); TtInv inv = new TtInv(); inv.setTtGen(ttGen); inv.setInvCur(RandomStringUtils.random(3)); inv.setInsuranceF(BigDecimal.ONE); ttGen.getTtInvs().add(inv); Pd pd = new Pd(); pd.setTtGen(ttGen); pd.setTtInv(inv); pd.setHsCodeD(RandomStringUtils.random(10)); inv.getPds().add(pd); return ttGen; } }