diff --git a/converter/pom.xml b/converter/pom.xml index 58f4e3e0a755c82a4f8737fee64c2fe966fed7b0..d4e935383e91546b13cac768fc93f4e8402ddcb3 100644 --- a/converter/pom.xml +++ b/converter/pom.xml @@ -22,5 +22,13 @@ <artifactId>xercesImpl</artifactId> <version>${xercesImp.version}</version> </dependency> + <!-- mockito used for testing --> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-all</artifactId> + <version>${mockito.version}</version> + <scope>test</scope> + </dependency> + </dependencies> </project> diff --git a/converter/src/main/java/lcsb/mapviewer/converter/ComplexZipConverter.java b/converter/src/main/java/lcsb/mapviewer/converter/ComplexZipConverter.java index 12f391a07b0474df7bfcbeda5e93ab8ccbc328e1..602b1a0379f8a724fde53bb169d130ca92210f72 100644 --- a/converter/src/main/java/lcsb/mapviewer/converter/ComplexZipConverter.java +++ b/converter/src/main/java/lcsb/mapviewer/converter/ComplexZipConverter.java @@ -108,14 +108,13 @@ public class ComplexZipConverter { entries = zipFile.entries(); Model result = null; - List<Layout> layouts = new ArrayList<Layout>(); + int overlayOrder = 1; + List<Layout> layouts = new ArrayList<>(); List<DataMiningSet> dataMiningSets = new ArrayList<>(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); if (!entry.isDirectory()) { ZipEntryFile zef = params.getEntry(entry.getName()); - logger.debug(entry.getName()); - logger.debug(zef); if (zef instanceof ModelZipEntryFile) { ModelZipEntryFile modelEntryFile = (ModelZipEntryFile) zef; InputStream is = zipFile.getInputStream(entry); @@ -129,7 +128,7 @@ public class ComplexZipConverter { result = model; } } else if (zef instanceof LayoutZipEntryFile) { - layouts.add(layoutZipEntryFileToLayout(params, zipFile, entry, (LayoutZipEntryFile) zef)); + layouts.add(layoutZipEntryFileToLayout(params, zipFile, entry, (LayoutZipEntryFile) zef, overlayOrder++)); } else if (zef instanceof ImageZipEntryFile) { continue; // imageEntries.add((ImageZipEntryFile) zef); @@ -372,7 +371,7 @@ public class ComplexZipConverter { * thrown when there is a problem with accessing {@link ZipFile} */ protected Layout layoutZipEntryFileToLayout(ComplexZipConverterParams params, ZipFile zipFile, ZipEntry entry, - LayoutZipEntryFile layoutEntry) throws IOException { + LayoutZipEntryFile layoutEntry, int order) throws IOException { Layout layout = new Layout(); layout.setDescription(layoutEntry.getDescription()); layout.setDirectory(params.getVisualizationDir() + "/" + layoutEntry.getName().replaceAll(" ", "_")); @@ -383,6 +382,7 @@ public class ComplexZipConverter { layout.setInputData(fileEntry); layout.setPublicLayout(true); layout.setTitle(layoutEntry.getName()); + layout.setOrderIndex(order); return layout; } diff --git a/converter/src/test/java/lcsb/mapviewer/converter/ComplexZipConverterTest.java b/converter/src/test/java/lcsb/mapviewer/converter/ComplexZipConverterTest.java index 4d768d5aa99d4578a1ffe8b58f9b0efd74d7c9e1..08b3878a844d724598170d1cff4154c73d3e9af6 100644 --- a/converter/src/test/java/lcsb/mapviewer/converter/ComplexZipConverterTest.java +++ b/converter/src/test/java/lcsb/mapviewer/converter/ComplexZipConverterTest.java @@ -7,20 +7,25 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import java.io.ByteArrayInputStream; import java.io.File; import java.io.InputStream; +import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import org.apache.log4j.Logger; import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.mockito.Mockito; import lcsb.mapviewer.common.MimeType; import lcsb.mapviewer.common.exception.InvalidArgumentException; import lcsb.mapviewer.common.exception.InvalidClassException; +import lcsb.mapviewer.converter.zip.LayoutZipEntryFile; import lcsb.mapviewer.converter.zip.ModelZipEntryFile; import lcsb.mapviewer.model.map.InconsistentModelException; +import lcsb.mapviewer.model.map.layout.Layout; import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.model.map.model.ModelFullIndexed; import lcsb.mapviewer.model.map.model.ModelSubmodelConnection; @@ -527,4 +532,23 @@ public class ComplexZipConverterTest { } } + @Test + public void testLayoutZipEntryFileToLayoutOrder() throws Exception { + ComplexZipConverter converter = new ComplexZipConverter(MockConverter.class); + ComplexZipConverterParams params = new ComplexZipConverterParams(); + ZipFile file = Mockito.mock(ZipFile.class); + params.zipFile(file); + LayoutZipEntryFile entry1 = new LayoutZipEntryFile("overlay1.txt", "name", "desc1"); + LayoutZipEntryFile entry2 = new LayoutZipEntryFile("overlay2.txt", "name", "desc1"); + params.entry(entry1); + params.entry(entry2); + ZipEntry entry = Mockito.mock(ZipEntry.class); + Mockito.when(file.getInputStream(entry)).thenReturn(new ByteArrayInputStream("".getBytes())); + + Layout overlay1 = converter.layoutZipEntryFileToLayout(params, file, entry, entry1, 1); + Layout overlay2 = converter.layoutZipEntryFileToLayout(params, file, entry, entry2, 2); + assertTrue(overlay1.getOrderIndex() > 0); + assertTrue(overlay2.getOrderIndex() > overlay1.getOrderIndex()); + } + } diff --git a/model/src/main/java/lcsb/mapviewer/model/map/layout/Layout.java b/model/src/main/java/lcsb/mapviewer/model/map/layout/Layout.java index 382550c682f8ac8336cd240da853db01ce160ce0..78add52b8436ccf274e2d53bc497f799b95d1645 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/layout/Layout.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/layout/Layout.java @@ -195,7 +195,7 @@ public class Layout implements Serializable { this.inputData = new UploadedFileEntry(layout.getInputData()); } this.hierarchyViewLevel = layout.hierarchyViewLevel; - + this.orderIndex = layout.orderIndex; } /** diff --git a/model/src/test/java/lcsb/mapviewer/model/map/layout/LayoutTest.java b/model/src/test/java/lcsb/mapviewer/model/map/layout/LayoutTest.java index 1c8759c39cfb8760b9b8771a57ffdb8c45b7ae44..10f0c19abdb29d390df98775230e71bec9a7ab19 100644 --- a/model/src/test/java/lcsb/mapviewer/model/map/layout/LayoutTest.java +++ b/model/src/test/java/lcsb/mapviewer/model/map/layout/LayoutTest.java @@ -21,147 +21,161 @@ import lcsb.mapviewer.model.map.model.ModelFullIndexed; public class LayoutTest { - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - - @Test - public void testSerialization() { - try { - SerializationUtils.serialize(new Layout()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testConstructor() { - try { - String title = "TIT"; - String dir = "TIT"; - boolean publicL = true; - Layout layout = new Layout(title, dir, publicL); - assertEquals(title, layout.getTitle()); - assertEquals(dir, layout.getDirectory()); - assertEquals(publicL, layout.isPublicLayout()); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testConstructor2() { - try { - String title = "TIT"; - String dir = "TIT"; - boolean publicL = true; - Layout layout = new Layout(title, dir, publicL); - Layout layout2 = new Layout(layout); - assertNotNull(layout2); - UploadedFileEntry fileEntry = new UploadedFileEntry(); - fileEntry.setFileContent(new byte[] {}); - - layout.setInputData(fileEntry); - Layout layout3 = new Layout(layout); - assertNotNull(layout3); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testCopy() { - try { - String title = "TIT"; - String dir = "TIT"; - boolean publicL = true; - Layout layout = new Layout(title, dir, publicL); - Layout layout2 = layout.copy(); - assertNotNull(layout2); - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testInvalidCopy() { - try { - Layout layout = new Layout() { - - /** - * - */ - private static final long serialVersionUID = 1L; - }; - layout.copy(); - fail("Exception expected"); - } catch (NotImplementedException e) { - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } - - @Test - public void testGetters() { - try { - ModelFullIndexed model = new ModelFullIndexed(null); - Set<Layout> layouts = new HashSet<>(); - boolean hierarchicalView = false; - boolean publicLayout = true; - int id = 62; - String description = "qds"; - String directory = "vcccv"; - String title = "tit"; - LayoutStatus status = LayoutStatus.FAILURE; - double progress = 1.6; - UploadedFileEntry inputData = new UploadedFileEntry(); - Layout parentLayout = new Layout(); - Layout layout = new Layout(); - layout.setHierarchicalView(hierarchicalView); - assertEquals(hierarchicalView, layout.isHierarchicalView()); - layout.setId(id); - assertEquals(id, layout.getId()); - layout.setDescription(description); - assertEquals(description, layout.getDescription()); - layout.setDirectory(directory); - assertEquals(directory, layout.getDirectory()); - layout.setTitle(title); - assertEquals(title, layout.getTitle()); - layout.setModel((ModelData) null); - assertNull(layout.getModel()); - layout.setCreator(null); - assertNull(layout.getCreator()); - layout.setStatus(status); - assertEquals(status, layout.getStatus()); - layout.setProgress(progress); - assertEquals(progress, layout.getProgress(), Configuration.EPSILON); - layout.setInputData(inputData); - assertEquals(inputData, layout.getInputData()); - layout.setParentLayout(parentLayout); - assertEquals(parentLayout, layout.getParentLayout()); - layout.setPublicLayout(publicLayout); - assertEquals(publicLayout, layout.isPublicLayout()); - - layout.setLayouts(layouts); - assertEquals(layouts, layout.getLayouts()); - layout.addLayout(parentLayout); - assertEquals(1, layouts.size()); - layout.setModel(model); - assertEquals(model.getModelData(), layout.getModel()); - - } catch (Exception e) { - e.printStackTrace(); - throw e; - } - } + @Before + public void setUp() throws Exception { + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testSerialization() { + try { + SerializationUtils.serialize(new Layout()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testConstructor() { + try { + String title = "TIT"; + String dir = "TIT"; + boolean publicL = true; + Layout layout = new Layout(title, dir, publicL); + assertEquals(title, layout.getTitle()); + assertEquals(dir, layout.getDirectory()); + assertEquals(publicL, layout.isPublicLayout()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testConstructor2() { + try { + String title = "TIT"; + String dir = "TIT"; + boolean publicL = true; + Layout layout = new Layout(title, dir, publicL); + Layout layout2 = new Layout(layout); + assertNotNull(layout2); + UploadedFileEntry fileEntry = new UploadedFileEntry(); + fileEntry.setFileContent(new byte[] {}); + + layout.setInputData(fileEntry); + Layout layout3 = new Layout(layout); + assertNotNull(layout3); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testConstructorWithOrder() { + try { + boolean publicL = true; + Layout overlay1 = new Layout(null, null, publicL); + overlay1.setOrderIndex(12); + Layout overlay2 = new Layout(overlay1); + assertEquals(overlay1.getOrderIndex(), overlay2.getOrderIndex()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testCopy() { + try { + String title = "TIT"; + String dir = "TIT"; + boolean publicL = true; + Layout layout = new Layout(title, dir, publicL); + Layout layout2 = layout.copy(); + assertNotNull(layout2); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testInvalidCopy() { + try { + Layout layout = new Layout() { + + /** + * + */ + private static final long serialVersionUID = 1L; + }; + layout.copy(); + fail("Exception expected"); + } catch (NotImplementedException e) { + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + + @Test + public void testGetters() { + try { + ModelFullIndexed model = new ModelFullIndexed(null); + Set<Layout> layouts = new HashSet<>(); + boolean hierarchicalView = false; + boolean publicLayout = true; + int id = 62; + String description = "qds"; + String directory = "vcccv"; + String title = "tit"; + LayoutStatus status = LayoutStatus.FAILURE; + double progress = 1.6; + UploadedFileEntry inputData = new UploadedFileEntry(); + Layout parentLayout = new Layout(); + Layout layout = new Layout(); + layout.setHierarchicalView(hierarchicalView); + assertEquals(hierarchicalView, layout.isHierarchicalView()); + layout.setId(id); + assertEquals(id, layout.getId()); + layout.setDescription(description); + assertEquals(description, layout.getDescription()); + layout.setDirectory(directory); + assertEquals(directory, layout.getDirectory()); + layout.setTitle(title); + assertEquals(title, layout.getTitle()); + layout.setModel((ModelData) null); + assertNull(layout.getModel()); + layout.setCreator(null); + assertNull(layout.getCreator()); + layout.setStatus(status); + assertEquals(status, layout.getStatus()); + layout.setProgress(progress); + assertEquals(progress, layout.getProgress(), Configuration.EPSILON); + layout.setInputData(inputData); + assertEquals(inputData, layout.getInputData()); + layout.setParentLayout(parentLayout); + assertEquals(parentLayout, layout.getParentLayout()); + layout.setPublicLayout(publicLayout); + assertEquals(publicLayout, layout.isPublicLayout()); + + layout.setLayouts(layouts); + assertEquals(layouts, layout.getLayouts()); + layout.addLayout(parentLayout); + assertEquals(1, layouts.size()); + layout.setModel(model); + assertEquals(model.getModelData(), layout.getModel()); + + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } }