Compare commits

..

No commits in common. "9328601d2d5d1dba4c1d9bda310617d950e6fa96" and "0c73f6f44d24e8e89ede0eeee87bf1300f4f2d3e" have entirely different histories.

3 changed files with 10 additions and 17 deletions

View File

@ -3,11 +3,10 @@ package ovh.herisson.Clyde;
import org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.id.IdentifierGenerator;
import java.sql.*;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class RegNoGenerator implements IdentifierGenerator {
private final UserSaveCounter usv = UserSaveCounter.getInstance();
@ -25,9 +24,9 @@ public class RegNoGenerator implements IdentifierGenerator {
ResultSet set = statement.executeQuery(query);
long resp = 0;
Calendar c = new GregorianCalendar();
if(set.next()){
resp = set.getLong(1)+((c.get(Calendar.YEAR)%1000)*10000);
resp = set.getLong(1)+1000;
System.out.println(resp);
}
conn.close();

View File

@ -23,7 +23,6 @@ import ovh.herisson.Clyde.Repositories.TokenRepository;
import ovh.herisson.Clyde.Repositories.UserRepository;
import ovh.herisson.Clyde.Responses.UnauthorizedResponse;
import ovh.herisson.Clyde.Services.TokenService;
import ovh.herisson.Clyde.Services.UserService;
import ovh.herisson.Clyde.Tables.Role;
import ovh.herisson.Clyde.Tables.Token;
import ovh.herisson.Clyde.Tables.User;
@ -48,8 +47,6 @@ public class UserControllerTest {
@Autowired
private TokenService tokenService;
@Autowired
private UserService userService;
@Autowired
private UserRepository userRepository;
@Autowired
@ -82,13 +79,12 @@ public class UserControllerTest {
tokenRepository.deleteAll();
userRepository.deleteAll();
}
@Test
//Verifie qu'un user qui n'a pas les permissions admin ou secretaire ne peut pas post
public void userPostTest(){
User god = new User("god","god","admin@admin.com","everywhere","every",new Date(0), null, Role.Admin,"goddoesntneedpassword");
Token godToken = new Token(god, tokenService.generateNewToken(), new Date());
userService.save(god);
userRepository.save(god);
tokenService.saveToken(godToken);
//Can god post herobrine himself ?
@ -101,7 +97,7 @@ public class UserControllerTest {
//Can noob post herobrine without authorizations (no)
User noob = new User("boon","noob","noob@student.com","everywhere","every",new Date(0), null, Role.Student,"noob");
Token noobToken = new Token(noob, tokenService.generateNewToken(), new Date());
userService.save(noob);
userRepository.save(noob);
tokenService.saveToken(noobToken);
with().body(herobrine).contentType(ContentType.JSON).header("Authorization", noobToken.getToken()).when().request("POST", "/user").then().statusCode(401);

View File

@ -7,7 +7,6 @@ import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.test.context.TestPropertySource;
import ovh.herisson.Clyde.Services.UserService;
import ovh.herisson.Clyde.Tables.Role;
import ovh.herisson.Clyde.Tables.User;
@ -25,7 +24,6 @@ public class UserRepoTest {
@BeforeEach
public void setup(){
userRepo.deleteAll();
User herobrine = new User("brine","hero","admin@admin.com","in your WalLs","ShadowsLand", new GregorianCalendar(2005, 4, 3).getTime(), null, Role.Admin,"admin");
userRepo.save(herobrine);
}
@ -36,8 +34,8 @@ public class UserRepoTest {
}
@Test
public void usertest(){
Assert.assertEquals("brine", userRepo.findByEmail("admin@admin.com").getLastName());
Assert.assertTrue(new GregorianCalendar(2005, 4, 3).getTime().equals(userRepo.findByEmail("admin@admin.com").getBirthDate()));
Assert.assertEquals("brine", userRepo.findById(1).getLastName());
Assert.assertTrue(new GregorianCalendar(2005, 4, 3).getTime().equals(userRepo.findById(1).getBirthDate()));
}
}