Moved repository master into its own directory

This commit is contained in:
Chris Shields
2020-07-21 10:43:33 +01:00
parent a7afb73e58
commit cbd58ea958
6316 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,78 @@
/*
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.service;
import static org.junit.Assert.fail;
import java.lang.reflect.Method;
import org.alfresco.util.ApplicationContextHelper;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
public class ServiceRegistryTest
{
protected ApplicationContext ctx;
protected ServiceRegistry serviceRegistry;
@Before
public void before() throws Exception
{
ctx = ApplicationContextHelper.getApplicationContext();
serviceRegistry = (ServiceRegistry) ctx.getBean("ServiceRegistry");
}
@Test
public void testServiceRegistryGetters() throws Exception
{
Method[] methods = serviceRegistry.getClass().getMethods();
for (Method method : methods)
{
if (method.getName().startsWith("get") && (method.getParameterTypes().length == 0))
{
try
{
method.invoke(serviceRegistry, null);
}
catch (java.lang.reflect.InvocationTargetException i)
{
if (i.getTargetException() instanceof UnsupportedOperationException)
{
continue;
}
fail("Failed to invoke " + method.getName() + " : " + i.getTargetException().getMessage());
}
catch (Exception e)
{
fail("Failed to invoke " + method.getName() + " : " + e.getMessage());
}
}
}
}
}

View File

@@ -0,0 +1,151 @@
/*
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.service.cmr.calendar;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
/**
* Tests for the {@link CalendarRecurrenceHelper} class.
*
* @author Matt Ward
*/
public class CalendarRecurrenceHelperTest
{
@Test
public void fixOutlookRecurrenceQuirks_GenuineMonthlyRecurrenceParamsLeftAsIs()
{
Map<String, String> in = Params.fromKVPs("BYMONTHDAY=24", "FREQ=MONTHLY", "INTERVAL=1");
Map<String, String> out = CalendarRecurrenceHelper.fixOutlookRecurrenceQuirks(Params.fromMap(in));
// A monthly recurring event specified correctly, will remain untouched.
assertEquals(in, out);
// Double check we're not just comparing in with itself.
assertNotSame(in, out);
}
/**
* ALF-18928: Yearly recurring event specified incorrectly (as monthly) by outlook.
*/
@Test
public void fixOutlookRecurrenceQuirks_MonthlyRecurrenceThatShouldBeYearly()
{
Map<String, String> in = Params.fromKVPs("BYMONTHDAY=25", "FREQ=MONTHLY", "INTERVAL=24", "BYMONTH=7");
Map<String, String> out = CalendarRecurrenceHelper.fixOutlookRecurrenceQuirks(Params.fromMap(in));
// A yearly recurring event that has been incorrectly specified as monthly, is fixed up.
// Note FREQ and INTERVAL have been corrected.
assertEquals(Params.fromKVPs("BYMONTHDAY=25", "FREQ=YEARLY", "INTERVAL=2", "BYMONTH=7"), out);
}
@Test
public void fixOutlookRecurrenceQuirks_YearlyRecurrenceParamsLeftAsIs()
{
Map<String, String> in = Params.fromKVPs("BYMONTHDAY=25", "FREQ=YEARLY", "INTERVAL=2", "BYMONTH=7");
Map<String, String> out = CalendarRecurrenceHelper.fixOutlookRecurrenceQuirks(Params.fromMap(in));
// A yearly recurring event specified correctly, will remain untouched.
assertEquals(in, out);
// Double check we're not just comparing in with itself.
assertNotSame(in, out);
}
// MNT-10006 fix. Validates the patterns 'weekday', 'weekend day', 'day'
@Test
public void fixOutLookRecurrenceQuirks_weekdayRecurrenceRule()
{
Map<String, String> recurrenceRule = Params.fromKVPs("FREQ=MONTHLY", "BYDAY=MO,TU,WE,TH,FR", "INTERVAL=1", "BYSETPOS=1");
Map<String, String> fixedRecurrenceRule = CalendarRecurrenceHelper.fixOutlookRecurrenceQuirks(Params.fromMap(recurrenceRule));
assertEquals(null, fixedRecurrenceRule.get("BYDAY"));
assertEquals(null, fixedRecurrenceRule.get("BYSETPOS"));
assertEquals("1", fixedRecurrenceRule.get("BYWEEKDAY"));
assertEquals("MO,TU,WE,TH,FR", fixedRecurrenceRule.get("WEEKDAYS"));
}
@Test
public void fixOutLookRecurrenceQuirks_weekendDayRecurrenceRule()
{
Map<String, String> recurrenceRule = Params.fromKVPs("FREQ=MONTHLY", "BYDAY=SU,SA", "INTERVAL=1", "BYSETPOS=1");
Map<String, String> fixedRecurrenceRule = CalendarRecurrenceHelper.fixOutlookRecurrenceQuirks(Params.fromMap(recurrenceRule));
assertEquals(null, fixedRecurrenceRule.get("BYDAY"));
assertEquals(null, fixedRecurrenceRule.get("BYSETPOS"));
assertEquals("1", fixedRecurrenceRule.get("BYWEEKENDDAY"));
assertEquals("SU,SA", fixedRecurrenceRule.get("WEEKENDS"));
}
@Test
public void fixOutLookRecurrenceQuirks_dayRecurrenceRule()
{
Map<String, String> recurrenceRule = Params.fromKVPs("FREQ=MONTHLY", "BYDAY=SU,MO,TU,WE,TH,FR,SA", "INTERVAL=1", "BYSETPOS=1");
Map<String, String> fixedRecurrenceRule = CalendarRecurrenceHelper.fixOutlookRecurrenceQuirks(Params.fromMap(recurrenceRule));
assertEquals("1", fixedRecurrenceRule.get("BYANYDAY"));
assertEquals(null, fixedRecurrenceRule.get("BYSETPOS"));
assertEquals(null, fixedRecurrenceRule.get("BYMONTHDAY"));
assertEquals("SU,MO,TU,WE,TH,FR,SA", fixedRecurrenceRule.get("DAY"));
}
/**
* Inner class just here to make the tests more readable.
*/
private static class Params extends HashMap<String, String>
{
private static final long serialVersionUID = 1648766671461600951L;
private Params()
{
}
private Params(Map<String, String> params)
{
super(params);
}
private static Params fromMap(Map<String, String> params)
{
return new Params(params);
}
private static Params fromKVPs(String... keyValuePairs)
{
Params params = new Params();
for (String kvp : keyValuePairs)
{
String[] split = kvp.split("=");
assertEquals("Key/value pair is not valid: " + kvp, 2, split.length);
params.put(split[0], split[1]);
}
return params;
}
}
}

View File

@@ -0,0 +1,78 @@
/*
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.service.cmr.calendar;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class CalendarTimezoneHelperTest {
/**
* Ensure that iCal lines are split into key and value
* by the first unquoted colon
*/
@Test
public void icalLineKeyValue(){
//blank line
String icalLine = "";
String[] keyVal = CalendarTimezoneHelper.icalLineKeyValue(icalLine);
assertEquals("", keyVal[0]);
assertEquals("", keyVal[1]);
//single unquoted
icalLine = "a:b";
keyVal = CalendarTimezoneHelper.icalLineKeyValue(icalLine);
assertEquals("a", keyVal[0]);
assertEquals("b", keyVal[1]);
//multiple unquoted colons
icalLine = "a:bcd:ds";
keyVal = CalendarTimezoneHelper.icalLineKeyValue(icalLine);
assertEquals("a", keyVal[0]);
assertEquals("bcd:ds", keyVal[1]);
//deliminating colon preceded by quoted colon
icalLine = "a\":bcdA\":ds";
keyVal = CalendarTimezoneHelper.icalLineKeyValue(icalLine);
assertEquals("a\":bcdA\"", keyVal[0]);
assertEquals("ds", keyVal[1]);
//deliminating colon preceded and followed by quoted colons
icalLine = "a\":bcdA\":ds\"hello\"";
keyVal = CalendarTimezoneHelper.icalLineKeyValue(icalLine);
assertEquals("a\":bcdA\"", keyVal[0]);
assertEquals("ds\"hello\"", keyVal[1]);
//unbalanced quotes
icalLine = "a\":bcdA:ds";
keyVal = CalendarTimezoneHelper.icalLineKeyValue(icalLine);
assertEquals("", keyVal[0]);
assertEquals("", keyVal[1]);
}
}

View File

@@ -0,0 +1,148 @@
/*
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.service.cmr.repository;
import static org.junit.Assert.*;
import org.alfresco.error.AlfrescoRuntimeException;
import org.junit.Before;
import org.junit.Test;
/**
* Test {@link TemporalSourceOptions}.
*
* @author Ray Gauss II
*
* @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
*/
@Deprecated
public class TemporalSourceOptionsTest
{
private TemporalSourceOptions temporalSourceOptions;
private String[] expectedFailures = new String[] {
"not even close",
"2 hours",
"01:00", // Incomplete: hours, minutes, and seconds required
"0.01", // Incomplete: hours, minutes, and seconds required
"00.00.01", // Delimiter is incorrect
"1:30:15", // Hours, minutes, and seconds must have leading zeros
"00:99:99" // Minutes and seconds can not be greater than 60
};
private String[] expectedSuccesses = new String[] {
"00:00:00.05",
"00:01:30",
"01:01:01",
"01:01:01.1",
"99:59:59.999",
"99:00:00"
};
@Before
public void setUp() throws Exception
{
temporalSourceOptions = new TemporalSourceOptions();
}
protected void setDurationWithExpectedFailure(String value)
{
try
{
temporalSourceOptions.setDuration(value);
fail("'" + value + "' should be invalid");
}
catch (AlfrescoRuntimeException e)
{
// expected
}
}
protected void setDurationWithExpectedSuccess(String value)
{
try
{
temporalSourceOptions.setDuration(value);
}
catch (AlfrescoRuntimeException e)
{
fail(e.getMessage());
}
}
protected void setOffsetWithExpectedFailure(String value)
{
try
{
temporalSourceOptions.setOffset(value);
fail("'" + value + "' should be invalid");
}
catch (AlfrescoRuntimeException e)
{
// expected
}
}
protected void setOffsetWithExpectedSuccess(String value)
{
try
{
temporalSourceOptions.setOffset(value);
}
catch (AlfrescoRuntimeException e)
{
fail(e.getMessage());
}
}
@Test
public void testDurationValidation() throws Exception
{
for (String expectedFailure : expectedFailures)
{
setDurationWithExpectedFailure(expectedFailure);
}
for (String expectedSuccess : expectedSuccesses)
{
setDurationWithExpectedSuccess(expectedSuccess);
}
}
@Test
public void testOffsetValidation() throws Exception
{
for (String expectedFailure : expectedFailures)
{
setOffsetWithExpectedFailure(expectedFailure);
}
for (String expectedSuccess : expectedSuccesses)
{
setOffsetWithExpectedSuccess(expectedSuccess);
}
}
}

View File

@@ -0,0 +1,391 @@
/*
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.service.cmr.repository;
import static org.junit.Assert.assertEquals;
import java.util.HashMap;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
/**
* Test TransformationOptionLimits
*
* @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
*/
@Deprecated
public class TransformationOptionLimitsTest
{
private TransformationOptionLimits limits;
@Before
public void setUp() throws Exception
{
limits = new TransformationOptionLimits();
}
@Test
public void testTimeoutMs() throws Exception
{
long value = 1234;
limits.setTimeoutMs(value);
long actual = limits.getTimeoutMs();
assertEquals("Getter did not return set value", value, actual);
}
@Test
public void testReadLimitTimeMs() throws Exception
{
long value = 1234;
limits.setReadLimitTimeMs(value);
long actual = limits.getReadLimitTimeMs();
assertEquals("Getter did not return set value", value, actual);
}
@Test
public void testMaxSourceSizeKBytes() throws Exception
{
long value = 1234;
limits.setMaxSourceSizeKBytes(value);
long actual = limits.getMaxSourceSizeKBytes();
assertEquals("Getter did not return set value", value, actual);
}
@Test
public void testReadLimitKBytes() throws Exception
{
long value = 1234;
limits.setReadLimitKBytes(value);
long actual = limits.getReadLimitKBytes();
assertEquals("Getter did not return set value", value, actual);
}
@Test
public void testMaxPages() throws Exception
{
int value = 1234;
limits.setMaxPages(value);
int actual = limits.getMaxPages();
assertEquals("Getter did not return set value", value, actual);
}
@Test
public void testPageLimit() throws Exception
{
int value = 1234;
limits.setPageLimit(value);
int actual = limits.getPageLimit();
assertEquals("Getter did not return set value", value, actual);
}
@Test
public void testTimeException() throws Exception
{
String message = null;
limits.setTimeoutMs(1);
try
{
limits.setReadLimitTimeMs(1);
}
catch (IllegalArgumentException e)
{
message = e.getMessage();
}
assertEquals("Wrong exception message", TransformationOptionLimits.TIME_MESSAGE, message);
}
@Test
public void testKBytesException() throws Exception
{
String message = null;
limits.setMaxSourceSizeKBytes(1);
try
{
limits.setReadLimitKBytes(1);
}
catch (IllegalArgumentException e)
{
message = e.getMessage();
}
assertEquals("Wrong exception message", TransformationOptionLimits.KBYTES_MESSAGE, message);
}
@Test
public void testPageException() throws Exception
{
String message = null;
limits.setPageLimit(1);
try
{
limits.setMaxPages(1);
}
catch (IllegalArgumentException e)
{
message = e.getMessage();
}
assertEquals("Wrong exception message", TransformationOptionLimits.PAGES_MESSAGE, message);
}
@Test
public void testMapMax() throws Exception
{
limits.setTimeoutMs(123);
limits.setMaxSourceSizeKBytes(456);
limits.setMaxPages(789);
Map<String, Object> optionsMap = new HashMap<String, Object>();
limits.toMap(optionsMap);
TransformationOptionLimits actual = new TransformationOptionLimits();
actual.set(optionsMap);
assertEquals("Did not match original values", limits, actual);
}
@Test
public void testMapLimit() throws Exception
{
limits.setReadLimitTimeMs(123);
limits.setReadLimitKBytes(456);
limits.setPageLimit(789);
Map<String, Object> optionsMap = new HashMap<String, Object>();
limits.toMap(optionsMap);
TransformationOptionLimits actual = new TransformationOptionLimits();
actual.set(optionsMap);
assertEquals("Did not match original values", limits, actual);
}
@Test
public void testTimePair() throws Exception
{
int value = 1234;
limits.setTimeoutMs(value);
long actual = limits.getTimePair().getMax();
assertEquals("Returned TransformationOptionPair did not contain set value", value, actual);
}
@Test
public void testKBytesPair() throws Exception
{
int value = 1234;
limits.setMaxSourceSizeKBytes(value);
long actual = limits.getKBytesPair().getMax();
assertEquals("Returned TransformationOptionPair did not contain set value", value, actual);
}
@Test
public void testPagePair() throws Exception
{
int value = 1234;
limits.setMaxPages(value);
long actual = limits.getPagesPair().getMax();
assertEquals("Returned TransformationOptionPair did not contain set value", value, actual);
}
@Test
public void testCombineOrder() throws Exception
{
limits.setReadLimitTimeMs(123);
limits.setReadLimitKBytes(45);
limits.setMaxPages(789);
TransformationOptionLimits second = new TransformationOptionLimits();
second.setReadLimitTimeMs(12);
second.setReadLimitKBytes(456);
second.setMaxPages(789);
TransformationOptionLimits combined = limits.combine(second);
TransformationOptionLimits combinedOtherWay = second.combine(limits);
assertEquals("The combine order should not matter", combined, combinedOtherWay);
}
@Test
public void testCombine() throws Exception
{
limits.setReadLimitTimeMs(123);
limits.setReadLimitKBytes(45);
limits.setPageLimit(789);
TransformationOptionLimits second = new TransformationOptionLimits();
second.setTimeoutMs(12);
second.setMaxSourceSizeKBytes(456);
second.setMaxPages(789);
TransformationOptionLimits combined = limits.combine(second);
assertEquals("Expected the lower value", 12, combined.getTimeoutMs()); // max <
assertEquals("Expected the lower value", 45, combined.getReadLimitKBytes()); // limit <
assertEquals("Expected the lower value", 789, combined.getMaxPages()); // max =
assertEquals("Expected -1 as max is set", -1, combined.getReadLimitTimeMs()); // max <
assertEquals("Expected -1 as limit is set", -1, combined.getMaxSourceSizeKBytes()); // limit <
assertEquals("Expected -1 as limit is the same", -1, combined.getPageLimit()); // max =
}
@Test
public void testCombineLimits() throws Exception
{
limits.setReadLimitTimeMs(123);
limits.setReadLimitKBytes(45);
limits.setPageLimit(789);
TransformationOptionLimits second = new TransformationOptionLimits();
second.setReadLimitTimeMs(12);
second.setReadLimitKBytes(-1);
second.setPageLimit(789);
TransformationOptionLimits combined = limits.combine(second);
assertEquals("Expected the lower value", 12, combined.getReadLimitTimeMs());
assertEquals("Expected the lower value", 45, combined.getReadLimitKBytes());
assertEquals("Expected the lower value", 789, combined.getPageLimit());
}
@Test
public void testCombineUpper() throws Exception
{
limits.setReadLimitTimeMs(123);
limits.setReadLimitKBytes(45);
limits.setPageLimit(789);
TransformationOptionLimits second = new TransformationOptionLimits();
second.setTimeoutMs(12);
second.setMaxSourceSizeKBytes(456);
second.setMaxPages(789);
TransformationOptionLimits combined = limits.combineUpper(second);
assertEquals("Expected -1 as only one max value was set", -1, combined.getTimeoutMs());
assertEquals("Expected -1 as only one max value was set", -1, combined.getMaxSourceSizeKBytes());
assertEquals("Expected -1 as only one max value was set", -1, combined.getMaxPages());
assertEquals("Expected -1 as only one limit value was set", -1, combined.getReadLimitTimeMs());
assertEquals("Expected -1 as only one limit value was set", -1, combined.getReadLimitKBytes());
assertEquals("Expected -1 as only one limit value was set", -1, combined.getPageLimit());
}
@Test
public void testCombineUpperLimits() throws Exception
{
limits.setReadLimitTimeMs(123);
limits.setReadLimitKBytes(45);
limits.setPageLimit(789);
TransformationOptionLimits second = new TransformationOptionLimits();
second.setReadLimitTimeMs(12);
second.setReadLimitKBytes(-1);
second.setPageLimit(789);
TransformationOptionLimits combined = limits.combineUpper(second);
assertEquals("Expected the higher value", 123, combined.getReadLimitTimeMs());
assertEquals("Expected -1 as only one limit value was set", -1, combined.getReadLimitKBytes());
assertEquals("Expected the higher value", 789, combined.getPageLimit());
}
@Test
public void testCombineDynamic() throws Exception
{
limits.setReadLimitTimeMs(123);
limits.setReadLimitKBytes(45);
limits.setMaxPages(789);
TransformationOptionLimits second = new TransformationOptionLimits();
second.setReadLimitTimeMs(12);
second.setReadLimitKBytes(456);
second.setMaxPages(789);
TransformationOptionLimits combined = limits.combine(second);
// Test dynamic change of value
limits.setReadLimitKBytes(4560);
assertEquals("Expected the lower value", 456, combined.getReadLimitKBytes());
}
@Test(expected=UnsupportedOperationException.class)
public void testCombineSetTimeoutMs() throws Exception
{
TransformationOptionLimits combined = limits.combine(limits); // may combine with itself
combined.setTimeoutMs(1);
}
@Test(expected=UnsupportedOperationException.class)
public void testCombineSetReadLimitTimeMs() throws Exception
{
TransformationOptionLimits combined = limits.combine(limits); // may combine with itself
combined.setReadLimitTimeMs(1);
}
@Test(expected=UnsupportedOperationException.class)
public void testCombineSetMaxSourceSizeKBytes() throws Exception
{
TransformationOptionLimits combined = limits.combine(limits); // may combine with itself
combined.setMaxSourceSizeKBytes(1);
}
@Test(expected=UnsupportedOperationException.class)
public void testCombineSetReadLimitKBytes() throws Exception
{
TransformationOptionLimits combined = limits.combine(limits); // may combine with itself
combined.setReadLimitKBytes(1);
}
@Test(expected=UnsupportedOperationException.class)
public void testCombineSetMaxPages() throws Exception
{
TransformationOptionLimits combined = limits.combine(limits); // may combine with itself
combined.setMaxPages(1);
}
@Test(expected=UnsupportedOperationException.class)
public void testCombineSetPageLimit() throws Exception
{
TransformationOptionLimits combined = limits.combine(limits); // may combine with itself
combined.setPageLimit(1);
}
@Test(expected=UnsupportedOperationException.class)
public void testCombineSetMap() throws Exception
{
TransformationOptionLimits combined = limits.combine(limits); // may combine with itself
combined.set(null);
}
}

View File

@@ -0,0 +1,362 @@
/*
* #%L
* Alfresco Repository
* %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited
* %%
* This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms:
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
package org.alfresco.service.cmr.repository;
import java.util.HashMap;
import java.util.Map;
import org.alfresco.service.cmr.repository.TransformationOptionPair.Action;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
/**
* Test TransformationOptionPair
*
* @deprecated The transformations code is being moved out of the codebase and replaced by the new async RenditionService2 or other external libraries.
*/
@Deprecated
public class TransformationOptionPairTest
{
TransformationOptionPair pair;
@Before
public void setUp() throws Exception
{
pair = new TransformationOptionPair();
}
@Test
public void testUnset() throws Exception
{
long value = -1;
long actual = pair.getMax();
assertEquals("Getter did not return unset value", value, actual);
assertEquals("getValue() did not return set value", value, pair.getValue());
assertEquals("Expected action not returned", null, pair.getAction());
}
@Test
public void testMax() throws Exception
{
long value = 1234;
pair.setMax(value, null);
long actual = pair.getMax();
assertEquals("Getter did not return set value", value, actual);
assertEquals("getValue() did not return set value", value, pair.getValue());
assertEquals("Expected action not returned", Action.THROW_EXCEPTION, pair.getAction());
}
@Test
public void testLimit() throws Exception
{
long value = 1234;
pair.setLimit(value, null);
long actual = pair.getLimit();
assertEquals("Getter did not return set value", value, actual);
assertEquals("getValue() did not return set value", value, pair.getValue());
assertEquals("Expected action not returned", Action.RETURN_EOF, pair.getAction());
}
@Test
public void testMaxAlreadySet() throws Exception
{
String message = "Oh no the other value is set";
String actual = null;
pair.setMax(1234, null);
try
{
pair.setLimit(111, message);
}
catch (IllegalArgumentException e)
{
actual = e.getMessage();
}
assertEquals("Expected an IllegalArgumentException message", message, actual);
}
@Test
public void testLimitAlreadySet() throws Exception
{
String message = "Oh no the other value is set";
String actual = null;
pair.setLimit(1234, null);
try
{
pair.setMax(111, message);
}
catch (IllegalArgumentException e)
{
actual = e.getMessage();
}
assertEquals("Expected an IllegalArgumentException message", message, actual);
}
@Test
public void testSetMaxMultipleTimes() throws Exception
{
long value = 1234;
pair.setMax(1, null);
pair.setMax(2, null); // Should be no exception
pair.setMax(value, null);
long actual = pair.getMax();
assertEquals("Getter did not return set value", value, actual);
}
@Test
public void testSetLimitMultipleTimes() throws Exception
{
long value = 1234;
pair.setLimit(1, null);
pair.setLimit(2, null); // Should be no exception
pair.setLimit(value, null);
long actual = pair.getLimit();
assertEquals("Getter did not return set value", value, actual);
}
@Test
public void testSetMaxClearLimit() throws Exception
{
long value = 1234;
pair.setMax(value, null);
pair.setLimit(-1, null);
long actual = pair.getMax();
assertEquals("Getter did not return set value", value, actual);
}
@Test
public void testSetLimitClearMax() throws Exception
{
long value = 1234;
pair.setLimit(value, null);
pair.setMax(-1, null);
long actual = pair.getLimit();
assertEquals("Getter did not return set value", value, actual);
}
@Test
public void testSetClearSet() throws Exception
{
// Test there is no exception if we clear the other value first
String message = "Oh no the other value is set";
pair.setLimit(1, message);
pair.setLimit(-1, message);
pair.setMax(1, message);
pair.setMax(-1, message);
pair.setLimit(1, message);
}
@Test
public void testMapMax() throws Exception
{
String maxKey = "Max";
String limitKey = "Limit";
String message = "Oh no the other value is set";
pair.setMax(123, null);
Map<String, Object> optionsMap = new HashMap<String, Object>();
pair.toMap(optionsMap, maxKey, limitKey);
TransformationOptionPair actual = new TransformationOptionPair();
actual.set(optionsMap, maxKey, limitKey, message);
assertEquals("Did not match original values", pair, actual);
}
@Test
public void testMapLimit() throws Exception
{
String maxKey = "Max";
String limitKey = "Limit";
String message = "Oh no the other value is set";
pair.setLimit(123, null);
Map<String, Object> optionsMap = new HashMap<String, Object>();
pair.toMap(optionsMap, maxKey, limitKey);
TransformationOptionPair actual = new TransformationOptionPair();
actual.set(optionsMap, maxKey, limitKey, message);
assertEquals("Did not match original values", pair, actual);
}
@Test
public void testMapBothSet() throws Exception
{
String maxKey = "Max";
String limitKey = "Limit";
String message = "Oh no the other value is set";
pair.setLimit(123, null);
Map<String, Object> optionsMap = new HashMap<String, Object>();
pair.toMap(optionsMap, maxKey, limitKey);
optionsMap.put(maxKey, 456L); // Introduce error
String actual = null;
TransformationOptionPair pair2 = new TransformationOptionPair();
try
{
pair2.set(optionsMap, maxKey, limitKey, message);
}
catch (IllegalArgumentException e)
{
actual = e.getMessage();
}
assertEquals("Expected an IllegalArgumentException message", message, actual);
}
@Test
public void testMapNeitherSet() throws Exception
{
// Original value should not be changed if keys don't exist
long value = 1234;
String maxKey = "Max";
String limitKey = "Limit";
String message = "Oh no the other value is set";
pair.setLimit(value, null);
Map<String, Object> optionsMap = new HashMap<String, Object>();
optionsMap.put("AnotherKey", 456L);
pair.set(optionsMap, maxKey, limitKey, message);
long actual = pair.getLimit();
assertEquals("Original value should not be changed", value, actual);
}
@Test
public void testCombineOrder() throws Exception
{
TransformationOptionPair second = new TransformationOptionPair();
pair.setMax(123, null);
second.setMax(12, null);
TransformationOptionPair combined = pair.combine(second);
TransformationOptionPair combinedOtherWay = second.combine(pair);
assertEquals("The combine order should not matter", combined, combinedOtherWay);
}
@Test
public void testCombineMax() throws Exception
{
TransformationOptionPair second = new TransformationOptionPair();
pair.setMax(123, null);
second.setMax(12, null);
TransformationOptionPair combined = pair.combine(second);
assertEquals("Expected the lower value", 12, combined.getValue());
assertEquals("Expected the lower value", 12, combined.getMax());
}
@Test
public void testCombineLimit() throws Exception
{
TransformationOptionPair second = new TransformationOptionPair();
pair.setLimit(123, null);
second.setLimit(12, null);
TransformationOptionPair combined = pair.combine(second);
assertEquals("Expected the lower value", 12, combined.getValue());
assertEquals("Expected the lower value", 12, combined.getLimit());
}
@Test
public void testCombineMaxWins() throws Exception
{
// Try both max and limit values where max is lower
TransformationOptionPair second = new TransformationOptionPair();
pair.setLimit(123, null);
second.setMax(12, null);
TransformationOptionPair combined = pair.combine(second);
assertEquals("Expected the lower value", 12, combined.getValue());
assertEquals("Expected the lower value", 12, combined.getMax());
assertEquals("Expected unset value", -1, combined.getLimit());
}
@Test
public void testCombineLimitWins() throws Exception
{
// Try both max and limit values where limit is lower
TransformationOptionPair second = new TransformationOptionPair();
pair.setMax(123, null);
second.setLimit(12, null);
TransformationOptionPair combined = pair.combine(second);
assertEquals("Expected the lower value", 12, combined.getValue());
assertEquals("Expected the lower value", 12, combined.getLimit());
assertEquals("Expected unset value", -1, combined.getMax());
}
@Test
public void testCombineDynamicChange() throws Exception
{
TransformationOptionPair second = new TransformationOptionPair();
pair.setMax(123, null);
second.setMax(1234, null);
TransformationOptionPair combined = pair.combine(second);
// Test dynamic changes of value
pair.setMax(45, null);
assertEquals("Expected the lower value", 45, combined.getMax());
assertEquals("Expected an unset value", -1, combined.getLimit());
second.setMax(-1, null);
second.setLimit(10, null);
assertEquals("Expected an unset value", -1, combined.getMax());
assertEquals("Expected the lower value", 10, combined.getLimit());
}
@Test(expected=UnsupportedOperationException.class)
public void testCombineSetMax() throws Exception
{
TransformationOptionPair combined = pair.combine(pair); // may combine with itself
combined.setMax(1, null);
}
@Test(expected=UnsupportedOperationException.class)
public void testCombineSetLimit() throws Exception
{
TransformationOptionPair combined = pair.combine(pair); // may combine with itself
combined.setLimit(1, null);
}
@Test(expected=UnsupportedOperationException.class)
public void testCombineSetMap() throws Exception
{
TransformationOptionPair combined = pair.combine(pair); // may combine with itself
combined.set(null, null, null, null);
}
}