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.reindexing;
019
020import java.io.IOException;
021import java.util.HashMap;
022import java.util.Map;
023
024import org.apache.camel.EndpointInject;
025import org.apache.camel.Produce;
026import org.apache.camel.ProducerTemplate;
027import org.apache.camel.builder.RouteBuilder;
028import org.apache.camel.component.mock.MockEndpoint;
029import org.apache.camel.test.junit4.CamelTestSupport;
030import org.fcrepo.camel.FcrepoHeaders;
031
032import org.junit.Test;
033
034/**
035 * Test the usage processor
036 *
037 * @author acoburn
038 */
039public class UsageProcessorTest extends CamelTestSupport {
040
041    @EndpointInject(uri = "mock:result")
042    protected MockEndpoint resultEndpoint;
043
044    @Produce(uri = "direct:start")
045    protected ProducerTemplate template;
046
047    @Test
048    public void testUsageProcessor() throws Exception {
049        resultEndpoint.expectedMessageCount(1);
050
051        final Map<String, Object> headers = new HashMap<>();
052        headers.put(ReindexingHeaders.REST_PREFIX, "/reindexing");
053        headers.put(ReindexingHeaders.REST_PORT, "9999");
054        headers.put(FcrepoHeaders.FCREPO_BASE_URL, "localhost:8080/fcrepo/rest");
055
056        template.sendBodyAndHeaders("", headers);
057
058        assertMockEndpointsSatisfied();
059    }
060
061    @Override
062    protected RouteBuilder createRouteBuilder() {
063        return new RouteBuilder() {
064            @Override
065            public void configure() throws IOException {
066                from("direct:start")
067                    .process(new UsageProcessor())
068                    .to("mock:result");
069            }
070        };
071    }
072}