001/*
002 * Copyright 2016 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.FcrepoHeaders.FCREPO_IDENTIFIER;
020
021import org.junit.Test;
022import java.util.Map;
023import java.util.Properties;
024
025import com.google.common.collect.ImmutableMap;
026
027import org.apache.camel.builder.AdviceWithRouteBuilder;
028import org.apache.camel.Exchange;
029import org.apache.camel.util.ObjectHelper;
030import org.apache.commons.io.IOUtils;
031
032/**
033 * Test the route workflow with the 'includeBinaries' config property set to true.
034 *
035 * @author Bethany Seeger
036 * @since 2015-11-24
037 */
038
039public class BinaryEnabledRouteTest extends AbstractRouteTest {
040
041    @Override
042    protected Properties useOverridePropertiesWithPropertiesComponent() {
043        final Properties props = new Properties();
044
045        props.put("serialization.stream", "seda:foo");
046        props.put("input.stream", "seda:bar");
047        props.put("serialization.format", "RDF_XML");
048        props.put("serialization.descriptions", "metadata_file");
049        props.put("serialization.binaries", "binary_file");
050        props.put("serialization.includeBinaries", "true");
051        props.put("audit.container", auditContainer);
052
053        return props;
054    }
055
056    @Test
057    public void testMetadataUpdaterBinary() throws Exception {
058        context.getRouteDefinition("FcrepoSerializationBinaryUpdater").adviceWith(context,
059          new AdviceWithRouteBuilder() {
060              @Override
061              public void configure() throws Exception {
062                  replaceFromWith("direct:start");
063                  mockEndpointsAndSkip("*");
064              }
065        });
066        context.start();
067
068        getMockEndpoint("mock:file:binary_file").expectedMessageCount(1);
069        getMockEndpoint("mock:file:binary_file").expectedHeaderReceived(Exchange.FILE_NAME, "foo");
070
071        // send a file!
072        final String body = IOUtils.toString(ObjectHelper.loadResourceAsStream("binary.rdf"), "UTF-8");
073        final Map<String, Object> headers = ImmutableMap.of(
074            BASE_URL, baseURL,
075            FCREPO_IDENTIFIER, "foo");
076
077        template.sendBodyAndHeaders(body, headers);
078
079        assertMockEndpointsSatisfied();
080    }
081}