EchoSignSignatureServiceImpl implements EchoSignSignatureService { @Override public String getChildDocumentKey(String documentKey) { GetFormDataResult getFormDataResult = getCachedService().getFormData( echoSignApiKey, documentKey); String formDataCsv = getFormDataResult.getFormDataCsv(); String childDocumentKey = null; if (formDataCsv != null) { logger.info(formDataCsv); String[] splittedFormDataCsv = formDataCsv.split("\\r?\\n"); String[] keys = splittedFormDataCsv[0].replace("\"", "").split(","); int documentKeyIndex = Arrays.asList(keys).indexOf("Document Key"); if( documentKeyIndex != -1) { String[] values = splittedFormDataCsv[1].replace("\"", "").split(","); childDocumentKey = values[documentKeyIndex]; } } return childDocumentKey; } EchoSignSignatureServiceImpl(String echoSignServiceUrl,
			String echoSignApiKey); @Override String sendDocumentToSign(byte[] documentBytes,
			String documentFileName, String documentName,
			String recipientEmail, String messageToRecipient); @Override String sendDocumentToSign(byte[] documentBytes,
			String documentFileName, String documentName,
			String recipientEmail, String messageToRecipient,
			String signedDocumentUrl); @Override DocumentInfo getDocumentInfo(String documentKey); @Override byte[] getLatestDocument(String documentKey); @Override String getChildDocumentKey(String documentKey); Pong testPing(); byte[] testEchoFile(byte[] input); @Override EmbeddedWidgetCreationResult createEmbeddedWidget(
			byte[] documentBytes, String documentFileName, String documentName,
			String signedDocumentUrl, String email);  }
@Test public void testGetChildDocumentKey_ScnearioOne() { String mockFormDataCsv = "\"completed\",\"email\",\"role\",\"first\",\"last\",\"title\",\"company\",\"Transaction Number\""; GetFormDataResult mockGetFormDataResult=mock(GetFormDataResult.class); doReturn(mockFormDataCsv).when(mockGetFormDataResult).getFormDataCsv(); doReturn(mockGetFormDataResult).when(service).getFormData(mockEchoSignApiKey, mockDocumentKey); Assert.assertNull(sut.getChildDocumentKey(mockDocumentKey)); }
@Test public void testGetChildDocumentKey_ScnearioTwo() { String mockFormDataCsv = "\"completed\",\"email\",\"role\",\"first\",\"last\",\"title\",\"company\",\"Document Key\",\"Transaction Number\"\n" + "\"2015-04-08 11:31:20\",\"sadhana.chandravanka@feisystems.com\",\"SIGNER\",\"testConsent2\",\"Share\",\"\",\"\",\"XLS4XIRNXN6S3V6\",\"XLS4XIR84U26J58\""; String expected = "XLS4XIRNXN6S3V6"; GetFormDataResult mockGetFormDataResult=mock(GetFormDataResult.class); doReturn(mockFormDataCsv).when(mockGetFormDataResult).getFormDataCsv(); doReturn(mockGetFormDataResult).when(service).getFormData(mockEchoSignApiKey, mockDocumentKey); String actual = sut.getChildDocumentKey(mockDocumentKey); Assert.assertNotNull(actual); Assert.assertEquals(expected, actual); }
@Test public void testGetChildDocumentKey_ScnearioThree() { String mockFormDataCsv = "\"completed\",\"email\",\"role\",\"first\",\"last\",\"title\",\"company\",\"Transaction Number\"" + "\"2015-04-16 12:16:04\",\"cindy.li@feisystems.com\",\"SIGNER\",\"cindy\",\"li\",\"software developer\",\"fei systems\",\"XM6WKHU3JXV5X7D\""; GetFormDataResult mockGetFormDataResult=mock(GetFormDataResult.class); doReturn(mockFormDataCsv).when(mockGetFormDataResult).getFormDataCsv(); doReturn(mockGetFormDataResult).when(service).getFormData(mockEchoSignApiKey, mockDocumentKey); Assert.assertNull(sut.getChildDocumentKey(mockDocumentKey)); }
@Test public void testGetChildDocumentKey_ScnearioFour() { String mockFormDataCsv = "\"completed\",\"email\",\"role\",\"first\",\"last\",\"title\",\"company\",\"Document1 Key\",\"Transaction Number\"\n" + "\"2015-04-08 11:31:20\",\"sadhana.chandravanka@feisystems.com\",\"SIGNER\",\"testConsent2\",\"Share\",\"\",\"\",\"XLS4XIRNXN6S3V6\",\"XLS4XIR84U26J58\""; GetFormDataResult mockGetFormDataResult=mock(GetFormDataResult.class); doReturn(mockFormDataCsv).when(mockGetFormDataResult).getFormDataCsv(); doReturn(mockGetFormDataResult).when(service).getFormData(mockEchoSignApiKey, mockDocumentKey); Assert.assertNull(sut.getChildDocumentKey(mockDocumentKey)); }