### Question:
BinaryMetadataProcessor implements Processor { @Override public void process(final Exchange exchange) throws Exception { final Message in = exchange.getIn(); String fcrepoBinaryUri = (String) in.getHeader(FCREPO_URI); PID binPid = PIDs.get(fcrepoBinaryUri); BinaryObject binObj; try { binObj = repoObjLoader.getBinaryObject(binPid); } catch (ObjectTypeMismatchException e) { log.warn("Cannot extract binary metadata from {}, it is not a binary", binPid.getId()); return; } if (binObj.getContentUri() != null) { Model model = ModelFactory.createDefaultModel(); InputStream bodyStream = in.getBody(InputStream.class); bodyStream.reset(); model.read(bodyStream, null, "Turtle"); Resource resc = model.getResource(binPid.getRepositoryPath()); String binaryMimeType = resc.getProperty(hasMimeType).getObject().toString(); URI contentUri = binObj.getContentUri(); if (!contentUri.getScheme().equals("file")) { log.warn("Only file content URIs are supported at this time"); return; } in.setHeader(CdrBinaryPath, Paths.get(binObj.getContentUri()).toString()); in.setHeader(CdrBinaryMimeType, binaryMimeType); } else { log.warn("Cannot process {}, internal binaries are not currently supported", binPid.getId()); } }  @Override void process(final Exchange exchange); void setRepositoryObjectLoader(RepositoryObjectLoader repoObjLoader);  }### Answer:
@Test public void validExternalBinary() throws Exception { File file = new File(binaryBase + "/61/67/3d/" + CHECKSUM); file.getParentFile().mkdirs(); file.createNewFile(); when(repoObjLoader.getBinaryObject(binaryPid)).thenReturn(binaryObject); when(binaryObject.getContentUri()).thenReturn(file.toPath().toUri()); Model model = ModelFactory.createDefaultModel(); Resource resc = model.createResource(RESC_URI); resc.addProperty(RDF.type, Fcrepo4Repository.Binary); resc.addProperty(Ebucore.hasMimeType, MIMETYPE); resc.addProperty(Premis.hasMessageDigest, CHECKSUM_PREFIX + CHECKSUM); setMessageBody(model); processor.process(exchange); verify(message).setHeader(CdrBinaryMimeType, MIMETYPE); verify(message).setHeader(CdrBinaryPath, file.toPath().toString()); }
@Test public void nonbinaryObject() throws Exception { when(repoObjLoader.getBinaryObject(binaryPid)).thenThrow(new ObjectTypeMismatchException("")); Model model = ModelFactory.createDefaultModel(); Resource resc = model.createResource(RESC_ID); resc.addProperty(RDF.type, createResource(Fcrepo4Repository.Resource.getURI())); setMessageBody(model); processor.process(exchange); verify(message, never()).setHeader(eq(CdrBinaryPath), any()); }
@Test public void internalBinary() throws Exception { when(repoObjLoader.getBinaryObject(binaryPid)).thenReturn(binaryObject); when(binaryObject.getContentUri()).thenReturn(null); Model model = ModelFactory.createDefaultModel(); Resource resc = model.createResource(RESC_URI); resc.addProperty(RDF.type, Fcrepo4Repository.Binary); resc.addProperty(Ebucore.hasMimeType, MIMETYPE); resc.addProperty(Premis.hasMessageDigest, CHECKSUM_PREFIX + CHECKSUM); setMessageBody(model); processor.process(exchange); verify(message, never()).setHeader(eq(CdrBinaryPath), any()); }