001/* 002 * Licensed to DuraSpace under one or more contributor license agreements. 003 * See the NOTICE file distributed with this work for additional information 004 * regarding copyright ownership. 005 * 006 * DuraSpace licenses this file to you under the Apache License, 007 * Version 2.0 (the "License"); you may not use this file except in 008 * compliance with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.fcrepo.camel.serialization; 019 020import static org.apache.camel.Exchange.FILE_NAME; 021import static org.apache.camel.util.ObjectHelper.loadResourceAsStream; 022import static org.fcrepo.camel.serialization.SerializationRouter.SERIALIZATION_PATH; 023 024import org.junit.Test; 025import java.util.Properties; 026 027import org.apache.camel.builder.AdviceWithRouteBuilder; 028import org.apache.commons.io.IOUtils; 029 030/** 031 * Test the route workflow with the 'includeBinaries' config property set to true. 032 * 033 * @author Bethany Seeger 034 * @since 2015-11-24 035 */ 036 037public class BinaryEnabledRouteTest extends AbstractRouteTest { 038 039 @Override 040 protected Properties useOverridePropertiesWithPropertiesComponent() { 041 final Properties props = new Properties(); 042 043 props.put("serialization.stream", "seda:foo"); 044 props.put("input.stream", "seda:bar"); 045 props.put("serialization.format", "RDF_XML"); 046 props.put("serialization.descriptions", "metadata_file"); 047 props.put("serialization.binaries", "binary_file"); 048 props.put("serialization.includeBinaries", "true"); 049 props.put("filter.containers", baseURL + auditContainer); 050 051 return props; 052 } 053 054 @Test 055 public void testMetadataUpdaterBinary() throws Exception { 056 context.getRouteDefinition("FcrepoSerializationBinaryUpdater").adviceWith(context, 057 new AdviceWithRouteBuilder() { 058 @Override 059 public void configure() throws Exception { 060 replaceFromWith("direct:start"); 061 mockEndpointsAndSkip("*"); 062 } 063 }); 064 context.start(); 065 066 getMockEndpoint("mock:file:binary_file").expectedMessageCount(1); 067 getMockEndpoint("mock:file:binary_file").expectedHeaderReceived(FILE_NAME, "/foo"); 068 069 // send a file! 070 final String body = IOUtils.toString(loadResourceAsStream("binary.rdf"), "UTF-8"); 071 072 template.sendBodyAndHeader(body, SERIALIZATION_PATH, "/foo"); 073 074 assertMockEndpointsSatisfied(); 075 } 076}