AdapterComponentDocRepositoryOrchImpl { protected boolean setDocumentResponse(DocumentMetadata doc, DocumentResponse oDocResponse) { boolean bHasData = false; if (doc.getRawData().length > 0) { try { String url = StringUtil.convertToStringUTF8(doc.getRawData()); LOG.debug("Raw Data not null"); URI uri = new URI(url); File sourceFile = new File(uri); try { DataHandler dh = getLargeFileUtils().convertToDataHandler(sourceFile); oDocResponse.setDocument(dh); bHasData = true; } catch (IOException ex) { LOG.error("Failed to read contents of the file {}: {}", sourceFile.getName(), ex.getLocalizedMessage(), ex); bHasData = false; } } catch (URISyntaxException | UnsupportedEncodingException ue) { LOG.trace("Exception reading file: {}", ue.getLocalizedMessage(), ue); DataHandler dh = getLargeFileUtils().convertToDataHandler(doc.getRawData()); oDocResponse.setDocument(dh); bHasData = true; } } return bHasData; } AdapterComponentDocRepositoryOrchImpl(); DocumentService getDocumentService(); LargeFileUtils getLargeFileUtils(); UTCDateUtil getDateUtil(); RetrieveDocumentSetResponseType documentRepositoryRetrieveDocumentSet(RetrieveDocumentSetRequestType body); RegistryResponseType registerDocumentSet(RegisterDocumentSetRequestType body); RegistryResponseType documentRepositoryProvideAndRegisterDocumentSet(
        ProvideAndRegisterDocumentSetRequestType body); DocumentMetadata saveExtrinsicObject(ExtrinsicObjectType extrinsicObject, RegistryErrorList errorList,
        Map<String, DataHandler> docMap, boolean hasReplacementRequest);  }
@Test public void testSetDocumentResponse_Failure() { AdapterComponentDocRepositoryOrchImpl docRepo = new AdapterComponentDocRepositoryOrchImpl(); DocumentMetadata doc = new DocumentMetadata(); assertFalse(docRepo.setDocumentResponse(doc, null)); }
@Test public void testSetDocumentResponse_Success_File() throws IOException { Boolean result; String url = "file: AdapterComponentDocRepositoryOrchImpl docRepo = getDocRepoWithMockLargeFileUtils(); DocumentMetadata doc = mock(DocumentMetadata.class); DocumentResponse oDocResponse = mock(DocumentResponse.class); DataHandler dataHandler = mock(DataHandler.class); when(doc.getRawData()).thenReturn(url.getBytes()); when(largeFileUtils.convertToDataHandler(any(File.class))).thenReturn(dataHandler); result = docRepo.setDocumentResponse(doc, oDocResponse); verify(oDocResponse).setDocument(dataHandler); assertTrue(result); }
@Test public void testSetDocumentResponse_Success_String() { String url = "file: AdapterComponentDocRepositoryOrchImpl docRepo = getDocRepoWithMockLargeFileUtils(); DocumentMetadata doc = new DocumentMetadata(); Document document = new Document(doc); document.setRawData(url.getBytes()); DocumentResponse oDocResponse = mock(DocumentResponse.class); DataHandler dataHandler = mock(DataHandler.class); when(largeFileUtils.convertToDataHandler(any(byte[].class))).thenReturn(dataHandler); Boolean result = docRepo.setDocumentResponse(doc, oDocResponse); verify(oDocResponse).setDocument(dataHandler); assertTrue(result); }