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