@Test
  public void shouldProcessRegistration() throws Exception {
    Spitter unsaved = new Spitter("Gustavo", "Diaz", "gdiaz", "gd123");
    Spitter saved = new Spitter(24L, "Gustavo", "Diaz", "gdiaz", "gd123");
    SpitterRepository spittlerRepository = Mockito.mock(SpitterRepository.class);
    Mockito.when(spittlerRepository.save(unsaved)).thenReturn(saved);

    SpitterController spittleController = new SpitterController(spittlerRepository);

    MockMvc mockSpittleController = MockMvcBuilders.standaloneSetup(spittleController).build();

    mockSpittleController
        .perform(
            MockMvcRequestBuilders.post("/spitter/registerNoPic")
                .param("firstName", "Gustavo")
                .param("lastName", "Diaz")
                .param("userName", "gdiaz")
                .param("password", "gd123"))
        .andExpect(
            MockMvcResultMatchers.redirectedUrl(
                "/spitter/" + unsaved.getUserName() + "?id=" + unsaved.getFirstName()));

    // capture arguments pass to save call.
    ArgumentCaptor<Spitter> spitterArgumentCaptor = ArgumentCaptor.forClass(Spitter.class);
    Mockito.verify(spittlerRepository, Mockito.atLeastOnce()).save(spitterArgumentCaptor.capture());

    // assert save method was called using same arguments.
    Assert.assertThat(
        spitterArgumentCaptor.getValue(),
        org.hamcrest.beans.SamePropertyValuesAs.samePropertyValuesAs(unsaved));
  }
示例#2
0
  @Before
  public void setup() {

    TagController tagController = new TagController();
    ReflectionTestUtils.setField(tagController, "timelineService", timelineService);
    ReflectionTestUtils.setField(tagController, "tagMembershipService", tagMembershipService);
    ReflectionTestUtils.setField(tagController, "userTagRepository", userTagRepository);

    User authenticateUser = constructAUser(username + "@ippon.fr");
    AuthenticationService mockAuthenticationService = mock(AuthenticationService.class);
    when(mockAuthenticationService.getCurrentUser()).thenReturn(authenticateUser);
    ReflectionTestUtils.setField(tagController, "authenticationService", mockAuthenticationService);
    ReflectionTestUtils.setField(
        timelineService, "authenticationService", mockAuthenticationService);
    ReflectionTestUtils.setField(
        statusUpdateService, "authenticationService", mockAuthenticationService);
    ReflectionTestUtils.setField(
        tagMembershipService, "authenticationService", mockAuthenticationService);
    this.mockMvc = MockMvcBuilders.standaloneSetup(tagController).build();

    TimelineController timelineController = new TimelineController();
    ReflectionTestUtils.setField(timelineController, "timelineService", timelineService);
    ReflectionTestUtils.setField(timelineController, "statusUpdateService", statusUpdateService);
    this.timelineMockMvc = MockMvcBuilders.standaloneSetup(timelineController).build();
  }
  @Test
  public void mock_mvc_instance_is_overwritten_when_defined_in_specification() {
    // Given
    MockMvc otherMockMvcInstance = MockMvcBuilders.standaloneSetup(new PostController()).build();
    MockMvc thisMockMvcInstance = MockMvcBuilders.standaloneSetup(new GreetingController()).build();

    MockMvcRequestSpecification specToMerge =
        new MockMvcRequestSpecBuilder().setMockMvc(otherMockMvcInstance).build();

    // When
    MockMvcRequestSpecification spec = given().mockMvc(thisMockMvcInstance).spec(specToMerge);

    // Then
    assertThat(implOf(spec).getInstanceMockMvc()).isSameAs(otherMockMvcInstance);
  }
 @Before
 public void setup() {
   UserResource userResource = new UserResource();
   ReflectionTestUtils.setField(userResource, "userRepository", userRepository);
   ReflectionTestUtils.setField(userResource, "userService", userService);
   this.restUserMockMvc = MockMvcBuilders.standaloneSetup(userResource).build();
 }
 @Test
 public void correctlyRecordsMetricsForFailedDeferredResultResponse() throws Exception {
   AnnotationConfigApplicationContext context =
       new AnnotationConfigApplicationContext(Config.class, MetricFilterAutoConfiguration.class);
   MetricsFilter filter = context.getBean(MetricsFilter.class);
   CountDownLatch latch = new CountDownLatch(1);
   MockMvc mvc =
       MockMvcBuilders.standaloneSetup(new MetricFilterTestController(latch))
           .addFilter(filter)
           .build();
   String attributeName = MetricsFilter.class.getName() + ".StopWatch";
   MvcResult result =
       mvc.perform(post("/createFailure"))
           .andExpect(status().isOk())
           .andExpect(request().asyncStarted())
           .andExpect(request().attribute(attributeName, is(notNullValue())))
           .andReturn();
   latch.countDown();
   try {
     mvc.perform(asyncDispatch(result));
     fail();
   } catch (Exception ex) {
     assertThat(result.getRequest().getAttribute(attributeName)).isNull();
     verify(context.getBean(CounterService.class)).increment("status.500.createFailure");
   } finally {
     context.close();
   }
 }
示例#6
0
 @PostConstruct
 public void setup() {
   MockitoAnnotations.initMocks(this);
   CouponResource couponResource = new CouponResource();
   ReflectionTestUtils.setField(couponResource, "couponRepository", couponRepository);
   this.restCouponMockMvc = MockMvcBuilders.standaloneSetup(couponResource).build();
 }
 @PostConstruct
 public void setup() {
   MockitoAnnotations.initMocks(this);
   DTUserResource dTUserResource = new DTUserResource();
   ReflectionTestUtils.setField(dTUserResource, "dTUserRepository", dTUserRepository);
   this.restDTUserMockMvc = MockMvcBuilders.standaloneSetup(dTUserResource).build();
 }
 @Before
 public void setup() {
   this.mockMvc =
       MockMvcBuilders.standaloneSetup(petController)
           .setConversionService(formattingConversionServiceFactoryBean.getObject())
           .build();
 }
  @Before
  public void setup() {

    MockitoAnnotations.initMocks(this);

    account =
        new Account(
            "john",
            "malkovich",
            "Ireland",
            new BigInteger("500600700"),
            new BigInteger("1234567890"),
            new BigDecimal(25),
            "EUR");

    accountForm = new AccountForm();
    accountForm.setName("john");
    accountForm.setSurname("malkovich");
    accountForm.setAddress("Ireland");
    accountForm.setPhone(new BigInteger("500600700"));
    accountForm.setIban(new BigInteger("1234567890"));
    accountForm.setBalance(new BigDecimal(25));
    accountForm.setCurrency("EUR");

    viewResolver = new InternalResourceViewResolver();
    viewResolver.setPrefix("/WEB-INF/views/");
    viewResolver.setSuffix(".jsp");

    mockMvc =
        MockMvcBuilders.standaloneSetup(accountController).setViewResolvers(viewResolver).build();
  }
 @PostConstruct
 public void setup() {
   MockitoAnnotations.initMocks(this);
   AuthorResource authorResource = new AuthorResource();
   ReflectionTestUtils.setField(authorResource, "authorRepository", authorRepository);
   this.restAuthorMockMvc = MockMvcBuilders.standaloneSetup(authorResource).build();
 }
 @PostConstruct
 public void setup() {
   MockitoAnnotations.initMocks(this);
   TableNoResource tableNoResource = new TableNoResource();
   ReflectionTestUtils.setField(tableNoResource, "tableNoRepository", tableNoRepository);
   this.restTableNoMockMvc = MockMvcBuilders.standaloneSetup(tableNoResource).build();
 }
 @BeforeMethod
 public void setUp() {
   mockMvc =
       MockMvcBuilders.standaloneSetup(homeController)
           .setMessageConverters(new GsonHttpMessageConverter())
           .build();
 }
  @Test
  public void testGetText() throws Exception {
    String inputString = "User related info!";
    FormData data = new FormData();
    data.setComment(inputString);

    mockMvc = MockMvcBuilders.standaloneSetup(new ActionController()).build();
    MvcResult result =
        this.mockMvc
            .perform(get("/users").contentType(MediaType.APPLICATION_JSON).content(data.toString()))
            .andExpect(status().isOk())
            .andReturn();
    String returnString = result.getResponse().getContentAsString();
    ObjectMapper objectMapper = new ObjectMapper();
    logger.info("Call to /users returned: " + returnString);

    // convert json string to object
    FormActionResult returnData =
        objectMapper.readValue(returnString.getBytes(), FormActionResult.class);
    String expectedString = returnData.getFormData().getComment();
    logger.debug("USERS ACTION RETURNED: " + expectedString);

    assertTrue(
        "Expected data: \"" + inputString + "\"  actual data=\"" + expectedString + "\" ",
        inputString.equals(expectedString));
  }
示例#14
0
 @Before
 public void setup() {
   MockitoAnnotations.initMocks(this);
   AuditEventService auditEventService =
       new AuditEventService(auditEventRepository, auditEventConverter);
   AuditResource auditResource = new AuditResource(auditEventService);
   this.restAuditMockMvc = MockMvcBuilders.standaloneSetup(auditResource).build();
 }
示例#15
0
 @PostConstruct
 public void setup() {
   MockitoAnnotations.initMocks(this);
   ForumResource forumResource = new ForumResource();
   ReflectionTestUtils.setField(forumResource, "forumRepository", forumRepository);
   ReflectionTestUtils.setField(forumResource, "forumSearchRepository", forumSearchRepository);
   this.restForumMockMvc = MockMvcBuilders.standaloneSetup(forumResource).build();
 }
  @Before
  public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    mvc = MockMvcBuilders.standaloneSetup(logController).build();

    setUpActivityServiceMock();
    setUpLogServiceMock();
  }
  protected StandaloneMockMvcBuilder createBasicMockMvcBuilder(Object controller) {

    return MockMvcBuilders.standaloneSetup(controller)
        .setMessageConverters(new MappingJackson2HttpMessageConverter())
        .setHandlerExceptionResolvers(
            createExceptionResolver(new GlobalExceptionHandler()),
            new ResponseStatusExceptionResolver());
  }
示例#18
0
 @Before
 public void setup() {
   ExceptionHandlerExceptionResolver resolvers = createExceptionResolver();
   RestAssuredMockMvc.mockMvc =
       MockMvcBuilders.standaloneSetup(controller).setHandlerExceptionResolvers(resolvers).build();
   requestSpec =
       given().header(HttpHeaders.ACCEPT, ContentType.JSON).contentType(ContentType.JSON);
 }
  @Before
  public void setup() {
    principalUser = new User("Test", "User");

    MockitoAnnotations.initMocks(this);

    mockMvc = MockMvcBuilders.standaloneSetup(homeController).build();
  }
示例#20
0
 @Before
 public void init() {
   MockitoAnnotations.initMocks(this);
   tc = new MobileController();
   ReflectionTestUtils.setField(tc, "tripsService", tripsService);
   ReflectionTestUtils.setField(tc, "messageSource", messageSource);
   mockMvc = MockMvcBuilders.standaloneSetup(tc).build();
 }
  @Before
  public void setup() {
    MockitoAnnotations.initMocks(this);
    AnalyticsResource resource = new AnalyticsResource();
    resource.setService(service);
    restUserMockMvc = MockMvcBuilders.standaloneSetup(resource).build();

    mapper = new ObjectMapper();
    testData = new ArrayList<AnalyticsLog>();

    app = new App();
    app.setName("Testapp");
    app.setId(5L);
    app.setDateCreated(new DateTime());
    app.setDateUpdated(new DateTime());
    app.setApplicationKey(UUID.randomUUID());

    secondApp = new App();
    secondApp.setName("Testapp 2");
    secondApp.setId(2L);
    secondApp.setDateCreated(new DateTime());
    secondApp.setDateUpdated(new DateTime());
    secondApp.setApplicationKey(UUID.randomUUID());

    event = new NotificationEvent();
    event.setName("Event 2");
    event.setId(1L);
    event.setMessage("Test");
    event.setTitle("test");
    event.setDateUpdated(new DateTime());
    event.setDateCreated(new DateTime());
    event.getApps().add(app);

    beacon = new Beacon();
    beacon.setName("Event 2");
    beacon.setId(1L);
    beacon.setDateUpdated(new DateTime());
    beacon.setDateCreated(new DateTime());

    AnalyticsLog log = new AnalyticsLog();
    log.setId(11L);
    log.setDateUpdated(new DateTime());
    log.setDateCreated(new DateTime());
    log.setOccuredEvent(event);
    log.setBeacon(beacon);
    log.setApp(app);

    AnalyticsLog secondLog = new AnalyticsLog();
    secondLog.setId(1212L);
    secondLog.setDateUpdated(new DateTime());
    secondLog.setDateCreated(new DateTime().minusDays(5));
    secondLog.setOccuredEvent(event);
    secondLog.setBeacon(beacon);
    secondLog.setApp(app);

    testData.add(log);
    testData.add(secondLog);
  }
 @BeforeMethod
 public void setUp() throws Exception {
   jobService = mock(JobService.class);
   jobsController = new JobsController(jobService);
   mockMvc =
       MockMvcBuilders.standaloneSetup(jobsController)
           .defaultRequest(MockMvcRequestBuilders.get("/").contextPath("/some-microservice"))
           .build();
 }
  @Before
  public void setup() {

    // Process mock annotations
    MockitoAnnotations.initMocks(this);

    // Setup Spring test in standalone mode
    this.mockMvc = MockMvcBuilders.standaloneSetup(employeeController).build();
  }
 @PostConstruct
 public void setup() {
   MockitoAnnotations.initMocks(this);
   InvoiceAttributeResource invoiceAttributeResource = new InvoiceAttributeResource();
   ReflectionTestUtils.setField(
       invoiceAttributeResource, "invoiceAttributeRepository", invoiceAttributeRepository);
   this.restInvoiceAttributeMockMvc =
       MockMvcBuilders.standaloneSetup(invoiceAttributeResource).build();
 }
 @PostConstruct
 public void setup() {
   MockitoAnnotations.initMocks(this);
   CommercialOperationResource commercialOperationResource = new CommercialOperationResource();
   ReflectionTestUtils.setField(
       commercialOperationResource, "commercialOperationService", commercialOperationService);
   this.restCommercialOperationMockMvc =
       MockMvcBuilders.standaloneSetup(commercialOperationResource).build();
 }
示例#26
0
  @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();
  }
 @PostConstruct
 public void setup() {
   MockitoAnnotations.initMocks(this);
   ShipOrderResource shipOrderResource = new ShipOrderResource();
   ReflectionTestUtils.setField(shipOrderResource, "shipOrderRepository", shipOrderRepository);
   this.restShipOrderMockMvc =
       MockMvcBuilders.standaloneSetup(shipOrderResource)
           .setMessageConverters(jacksonMessageConverter)
           .build();
 }
示例#28
0
 @PostConstruct
 public void setup() {
   MockitoAnnotations.initMocks(this);
   JugadorResource jugadorResource = new JugadorResource();
   ReflectionTestUtils.setField(jugadorResource, "jugadorRepository", jugadorRepository);
   this.restJugadorMockMvc =
       MockMvcBuilders.standaloneSetup(jugadorResource)
           .setMessageConverters(jacksonMessageConverter)
           .build();
 }
 @PostConstruct
 public void setup() {
   MockitoAnnotations.initMocks(this);
   Bill_serviceResource bill_serviceResource = new Bill_serviceResource();
   ReflectionTestUtils.setField(bill_serviceResource, "bill_serviceService", bill_serviceService);
   this.restBill_serviceMockMvc =
       MockMvcBuilders.standaloneSetup(bill_serviceResource)
           .setCustomArgumentResolvers(pageableArgumentResolver)
           .setMessageConverters(jacksonMessageConverter)
           .build();
 }
 @PostConstruct
 public void setup() {
   MockitoAnnotations.initMocks(this);
   BookResource bookResource = new BookResource();
   ReflectionTestUtils.setField(bookResource, "bookRepository", bookRepository);
   this.restBookMockMvc =
       MockMvcBuilders.standaloneSetup(bookResource)
           .setCustomArgumentResolvers(pageableArgumentResolver)
           .setMessageConverters(jacksonMessageConverter)
           .build();
 }