Commit 50c92125 authored by Killian LUCAS's avatar Killian LUCAS
Browse files

databse, AccessingDataJpaApplication to start apply

parent e0e40983
package fr.univnantes.alma.data.item;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
@SpringBootApplication
public class AccessingDataJpaApplication {
private static final Logger log = LoggerFactory.getLogger(AccessingDataJpaApplication.class);
public static void main(String[] args) {
SpringApplication.run(AccessingDataJpaApplication.class);
}
}
/*
@Bean
public CommandLineRunner demo(UserRepository repository) {
return (args) -> {
// save a few Users
repository.save(new User("JackyLove@world.net", "Jetecarryenadc","JackyLove"));
repository.save(new User("Faker@world.net", "Babibel","Faker"));
// fetch all Users (done)
log.info("Users found with findAll():");
log.info("-------------------------------");
for (User User : repository.findAll()) {
log.info(User.toString());
}
log.info("");
// fetch an individual User by ID (done)
User User = repository.findById(1L);
log.info("User found with findById(1L):");
log.info("--------------------------------");
log.info(User.toString());
log.info("");
// fetch Users by last name
log.info("User found with findByLastName('Faker'):");
log.info("--------------------------------------------");
repository.findByPseudo("Faker").forEach(faker -> {
log.info(faker.toString());
});
// for (User bauer : repository.findByLastName("Bauer")) {
// log.info(bauer.toString());
// }
log.info("");
};
}
}*/
\ No newline at end of file
package fr.univnantes.alma.data.item;
import java.util.List;
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.item;
import static org.assertj.core.api.Assertions.assertThat;
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 repository;
@Test
public void no_User(){
Iterable<User> customers = repository.findAll();
assertThat(customers).isEmpty();
}
@Test
public void should_store(){
User u = new User("ok","Jetecarryenadc","ok");
User user = repository.save(new User("JackyLove@world.net", "Jetecarryenadc","JackyLove"));
assertThat(user).hasFieldOrPropertyWithValue("mail","JackyLove@world.net");
// assertThat(user).hasFieldOrPropertyWithValue("password",u.getPasswordHash());
assertThat(user).hasFieldOrPropertyWithValue("pseudo","JackyLove");
}
}
\ No newline at end of file
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