last test
This commit is contained in:
parent
77c3b9e3a5
commit
c5f09a91ec
14
buisnesslogic/src/test/java/com/plannaplan/models/ExportDataTest.java
Executable file
14
buisnesslogic/src/test/java/com/plannaplan/models/ExportDataTest.java
Executable file
@ -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"));
|
||||||
|
}
|
||||||
|
}
|
@ -259,10 +259,10 @@ public class CommisionControllerTest extends AbstractControllerTest {
|
|||||||
UserRoles.STUDENT);
|
UserRoles.STUDENT);
|
||||||
this.service.save(otherUser);
|
this.service.save(otherUser);
|
||||||
}
|
}
|
||||||
if (CommisionControllerTest.admin == null) {
|
if (CommisionControllerTest.admin == null) {
|
||||||
CommisionControllerTest.admin = new User(null, null, TEST_COMMISIONS_ADMIN_EMAIL, UserRoles.ADMIN);
|
CommisionControllerTest.admin = new User(null, null, TEST_COMMISIONS_ADMIN_EMAIL, UserRoles.ADMIN);
|
||||||
this.service.save(admin);
|
this.service.save(admin);
|
||||||
}
|
}
|
||||||
if (CommisionControllerTest.asker == null) {
|
if (CommisionControllerTest.asker == null) {
|
||||||
CommisionControllerTest.asker = new User(null, null, TEST_COMMISIONS_DEANERY_EMAIL, UserRoles.DEANERY);
|
CommisionControllerTest.asker = new User(null, null, TEST_COMMISIONS_DEANERY_EMAIL, UserRoles.DEANERY);
|
||||||
this.service.save(asker);
|
this.service.save(asker);
|
||||||
@ -275,39 +275,36 @@ public class CommisionControllerTest extends AbstractControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldExportData() throws Exception{
|
public void shouldExportData() throws Exception {
|
||||||
this.checkUsers();
|
this.checkUsers();
|
||||||
final User admin = this.service.checkForUser(TEST_COMMISIONS_ADMIN_EMAIL, null);
|
final User admin = this.service.checkForUser(TEST_COMMISIONS_ADMIN_EMAIL, null);
|
||||||
final String token = this.service.login(admin).getToken();
|
final String token = this.service.login(admin).getToken();
|
||||||
|
|
||||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||||
mockMvc.perform(get(EXPORT_DATA).header("Authorization", "Bearer " + token)).andExpect(status().isOk());
|
mockMvc.perform(get(EXPORT_DATA).header("Authorization", "Bearer " + token)).andExpect(status().isOk());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldNotExportDataDueToWrongPermision() throws Exception{
|
public void shouldNotExportDataDueToWrongPermision() throws Exception {
|
||||||
this.checkUsers();
|
this.checkUsers();
|
||||||
final User student = this.service.checkForUser(TEST_COMMISIONS_STUDENT_EMAIL, null);
|
final User student = this.service.checkForUser(TEST_COMMISIONS_STUDENT_EMAIL, null);
|
||||||
final String token = this.service.login(student).getToken();
|
final String token = this.service.login(student).getToken();
|
||||||
|
|
||||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||||
mockMvc.perform(get(EXPORT_DATA).header("Authorization", "Bearer " + token)).andExpect(status().is4xxClientError());
|
mockMvc.perform(get(EXPORT_DATA).header("Authorization", "Bearer " + token))
|
||||||
|
.andExpect(status().is4xxClientError());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldExportDataBeCsvFile() throws Exception{
|
public void shouldExportDataBeCsvFile() throws Exception {
|
||||||
this.checkUsers();
|
this.checkUsers();
|
||||||
final User admin = this.service.checkForUser(TEST_COMMISIONS_ADMIN_EMAIL, null);
|
final User admin = this.service.checkForUser(TEST_COMMISIONS_ADMIN_EMAIL, null);
|
||||||
final String token = this.service.login(admin).getToken();
|
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)
|
assertTrue(
|
||||||
.header("Authorization", "Bearer " + token))
|
mockMvc.perform(get(EXPORT_DATA).header("Authorization", "Bearer " + token)).andExpect(status().isOk())
|
||||||
.andExpect(status().isOk())
|
.andReturn().getResponse().getContentAsString().contains("user_id, zaj_cykl_id, gr_nr"));
|
||||||
.andReturn()
|
|
||||||
.getResponse()
|
|
||||||
.getContentAsString()
|
|
||||||
.contains("user_id, zaj_cykl_id, gr_nr"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user