/** * Copyright (c) 2012 - 2018 Data In Motion and others. * All rights reserved. * * This program and the accompanying materials are made available under the terms of the * Eclipse Public License v1.0 which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Data In Motion - initial API and implementation */ package org.gecko.rsa.provider; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.nio.file.Files; import java.util.UUID; import org.gecko.rsa.provider.marker.FileMarker; import org.junit.Test; /** * * @author ilenia * @since 02.05.2019 */ public class FileSerializationTest { @Test public void testFileMarker() { File file = new File("data/test.txt"); byte[] fileContent; try { fileContent = Files.readAllBytes(file.toPath()); String uuid = UUID.randomUUID().toString(); FileMarker fileMarker = new FileMarker(file, fileContent, uuid); assertEquals(uuid + "_test.txt", fileMarker.getFileName()); byte[] content = fileMarker.getFileContent(); assertEquals("Hello world!", new String(content)); } catch (IOException e) { fail("IOError"); } } @Test public void testFileSerialization() { File file = new File("data/test.txt"); byte[] fileContent; String uuid = UUID.randomUUID().toString(); try { fileContent = Files.readAllBytes(file.toPath()); FileMarker fileMarker = new FileMarker(file, fileContent, uuid); File folder = new File(System.getProperty("java.io.tmpdir") + "/RSA/"); folder.mkdirs(); FileOutputStream fos = new FileOutputStream(System.getProperty("java.io.tmpdir") + "/RSA/"+uuid+"_test.txt"); fos.write(fileMarker.getFileContent()); fos.close(); } catch (IOException e) { fail("IOError"); } File serFile = new File(System.getProperty("java.io.tmpdir") + "/RSA/" + uuid + "_test.txt"); try { byte[] content = Files.readAllBytes(serFile.toPath()); assertEquals("Hello world!", new String(content)); } catch (IOException e) { fail("IOError"); } serFile.delete(); } }