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; 019 020import org.apache.camel.EndpointInject; 021import org.apache.camel.Produce; 022import org.apache.camel.ProducerTemplate; 023import org.apache.camel.builder.RouteBuilder; 024import org.apache.camel.component.mock.MockEndpoint; 025import org.apache.camel.test.junit4.CamelTestSupport; 026import org.fcrepo.camel.FcrepoHeaders; 027 028import org.junit.Test; 029 030/** 031 * Test the route workflow. 032 * 033 * @author Aaron Coburn 034 * @since 2015-05-8 035 */ 036public class PathProcessorTest extends CamelTestSupport { 037 038 @EndpointInject(uri = "mock:result") 039 protected MockEndpoint resultEndpoint; 040 041 @Produce(uri = "direct:start") 042 protected ProducerTemplate template; 043 044 @Test 045 public void testPathProcessor() throws Exception { 046 047 final String path = "/foo/bar"; 048 final String root = "/"; 049 final String baseUrl1 = "http://localhost:8080/fcrepo/rest"; 050 final String baseUrl2 = "localhost:8983/fcrepo/rest"; 051 052 resultEndpoint.expectedMessageCount(4); 053 resultEndpoint.expectedHeaderValuesReceivedInAnyOrder( 054 FcrepoHeaders.FCREPO_IDENTIFIER, root, path, root, path); 055 056 template.sendBodyAndHeader(baseUrl1 + path, FcrepoHeaders.FCREPO_BASE_URL, baseUrl1); 057 template.sendBodyAndHeader(baseUrl1 + root, FcrepoHeaders.FCREPO_BASE_URL, baseUrl1); 058 template.sendBodyAndHeader("http://" + baseUrl2 + path, FcrepoHeaders.FCREPO_BASE_URL, baseUrl2); 059 template.sendBodyAndHeader("http://" + baseUrl2 + root, FcrepoHeaders.FCREPO_BASE_URL, baseUrl2); 060 061 assertMockEndpointsSatisfied(); 062 } 063 064 @Override 065 protected RouteBuilder createRouteBuilder() { 066 return new RouteBuilder() { 067 @Override 068 public void configure() throws IOException { 069 from("direct:start") 070 .process(new PathProcessor()) 071 .to("mock:result"); 072 } 073 }; 074 } 075}