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