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 org.junit.Assert.assertEquals; 021import static org.junit.Assert.assertNotNull; 022 023import org.apache.camel.Processor; 024import org.apache.camel.Producer; 025import org.apache.camel.RuntimeCamelException; 026import org.junit.Test; 027import org.junit.runner.RunWith; 028import org.mockito.Mock; 029import org.mockito.runners.MockitoJUnitRunner; 030 031/** 032 * @author ajs6f 033 */ 034@RunWith(MockitoJUnitRunner.class) 035public class FcrepoEndpointTest { 036 037 private final String FCREPO_URI = "fcrepo:foo/rest"; 038 039 private final String FCREPO_PATH = "foo/rest"; 040 041 @Mock 042 private FcrepoComponent mockContext; 043 044 @Mock 045 private Processor mockProcessor; 046 047 private FcrepoConfiguration testConfig = new FcrepoConfiguration(); 048 049 @Test(expected = RuntimeCamelException.class) 050 public void testNoConsumerCanBeCreated() throws RuntimeCamelException { 051 final FcrepoEndpoint testEndpoint = new FcrepoEndpoint(FCREPO_URI, FCREPO_PATH, mockContext, testConfig); 052 testEndpoint.createConsumer(mockProcessor); 053 } 054 055 @Test 056 public void testCreateTransactionTemplate() { 057 final FcrepoEndpoint testEndpoint = new FcrepoEndpoint(FCREPO_URI, FCREPO_PATH, mockContext, testConfig); 058 assertNotNull(testEndpoint.createTransactionTemplate()); 059 testEndpoint.setTransactionManager(new FcrepoTransactionManager()); 060 assertNotNull(testEndpoint.createTransactionTemplate()); 061 } 062 063 @Test 064 public void testCreateProducer() { 065 final FcrepoEndpoint testEndpoint = new FcrepoEndpoint(FCREPO_URI, FCREPO_PATH, mockContext, testConfig); 066 final Producer testProducer = testEndpoint.createProducer(); 067 assertEquals(testEndpoint, testProducer.getEndpoint()); 068 } 069 070 @Test 071 public void testBaseUrl() { 072 final FcrepoEndpoint testEndpoint = new FcrepoEndpoint(FCREPO_URI, FCREPO_PATH, mockContext, testConfig); 073 assertEquals(testEndpoint.getBaseUrl(), FCREPO_PATH); 074 } 075 076 @Test 077 public void testBaseUrlWithScheme1() { 078 final FcrepoEndpoint testEndpoint = new FcrepoEndpoint("fcrepo:localhost:8080/rest", "localhost:8080/rest", 079 mockContext, testConfig); 080 assertEquals("http://localhost:8080/rest", testEndpoint.getBaseUrlWithScheme()); 081 } 082 083 @Test 084 public void testBaseUrlWithScheme2() { 085 final FcrepoEndpoint testEndpoint = new FcrepoEndpoint("fcrepo:https://localhost/rest", 086 "https://localhost/rest", 087 mockContext, testConfig); 088 assertEquals("https://localhost/rest", testEndpoint.getBaseUrlWithScheme()); 089 } 090 091 @Test 092 public void testBaseUrlWithScheme3() { 093 final FcrepoEndpoint testEndpoint = new FcrepoEndpoint("fcrepo://localhost:443/rest", 094 "localhost:443/rest", 095 mockContext, testConfig); 096 assertEquals("https://localhost:443/rest", testEndpoint.getBaseUrlWithScheme()); 097 } 098 099 @Test 100 public void testBaseUrlWithScheme4() { 101 final FcrepoEndpoint testEndpoint = new FcrepoEndpoint("fcrepo:http://localhost:8080/rest", 102 "http://localhost:8080/rest", 103 mockContext, testConfig); 104 assertEquals("http://localhost:8080/rest", testEndpoint.getBaseUrlWithScheme()); 105 } 106 107 @Test 108 public void testConfiguration() { 109 final FcrepoConfiguration config = new FcrepoConfiguration(); 110 config.setFixity(true); 111 112 final FcrepoEndpoint testEndpoint = new FcrepoEndpoint(FCREPO_URI, FCREPO_PATH, mockContext, testConfig); 113 assertEquals(false, testEndpoint.getFixity()); 114 testEndpoint.setConfiguration(config); 115 assertEquals(true, testEndpoint.getFixity()); 116 } 117 118 @Test 119 public void testThrowExceptionOnFailure() { 120 final FcrepoEndpoint testEndpoint = new FcrepoEndpoint(FCREPO_URI, FCREPO_PATH, mockContext, testConfig); 121 assertEquals(true, testEndpoint.getThrowExceptionOnFailure()); 122 testEndpoint.setThrowExceptionOnFailure(false); 123 assertEquals(false, testEndpoint.getThrowExceptionOnFailure()); 124 } 125 126 @Test 127 public void testFixity() { 128 final FcrepoEndpoint testEndpoint = new FcrepoEndpoint(FCREPO_URI, FCREPO_PATH, mockContext, testConfig); 129 assertEquals(false, testEndpoint.getFixity()); 130 testEndpoint.setFixity(true); 131 assertEquals(true, testEndpoint.getFixity()); 132 } 133 134 @Test 135 public void testMetadata() { 136 final FcrepoEndpoint testEndpoint = new FcrepoEndpoint(FCREPO_URI, FCREPO_PATH, mockContext, testConfig); 137 assertEquals(true, testEndpoint.getMetadata()); 138 testEndpoint.setMetadata(false); 139 assertEquals(false, testEndpoint.getMetadata()); 140 } 141 142 @Test 143 public void testAuthHost() { 144 final FcrepoEndpoint testEndpoint = new FcrepoEndpoint(FCREPO_URI, FCREPO_PATH, mockContext, testConfig); 145 final String authHost = "example.org"; 146 assertEquals(null, testEndpoint.getAuthHost()); 147 testEndpoint.setAuthHost(authHost); 148 assertEquals(authHost, testEndpoint.getAuthHost()); 149 } 150 151 @Test 152 public void testAuthUser() { 153 final FcrepoEndpoint testEndpoint = new FcrepoEndpoint(FCREPO_URI, FCREPO_PATH, mockContext, testConfig); 154 final String authUser = "fedoraAdmin"; 155 assertEquals(null, testEndpoint.getAuthUsername()); 156 testEndpoint.setAuthUsername(authUser); 157 assertEquals(authUser, testEndpoint.getAuthUsername()); 158 } 159 160 @Test 161 public void testAuthPassword() { 162 final FcrepoEndpoint testEndpoint = new FcrepoEndpoint(FCREPO_URI, FCREPO_PATH, mockContext, testConfig); 163 final String authPassword = "foo"; 164 assertEquals(null, testEndpoint.getAuthPassword()); 165 testEndpoint.setAuthPassword(authPassword); 166 assertEquals(authPassword, testEndpoint.getAuthPassword()); 167 } 168 169 @Test 170 public void testAccept() { 171 final FcrepoEndpoint testEndpoint = new FcrepoEndpoint(FCREPO_URI, FCREPO_PATH, mockContext, testConfig); 172 final String accept1 = "application/rdf+xml"; 173 final String accept2 = "text/turtle"; 174 final String accept3 = "application/ld+json"; 175 final String accept4 = "application/sparql-update"; 176 assertEquals(null, testEndpoint.getAccept()); 177 testEndpoint.setAccept("application/rdf xml"); 178 assertEquals(accept1, testEndpoint.getAccept()); 179 testEndpoint.setAccept(accept2); 180 assertEquals(accept2, testEndpoint.getAccept()); 181 testEndpoint.setAccept(accept3); 182 assertEquals(accept3, testEndpoint.getAccept()); 183 testEndpoint.setAccept(accept4); 184 assertEquals(accept4, testEndpoint.getAccept()); 185 } 186 187 @Test 188 public void testContentType() { 189 final FcrepoEndpoint testEndpoint = new FcrepoEndpoint(FCREPO_URI, FCREPO_PATH, mockContext, testConfig); 190 final String contentType1 = "application/rdf+xml"; 191 final String contentType2 = "text/turtle"; 192 final String contentType3 = "application/ld+json"; 193 final String contentType4 = "application/sparql-update"; 194 assertEquals(null, testEndpoint.getContentType()); 195 testEndpoint.setContentType("application/rdf xml"); 196 assertEquals(contentType1, testEndpoint.getContentType()); 197 testEndpoint.setContentType(contentType2); 198 assertEquals(contentType2, testEndpoint.getContentType()); 199 testEndpoint.setContentType(contentType3); 200 assertEquals(contentType3, testEndpoint.getContentType()); 201 testEndpoint.setContentType(contentType4); 202 assertEquals(contentType4, testEndpoint.getContentType()); 203 } 204 205 @Test 206 public void testPreferOmit() { 207 final FcrepoEndpoint testEndpoint = new FcrepoEndpoint(FCREPO_URI, FCREPO_PATH, mockContext, testConfig); 208 final String omit1 = "PreferContainment"; 209 final String omit2 = "http://www.w3.org/ns/ldp#PreferMembership"; 210 final String omit3 = "http://www.w3.org/ns/ldp#PreferMinimalContainer " + 211 "http://www.w3.org/ns/ldp#PreferContainment"; 212 assertEquals(null, testEndpoint.getPreferOmit()); 213 testEndpoint.setPreferOmit(omit1); 214 assertEquals(omit1, testEndpoint.getPreferOmit()); 215 testEndpoint.setPreferOmit(omit2); 216 assertEquals(omit2, testEndpoint.getPreferOmit()); 217 testEndpoint.setPreferOmit(omit3); 218 assertEquals(omit3, testEndpoint.getPreferOmit()); 219 } 220 221 @Test 222 public void testPreferInclude() { 223 final FcrepoEndpoint testEndpoint = new FcrepoEndpoint(FCREPO_URI, FCREPO_PATH, mockContext, testConfig); 224 final String include1 = "PreferContainment"; 225 final String include2 = "http://www.w3.org/ns/ldp#PreferMembership"; 226 final String include3 = "http://www.w3.org/ns/ldp#PreferMinimalContainer " + 227 "http://www.w3.org/ns/ldp#PreferContainment"; 228 assertEquals(null, testEndpoint.getPreferInclude()); 229 testEndpoint.setPreferInclude(include1); 230 assertEquals(include1, testEndpoint.getPreferInclude()); 231 testEndpoint.setPreferInclude(include2); 232 assertEquals(include2, testEndpoint.getPreferInclude()); 233 testEndpoint.setPreferInclude(include3); 234 assertEquals(include3, testEndpoint.getPreferInclude()); 235 } 236 237 @Test 238 public void testSingleton() { 239 final FcrepoEndpoint testEndpoint = new FcrepoEndpoint(FCREPO_URI, FCREPO_PATH, mockContext, testConfig); 240 assertEquals(true, testEndpoint.isSingleton()); 241 } 242 243}