1

I am using flyweight db script to setup the database :

CREATE SEQUENCE user_id_seq START WITH 1;
CREATE TABLE user (
  id            SERIAL          NOT NULL PRIMARY KEY,
  email         VARCHAR(64)     NOT NULL,
  nick          VARCHAR(64)     NOT NULL,
  pw            VARCHAR(64)     NOT NULL,

  -- role: admin, simple, member, leader, judge
  role          VARCHAR(64)     NOT NULL,
  judge         INTEGER         ,
  camp          INTEGER         ,

);

after first test the user is inserted and the sequence increased by one , before the second test I can drop the user table , but I don't know how to return user_id_seq to be back on 1.

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = BasicApplication.class)
public class UserRepositoryTest {

    @Autowired
    UserRepository userRepository;

    @Test
    public void insertUser(){

        User user = new User();
        user.setNick("roman");
        user.setRole("ROLE_ADMIN");

        PasswordEncoder pwEncoder = new BCryptPasswordEncoder();
        String pw = pwEncoder.encode("123");

        user.setPw(pw);

        userRepository.save(user);

        long userCount = userRepository.count();
        isTrue(userCount == 1);

        boolean exists = userRepository.exists(1);
        isTrue(exists);

        User fetchedUser = userRepository.findOne(1);

        assertEquals(fetchedUser.getNick(), "roman");
        assertEquals(fetchedUser.getPw(), pw);
        assertEquals(fetchedUser.getRole(), "ROLE_ADMIN");

    }

}

Any advice is welcome.

Roman Mandeleil
  • 306
  • 4
  • 12
  • 1
    Possible duplicate of [How do I reset a sequence in Oracle?](http://stackoverflow.com/questions/51470/how-do-i-reset-a-sequence-in-oracle) – Augusto Oct 26 '15 at 20:15

1 Answers1

1

Found the answer, that is all you need:

https://github.com/flyway/flyway-test-extensions

Roman Mandeleil
  • 306
  • 4
  • 12