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.apache.camel.util.ObjectHelper.loadResourceAsStream; 021import static org.fcrepo.camel.FcrepoHeaders.FCREPO_URI; 022import static org.fcrepo.camel.serialization.SerializationRouter.SERIALIZATION_PATH; 023 024import org.junit.Test; 025 026import org.apache.camel.builder.AdviceWithRouteBuilder; 027 028/** 029 * Test the route workflow (property 'includeBinaries' is false). 030 * 031 * @author Bethany Seeger 032 * @since 2015-09-28 033 */ 034 035public class BinaryDisabledRouteTest extends AbstractRouteTest { 036 037 @Test 038 public void testMetatdataSerialization() throws Exception { 039 context.getRouteDefinition("FcrepoSerialization").adviceWith(context, new AdviceWithRouteBuilder() { 040 @Override 041 public void configure() throws Exception { 042 replaceFromWith("direct:start"); 043 mockEndpointsAndSkip("*"); 044 } 045 }); 046 context.start(); 047 048 getMockEndpoint("mock:direct:metadata").expectedMessageCount(1); 049 getMockEndpoint("mock:direct:binary").expectedMessageCount(1); 050 getMockEndpoint("mock:direct:delete").expectedMessageCount(0); 051 052 // send a file! 053 template.sendBody(loadResourceAsStream("event.json")); 054 055 assertMockEndpointsSatisfied(); 056 } 057 058 @Test 059 public void testMetadataSerializationRemoveNode() throws Exception { 060 context.getRouteDefinition("FcrepoSerialization").adviceWith(context, new AdviceWithRouteBuilder() { 061 @Override 062 public void configure() throws Exception { 063 replaceFromWith("direct:start"); 064 mockEndpointsAndSkip("*"); 065 } 066 }); 067 context.start(); 068 069 getMockEndpoint("mock:direct:metadata").expectedMessageCount(0); 070 getMockEndpoint("mock:direct:binary").expectedMessageCount(0); 071 getMockEndpoint("mock:direct:delete").expectedMessageCount(1); 072 073 template.sendBody(loadResourceAsStream("event_delete_resource.json")); 074 075 assertMockEndpointsSatisfied(); 076 } 077 078 @Test 079 public void testMetadataReSerialization() throws Exception { 080 context.getRouteDefinition("FcrepoReSerialization").adviceWith(context, new AdviceWithRouteBuilder() { 081 @Override 082 public void configure() throws Exception { 083 replaceFromWith("direct:start"); 084 mockEndpointsAndSkip("*"); 085 } 086 }); 087 context.start(); 088 089 getMockEndpoint("mock:direct:metadata").expectedMessageCount(1); 090 getMockEndpoint("mock:direct:binary").expectedMessageCount(1); 091 092 template.sendBodyAndHeader(loadResourceAsStream("binary.rdf"), FCREPO_URI, baseURL); 093 094 assertMockEndpointsSatisfied(); 095 } 096 097 @Test 098 public void testMetadataUpdaterIndexable() throws Exception { 099 context.getRouteDefinition("FcrepoSerializationMetadataUpdater").adviceWith(context, 100 new AdviceWithRouteBuilder() { 101 @Override 102 public void configure() throws Exception { 103 replaceFromWith("direct:start"); 104 mockEndpointsAndSkip("*"); 105 weaveAddLast().to("mock:result"); 106 } 107 }); 108 context.start(); 109 110 resultEndpoint.expectedMessageCount(1); 111 112 // send a file! 113 template.sendBody(loadResourceAsStream("indexable.rdf")); 114 115 assertMockEndpointsSatisfied(); 116 } 117 118 @Test 119 public void testMetadataUpdaterBinary() throws Exception { 120 context.getRouteDefinition("FcrepoSerializationBinaryUpdater").adviceWith(context, 121 new AdviceWithRouteBuilder() { 122 @Override 123 public void configure() throws Exception { 124 replaceFromWith("direct:start"); 125 mockEndpointsAndSkip("*"); 126 } 127 }); 128 context.start(); 129 // this should be zero because writing binaries is disabled by default. 130 getMockEndpoint("mock:file:binary_file").expectedMessageCount(0); 131 132 template.sendBodyAndHeader(loadResourceAsStream("binary.rdf"), SERIALIZATION_PATH, "/foo"); 133 134 assertMockEndpointsSatisfied(); 135 } 136}