@Test @Transactional public void testSaveInvalidLogin() throws Exception { UserDTO invalidUser = new UserDTO( "funky-log!n", // login <-- invalid "Funky", // firstName "One", // lastName "funky@example.com", // e-mail true, // activated "en", // langKey new HashSet<>(Arrays.asList(AuthoritiesConstants.USER)) ); restUserMockMvc.perform( post("/api/account") .contentType(TestUtil.APPLICATION_JSON_UTF8) .content(TestUtil.convertObjectToJsonBytes(invalidUser))) .andExpect(status().isBadRequest()); Optional<User> user = userRepository.findOneByEmail("funky@example.com"); assertThat(user.isPresent()).isFalse(); } }
@Test @Transactional public void testRegisterValid() throws Exception { ManagedUserVM validUser = new ManagedUserVM( null, // id "joe", // login "password", // password "Joe", // firstName "Shmoe", // lastName "joe@example.com", // e-mail true, // activated "en", // langKey new HashSet<>(Arrays.asList(AuthoritiesConstants.USER)), null, // createdBy null, // createdDate null, // lastModifiedBy null // lastModifiedDate ); restMvc.perform( post("/api/register") .contentType(TestUtil.APPLICATION_JSON_UTF8) .content(TestUtil.convertObjectToJsonBytes(validUser))) .andExpect(status().isCreated()); Optional<User> user = userRepository.findOneByLogin("joe"); assertThat(user.isPresent()).isTrue(); }
@Test @Transactional public void createBar() throws Exception { int databaseSizeBeforeCreate = barRepository.findAll().size(); // Create the Bar restBarMockMvc.perform(post("/api/bars") .contentType(TestUtil.APPLICATION_JSON_UTF8) .content(TestUtil.convertObjectToJsonBytes(bar))) .andExpect(status().isCreated()); // Validate the Bar in the database List<Bar> bars = barRepository.findAll(); assertThat(bars).hasSize(databaseSizeBeforeCreate + 1); Bar testBar = bars.get(bars.size() - 1); assertThat(testBar.getValue()).isEqualTo(DEFAULT_VALUE); }
@Test @Transactional public void createFoo() throws Exception { int databaseSizeBeforeCreate = fooRepository.findAll().size(); // Create the Foo restFooMockMvc.perform(post("/api/foos") .contentType(TestUtil.APPLICATION_JSON_UTF8) .content(TestUtil.convertObjectToJsonBytes(foo))) .andExpect(status().isCreated()); // Validate the Foo in the database List<Foo> foos = fooRepository.findAll(); assertThat(foos).hasSize(databaseSizeBeforeCreate + 1); Foo testFoo = foos.get(foos.size() - 1); assertThat(testFoo.getValue()).isEqualTo(DEFAULT_VALUE); }
@Test @Transactional public void testRegisterInvalidLogin() throws Exception { ManagedUserVM invalidUser = new ManagedUserVM( null, // id "funky-log!n", // login <-- invalid "password", // password "Funky", // firstName "One", // lastName "funky@example.com", // e-mail true, // activated "en", // langKey new HashSet<>(Arrays.asList(AuthoritiesConstants.USER)), null, // createdBy null, // createdDate null, // lastModifiedBy null // lastModifiedDate ); restUserMockMvc.perform( post("/api/register") .contentType(TestUtil.APPLICATION_JSON_UTF8) .content(TestUtil.convertObjectToJsonBytes(invalidUser))) .andExpect(status().isBadRequest()); Optional<User> user = userRepository.findOneByEmail("funky@example.com"); assertThat(user.isPresent()).isFalse(); }
@Test @Transactional public void testRegisterInvalidEmail() throws Exception { ManagedUserVM invalidUser = new ManagedUserVM( null, // id "bob", // login "password", // password "Bob", // firstName "Green", // lastName "invalid", // e-mail <-- invalid true, // activated "en", // langKey new HashSet<>(Arrays.asList(AuthoritiesConstants.USER)), null, // createdBy null, // createdDate null, // lastModifiedBy null // lastModifiedDate ); restUserMockMvc.perform( post("/api/register") .contentType(TestUtil.APPLICATION_JSON_UTF8) .content(TestUtil.convertObjectToJsonBytes(invalidUser))) .andExpect(status().isBadRequest()); Optional<User> user = userRepository.findOneByLogin("bob"); assertThat(user.isPresent()).isFalse(); }
@Test @Transactional public void testRegisterInvalidPassword() throws Exception { ManagedUserVM invalidUser = new ManagedUserVM( null, // id "bob", // login "123", // password with only 3 digits "Bob", // firstName "Green", // lastName "bob@example.com", // e-mail true, // activated "en", // langKey new HashSet<>(Arrays.asList(AuthoritiesConstants.USER)), null, // createdBy null, // createdDate null, // lastModifiedBy null // lastModifiedDate ); restUserMockMvc.perform( post("/api/register") .contentType(TestUtil.APPLICATION_JSON_UTF8) .content(TestUtil.convertObjectToJsonBytes(invalidUser))) .andExpect(status().isBadRequest()); Optional<User> user = userRepository.findOneByLogin("bob"); assertThat(user.isPresent()).isFalse(); }
@Test @Transactional public void testRegisterAdminIsIgnored() throws Exception { ManagedUserVM validUser = new ManagedUserVM( null, // id "badguy", // login "password", // password "Bad", // firstName "Guy", // lastName "badguy@example.com", // e-mail true, // activated "en", // langKey new HashSet<>(Arrays.asList(AuthoritiesConstants.ADMIN)), null, // createdBy null, // createdDate null, // lastModifiedBy null // lastModifiedDate ); restMvc.perform( post("/api/register") .contentType(TestUtil.APPLICATION_JSON_UTF8) .content(TestUtil.convertObjectToJsonBytes(validUser))) .andExpect(status().isCreated()); Optional<User> userDup = userRepository.findOneByLogin("badguy"); assertThat(userDup.isPresent()).isTrue(); assertThat(userDup.get().getAuthorities()).hasSize(1) .containsExactly(authorityRepository.findOne(AuthoritiesConstants.USER)); }
@Test @Transactional public void updateFoo() throws Exception { // Initialize the database fooRepository.saveAndFlush(foo); int databaseSizeBeforeUpdate = fooRepository.findAll().size(); // Update the foo Foo updatedFoo = fooRepository.findOne(foo.getId()); updatedFoo.setValue(UPDATED_VALUE); restFooMockMvc.perform(put("/api/foos") .contentType(TestUtil.APPLICATION_JSON_UTF8) .content(TestUtil.convertObjectToJsonBytes(updatedFoo))) .andExpect(status().isOk()); // Validate the Foo in the database List<Foo> foos = fooRepository.findAll(); assertThat(foos).hasSize(databaseSizeBeforeUpdate); Foo testFoo = foos.get(foos.size() - 1); assertThat(testFoo.getValue()).isEqualTo(UPDATED_VALUE); }
@Test @Transactional public void updateBar() throws Exception { // Initialize the database barRepository.saveAndFlush(bar); int databaseSizeBeforeUpdate = barRepository.findAll().size(); // Update the bar Bar updatedBar = barRepository.findOne(bar.getId()); updatedBar.setValue(UPDATED_VALUE); restBarMockMvc.perform(put("/api/bars") .contentType(TestUtil.APPLICATION_JSON_UTF8) .content(TestUtil.convertObjectToJsonBytes(updatedBar))) .andExpect(status().isOk()); // Validate the Bar in the database List<Bar> bars = barRepository.findAll(); assertThat(bars).hasSize(databaseSizeBeforeUpdate); Bar testBar = bars.get(bars.size() - 1); assertThat(testBar.getValue()).isEqualTo(UPDATED_VALUE); }
post("/api/register") .contentType(TestUtil.APPLICATION_JSON_UTF8) .content(TestUtil.convertObjectToJsonBytes(validUser))) .andExpect(status().isCreated()); post("/api/register") .contentType(TestUtil.APPLICATION_JSON_UTF8) .content(TestUtil.convertObjectToJsonBytes(duplicatedUser))) .andExpect(status().is4xxClientError());
post("/api/register") .contentType(TestUtil.APPLICATION_JSON_UTF8) .content(TestUtil.convertObjectToJsonBytes(validUser))) .andExpect(status().isCreated()); post("/api/register") .contentType(TestUtil.APPLICATION_JSON_UTF8) .content(TestUtil.convertObjectToJsonBytes(duplicatedUser))) .andExpect(status().is4xxClientError());