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.serialization; 019 020import static org.fcrepo.camel.JmsHeaders.BASE_URL; 021import static org.fcrepo.camel.JmsHeaders.EVENT_TYPE; 022import static org.fcrepo.camel.JmsHeaders.IDENTIFIER; 023import static org.fcrepo.camel.RdfNamespaces.REPOSITORY; 024 025import org.junit.Test; 026import java.util.Map; 027 028import com.google.common.collect.ImmutableMap; 029import org.apache.camel.builder.AdviceWithRouteBuilder; 030import org.apache.camel.util.ObjectHelper; 031import org.apache.commons.io.IOUtils; 032 033/** 034 * Test the route workflow (property 'includeBinaries' is false). 035 * 036 * @author Bethany Seeger 037 * @since 2015-09-28 038 */ 039 040public class BinaryDisabledRouteTest extends AbstractRouteTest { 041 042 @Test 043 public void testMetatdataSerialization() throws Exception { 044 context.getRouteDefinition("FcrepoSerialization").adviceWith(context, new AdviceWithRouteBuilder() { 045 @Override 046 public void configure() throws Exception { 047 replaceFromWith("direct:start"); 048 mockEndpointsAndSkip("*"); 049 } 050 }); 051 context.start(); 052 053 getMockEndpoint("mock:direct:metadata").expectedMessageCount(1); 054 getMockEndpoint("mock:direct:binary").expectedMessageCount(1); 055 getMockEndpoint("mock:direct:delete").expectedMessageCount(0); 056 057 // send a file! 058 final String body = IOUtils.toString(ObjectHelper.loadResourceAsStream("binary.rdf"), "UTF-8"); 059 final Map<String, Object> headers = ImmutableMap.of(BASE_URL, baseURL); 060 061 template.sendBodyAndHeaders(body, headers); 062 063 assertMockEndpointsSatisfied(); 064 } 065 066 @Test 067 public void testMetadataSerializationRemoveNode() throws Exception { 068 context.getRouteDefinition("FcrepoSerialization").adviceWith(context, new AdviceWithRouteBuilder() { 069 @Override 070 public void configure() throws Exception { 071 replaceFromWith("direct:start"); 072 mockEndpointsAndSkip("*"); 073 } 074 }); 075 context.start(); 076 077 getMockEndpoint("mock:direct:metadata").expectedMessageCount(0); 078 getMockEndpoint("mock:direct:binary").expectedMessageCount(0); 079 getMockEndpoint("mock:direct:delete").expectedMessageCount(1); 080 081 // send a file! 082 final String body = IOUtils.toString(ObjectHelper.loadResourceAsStream("binary.rdf"), "UTF-8"); 083 final Map<String, Object> headers = ImmutableMap.of( 084 BASE_URL, baseURL, 085 IDENTIFIER, identifier, 086 EVENT_TYPE, REPOSITORY + "NODE_REMOVED"); 087 088 template.sendBodyAndHeaders(body, headers); 089 090 assertMockEndpointsSatisfied(); 091 } 092 093 @Test 094 public void testMetadataReSerialization() throws Exception { 095 context.getRouteDefinition("FcrepoReSerialization").adviceWith(context, new AdviceWithRouteBuilder() { 096 @Override 097 public void configure() throws Exception { 098 replaceFromWith("direct:start"); 099 mockEndpointsAndSkip("*"); 100 } 101 }); 102 context.start(); 103 104 getMockEndpoint("mock:direct:metadata").expectedMessageCount(1); 105 getMockEndpoint("mock:direct:binary").expectedMessageCount(1); 106 107 // send a file! 108 final String body = IOUtils.toString(ObjectHelper.loadResourceAsStream("binary.rdf"), "UTF-8"); 109 final Map<String, Object> headers = ImmutableMap.of(BASE_URL, baseURL); 110 111 template.sendBodyAndHeaders(body, headers); 112 113 assertMockEndpointsSatisfied(); 114 } 115 116 @Test 117 public void testMetadataUpdaterIndexable() throws Exception { 118 context.getRouteDefinition("FcrepoSerializationMetadataUpdater").adviceWith(context, 119 new AdviceWithRouteBuilder() { 120 @Override 121 public void configure() throws Exception { 122 replaceFromWith("direct:start"); 123 mockEndpointsAndSkip("*"); 124 weaveAddLast().to("mock:result"); 125 } 126 }); 127 context.start(); 128 129 resultEndpoint.expectedMessageCount(1); 130 131 // send a file! 132 final String body = IOUtils.toString(ObjectHelper.loadResourceAsStream("indexable.rdf"), "UTF-8"); 133 final Map<String, Object> headers = ImmutableMap.of(BASE_URL, baseURL); 134 135 template.sendBodyAndHeaders(body, headers); 136 137 assertMockEndpointsSatisfied(); 138 } 139 140 @Test 141 public void testMetadataUpdaterBinary() throws Exception { 142 context.getRouteDefinition("FcrepoSerializationBinaryUpdater").adviceWith(context, 143 new AdviceWithRouteBuilder() { 144 @Override 145 public void configure() throws Exception { 146 replaceFromWith("direct:start"); 147 mockEndpointsAndSkip("*"); 148 } 149 }); 150 context.start(); 151 // this should be zero because writing binaries is disabled by default. 152 getMockEndpoint("mock:file:binary_file").expectedMessageCount(0); 153 154 // send a file! 155 final String body = IOUtils.toString(ObjectHelper.loadResourceAsStream("binary.rdf"), "UTF-8"); 156 final Map<String, Object> headers = ImmutableMap.of( 157 BASE_URL, baseURL, 158 IDENTIFIER, "foo"); 159 160 template.sendBodyAndHeaders(body, headers); 161 162 assertMockEndpointsSatisfied(); 163 } 164}