mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
ALF-17960: TemporalSourceOptions Should Define a Required Format for Offset and Duration
- Added TemporalSourceOptions.validateTimeString which checks the value against a regular expression validator - Added a call to validateTimeString in the setters for offset and duration - Added TemporalSourceOptionsTest which tests validation success and failures - Added TemporalSourceOptionsTest to ContentMinimalContextTestSuite git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@46601 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -52,6 +52,7 @@ import org.alfresco.repo.content.transform.TextMiningContentTransformerTest;
|
|||||||
import org.alfresco.repo.content.transform.TextToPdfContentTransformerTest;
|
import org.alfresco.repo.content.transform.TextToPdfContentTransformerTest;
|
||||||
import org.alfresco.repo.content.transform.TikaAutoContentTransformerTest;
|
import org.alfresco.repo.content.transform.TikaAutoContentTransformerTest;
|
||||||
import org.alfresco.repo.content.transform.magick.ImageMagickContentTransformerTest;
|
import org.alfresco.repo.content.transform.magick.ImageMagickContentTransformerTest;
|
||||||
|
import org.alfresco.service.cmr.repository.TemporalSourceOptionsTest;
|
||||||
import org.alfresco.service.cmr.repository.TransformationOptionLimitsTest;
|
import org.alfresco.service.cmr.repository.TransformationOptionLimitsTest;
|
||||||
import org.alfresco.service.cmr.repository.TransformationOptionPairTest;
|
import org.alfresco.service.cmr.repository.TransformationOptionPairTest;
|
||||||
import org.alfresco.util.ApplicationContextHelper;
|
import org.alfresco.util.ApplicationContextHelper;
|
||||||
@@ -95,6 +96,9 @@ public class ContentMinimalContextTestSuite extends TestSuite
|
|||||||
suite.addTest(new JUnit4TestAdapter(TransformationOptionLimitsTest.class));
|
suite.addTest(new JUnit4TestAdapter(TransformationOptionLimitsTest.class));
|
||||||
suite.addTest(new JUnit4TestAdapter(TransformationOptionPairTest.class));
|
suite.addTest(new JUnit4TestAdapter(TransformationOptionPairTest.class));
|
||||||
|
|
||||||
|
// Source options
|
||||||
|
suite.addTest(new JUnit4TestAdapter(TemporalSourceOptionsTest.class));
|
||||||
|
|
||||||
// Metadata tests
|
// Metadata tests
|
||||||
suite.addTestSuite( DWGMetadataExtracterTest.class );
|
suite.addTestSuite( DWGMetadataExtracterTest.class );
|
||||||
suite.addTestSuite( HtmlMetadataExtracterTest.class );
|
suite.addTestSuite( HtmlMetadataExtracterTest.class );
|
||||||
|
@@ -21,6 +21,7 @@ package org.alfresco.service.cmr.repository;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.alfresco.error.AlfrescoRuntimeException;
|
||||||
import org.alfresco.service.cmr.repository.AbstractTransformationSourceOptions;
|
import org.alfresco.service.cmr.repository.AbstractTransformationSourceOptions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -38,6 +39,9 @@ import org.alfresco.service.cmr.repository.AbstractTransformationSourceOptions;
|
|||||||
public class TemporalSourceOptions extends AbstractTransformationSourceOptions
|
public class TemporalSourceOptions extends AbstractTransformationSourceOptions
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/** Validation regex for hh:mm:ss[.xxx], ignoring leap seconds and allowing up to 99 hours */
|
||||||
|
private static final String VALID_TIME_STRING_REGEX = "\\d{2}:[0-5][0-9]:[0-5][0-9](\\.\\d{1,3})?";
|
||||||
|
|
||||||
/** The offset time code from which to start the transformation */
|
/** The offset time code from which to start the transformation */
|
||||||
private String offset;
|
private String offset;
|
||||||
|
|
||||||
@@ -72,6 +76,7 @@ public class TemporalSourceOptions extends AbstractTransformationSourceOptions
|
|||||||
*/
|
*/
|
||||||
public void setOffset(String offset)
|
public void setOffset(String offset)
|
||||||
{
|
{
|
||||||
|
TemporalSourceOptions.validateTimeString(offset);
|
||||||
this.offset = offset;
|
this.offset = offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,9 +99,23 @@ public class TemporalSourceOptions extends AbstractTransformationSourceOptions
|
|||||||
*/
|
*/
|
||||||
public void setDuration(String duration)
|
public void setDuration(String duration)
|
||||||
{
|
{
|
||||||
|
TemporalSourceOptions.validateTimeString(duration);
|
||||||
this.duration = duration;
|
this.duration = duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates that the given value is of the form hh:mm:ss[.xxx]
|
||||||
|
*
|
||||||
|
* @param value
|
||||||
|
*/
|
||||||
|
public static void validateTimeString(String value)
|
||||||
|
{
|
||||||
|
if (value != null && !value.matches(VALID_TIME_STRING_REGEX))
|
||||||
|
{
|
||||||
|
throw new AlfrescoRuntimeException("'" + value + "' is not a valid time specification of the form hh:mm:ss[.xxx]");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TransformationSourceOptions mergedOptions(TransformationSourceOptions overridingOptions)
|
public TransformationSourceOptions mergedOptions(TransformationSourceOptions overridingOptions)
|
||||||
{
|
{
|
||||||
|
@@ -0,0 +1,138 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2005-2013 Alfresco Software Limited.
|
||||||
|
*
|
||||||
|
* This file is part of Alfresco
|
||||||
|
*
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
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
|
||||||
|
*/
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Reference in New Issue
Block a user