-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added uploading blocked pages list files [#112]
- Loading branch information
Showing
28 changed files
with
900 additions
and
43 deletions.
There are no files selected for viewing
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
38 changes: 38 additions & 0 deletions
38
comixed-adaptors/src/main/java/org/comixedproject/adaptors/csv/CsvRowDecoder.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,38 @@ | ||
/* | ||
* ComiXed - A digital comic book library management application. | ||
* Copyright (C) 2021, The ComiXed Project | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program 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 General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses> | ||
*/ | ||
|
||
package org.comixedproject.adaptors.csv; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* <code>CsvRowDecoder</code> defines a type that processes a single row of data from a CSV file | ||
* being processed. | ||
* | ||
* @author Darryl L. Pierce | ||
*/ | ||
@FunctionalInterface | ||
public interface CsvRowDecoder { | ||
/** | ||
* Processes a single row from the CSV file. | ||
* | ||
* @param index the row number | ||
* @param row the row | ||
*/ | ||
public void processRow(final int index, final List<String> row); | ||
} |
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
63 changes: 63 additions & 0 deletions
63
comixed-adaptors/src/test/java/org/comixedproject/adaptors/csv/CsvAdaptorTest.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,63 @@ | ||
package org.comixedproject.adaptors.csv; | ||
|
||
import static junit.framework.TestCase.assertEquals; | ||
import static junit.framework.TestCase.assertNotNull; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.comixedproject.model.blockedpage.BlockedPage; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class CsvAdaptorTest { | ||
private static final String TEST_PAGE_LABEL = "The blocked page label"; | ||
private static final String TEST_PAGE_HASH = "The page hash"; | ||
private static final String TEST_PAGE_SNAPSHOT = "The blocked page content encoded"; | ||
private static final String LABEL = "LABEL"; | ||
private static final String HASH = "HASH"; | ||
private static final String SNAPSHOT = "SNAPSHOT"; | ||
|
||
@InjectMocks private CsvAdaptor adaptor; | ||
|
||
private BlockedPage blockedPage = | ||
new BlockedPage(TEST_PAGE_LABEL, TEST_PAGE_HASH, TEST_PAGE_SNAPSHOT); | ||
private List<BlockedPage> blockedPages = new ArrayList<>(); | ||
|
||
@Test | ||
public void testEncodeAndDecode() throws IOException { | ||
blockedPages.add(blockedPage); | ||
|
||
final byte[] encoded = | ||
adaptor.encodeRecords( | ||
blockedPages, | ||
(index, model) -> { | ||
if (index == 0) { | ||
return new String[] {LABEL, HASH, SNAPSHOT}; | ||
} else { | ||
return new String[] {model.getLabel(), model.getHash(), model.getSnapshot()}; | ||
} | ||
}); | ||
|
||
assertNotNull(encoded); | ||
|
||
adaptor.decodeRecords( | ||
new ByteArrayInputStream(encoded), | ||
new String[] {LABEL, HASH, SNAPSHOT}, | ||
(index, row) -> { | ||
if (index == 0) { | ||
assertEquals(LABEL, row.get(0)); | ||
assertEquals(HASH, row.get(1)); | ||
assertEquals(SNAPSHOT, row.get(2)); | ||
} else { | ||
assertEquals(TEST_PAGE_LABEL, row.get(0)); | ||
assertEquals(TEST_PAGE_HASH, row.get(1)); | ||
assertEquals(TEST_PAGE_SNAPSHOT, row.get(2)); | ||
} | ||
}); | ||
} | ||
} |
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
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
Oops, something went wrong.