@Before public void initTest() { bar = createEntity(em); }
@Before public void initTest() { foo = createEntity(em); }
@PostConstruct public void setup() { MockitoAnnotations.initMocks(this); BarResource barResource = new BarResource(); ReflectionTestUtils.setField(barResource, "barRepository", barRepository); this.restBarMockMvc = MockMvcBuilders.standaloneSetup(barResource) .setCustomArgumentResolvers(pageableArgumentResolver) .setMessageConverters(jacksonMessageConverter).build(); }
ManagedUserVM duplicatedUser = new ManagedUserVM(validUser.getId(), validUser.getLogin(), validUser.getPassword(), validUser.getLogin(), validUser.getLastName(), "alicejr@example.com", true, validUser.getLangKey(), validUser.getAuthorities(), validUser.getCreatedBy(), validUser.getCreatedDate(), validUser.getLastModifiedBy(), validUser.getLastModifiedDate()); 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());
@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); }
@PostConstruct public void setup() { MockitoAnnotations.initMocks(this); FooResource fooResource = new FooResource(); ReflectionTestUtils.setField(fooResource, "fooRepository", fooRepository); this.restFooMockMvc = MockMvcBuilders.standaloneSetup(fooResource) .setCustomArgumentResolvers(pageableArgumentResolver) .setMessageConverters(jacksonMessageConverter).build(); }
@Before public void setup() { MockitoAnnotations.initMocks(this); AuditEventService auditEventService = new AuditEventService(auditEventRepository, auditEventConverter); AuditResource auditResource = new AuditResource(auditEventService); this.restAuditMockMvc = MockMvcBuilders.standaloneSetup(auditResource) .setCustomArgumentResolvers(pageableArgumentResolver) .setMessageConverters(jacksonMessageConverter).build(); }
@Before public void setup() { UserResource userResource = new UserResource(); ReflectionTestUtils.setField(userResource, "userRepository", userRepository); ReflectionTestUtils.setField(userResource, "userService", userService); this.restUserMockMvc = MockMvcBuilders.standaloneSetup(userResource).build(); }
@Before public void setup() { MockitoAnnotations.initMocks(this); doNothing().when(mockMailService).sendActivationEmail((User) anyObject(), anyString()); AccountResource accountResource = new AccountResource(); ReflectionTestUtils.setField(accountResource, "userRepository", userRepository); ReflectionTestUtils.setField(accountResource, "userService", userService); ReflectionTestUtils.setField(accountResource, "mailService", mockMailService); AccountResource accountUserMockResource = new AccountResource(); ReflectionTestUtils.setField(accountUserMockResource, "userRepository", userRepository); ReflectionTestUtils.setField(accountUserMockResource, "userService", mockUserService); ReflectionTestUtils.setField(accountUserMockResource, "mailService", mockMailService); this.restMvc = MockMvcBuilders.standaloneSetup(accountResource).build(); this.restUserMockMvc = MockMvcBuilders.standaloneSetup(accountUserMockResource).build(); }
ManagedUserVM duplicatedUser = new ManagedUserVM(validUser.getId(), "johnjr", validUser.getPassword(), validUser.getLogin(), validUser.getLastName(), validUser.getEmail(), true, validUser.getLangKey(), validUser.getAuthorities(), validUser.getCreatedBy(), validUser.getCreatedDate(), validUser.getLastModifiedBy(), validUser.getLastModifiedDate()); 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());
@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 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 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 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 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 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); }