chckpoint: test to buisnesslogic/src/test/java/com/plannaplan/repositories/AppConfigRepositoryTest.java
This commit is contained in:
parent
062b02da6c
commit
0b807e355c
@ -3,7 +3,10 @@ package com.plannaplan.repositories;
|
||||
import com.plannaplan.entities.AppConfig;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
|
||||
public interface AppConfigRepository extends JpaRepository<AppConfig, Long> {
|
||||
|
||||
@Query("FROM AppConfig ORDER BY configDate DESC")
|
||||
AppConfig getCurrentConfig();
|
||||
}
|
||||
|
@ -23,4 +23,5 @@ public class AppConfigService {
|
||||
public AppConfig save(AppConfig appConfig) {
|
||||
return this.repo.save(appConfig);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,33 @@
|
||||
package com.plannaplan.repositories;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.sql.Date;
|
||||
|
||||
import com.plannaplan.entities.AppConfig;
|
||||
import com.plannaplan.models.TourData;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@ContextConfiguration
|
||||
public class AppConfigRepositoryTest {
|
||||
|
||||
@Autowired
|
||||
private AppConfigRepository repo;
|
||||
|
||||
@Test
|
||||
public void shouldReturnNewestConfigInstance() {
|
||||
final Date dateToCheck = new Date(System.currentTimeMillis());
|
||||
this.repo.save(new AppConfig(new TourData(null, null), new TourData(null, null)));
|
||||
this.repo.save(new AppConfig(new TourData(dateToCheck, null), new TourData(null, null)));
|
||||
|
||||
assertTrue(this.repo.getCurrentConfig().getFirstTourStart().equals(dateToCheck));
|
||||
}
|
||||
}
|
@ -2,11 +2,14 @@ package com.plannaplan.controllers;
|
||||
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.*;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import com.plannaplan.entities.AppConfig;
|
||||
import com.plannaplan.entities.User;
|
||||
import com.plannaplan.services.AppConfigService;
|
||||
import com.plannaplan.services.UserService;
|
||||
import com.plannaplan.types.UserRoles;
|
||||
|
||||
@ -36,6 +39,9 @@ public class ConfigControllerTest extends AbstractControllerTest {
|
||||
@Autowired
|
||||
private UserService service;
|
||||
|
||||
@Autowired
|
||||
private AppConfigService configService;
|
||||
|
||||
@Test
|
||||
public void shouldReturnNoAuthorized() throws Exception {
|
||||
final InputStream inputStream = getClass().getClassLoader().getResourceAsStream(FILE_NAME);
|
||||
@ -63,6 +69,23 @@ public class ConfigControllerTest extends AbstractControllerTest {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldInsertedDataBeSameInDatabase() throws Exception {
|
||||
final String mail = "shouldReturnOKAuthorized@ConfigController.test";
|
||||
final User usr = this.service.save(new User(null, null, mail, UserRoles.ADMIN));
|
||||
|
||||
final InputStream inputStream = getClass().getClassLoader().getResourceAsStream(FILE_NAME);
|
||||
final MockMultipartFile file = new MockMultipartFile("file", inputStream);
|
||||
final String token = this.service.login(usr).getToken();
|
||||
|
||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||
mockMvc.perform(multipart(CONFIG_ENDPOINT).file(file).param(FIRST_TOUR_START, "12.12.2020")
|
||||
.param(FIRST_TOUR_END, "14.12.2020").param(SECOND_TOUR_START, "16.12.2020")
|
||||
.param(SECOND_TOUR_END, "20.12.2020").header("Authorization", "Bearer " + token))
|
||||
.andExpect(status().isOk());
|
||||
assertFalse(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnDenyNoAdminAuthorized() throws Exception {
|
||||
final String mail = "shouldReturnDenyNoAdminAuthorized@ConfigController.test";
|
||||
|
Loading…
Reference in New Issue
Block a user