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