io.restassured.module.mockmvc.RestAssuredMockMvc Java Examples

The following examples show how to use io.restassured.module.mockmvc.RestAssuredMockMvc. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ApiCatalogControllerTests.java    From api-layer with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void whenGetAllContainers_givenNothing_thenReturnContainersWithState() {
    Application service1 = new Application("service-1");
    service1.addInstance(getStandardInstance("service1", InstanceInfo.InstanceStatus.UP));

    Application service2 = new Application("service-2");
    service1.addInstance(getStandardInstance("service2", InstanceInfo.InstanceStatus.DOWN));

    given(this.cachedServicesService.getService("service1")).willReturn(service1);
    given(this.cachedServicesService.getService("service2")).willReturn(service2);
    given(this.cachedProductFamilyService.getAllContainers()).willReturn(createContainers());

    RestAssuredMockMvc.standaloneSetup(apiCatalogController);
    RestAssuredMockMvc.given().
        when().
        get("/containers").
        then().
        statusCode(200);
}
 
Example #2
Source File: ApplicationRestAssuredMockMvcTest.java    From spring-microservice-sample with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void createPostWithoutAuthentication() throws Exception {
    Post _data = Post.builder().title("my first post").content("my content of my post").build();
    given(this.postService.createPost(any(PostForm.class)))
        .willReturn(_data);


    //@formatter:off
    RestAssuredMockMvc.given()
            .body(objectMapper.writeValueAsString(PostForm.builder().title("my first post").content("my content of my post").build()))
            .contentType(ContentType.JSON)
        .when()
            .post("/posts")
        .then()
            .assertThat()
            .statusCode(HttpStatus.SC_UNAUTHORIZED);
    //@formatter:on


    verify(this.postService, times(0)).createPost(any(PostForm.class));
    verifyNoMoreInteractions(this.postService);
}
 
Example #3
Source File: UserServiceBase.java    From code-examples with MIT License 6 votes vote down vote up
@Before
public void setup() {
  User savedUser = new User();
  savedUser.setFirstName("Arthur");
  savedUser.setLastName("Dent");
  savedUser.setId(42L);
  when(userRepository.save(any(User.class))).thenReturn(savedUser);
  RestAssuredMockMvc.webAppContextSetup(webApplicationContext);

  when(userRepository.findById(eq(42L))).thenReturn(Optional.of(savedUser));
}
 
Example #4
Source File: ApplicationRestAssuredMockMvcTest.java    From spring-microservice-sample with GNU General Public License v3.0 6 votes vote down vote up
@Test
@WithMockUser
public void createPostWithMockUser() throws Exception {
    Post _data = Post.builder().title("my first post").content("my content of my post").build();
    given(this.postService.createPost(any(PostForm.class)))
        .willReturn(_data);

    //@formatter:off
    RestAssuredMockMvc.given()
            .body(objectMapper.writeValueAsString(PostForm.builder().title("my first post").content("my content of my post").build()))
            .contentType(ContentType.JSON)
        .when()
            .post("/posts")
        .then()
            .assertThat()
            .header("Location", containsString("/posts"));
    //@formatter:on

    verify(this.postService, times(1)).createPost(any(PostForm.class));
}
 
Example #5
Source File: FraudBaseWithStandaloneSetup.java    From spring-cloud-contract with Apache License 2.0 5 votes vote down vote up
@BeforeEach
public void setup(TestInfo info, RestDocumentationContextProvider restDocumentation) {
	RestAssuredMockMvc.standaloneSetup(MockMvcBuilders
			.standaloneSetup(new FraudDetectionController())
			.apply(documentationConfiguration(restDocumentation))
			.alwaysDo(document(
					getClass().getSimpleName() + "_" + info.getDisplayName())));
}
 
Example #6
Source File: ContractBaseTest.java    From credhub with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {

  RestAssuredMockMvc
    .mockMvc(
      MockMvcBuilders
        .webAppContextSetup(webApplicationContext)
        .apply(springSecurity())
        .build()
    );
}
 
Example #7
Source File: CommandContractTest.java    From ESarch with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    final CommandGateway commandGateway = mock(CommandGateway.class);

    when(commandGateway.send(any())).thenReturn(completedFuture(null));
    when(commandGateway.send(any(CreateCompanyCommand.class)))
            .thenReturn(completedFuture(COMPANY_ID));
    when(commandGateway.send(any(CreateOrderBookCommand.class)))
            .thenReturn(completedFuture(ORDER_BOOK_ID));
    when(commandGateway.send(any(CreatePortfolioCommand.class)))
            .thenReturn(completedFuture(PORTFOLIO_ID));
    when(commandGateway.send(any(CreateUserCommand.class)))
            .thenReturn(completedFuture(USER_ID));
    when(commandGateway.send(any(StartBuyTransactionCommand.class)))
            .thenReturn(completedFuture(BUY_TRANSACTION_ID));
    when(commandGateway.send(any(StartSellTransactionCommand.class)))
            .thenReturn(completedFuture(SELL_TRANSACTION_ID));

    final ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.registerModule(new KotlinModule());
    final JsonSchemaGenerator jsonSchemaGenerator = new JsonSchemaGenerator(objectMapper);

    final CommandController commandController =
            new CommandController(commandGateway, objectMapper, jsonSchemaGenerator);
    commandController.setBeanClassLoader(this.getClass().getClassLoader());

    RestAssuredMockMvc.standaloneSetup(commandController);
}
 
Example #8
Source File: UserControllerIntegrationTest.java    From java-starthere with MIT License 5 votes vote down vote up
@Before
public void setUp() throws Exception
{
    RestAssuredMockMvc.webAppContextSetup(webApplicationContext);

    mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext)
                             .apply(SecurityMockMvcConfigurers.springSecurity())
                             .build();
}
 
Example #9
Source File: BeerRestBase.java    From spring-cloud-contract-samples with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
	RestAssuredMockMvc.mockMvc(MockMvcBuilders.standaloneSetup(this.producerController, this.statsController)
			.apply(documentationConfiguration(this.restDocumentation))
			.alwaysDo(document(getClass().getSimpleName() + "_" + this.testName.getMethodName()))
			.build());
}
 
Example #10
Source File: MvcTest.java    From friendly-id with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
	mockMvcBuilder = standaloneSetup(new FooController(mock(EntityLinks.class)));
	DefaultFormattingConversionService service = new DefaultFormattingConversionService();
	service.addConverter(new StringToUuidConverter());
	mockMvcBuilder.setMessageConverters(jackson2HttpMessageConverter()).setConversionService(service);
	RestAssuredMockMvc.standaloneSetup(mockMvcBuilder);
}
 
Example #11
Source File: BeerIntoxicationBase.java    From spring-cloud-contract-samples with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
	//remove::start[]
	RestAssuredMockMvc.mockMvc(MockMvcBuilders.webAppContextSetup(this.context)
			.apply(documentationConfiguration(this.restDocumentation))
			.alwaysDo(document(getClass().getSimpleName() + "_" + this.testName.getMethodName()))
			.build());
	//remove::end[]
}
 
Example #12
Source File: MessageControllerIntegrationTest.java    From holdmail with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {

    super.setUp();

    smtpClient = new TestMailClient(smtpServerPort, "localhost");
    RestAssuredMockMvc.webAppContextSetup(webAppCtx);
}
 
Example #13
Source File: FraudBaseWithWebAppSetup.java    From spring-cloud-contract with Apache License 2.0 5 votes vote down vote up
@BeforeEach
public void setup(TestInfo info, RestDocumentationContextProvider restDocumentation) {
	RestAssuredMockMvc.mockMvc(MockMvcBuilders.webAppContextSetup(this.context)
			.apply(documentationConfiguration(restDocumentation))
			.alwaysDo(document(
					getClass().getSimpleName() + "_" + info.getDisplayName()))
			.build());
}
 
Example #14
Source File: BeerRestBase.java    From spring-cloud-contract-samples with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() {
	RestAssuredMockMvc.standaloneSetup(this.producerController, this.statsController);
}
 
Example #15
Source File: BeerRestBase.java    From spring-cloud-contract-samples with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() {
	RestAssuredMockMvc.standaloneSetup(this.producerController,
			new CarRentalHistoryController(someServiceStub()));
}
 
Example #16
Source File: BeerIntoxicationBase.java    From spring-cloud-contract-samples with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() {
	//remove::start[]
	RestAssuredMockMvc.webAppContextSetup(this.webApplicationContext);
	//remove::end[]
}
 
Example #17
Source File: BeerRestBase.java    From spring-cloud-contract-samples with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() {
	RestAssuredMockMvc.standaloneSetup(this.producerController);
}
 
Example #18
Source File: BeerRestBase.java    From spring-cloud-contract-samples with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() {
	RestAssuredMockMvc.webAppContextSetup(this.context);
}
 
Example #19
Source File: BeerRestBase.java    From spring-cloud-contract-samples with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() {
	RestAssuredMockMvc.standaloneSetup(this.producerController, this.statsController);
}
 
Example #20
Source File: BeerRestBase.java    From spring-cloud-contract-samples with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() {
	RestAssuredMockMvc.standaloneSetup(this.producerController);
}
 
Example #21
Source File: BeerStuffBase.java    From spring-cloud-contract-samples with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() {
	RestAssuredMockMvc.standaloneSetup(new StuffController());
}
 
Example #22
Source File: BeerIntoxicationBase.java    From spring-cloud-contract-samples with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() {
	//remove::start[]
	RestAssuredMockMvc.webAppContextSetup(this.webApplicationContext);
	//remove::end[]
}
 
Example #23
Source File: BeerRestBase.java    From spring-cloud-contract-samples with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() {
	RestAssuredMockMvc.standaloneSetup(this.producerController);
}
 
Example #24
Source File: BeerRestBase.java    From spring-cloud-contract-samples with Apache License 2.0 4 votes vote down vote up
@BeforeEach
public void setup() {
	given(this.personCheckingService.shouldGetBeer(argThat(oldEnough()))).willReturn(true);
	given(this.statsService.findBottlesByName(anyString())).willReturn(new Random().nextInt());
	RestAssuredMockMvc.standaloneSetup(this.producerController, this.statsController);
}
 
Example #25
Source File: BeerIntoxicationBase.java    From spring-cloud-contract-samples with Apache License 2.0 4 votes vote down vote up
@BeforeEach
public void setup() {
	//remove::start[]
	RestAssuredMockMvc.webAppContextSetup(this.webApplicationContext);
	//remove::end[]
}
 
Example #26
Source File: BaseClass.java    From github-analytics with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() {
	RestAssuredMockMvc.standaloneSetup(new IssuesController(issuesService()));
}
 
Example #27
Source File: UserControllerUnitTest.java    From java-starthere with MIT License 4 votes vote down vote up
@Before
public void setUp() throws Exception
{
    userList = new ArrayList<>();

    Role r1 = new Role("admin");
    r1.setRoleid(1);
    Role r2 = new Role("user");
    r2.setRoleid(2);
    Role r3 = new Role("data");
    r3.setRoleid(3);

    // admin, data, user
    ArrayList<UserRoles> admins = new ArrayList<>();
    admins.add(new UserRoles(new User(), r1));
    admins.add(new UserRoles(new User(), r2));
    admins.add(new UserRoles(new User(), r3));
    User u1 = new User("admin", "ILuvM4th!", "[email protected]", admins);

    u1.getUseremails()
      .add(new Useremail(u1, "[email protected]"));
    u1.getUseremails().get(0).setUseremailid(10);

    u1.getUseremails()
      .add(new Useremail(u1, "[email protected]"));
    u1.getUseremails().get(1).setUseremailid(11);

    u1.setUserid(101);
    userList.add(u1);

    // data, user
    ArrayList<UserRoles> datas = new ArrayList<>();
    datas.add(new UserRoles(new User(), r3));
    datas.add(new UserRoles(new User(), r2));
    User u2 = new User("cinnamon", "1234567", "[email protected]", datas);

    u2.getUseremails()
      .add(new Useremail(u2, "[email protected]"));
    u2.getUseremails().get(0).setUseremailid(20);

    u2.getUseremails()
      .add(new Useremail(u2, "[email protected]"));
    u2.getUseremails().get(1).setUseremailid(21);

    u2.getUseremails()
      .add(new Useremail(u2, "[email protected]"));
    u2.getUseremails().get(2).setUseremailid(22);

    u2.setUserid(102);
    userList.add(u2);

    // user
    ArrayList<UserRoles> users = new ArrayList<>();
    users.add(new UserRoles(new User(), r1));
    User u3 = new User("testingbarn", "ILuvM4th!", "[email protected]", users);

    u3.getUseremails()
      .add(new Useremail(u3, "[email protected]"));
    u3.getUseremails().get(0).setUseremailid(30);

    u3.setUserid(103);
    userList.add(u3);

    users = new ArrayList<>();
    users.add(new UserRoles(new User(), r2));
    User u4 = new User("testingcat", "password", "[email protected]", users);
    u4.setUserid(104);
    userList.add(u4);

    users = new ArrayList<>();
    users.add(new UserRoles(new User(), r2));
    User u5 = new User("testingdog", "password", "[email protected]", users);
    u5.setUserid(105);
    userList.add(u5);

    System.out.println("\n*** Seed Data ***");
    for (User u : userList)
    {
        System.out.println(u);
    }
    System.out.println("*** Seed Data ***\n");

    RestAssuredMockMvc.webAppContextSetup(webApplicationContext);

    mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext)
                             .apply(SecurityMockMvcConfigurers.springSecurity())
                             .build();
}
 
Example #28
Source File: CourseControllerUnitTest.java    From tutorials with MIT License 4 votes vote down vote up
@Before
public void initialiseRestAssuredMockMvcStandalone() {
    RestAssuredMockMvc.standaloneSetup(courseController, courseControllerExceptionHandler);
}
 
Example #29
Source File: YmlFraudBase.java    From spring-cloud-contract with Apache License 2.0 4 votes vote down vote up
@BeforeEach
public void setup() {
	RestAssuredMockMvc.standaloneSetup(new FraudDetectionController(),
			new FraudStatsController(stubbedStatsProvider()));
}
 
Example #30
Source File: BeerRestBase.java    From spring-cloud-contract-samples with Apache License 2.0 4 votes vote down vote up
@Before
public void setup() {
	RestAssuredMockMvc.standaloneSetup(this.producerController, this.statsController);
}