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