Commit ea27259d authored by Corentin Guillevic's avatar Corentin Guillevic
Browse files

Remove module Database

parent bddb7316
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.0</version>
<relativePath/>
</parent>
<groupId>fr.univnantes.alma</groupId>
<artifactId>not-alone-database</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Not Alone Database</name>
<description>Spring Boot Not Alone database</description>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.6.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
package fr.univnantes.alma.data;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class AccessingDataJpaApplication {
private static final Logger log = LoggerFactory.getLogger(AccessingDataJpaApplication.class);
public static void main(String[] args) {
SpringApplication.run(AccessingDataJpaApplication.class);
}
}
\ No newline at end of file
package fr.univnantes.alma.data.item;
import javax.persistence.*;
@Entity
@Table(name="users")
public class User {
@Id
@GeneratedValue(strategy= GenerationType.AUTO)
private Long id;
private String mail;
private String passwordHash;
private String pseudo;
//Only for JPA
protected User(){}
public User(String mail, String password, String pseudo){
this.mail = mail;
this.passwordHash = hash(password);
this.pseudo = pseudo;
}
@Override
public String toString() {
return String.format(
"User[id=%d, mail='%s', password='%s',pseudo='%s']",
id, mail, passwordHash,pseudo);
}
public Long getId(){
return id;
}
public String getMail() {
return mail;
}
public String getPasswordHash() {
return passwordHash;
}
public String getPseudo() {
return pseudo;
}
public boolean verifyPassword(String password){
//TODO upgrade this function
return passwordHash.equals(hash(password));
}
private String hash(String s){
//TODO find a hash method
return s;
}
}
package fr.univnantes.alma.data.item;
import java.util.List;
import fr.univnantes.alma.data.item.User;
import org.springframework.data.repository.CrudRepository;
public interface UserRepository extends CrudRepository<User, Long> {
List<User> findByPseudo(String pseudo);
User findById(long id);
}
\ No newline at end of file
package fr.univnantes.alma.data;
import static org.assertj.core.api.Assertions.assertThat;
import fr.univnantes.alma.data.item.User;
import fr.univnantes.alma.data.item.UserRepository;
import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@DataJpaTest
public class DataStoreTest {
@Autowired
private TestEntityManager entityManager;
@Autowired
UserRepository userRepository;
@Test
public void no_User(){
Iterable<User> users = userRepository.findAll();
Assertions.assertThat(users).isEmpty();
}
@Test
public void testUserRepository__store(){
User user = userRepository.save(new User("JackyLove@world.net", "Jetecarryenadc","JackyLove"));
Assertions.assertThat(user).hasFieldOrPropertyWithValue("mail","JackyLove@world.net");
// assertThat(user).hasFieldOrPropertyWithValue("password",u.getPasswordHash());
Assertions.assertThat(user).hasFieldOrPropertyWithValue("pseudo","JackyLove");
}
}
\ No newline at end of file
......@@ -21,11 +21,6 @@
</properties>
<dependencies>
<dependency>
<groupId>fr.univnantes.alma</groupId>
<artifactId>not-alone-database</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
......@@ -42,23 +37,29 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.atlanmod.commons</groupId>
<artifactId>commons-core</artifactId>
<version>1.0.6</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
......@@ -77,7 +78,6 @@
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.version}</version>
<executions>
<!-- Active l'agent JaCoCo -->
<execution>
<id>prepare-agent-exe</id>
......@@ -85,7 +85,6 @@
<goal>prepare-agent</goal>
</goals>
</execution>
<!-- Génère un rapport HTML -->
<execution>
<id>report-exe</id>
......@@ -94,7 +93,6 @@
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
......
package fr.univnantes.alma.common;
import fr.univnantes.alma.data.item.User;
import fr.univnantes.alma.server.game.item.card.*;
import fr.univnantes.alma.server.game.item.card.CardName;
import fr.univnantes.alma.server.game.item.card.PlaceCard;
import fr.univnantes.alma.server.game.item.card.SurvivalCard;
import fr.univnantes.alma.server.game.item.card.TrackingCard;
import java.util.List;
public interface NotAloneDatabase {
public boolean existUser(String idUser);
public boolean addUser(User user);
public User findUser(String idUser);
public PlaceCard findPlaceCard(String idCard);
......
......@@ -4,6 +4,8 @@ import fr.univnantes.alma.common.NotAloneDatabase;
public class DatabaseFactory {
private DatabaseFactory(){}
public static NotAloneDatabase getDatabase(){
return new DatabaseStub();
}
......
package fr.univnantes.alma.data;
import fr.univnantes.alma.common.NotAloneDatabase;
import fr.univnantes.alma.data.item.User;
import fr.univnantes.alma.server.game.item.Phase;
import fr.univnantes.alma.server.game.item.card.CardName;
import fr.univnantes.alma.server.game.item.card.PlaceCard;
......@@ -16,13 +15,11 @@ public class DatabaseStub implements NotAloneDatabase {
private Map<String, PlaceCard> placeCardMap;
private Map<String, SurvivalCard> survivalCardMap;
private Map<String, TrackingCard> trackingCardMap;
private Map<String, User> users;
public DatabaseStub() {
initializePlaceCardMap();
initializeSurvivalCardMap();
initializeTrackingCardMap();
users = new HashMap<>();
}
private void initializePlaceCardMap(){
......@@ -124,28 +121,6 @@ public class DatabaseStub implements NotAloneDatabase {
trackingCardMap.put("ZONE_INTERDITE", new TrackingCard(CardName.ZONE_INTERDITE, "Zone interdite", "Lorem ipsum", Phase.PREPHASE_2));
}
@Override
public boolean existUser(String idUser) {
return users.containsKey(idUser);
}
@Override
public boolean addUser(User user) {
if(!users.containsKey(user.getMail())){
users.put(user.getMail(), user);
return true;
}
else{
return false;
}
}
@Override
public User findUser(String idUser) {
return users.get(idUser);
}
public PlaceCard findPlaceCard(String idCard) {
return placeCardMap.get(idCard);
}
......
......@@ -14,7 +14,7 @@ import org.springframework.context.annotation.Configuration;
@Configuration
@EnableAutoConfiguration
@ComponentScan(basePackages = {"fr.univnantes.alma.server"})
@ComponentScan(basePackages = {"fr.univnantes.alma"})
public class NotAloneApplication {
public static void main(String[] args) {
......
......@@ -54,25 +54,13 @@ class NotAloneApplicationTest {
}
@Test
void testCreateGame_allIsTrue() throws TException {
List<TCard> placeCards = new ArrayList<>();
placeCards.add(new TCard("PLACE","NEXUS", new ArrayList<>()));
placeCards.add(new TCard("PLACE","JUNGLE", new ArrayList<>()));
placeCards.add(new TCard("PLACE","RIVIERE", new ArrayList<>()));
placeCards.add(new TCard("PLACE","DOME", new ArrayList<>()));
placeCards.add(new TCard("PLACE","ROVER", new ArrayList<>()));
placeCards.add(new TCard("PLACE","MANGROVE", new ArrayList<>()));
placeCards.add(new TCard("PLACE","ABRI", new ArrayList<>()));
placeCards.add(new TCard("PLACE","EPAVE", new ArrayList<>()));
placeCards.add(new TCard("PLACE","FUNGI", new ArrayList<>()));
placeCards.add(new TCard("PLACE","PORTAIL", new ArrayList<>()));
void testCreateRoom_allIsTrue() throws TException {
TRoomId id = client.createRoom(new TPlayer("5", "Name", "192.168.1.1", 8080));
assertThat(Integer.parseInt(id.getToken())).isGreaterThanOrEqualTo(1000);
}
@Test
void testJoinGame() throws TException, InterruptedException {
void testJoinRoom() throws TException, InterruptedException {
TRoomId id = client.createRoom(new TPlayer("join1", "Name", "192.168.1.1", 8080));
Response response = client.joinRoom(new TPlayer("join2", "Name", "192.168.1.1", 8080), id);
......@@ -113,7 +101,6 @@ class NotAloneApplicationTest {
response = client.joinRoom(new TPlayer("start3", "Name", "192.168.1.1", 8080), id);
assertFalse(response.state);
*/
*/
}
}
......@@ -19,7 +19,6 @@
<modules>
<module>not-alone-doc</module>
<module>not-alone-database</module>
<module>not-alone-server</module>
<module>not-alone-web</module>
<module>not-alone-core</module>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment