Skip to content
Snippets Groups Projects
Commit 53ea7c74 authored by Robert Goldmann's avatar Robert Goldmann
Browse files

#691 - fixed importer tests

parent 248f0b07
No related branches found
No related tags found
No related merge requests found
...@@ -92,18 +92,4 @@ class CategoryImporterTest ...@@ -92,18 +92,4 @@ class CategoryImporterTest
assertThat(resultItem).isEqualTo(expected); assertThat(resultItem).isEqualTo(expected);
assertThat(category).hasFieldOrPropertyWithValue("ID", 3); assertThat(category).hasFieldOrPropertyWithValue("ID", 3);
} }
@Test
void test_importCategories_errorIsCollected()
{
final Category category = new Category("Category1", "#ff0000", CategoryType.CUSTOM);
final CategoryImporter importer = new CategoryImporter(categoryRepository);
final ImportResultItem resultItem = importer.importItems(List.of(category));
assertThat(resultItem.getNumberOfImportedItems())
.isZero();
assertThat(resultItem.getCollectedErrorMessages())
.hasSize(1);
}
} }
\ No newline at end of file
package de.deadlocker8.budgetmaster.unit.database.importer; package de.deadlocker8.budgetmaster.unit.database.importer;
import de.deadlocker8.budgetmaster.Main; import de.deadlocker8.budgetmaster.Main;
import de.deadlocker8.budgetmaster.categories.Category;
import de.deadlocker8.budgetmaster.categories.CategoryType;
import de.deadlocker8.budgetmaster.charts.Chart; import de.deadlocker8.budgetmaster.charts.Chart;
import de.deadlocker8.budgetmaster.charts.ChartService; import de.deadlocker8.budgetmaster.charts.ChartService;
import de.deadlocker8.budgetmaster.charts.ChartType; import de.deadlocker8.budgetmaster.charts.ChartType;
import de.deadlocker8.budgetmaster.database.importer.CategoryImporter;
import de.deadlocker8.budgetmaster.database.importer.ChartImporter; import de.deadlocker8.budgetmaster.database.importer.ChartImporter;
import de.deadlocker8.budgetmaster.database.importer.ImageImporter; import de.deadlocker8.budgetmaster.database.importer.ImageImporter;
import de.deadlocker8.budgetmaster.images.Image; import de.deadlocker8.budgetmaster.images.Image;
...@@ -13,6 +16,7 @@ import de.deadlocker8.budgetmaster.services.EntityType; ...@@ -13,6 +16,7 @@ import de.deadlocker8.budgetmaster.services.EntityType;
import de.deadlocker8.budgetmaster.services.ImportResultItem; import de.deadlocker8.budgetmaster.services.ImportResultItem;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
...@@ -30,6 +34,9 @@ class ChartImporterTest ...@@ -30,6 +34,9 @@ class ChartImporterTest
@Autowired @Autowired
private ChartService chartService; private ChartService chartService;
@Mock
private ChartService mockedChartService;
@Test @Test
void test_importCharts() void test_importCharts()
{ {
...@@ -48,4 +55,23 @@ class ChartImporterTest ...@@ -48,4 +55,23 @@ class ChartImporterTest
assertThat(chart).hasFieldOrPropertyWithValue("ID", chartService.getRepository().findAll().size()); assertThat(chart).hasFieldOrPropertyWithValue("ID", chartService.getRepository().findAll().size());
} }
@Test
void test_import_errorIsCollected()
{
final Chart chart = new Chart();
chart.setID(9);
chart.setName("The best chart");
chart.setType(ChartType.CUSTOM);
chart.setVersion(7);
chart.setScript("/* This list will be dynamically filled with all the transactions between\r\n* the start and and date you select on the \"Show Chart\" page\r\n* and filtered according to your specified filter.\r\n* An example entry for this list and tutorial about how to create custom charts ca be found in the BudgetMaster wiki:\r\n* https://github.com/deadlocker8/BudgetMaster/wiki/How-to-create-custom-charts\r\n*/\r\nvar transactionData \u003d [];\r\n\r\n// Prepare your chart settings here (mandatory)\r\nvar plotlyData \u003d [{\r\n x: [],\r\n y: [],\r\n type: \u0027bar\u0027\r\n}];\r\n\r\n// Add your Plotly layout settings here (optional)\r\nvar plotlyLayout \u003d {};\r\n\r\n// Add your Plotly configuration settings here (optional)\r\nvar plotlyConfig \u003d {\r\n showSendToCloud: false,\r\n displaylogo: false,\r\n showLink: false,\r\n responsive: true\r\n};\r\n\r\n// Don\u0027t touch this line\r\nPlotly.newPlot(\"containerID\", plotlyData, plotlyLayout, plotlyConfig);\r\n");
final ChartImporter importer = new ChartImporter(mockedChartService);
final ImportResultItem resultItem = importer.importItems(List.of(chart));
assertThat(resultItem.getNumberOfImportedItems())
.isZero();
assertThat(resultItem.getCollectedErrorMessages())
.hasSize(1);
}
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment