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.integration; 019 020import static org.fcrepo.camel.FcrepoProducer.DEFAULT_CONTENT_TYPE; 021 022import org.apache.camel.EndpointInject; 023import org.apache.camel.Exchange; 024import org.apache.camel.Produce; 025import org.apache.camel.ProducerTemplate; 026import org.apache.camel.builder.RouteBuilder; 027import org.apache.camel.component.mock.MockEndpoint; 028import org.apache.camel.test.junit4.CamelTestSupport; 029import org.junit.Test; 030 031/** 032 * Test the retrieved content-type from a fcrepo endpoint 033 * when the Accept type is put in a message header. 034 * @author Aaron Coburn 035 * @since November 7, 2014 036 */ 037public class FcrepoContentTypeHeaderIT 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 testContentTypeJson() throws InterruptedException { 047 resultEndpoint.expectedHeaderReceived("Content-Type", "application/ld+json"); 048 resultEndpoint.expectedMessageCount(2); 049 050 template.sendBodyAndHeader(null, "Accept", "application/ld+json"); 051 template.sendBodyAndHeader(null, Exchange.ACCEPT_CONTENT_TYPE, "application/ld+json"); 052 053 resultEndpoint.assertIsSatisfied(); 054 } 055 056 @Test 057 public void testContentTypeRdfXml() throws InterruptedException { 058 resultEndpoint.expectedHeaderReceived("Content-Type", "application/rdf+xml"); 059 resultEndpoint.expectedMessageCount(2); 060 061 template.sendBodyAndHeader(null, "Accept", "application/rdf+xml"); 062 template.sendBodyAndHeader(null, Exchange.ACCEPT_CONTENT_TYPE, "application/rdf+xml"); 063 064 resultEndpoint.assertIsSatisfied(); 065 } 066 067 @Test 068 public void testContentTypeNTriples() throws InterruptedException { 069 resultEndpoint.expectedHeaderReceived("Content-Type", "application/n-triples"); 070 resultEndpoint.expectedMessageCount(2); 071 072 template.sendBodyAndHeader(null, "Accept", "application/n-triples"); 073 template.sendBodyAndHeader(null, Exchange.ACCEPT_CONTENT_TYPE, "application/n-triples"); 074 075 resultEndpoint.assertIsSatisfied(); 076 } 077 078 @Test 079 public void testContentTypeTurtle() throws InterruptedException { 080 resultEndpoint.expectedHeaderReceived("Content-Type", "text/turtle"); 081 resultEndpoint.expectedMessageCount(2); 082 083 template.sendBodyAndHeader(null, "Accept", "text/turtle"); 084 template.sendBodyAndHeader(null, Exchange.ACCEPT_CONTENT_TYPE, "text/turtle"); 085 086 resultEndpoint.assertIsSatisfied(); 087 } 088 089 @Test 090 public void testContentTypeN3() throws InterruptedException { 091 resultEndpoint.expectedHeaderReceived("Content-Type", "text/rdf+n3"); 092 resultEndpoint.expectedMessageCount(2); 093 094 template.sendBodyAndHeader(null, "Accept", "text/rdf+n3"); 095 template.sendBodyAndHeader(null, Exchange.ACCEPT_CONTENT_TYPE, "text/rdf+n3"); 096 097 resultEndpoint.assertIsSatisfied(); 098 } 099 100 101 @Test 102 public void testContentTypeDefault() throws InterruptedException { 103 resultEndpoint.expectedHeaderReceived("Content-Type", DEFAULT_CONTENT_TYPE); 104 resultEndpoint.expectedMessageCount(1); 105 106 template.sendBody(null); 107 108 resultEndpoint.assertIsSatisfied(); 109 } 110 111 112 @Override 113 protected RouteBuilder createRouteBuilder() { 114 return new RouteBuilder() { 115 @Override 116 public void configure() { 117 final String fcrepo_uri = FcrepoTestUtils.getFcrepoEndpointUri(); 118 119 from("direct:start") 120 .to(fcrepo_uri) 121 .to("mock:result"); 122 } 123 }; 124 } 125}