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; 019 020import static java.util.Collections.emptyMap; 021import static org.junit.Assert.assertEquals; 022import static org.junit.Assert.assertNull; 023 024import java.util.Map; 025 026import org.apache.camel.CamelContext; 027import org.apache.camel.Endpoint; 028import org.junit.Test; 029import org.junit.runner.RunWith; 030import org.mockito.Mock; 031import org.mockito.runners.MockitoJUnitRunner; 032 033/** 034 * @author ajs6f 035 */ 036@RunWith(MockitoJUnitRunner.class) 037public class FcrepoComponentTest { 038 039 private static final String TEST_ENDPOINT_URI = "fcrepo:foo"; 040 041 private static final Map<String, Object> EMPTY_MAP = emptyMap(); 042 043 @Mock 044 private CamelContext mockContext; 045 046 @Test 047 public void testCreateEndpoint() { 048 final FcrepoComponent testComponent = new FcrepoComponent(mockContext); 049 final Endpoint testEndpoint = testComponent.createEndpoint(TEST_ENDPOINT_URI, "", EMPTY_MAP); 050 assertEquals(mockContext, testEndpoint.getCamelContext()); 051 assertEquals(TEST_ENDPOINT_URI, testEndpoint.getEndpointUri()); 052 } 053 054 @Test 055 public void testCreateEndpointFromConfig() { 056 final FcrepoConfiguration configuration = new FcrepoConfiguration(); 057 058 configuration.setMetadata(false); 059 060 final FcrepoComponent testComponent = new FcrepoComponent(configuration); 061 final Endpoint testEndpoint = testComponent.createEndpoint(TEST_ENDPOINT_URI, "", EMPTY_MAP); 062 assertEquals(TEST_ENDPOINT_URI, testEndpoint.getEndpointUri()); 063 064 assertEquals(false, testComponent.getConfiguration().getMetadata()); 065 } 066 067 @Test 068 public void testPreConfiguredComponent() { 069 final FcrepoConfiguration config = new FcrepoConfiguration(); 070 config.setAuthUsername("foo"); 071 config.setAuthPassword("bar"); 072 config.setAuthHost("baz"); 073 074 final FcrepoComponent testComponent = new FcrepoComponent(); 075 076 testComponent.setConfiguration(config); 077 078 final Endpoint testEndpoint = testComponent.createEndpoint(TEST_ENDPOINT_URI, "", EMPTY_MAP); 079 080 assertEquals(TEST_ENDPOINT_URI, testEndpoint.getEndpointUri()); 081 assertEquals("foo", testComponent.getConfiguration().getAuthUsername()); 082 assertEquals("bar", testComponent.getConfiguration().getAuthPassword()); 083 assertEquals("baz", testComponent.getConfiguration().getAuthHost()); 084 } 085 086 @Test 087 public void testPostConfiguredComponent() { 088 final FcrepoComponent testComponent = new FcrepoComponent(); 089 final FcrepoTransactionManager txMgr = new FcrepoTransactionManager(); 090 testComponent.setAuthUsername("foo"); 091 testComponent.setAuthPassword("bar"); 092 testComponent.setAuthHost("baz"); 093 testComponent.setTransactionManager(txMgr); 094 095 final Endpoint testEndpoint = testComponent.createEndpoint(TEST_ENDPOINT_URI, "", EMPTY_MAP); 096 097 assertEquals(TEST_ENDPOINT_URI, testEndpoint.getEndpointUri()); 098 assertEquals("foo", testComponent.getConfiguration().getAuthUsername()); 099 assertEquals("bar", testComponent.getConfiguration().getAuthPassword()); 100 assertEquals("baz", testComponent.getConfiguration().getAuthHost()); 101 assertNull(testComponent.getConfiguration().getTransactionManager()); 102 assertEquals(txMgr, testComponent.getTransactionManager()); 103 104 testComponent.getConfiguration().setTransactionManager(txMgr); 105 106 assertEquals(txMgr, testComponent.getConfiguration().getTransactionManager()); 107 } 108 109 @Test 110 public void testCreateEndpointFromDefaultConstructor() { 111 final FcrepoComponent testComponent = new FcrepoComponent(); 112 final Endpoint testEndpoint = testComponent.createEndpoint(TEST_ENDPOINT_URI, "", EMPTY_MAP); 113 assertEquals(TEST_ENDPOINT_URI, testEndpoint.getEndpointUri()); 114 } 115 116}