From 68b3d482b0156ddae338dd4a8f12d0dec15e9436 Mon Sep 17 00:00:00 2001 From: Alan Davis Date: Mon, 7 Aug 2017 17:21:58 +0100 Subject: [PATCH] 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. --- .../transform/TransformerDebugTest.java | 40 +++++------- .../content/transform/TransformerLogTest.java | 62 ++++++++++--------- 2 files changed, 48 insertions(+), 54 deletions(-) diff --git a/src/test/java/org/alfresco/repo/content/transform/TransformerDebugTest.java b/src/test/java/org/alfresco/repo/content/transform/TransformerDebugTest.java index 5b1c65b1f0..c4191131f9 100644 --- a/src/test/java/org/alfresco/repo/content/transform/TransformerDebugTest.java +++ b/src/test/java/org/alfresco/repo/content/transform/TransformerDebugTest.java @@ -25,17 +25,6 @@ */ 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.NodeService; import org.alfresco.service.cmr.repository.TransformationOptions; @@ -44,6 +33,18 @@ import org.junit.Test; import org.mockito.Mock; 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. * @@ -142,15 +143,6 @@ public class TransformerDebugTest 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 public void alf18373Test() { @@ -169,16 +161,14 @@ public class TransformerDebugTest transformerDebug.popAvailable(); - // "0 --c) [---] transformer4<> > 50 KB\n"+ - // "0 --d) [---] transformer3<> > 50 KB\n"+ assertDebugEntriesEquals(new String[] { "0 pdf txt 1.5 MB ContentService.transform(...) NO transformers\n"+ "0 \n"+ "0 --a) [---] transformer1<> > 50 KB\n"+ "0 --b) [---] transformer3<> > 50 KB\n"+ "0 --c) [---] transformer4<> > 50 KB\n"+ - "0 Finished in NN ms Transformer NOT called"}, unnumbered(untimed(stripCR(debug.getEntries(10))))); - assertLogEntriesEquals(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 Finished in NN ms Transformer NOT called"}, unnumbered(untimed(debug.getEntries(10)))); + assertArrayEquals(new String[] { + "0 pdf txt WARN 1.5 MB NN ms No transformers as file is > 50 KB"}, unnumbered(untimed(stripDateStamp(log.getEntries(10))))); } } diff --git a/src/test/java/org/alfresco/repo/content/transform/TransformerLogTest.java b/src/test/java/org/alfresco/repo/content/transform/TransformerLogTest.java index 88c053801a..339e8fba22 100644 --- a/src/test/java/org/alfresco/repo/content/transform/TransformerLogTest.java +++ b/src/test/java/org/alfresco/repo/content/transform/TransformerLogTest.java @@ -1,28 +1,28 @@ -/* - * #%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 . - * #L% - */ +/* + * #%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 . + * #L% + */ package org.alfresco.repo.content.transform; import static org.junit.Assert.assertArrayEquals; @@ -60,15 +60,19 @@ public class TransformerLogTest 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(); - for (int i=actual.length-1; i >= 0; i--) + for (int i = actual.length-1; i >= 0; i--) { actual[i] = actual[i].substring(beginIndex); } - assertArrayEquals(expected, actual); + return actual; + } + + static void assertLogEntriesEquals(String[] expected, String[] actual) + { + assertArrayEquals(expected, stripDateStamp(actual)); } @Test