REPO-1995 TransformerDebugTest

There was a leading date on the log message and the code to zero out the trans ref did not know that.
This commit is contained in:
Alan Davis
2017-08-07 17:21:58 +01:00
parent 049526f4d1
commit 68b3d482b0
2 changed files with 48 additions and 54 deletions

View File

@@ -25,17 +25,6 @@
*/ */
package org.alfresco.repo.content.transform; package org.alfresco.repo.content.transform;
import static org.alfresco.repo.content.transform.TransformerDebugLogTest.assertDebugEntriesEquals;
import static org.alfresco.repo.content.transform.TransformerLogTest.assertLogEntriesEquals;
import static org.alfresco.repo.content.transform.TransformerPropertyNameExtractorTest.mockMimetypes;
import static org.mockito.Mockito.when;
import java.util.Arrays;
import java.util.List;
import java.util.StringJoiner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.alfresco.service.cmr.repository.MimetypeService; import org.alfresco.service.cmr.repository.MimetypeService;
import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.TransformationOptions; import org.alfresco.service.cmr.repository.TransformationOptions;
@@ -44,6 +33,18 @@ import org.junit.Test;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.MockitoAnnotations; import org.mockito.MockitoAnnotations;
import java.util.Arrays;
import java.util.List;
import java.util.StringJoiner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static org.alfresco.repo.content.transform.TransformerDebugLogTest.assertDebugEntriesEquals;
import static org.alfresco.repo.content.transform.TransformerLogTest.stripDateStamp;
import static org.alfresco.repo.content.transform.TransformerPropertyNameExtractorTest.mockMimetypes;
import static org.junit.Assert.assertArrayEquals;
import static org.mockito.Mockito.when;
/** /**
* Test class for TransformerDebug. * Test class for TransformerDebug.
* *
@@ -142,15 +143,6 @@ public class TransformerDebugTest
return actual; return actual;
} }
private String[] stripCR(String[] actual)
{
for (int i = actual.length-1; i >= 0; i--)
{
actual[i] = actual[i].replaceAll(" \r", "");
}
return actual;
}
@Test @Test
public void alf18373Test() public void alf18373Test()
{ {
@@ -169,16 +161,14 @@ public class TransformerDebugTest
transformerDebug.popAvailable(); transformerDebug.popAvailable();
// "0 --c) [---] transformer4<<Component>> > 50 KB\n"+
// "0 --d) [---] transformer3<<Component>> > 50 KB\n"+
assertDebugEntriesEquals(new String[] { assertDebugEntriesEquals(new String[] {
"0 pdf txt 1.5 MB ContentService.transform(...) NO transformers\n"+ "0 pdf txt 1.5 MB ContentService.transform(...) NO transformers\n"+
"0 \n"+ "0 \n"+
"0 --a) [---] transformer1<<Component>> > 50 KB\n"+ "0 --a) [---] transformer1<<Component>> > 50 KB\n"+
"0 --b) [---] transformer3<<Component>> > 50 KB\n"+ "0 --b) [---] transformer3<<Component>> > 50 KB\n"+
"0 --c) [---] transformer4<<Component>> > 50 KB\n"+ "0 --c) [---] transformer4<<Component>> > 50 KB\n"+
"0 Finished in NN ms Transformer NOT called"}, unnumbered(untimed(stripCR(debug.getEntries(10))))); "0 Finished in NN ms Transformer NOT called"}, unnumbered(untimed(debug.getEntries(10))));
assertLogEntriesEquals(new String[] { assertArrayEquals(new String[] {
"0 pdf txt WARN 1.5 MB NN ms No transformers as file is > 50 KB"}, unnumbered(untimed(stripCR(log.getEntries(10))))); "0 pdf txt WARN 1.5 MB NN ms No transformers as file is > 50 KB"}, unnumbered(untimed(stripDateStamp(log.getEntries(10)))));
} }
} }

View File

@@ -1,28 +1,28 @@
/* /*
* #%L * #%L
* Alfresco Repository * Alfresco Repository
* %% * %%
* Copyright (C) 2005 - 2016 Alfresco Software Limited * Copyright (C) 2005 - 2016 Alfresco Software Limited
* %% * %%
* This file is part of the Alfresco software. * This file is part of the Alfresco software.
* If the software was purchased under a paid Alfresco license, the terms of * If the software was purchased under a paid Alfresco license, the terms of
* the paid license agreement will prevail. Otherwise, the software is * the paid license agreement will prevail. Otherwise, the software is
* provided under the following open source license terms: * provided under the following open source license terms:
* *
* Alfresco is free software: you can redistribute it and/or modify * 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 * 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 * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* Alfresco is distributed in the hope that it will be useful, * Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details. * GNU Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>. * along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
* #L% * #L%
*/ */
package org.alfresco.repo.content.transform; package org.alfresco.repo.content.transform;
import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertArrayEquals;
@@ -60,15 +60,19 @@ public class TransformerLogTest
log.setTransformerConfig(transformerConfig); log.setTransformerConfig(transformerConfig);
} }
static void assertLogEntriesEquals(String[] expected, String[] actual) static String[] stripDateStamp(String[] actual)
{ {
// Strip the date prefix
int beginIndex = (TransformerLogger.DATE_FORMAT.format(new Date())+' ').length(); int beginIndex = (TransformerLogger.DATE_FORMAT.format(new Date())+' ').length();
for (int i=actual.length-1; i >= 0; i--) for (int i = actual.length-1; i >= 0; i--)
{ {
actual[i] = actual[i].substring(beginIndex); actual[i] = actual[i].substring(beginIndex);
} }
assertArrayEquals(expected, actual); return actual;
}
static void assertLogEntriesEquals(String[] expected, String[] actual)
{
assertArrayEquals(expected, stripDateStamp(actual));
} }
@Test @Test