-
Notifications
You must be signed in to change notification settings - Fork 391
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add serialization test for virtualized report
- Loading branch information
Showing
7 changed files
with
282 additions
and
8 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
jasperreports/tests/net/sf/jasperreports/NoVirtualizerContainer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* JasperReports - Free Java Reporting Library. | ||
* Copyright (C) 2001 - 2019 TIBCO Software Inc. All rights reserved. | ||
* http://www.jaspersoft.com | ||
* | ||
* Unless you have purchased a commercial license agreement from Jaspersoft, | ||
* the following license terms apply: | ||
* | ||
* This program is part of JasperReports. | ||
* | ||
* JasperReports 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. | ||
* | ||
* JasperReports 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 JasperReports. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package net.sf.jasperreports; | ||
|
||
import net.sf.jasperreports.engine.JRVirtualizer; | ||
|
||
/** | ||
* @author Lucian Chirita (lucianc@users.sourceforge.net) | ||
*/ | ||
public class NoVirtualizerContainer implements VirtualizerContainer | ||
{ | ||
|
||
@Override | ||
public JRVirtualizer getVirtualizer() | ||
{ | ||
return null; | ||
} | ||
|
||
@Override | ||
public void setReadOnly() | ||
{ | ||
//NOOP | ||
} | ||
|
||
@Override | ||
public void dispose() | ||
{ | ||
//NOOP | ||
} | ||
|
||
} |
60 changes: 60 additions & 0 deletions
60
jasperreports/tests/net/sf/jasperreports/OwnVirtualizerContainer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* JasperReports - Free Java Reporting Library. | ||
* Copyright (C) 2001 - 2019 TIBCO Software Inc. All rights reserved. | ||
* http://www.jaspersoft.com | ||
* | ||
* Unless you have purchased a commercial license agreement from Jaspersoft, | ||
* the following license terms apply: | ||
* | ||
* This program is part of JasperReports. | ||
* | ||
* JasperReports 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. | ||
* | ||
* JasperReports 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 JasperReports. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package net.sf.jasperreports; | ||
|
||
import net.sf.jasperreports.engine.JRVirtualizer; | ||
import net.sf.jasperreports.engine.fill.JRAbstractLRUVirtualizer; | ||
|
||
/** | ||
* @author Lucian Chirita (lucianc@users.sourceforge.net) | ||
*/ | ||
public class OwnVirtualizerContainer implements VirtualizerContainer | ||
{ | ||
|
||
private final JRAbstractLRUVirtualizer virtualizer; | ||
|
||
public OwnVirtualizerContainer(JRAbstractLRUVirtualizer virtualizer) | ||
{ | ||
this.virtualizer = virtualizer; | ||
} | ||
|
||
@Override | ||
public JRVirtualizer getVirtualizer() | ||
{ | ||
return virtualizer; | ||
} | ||
|
||
@Override | ||
public void setReadOnly() | ||
{ | ||
virtualizer.setReadOnly(true); | ||
} | ||
|
||
@Override | ||
public void dispose() | ||
{ | ||
virtualizer.cleanup(); | ||
} | ||
|
||
} |
97 changes: 97 additions & 0 deletions
97
jasperreports/tests/net/sf/jasperreports/PrintSerializer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* JasperReports - Free Java Reporting Library. | ||
* Copyright (C) 2001 - 2019 TIBCO Software Inc. All rights reserved. | ||
* http://www.jaspersoft.com | ||
* | ||
* Unless you have purchased a commercial license agreement from Jaspersoft, | ||
* the following license terms apply: | ||
* | ||
* This program is part of JasperReports. | ||
* | ||
* JasperReports 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. | ||
* | ||
* JasperReports 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 JasperReports. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package net.sf.jasperreports; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.ByteArrayOutputStream; | ||
import java.util.function.BiConsumer; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
|
||
import net.sf.jasperreports.engine.JRException; | ||
import net.sf.jasperreports.engine.JRVirtualizer; | ||
import net.sf.jasperreports.engine.JasperPrint; | ||
import net.sf.jasperreports.engine.util.JRLoader; | ||
import net.sf.jasperreports.engine.util.JRSaver; | ||
|
||
/** | ||
* @author Lucian Chirita (lucianc@users.sourceforge.net) | ||
*/ | ||
public class PrintSerializer implements BiConsumer<Report, JasperPrint> | ||
{ | ||
|
||
private static final Log log = LogFactory.getLog(PrintSerializer.class); | ||
|
||
private static final PrintSerializer INSTANCE_NO_VIRTUALIZER = new PrintSerializer(new NoVirtualizerContainer()); | ||
|
||
public static PrintSerializer instance() | ||
{ | ||
return INSTANCE_NO_VIRTUALIZER; | ||
} | ||
|
||
private VirtualizerContainer virtualizerContainer; | ||
|
||
public PrintSerializer(VirtualizerContainer virtualizerContainer) | ||
{ | ||
this.virtualizerContainer = virtualizerContainer; | ||
} | ||
|
||
@Override | ||
public void accept(Report report, JasperPrint print) | ||
{ | ||
try | ||
{ | ||
if (log.isDebugEnabled()) | ||
{ | ||
log.debug("Serializing report " + report.getJRXML()); | ||
} | ||
|
||
ByteArrayOutputStream printOut = new ByteArrayOutputStream(); | ||
JRSaver.saveObject(print, printOut); | ||
|
||
try | ||
{ | ||
JRVirtualizer virtualizer = virtualizerContainer.getVirtualizer(); | ||
if (log.isDebugEnabled()) | ||
{ | ||
log.debug("Loading serialized report " + report.getJRXML() + " with virtualizer " + virtualizer); | ||
} | ||
|
||
JasperPrint savedPrint = JRLoader.loadJasperPrint(new ByteArrayInputStream(printOut.toByteArray()), virtualizer); | ||
virtualizerContainer.setReadOnly(); | ||
report.checkDigest(savedPrint); | ||
} | ||
finally | ||
{ | ||
virtualizerContainer.dispose(); | ||
} | ||
} | ||
catch (JRException e) | ||
{ | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
jasperreports/tests/net/sf/jasperreports/VirtualizerContainer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* JasperReports - Free Java Reporting Library. | ||
* Copyright (C) 2001 - 2019 TIBCO Software Inc. All rights reserved. | ||
* http://www.jaspersoft.com | ||
* | ||
* Unless you have purchased a commercial license agreement from Jaspersoft, | ||
* the following license terms apply: | ||
* | ||
* This program is part of JasperReports. | ||
* | ||
* JasperReports 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. | ||
* | ||
* JasperReports 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 JasperReports. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
package net.sf.jasperreports; | ||
|
||
import net.sf.jasperreports.engine.JRVirtualizer; | ||
|
||
/** | ||
* @author Lucian Chirita (lucianc@users.sourceforge.net) | ||
*/ | ||
public interface VirtualizerContainer | ||
{ | ||
|
||
JRVirtualizer getVirtualizer(); | ||
|
||
void setReadOnly(); | ||
|
||
void dispose(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters