From c5f09a91ec396f296ec7a00a569c80392fcd6a70 Mon Sep 17 00:00:00 2001 From: Filip Izydorczyk Date: Mon, 18 Jan 2021 13:38:24 +0100 Subject: [PATCH] last test --- .../com/plannaplan/models/ExportDataTest.java | 14 +++++ .../controllers/CommisionControllerTest.java | 53 +++++++++---------- 2 files changed, 39 insertions(+), 28 deletions(-) create mode 100755 buisnesslogic/src/test/java/com/plannaplan/models/ExportDataTest.java diff --git a/buisnesslogic/src/test/java/com/plannaplan/models/ExportDataTest.java b/buisnesslogic/src/test/java/com/plannaplan/models/ExportDataTest.java new file mode 100755 index 0000000..8314fd5 --- /dev/null +++ b/buisnesslogic/src/test/java/com/plannaplan/models/ExportDataTest.java @@ -0,0 +1,14 @@ +package com.plannaplan.models; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.Test; + +public class ExportDataTest { + + @Test + public void shouldConvertDataToCSVRecord() { + final ExportData data = new ExportData("4234", "242352", "12"); + assertTrue(data.convertToCSVRecord().equals("4234,242352,12")); + } +} diff --git a/restservice/src/test/java/com/plannaplan/controllers/CommisionControllerTest.java b/restservice/src/test/java/com/plannaplan/controllers/CommisionControllerTest.java index e3af390..f09a5e1 100755 --- a/restservice/src/test/java/com/plannaplan/controllers/CommisionControllerTest.java +++ b/restservice/src/test/java/com/plannaplan/controllers/CommisionControllerTest.java @@ -259,10 +259,10 @@ public class CommisionControllerTest extends AbstractControllerTest { UserRoles.STUDENT); this.service.save(otherUser); } - if (CommisionControllerTest.admin == null) { - CommisionControllerTest.admin = new User(null, null, TEST_COMMISIONS_ADMIN_EMAIL, UserRoles.ADMIN); - this.service.save(admin); - } + if (CommisionControllerTest.admin == null) { + CommisionControllerTest.admin = new User(null, null, TEST_COMMISIONS_ADMIN_EMAIL, UserRoles.ADMIN); + this.service.save(admin); + } if (CommisionControllerTest.asker == null) { CommisionControllerTest.asker = new User(null, null, TEST_COMMISIONS_DEANERY_EMAIL, UserRoles.DEANERY); this.service.save(asker); @@ -275,39 +275,36 @@ public class CommisionControllerTest extends AbstractControllerTest { } @Test - public void shouldExportData() throws Exception{ - this.checkUsers(); - final User admin = this.service.checkForUser(TEST_COMMISIONS_ADMIN_EMAIL, null); - final String token = this.service.login(admin).getToken(); + public void shouldExportData() throws Exception { + this.checkUsers(); + final User admin = this.service.checkForUser(TEST_COMMISIONS_ADMIN_EMAIL, null); + final String token = this.service.login(admin).getToken(); - MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); - mockMvc.perform(get(EXPORT_DATA).header("Authorization", "Bearer " + token)).andExpect(status().isOk()); + MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); + mockMvc.perform(get(EXPORT_DATA).header("Authorization", "Bearer " + token)).andExpect(status().isOk()); } @Test - public void shouldNotExportDataDueToWrongPermision() throws Exception{ - this.checkUsers(); - final User student = this.service.checkForUser(TEST_COMMISIONS_STUDENT_EMAIL, null); - final String token = this.service.login(student).getToken(); + public void shouldNotExportDataDueToWrongPermision() throws Exception { + this.checkUsers(); + final User student = this.service.checkForUser(TEST_COMMISIONS_STUDENT_EMAIL, null); + final String token = this.service.login(student).getToken(); - MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); - mockMvc.perform(get(EXPORT_DATA).header("Authorization", "Bearer " + token)).andExpect(status().is4xxClientError()); + MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); + mockMvc.perform(get(EXPORT_DATA).header("Authorization", "Bearer " + token)) + .andExpect(status().is4xxClientError()); } @Test - public void shouldExportDataBeCsvFile() throws Exception{ - this.checkUsers(); - final User admin = this.service.checkForUser(TEST_COMMISIONS_ADMIN_EMAIL, null); - final String token = this.service.login(admin).getToken(); + public void shouldExportDataBeCsvFile() throws Exception { + this.checkUsers(); + final User admin = this.service.checkForUser(TEST_COMMISIONS_ADMIN_EMAIL, null); + final String token = this.service.login(admin).getToken(); - MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); + MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); - assertTrue(mockMvc.perform(get(EXPORT_DATA) - .header("Authorization", "Bearer " + token)) - .andExpect(status().isOk()) - .andReturn() - .getResponse() - .getContentAsString() - .contains("user_id, zaj_cykl_id, gr_nr")); + assertTrue( + mockMvc.perform(get(EXPORT_DATA).header("Authorization", "Bearer " + token)).andExpect(status().isOk()) + .andReturn().getResponse().getContentAsString().contains("user_id, zaj_cykl_id, gr_nr")); } }