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