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.fcrepo.camel.processor.ProcessorUtils.tokenizePropertyPlaceholder;
021import static org.junit.Assert.assertEquals;
022import static org.junit.Assert.assertTrue;
023
024import java.util.List;
025import java.util.Properties;
026
027import org.apache.camel.test.junit4.CamelTestSupport;
028import org.junit.Test;
029
030/**
031 * @author acoburn
032 */
033public class ProcessorUtilsTest extends CamelTestSupport {
034
035    @Override
036    protected Properties useOverridePropertiesWithPropertiesComponent() {
037         final Properties props = new Properties();
038         props.put("test.prop1", "one,two,three");
039         props.put("test.prop2", "    four   ,   five\n,six ");
040         props.put("test.prop3", "seven");
041         props.put("test.prop4", "eight,\n\t\tnine,\n   ten");
042         props.put("test.prop5", "");
043         props.put("test.prop6", "    ");
044         return props;
045    }
046
047    @Test
048    public void testPropertyTokenizerSimple() {
049        final List<String> list1 = tokenizePropertyPlaceholder(context, "{{test.prop1}}", "\\s*,\\s*");
050        assertEquals(3, list1.size());
051        assertTrue(list1.contains("one"));
052        assertTrue(list1.contains("two"));
053        assertTrue(list1.contains("three"));
054    }
055
056    @Test
057    public void testPropertyTokenizerWhitespace1() {
058        final List<String> list2 = tokenizePropertyPlaceholder(context, "{{test.prop2}}", "\\s*,\\s*");
059        assertEquals(3, list2.size());
060        assertTrue(list2.contains("four"));
061        assertTrue(list2.contains("five"));
062        assertTrue(list2.contains("six"));
063    }
064
065    @Test
066    public void testPropertyTokenizerSingleton() {
067        final List<String> list3 = tokenizePropertyPlaceholder(context, "{{test.prop3}}", "\\s*,\\s*");
068        assertEquals(1, list3.size());
069        assertTrue(list3.contains("seven"));
070    }
071
072    @Test
073    public void testPropertyTokenizerWhitespace2() {
074        final List<String> list4 = tokenizePropertyPlaceholder(context, "{{test.prop4}}", "\\s*,\\s*");
075        assertEquals(3, list4.size());
076        assertTrue(list4.contains("eight"));
077        assertTrue(list4.contains("nine"));
078        assertTrue(list4.contains("ten"));
079    }
080
081    @Test
082    public void testPropertyTokenizerEmpty1() {
083        final List<String> list5 = tokenizePropertyPlaceholder(context, "{{test.prop5}}", "\\s*,\\s*");
084        assertEquals(0, list5.size());
085    }
086
087    @Test
088    public void testPropertyTokenizerEmpty2() {
089        final List<String> list6 = tokenizePropertyPlaceholder(context, "{{test.prop6}}", "\\s*,\\s*");
090        assertEquals(0, list6.size());
091    }
092
093    @Test
094    public void testPropertyTokenizerNotDefined() {
095        final List<String> list7 = tokenizePropertyPlaceholder(context, "{{test.prop7}}", "\\s*,\\s*");
096        assertEquals(0, list7.size());
097    }
098}