001/**
002 * Copyright 2015 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.integration;
017
018import static org.apache.camel.Exchange.ACCEPT_CONTENT_TYPE;
019import static org.fcrepo.camel.integration.FcrepoTestUtils.getFcrepoEndpointUri;
020
021import org.apache.camel.EndpointInject;
022import org.apache.camel.Produce;
023import org.apache.camel.ProducerTemplate;
024import org.apache.camel.builder.RouteBuilder;
025import org.apache.camel.component.mock.MockEndpoint;
026import org.apache.camel.test.junit4.CamelTestSupport;
027import org.junit.Test;
028import org.junit.runner.RunWith;
029import org.springframework.test.context.ContextConfiguration;
030import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
031
032/**
033 * Test the retrieved content-type from a fcrepo endpoint
034 * when the Accept type is put directly on the endpoint.
035 * @author Aaron Coburn
036 * @since November 7, 2014
037 */
038@RunWith(SpringJUnit4ClassRunner.class)
039@ContextConfiguration({"/spring-test/test-container.xml"})
040public class FcrepoContentTypeEndpointIT extends CamelTestSupport {
041
042    @EndpointInject(uri = "mock:result")
043    protected MockEndpoint resultEndpoint;
044
045    @Produce(uri = "direct:start")
046    public ProducerTemplate template;
047
048    @Test
049    public void testContentTypeTurtle() throws InterruptedException {
050        resultEndpoint.expectedHeaderReceived("Content-Type", "text/turtle");
051        resultEndpoint.expectedMessageCount(1);
052
053        template.sendBody(null);
054
055        resultEndpoint.assertIsSatisfied();
056    }
057
058    @Test
059    public void testContentTypeN3() throws InterruptedException {
060        resultEndpoint.expectedHeaderReceived("Content-Type", "text/turtle");
061        resultEndpoint.expectedMessageCount(2);
062
063        template.sendBodyAndHeader(null, "Accept", "application/n-triples");
064        template.sendBodyAndHeader(null, ACCEPT_CONTENT_TYPE, "application/n-triples");
065
066        resultEndpoint.assertIsSatisfied();
067    }
068
069    @Override
070    protected RouteBuilder createRouteBuilder() {
071        return new RouteBuilder() {
072
073            @Override
074            public void configure() {
075                final String fcrepo_uri = getFcrepoEndpointUri();
076
077                from("direct:start")
078                        .to(fcrepo_uri + "?accept=text/turtle")
079                        .to("mock:result");
080            }
081        };
082    }
083}