org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get()

Here are the examples of the java api org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

849 Examples 7

19 Source : RasExceptionToHttpErrorConditionTranslatorTest.java
with GNU General Public License v3.0
from fogbow

private RequestBuilder createRequestBuilder() {
    return MockMvcRequestBuilders.get(TEST_CONTROLLER_REQUEST_SUFFIX);
}

19 Source : AppAuthControllerTest.java
with Apache License 2.0
from dromara

@Test
public void testUpdateSk() throws Exception {
    this.mockMvc.perform(MockMvcRequestBuilders.get("/appAuth/updateSk").param("appKey", "testAppKey").param("appSecret", "updateAppSecret")).andExpect(status().isOk()).andReturn();
}

19 Source : AppAuthControllerTest.java
with Apache License 2.0
from dromara

@Test
public void testFindPageByQuery() throws Exception {
    final PageParameter pageParameter = new PageParameter();
    final AppAuthQuery appAuthQuery = new AppAuthQuery("testAppKey", "18600000000", pageParameter);
    final CommonPager<AppAuthVO> commonPager = new CommonPager<>(pageParameter, Collections.singletonList(appAuthVO));
    given(this.appAuthService.listByPage(appAuthQuery)).willReturn(commonPager);
    this.mockMvc.perform(MockMvcRequestBuilders.get("/appAuth/findPageByQuery").param("appKey", "testAppKey").param("phone", "18600000000").param("currentPage", pageParameter.getCurrentPage() + "").param("pageSize", pageParameter.getPageSize() + "")).andExpect(status().isOk()).andExpect(jsonPath("$.message", is(SoulResultMessage.QUERY_SUCCESS))).andExpect(jsonPath("$.data.dataList[0].appKey", is(appAuthVO.getAppKey()))).andReturn();
}

19 Source : WebTestHelper.java
with Apache License 2.0
from airyhq

public ResultActions get(String url) throws Exception {
    return this.mvc.perform(MockMvcRequestBuilders.get(url));
}

18 Source : ServiceAccountsControllerV2Test.java
with Apache License 2.0
from tmobile

@Test
public void test_getServiceAccountMeta_success() throws Exception {
    UserDetails userDetails = getMockUser(false);
    String token = userDetails.getClientToken();
    String path = "ad/roles/testacc01";
    String expected = "{\n" + "  \"app-roles\": {\n" + "    \"role1\": \"read\"\n" + "  },\n" + "  \"managedBy\": \"user11\",\n" + "  \"name\": \"testacc01\",\n" + "  \"users\": {\n" + "    \"user11\": \"sudo\"\n" + "  }\n" + "}";
    ResponseEnreplacedy<String> responseEnreplacedyExpected = ResponseEnreplacedy.status(HttpStatus.OK).body(expected);
    when(serviceAccountsService.getServiceAccountMeta(token, userDetails, path)).thenReturn(responseEnreplacedyExpected);
    mockMvc.perform(MockMvcRequestBuilders.get("/v2/serviceaccounts/meta?path=ad/roles/testacc01").requestAttr("UserDetails", userDetails).header("vault-token", "5PDrOhsy4ig8L3EpsJZSLAMg").header("Content-Type", "application/json;charset=UTF-8")).andExpect(status().isOk()).andExpect(content().string(containsString(expected)));
}

18 Source : SelfSupportControllerTest.java
with Apache License 2.0
from tmobile

@Test
public void test_getsafes() throws Exception {
    String responseJson = "{\"shared\":[{\"s2\":\"read\"}],\"users\":[{\"s1\":\"read\"},{\"s5\":\"read\"}]}";
    ResponseEnreplacedy<String> responseEnreplacedyExpected = ResponseEnreplacedy.status(HttpStatus.OK).body(responseJson);
    UserDetails userDetails = getMockUser(false);
    when(selfSupportService.getSafes(userDetails, 10, 0)).thenReturn(responseEnreplacedyExpected);
    mockMvc.perform(MockMvcRequestBuilders.get("/v2/ss/sdb/safes?limit=10&offset=0").requestAttr("UserDetails", userDetails).header("vault-token", "5PDrOhsy4ig8L3EpsJZSLAMg").header("Content-Type", "application/json;charset=UTF-8")).andExpect(status().isOk()).andExpect(content().string(containsString(responseJson)));
}

18 Source : SelfSupportControllerTest.java
with Apache License 2.0
from tmobile

@Test
public void test_getInfo() throws Exception {
    String responseJson = "{\"data\": { \"description\": \"My first safe\", \"name\": \"mysafe01\", \"owner\": \"[email protected]\", \"type\": \"\" }}";
    ResponseEnreplacedy<String> responseEnreplacedyExpected = ResponseEnreplacedy.status(HttpStatus.OK).body(responseJson);
    UserDetails userDetails = getMockUser(false);
    when(selfSupportService.getInfo(userDetails, "users")).thenReturn(responseEnreplacedyExpected);
    mockMvc.perform(MockMvcRequestBuilders.get("/v2/ss/sdb/folder/users?path=users").requestAttr("UserDetails", userDetails).header("vault-token", "5PDrOhsy4ig8L3EpsJZSLAMg").header("Content-Type", "application/json;charset=UTF-8")).andExpect(status().isOk()).andExpect(content().string(containsString(responseJson)));
}

18 Source : SelfSupportControllerTest.java
with Apache License 2.0
from tmobile

@Test
public void test_getFoldersRecursively() throws Exception {
    String responseJson = "{  \"keys\": [    \"mysafe01\"  ]}";
    ResponseEnreplacedy<String> responseEnreplacedyExpected = ResponseEnreplacedy.status(HttpStatus.OK).body(responseJson);
    UserDetails userDetails = getMockUser(false);
    when(selfSupportService.getFoldersRecursively(userDetails, "users/safe1", 10, 0)).thenReturn(responseEnreplacedyExpected);
    mockMvc.perform(MockMvcRequestBuilders.get("/v2/ss/sdb/list?path=users/safe1&limit=10&offset=0").requestAttr("UserDetails", userDetails).header("vault-token", "5PDrOhsy4ig8L3EpsJZSLAMg").header("Content-Type", "application/json;charset=UTF-8")).andExpect(status().isOk()).andExpect(content().string(containsString(responseJson)));
}

18 Source : UserControllerMockMvcTest.java
with MIT License
from rieckpil

@Test
void shouldForbidAccessToUnauthenticatedRequests() throws Exception {
    this.mockMvc.perform(MockMvcRequestBuilders.get("/api/users")).andExpect(status().is4xxClientError());
}

18 Source : SpringMockMvcUtil.java
with Apache License 2.0
from Netflix

public static <E extends Message> E doGet(MockMvc mockMvc, String path, Clreplaced<E> enreplacedyType) throws Exception {
    return executeGet(mockMvc, newBuilder(enreplacedyType), MockMvcRequestBuilders.get(path).principal(JUNIT_AUTHENTICATION));
}

18 Source : CompetitionManagementDashboardControllerTest.java
with MIT License
from InnovateUKGitHub

@Test
public void showingDashboard() throws Exception {
    mockMvc.perform(MockMvcRequestBuilders.get("/dashboard")).andExpect(status().is3xxRedirection());
}

18 Source : InviteUserControllerTest.java
with MIT License
from InnovateUKGitHub

@Test
public void selectExternalRole() throws Exception {
    mockMvc.perform(MockMvcRequestBuilders.get("/admin/select-external-role")).andExpect(status().isOk()).andExpect(view().name("admin/select-external-role"));
}

18 Source : AbstractProcurementMilestoneControllerTest.java
with MIT License
from InnovateUKGitHub

@Test
public void get() throws Exception {
    long id = 1L;
    ResourceClazz resource = new ResourceClazz();
    resource.setDeliverable("Deliverables");
    when(service.get(refEq(IdClazz.of(id)))).thenReturn(serviceSuccess(resource));
    mockMvc.perform(MockMvcRequestBuilders.get("/test/{id}", id)).andExpect(status().isOk()).andExpect(jsonPath("$.deliverable", is("Deliverables")));
    verify(service).get(refEq(IdClazz.of(id)));
}

18 Source : RestActions.java
with MIT License
from hmcts

public ResultActions get(String urlTemplate) {
    return translateException(() -> mvc.perform(MockMvcRequestBuilders.get(urlTemplate).headers(httpHeaders).principal(new UsernamePreplacedwordAuthenticationToken(UUID.randomUUID().toString(), null))));
}

18 Source : BaseControllerTest.java
with Mozilla Public License 2.0
from hairless

protected MvcResult getMvcResult(String url) throws Exception {
    return mockMvc.perform(MockMvcRequestBuilders.get(url)).andDo(doreplacedent("get")).andReturn();
}

18 Source : ConfigClientTest.java
with Apache License 2.0
from fridujo

private void replacedertThatConfiguredValueIs(final String role) throws Exception {
    String userName = "user-" + userSequence.incrementAndGet();
    mockMvc.perform(MockMvcRequestBuilders.get("/whoami/" + userName)).andExpect(status().isOk()).andExpect(content().string("Hello! You're " + userName + " and you'll become a(n) " + role + "...\n"));
}

18 Source : PluginHandleControllerTest.java
with Apache License 2.0
from dromara

@Test
public void testQueryPluginHandles() throws Exception {
    given(this.pluginHandleService.listByPage(new PluginHandleQuery("2", null, new PageParameter(1, 1)))).willReturn(new CommonPager<>());
    this.mockMvc.perform(MockMvcRequestBuilders.get("/plugin-handle/", "1", 1, 1)).andExpect(status().isOk()).andReturn();
}

18 Source : PluginControllerTest.java
with Apache License 2.0
from dromara

@Test
public void testQueryAllPlugins() throws Exception {
    given(this.pluginService.listAll()).willReturn(new ArrayList<>());
    this.mockMvc.perform(MockMvcRequestBuilders.get("/plugin/all")).andExpect(status().isOk()).andReturn();
}

18 Source : AppAuthControllerTest.java
with Apache License 2.0
from dromara

@Test
public void testDetail() throws Exception {
    given(this.appAuthService.findById("0001")).willReturn(appAuthVO);
    this.mockMvc.perform(MockMvcRequestBuilders.get("/appAuth/detail").param("id", "0001")).andExpect(status().isOk()).andExpect(jsonPath("$.message", is(SoulResultMessage.DETAIL_SUCCESS))).andExpect(jsonPath("$.data.id", is(appAuthVO.getId()))).andReturn();
}

17 Source : HtmlUnitRequestBuilder.java
with MIT License
from Vip-Augus

@Override
public Object merge(@Nullable Object parent) {
    if (parent instanceof RequestBuilder) {
        if (parent instanceof MockHttpServletRequestBuilder) {
            MockHttpServletRequestBuilder copiedParent = MockMvcRequestBuilders.get("/");
            copiedParent.merge(parent);
            this.parentBuilder = copiedParent;
        } else {
            this.parentBuilder = (RequestBuilder) parent;
        }
        if (parent instanceof SmartRequestBuilder) {
            this.parentPostProcessor = (SmartRequestBuilder) parent;
        }
    }
    return this;
}

17 Source : TestStationFCController.java
with BSD 3-Clause "New" or "Revised" License
from Unidata

@Test
public void stationNotFoundStationDataset() throws Exception {
    RequestBuilder rb = MockMvcRequestBuilders.get(dataset).servletPath(dataset).param("accept", "netcdf").param("subset", "stns").param("stns", "mock_station").param("var", "air_temperature", "dew_point_temperature").param("time_start", "2006-03-25T00:00:00Z").param("time_end", "2006-04-28T00:00:00Z");
    this.mockMvc.perform(rb).andExpect(new ResultMatcher() {

        public void match(MvcResult result) throws Exception {
            // result.getResponse().getContentAsByteArray()
            Exception ex = result.getResolvedException();
            replacedertTrue(ex instanceof FeaturesNotFoundException);
        }
    });
}

17 Source : ServiceAccountsControllerV2Test.java
with Apache License 2.0
from tmobile

@Test
public void test_getServiceAccountsList_Details_success() throws Exception {
    UserDetails userDetails = getMockUser(false);
    String token = userDetails.getClientToken();
    String svcAccName = "testacc02";
    OnboardedServiceAccountDetails onboardedServiceAccountDetails = new OnboardedServiceAccountDetails();
    onboardedServiceAccountDetails.setLastVaultRotation("2018-05-24T17:14:38.677370855Z");
    onboardedServiceAccountDetails.setName(svcAccName + "@aaa.bbb.ccc.com");
    onboardedServiceAccountDetails.setPreplacedwordLastSet("2018-05-24T17:14:38.6038495Z");
    onboardedServiceAccountDetails.setTtl(100L);
    String expected = getJSON(onboardedServiceAccountDetails);
    ResponseEnreplacedy<String> responseEnreplacedyExpected = ResponseEnreplacedy.status(HttpStatus.OK).body(expected);
    when(serviceAccountsService.getServiceAccounts(userDetails, token, null, null)).thenReturn(responseEnreplacedyExpected);
    MvcResult result = mockMvc.perform(MockMvcRequestBuilders.get("/v2/serviceaccounts/list").header("vault-token", token).header("Content-Type", "application/json;charset=UTF-8").requestAttr("UserDetails", userDetails)).andExpect(status().isOk()).andReturn();
    String actual = result.getResponse().getContentreplacedtring();
    replacedertEquals(expected, actual);
}

17 Source : ServiceAccountsControllerV2Test.java
with Apache License 2.0
from tmobile

@Test
public void test_readSvcAccPwd_success() throws Exception {
    UserDetails userDetails = getMockUser(false);
    String token = userDetails.getClientToken();
    String svcAccName = "testacc02";
    String expected = "{\n" + "  \"current_preplacedword\": \"?@09AZGdnkinuq9OKXkeXW6D4oVGc\",\n" + "  \"last_preplacedword\": null,\n" + "  \"username\": \"testacc02\"\n" + "}";
    ResponseEnreplacedy<String> responseEnreplacedyExpected = ResponseEnreplacedy.status(HttpStatus.OK).body(expected);
    when(serviceAccountsService.readSvcAccPreplacedword(token, svcAccName, userDetails)).thenReturn(responseEnreplacedyExpected);
    MvcResult result = mockMvc.perform(MockMvcRequestBuilders.get("/v2/serviceaccounts/preplacedword").header("vault-token", token).header("Content-Type", "application/json;charset=UTF-8").requestAttr("UserDetails", userDetails).param("serviceAccountName", svcAccName)).andExpect(status().isOk()).andReturn();
    String actual = result.getResponse().getContentreplacedtring();
    replacedertEquals(expected, actual);
}

17 Source : SelfSupportControllerTest.java
with Apache License 2.0
from tmobile

@Test
public void test_readAppRole() throws Exception {
    String responseMessage = "sample response";
    ResponseEnreplacedy<String> responseEnreplacedyExpected = ResponseEnreplacedy.status(HttpStatus.OK).body(responseMessage);
    when(selfSupportService.readAppRole(Mockito.any(), Mockito.any())).thenReturn(responseEnreplacedyExpected);
    mockMvc.perform(MockMvcRequestBuilders.get("/v2/ss/approle/role/approle1").header("vault-token", "5PDrOhsy4ig8L3EpsJZSLAMg").header("Content-Type", "application/json;charset=UTF-8")).andExpect(status().isOk()).andExpect(content().string(containsString(responseMessage)));
}

17 Source : SelfSupportControllerTest.java
with Apache License 2.0
from tmobile

@Test
public void test_listRoles() throws Exception {
    String responseMessage = "{ \"keys\": [\"mytestawsrole\"]}";
    String token = "5PDrOhsy4ig8L3EpsJZSLAMg";
    userDetails.setUsername("adminuser");
    userDetails.setAdmin(false);
    userDetails.setClientToken(token);
    userDetails.setSelfSupportToken(token);
    ResponseEnreplacedy<String> responseEnreplacedyExpected = ResponseEnreplacedy.status(HttpStatus.OK).body(responseMessage);
    when(selfSupportService.listRoles(eq("5PDrOhsy4ig8L3EpsJZSLAMg"), eq(userDetails))).thenReturn(responseEnreplacedyExpected);
    mockMvc.perform(MockMvcRequestBuilders.get("/v2/ss/roles").header("vault-token", "5PDrOhsy4ig8L3EpsJZSLAMg").header("Content-Type", "application/json;charset=UTF-8")).andExpect(status().isOk());
}

17 Source : SelfSupportControllerTest.java
with Apache License 2.0
from tmobile

@Test
public void test_isAuthorized() throws Exception {
    String responseJson = "true";
    ResponseEnreplacedy<String> responseEnreplacedyExpected = ResponseEnreplacedy.status(HttpStatus.OK).body(String.valueOf(true));
    UserDetails userDetails = getMockUser(false);
    when(selfSupportService.isAuthorized(userDetails, "users/mysafe01")).thenReturn(responseEnreplacedyExpected);
    mockMvc.perform(MockMvcRequestBuilders.get("/auth/tvault/isauthorized?path=users/mysafe01").requestAttr("UserDetails", userDetails).header("vault-token", "5PDrOhsy4ig8L3EpsJZSLAMg").header("Content-Type", "application/json;charset=UTF-8")).andExpect(status().isOk()).andExpect(content().string(containsString(responseJson)));
}

17 Source : SelfSupportControllerTest.java
with Apache License 2.0
from tmobile

@Test
public void test_readAppRoleSecretId() throws Exception {
    String role_name = "testapprole01";
    String vaultToken = "5PDrOhsy4ig8L3EpsJZSLAMg";
    String role_id_response = "{\n" + "  \"data\": {\n" + "    \"secret_id\": \"generated-role-id\",\n" + "    \"secret_id_accessor\": \"accesssor-for-generated-role-id\"\n" + "  }\n" + "}";
    StringBuilder responseMessage = new StringBuilder(role_id_response);
    ResponseEnreplacedy<String> responseEnreplacedyExpected = ResponseEnreplacedy.status(HttpStatus.OK).body(responseMessage.toString());
    when(selfSupportService.readAppRoleSecretId(Mockito.any(), Mockito.any())).thenReturn(responseEnreplacedyExpected);
    mockMvc.perform(MockMvcRequestBuilders.get("/v2/ss/approle/" + role_name + "/secret_id").header("vault-token", vaultToken).header("Content-Type", "application/json;charset=UTF-8")).andExpect(status().isOk()).andExpect(content().string(containsString(responseMessage.toString())));
}

17 Source : SelfSupportControllerTest.java
with Apache License 2.0
from tmobile

@Test
public void test_listAppRoles() throws Exception {
    String vaultToken = "5PDrOhsy4ig8L3EpsJZSLAMg";
    String role_id_response = "{\n" + "  \"keys\": [\n" + "    \"testapprole01\"\n" + "  ]\n" + "}";
    StringBuilder responseMessage = new StringBuilder(role_id_response);
    ResponseEnreplacedy<String> responseEnreplacedyExpected = ResponseEnreplacedy.status(HttpStatus.OK).body(responseMessage.toString());
    when(selfSupportService.listAppRoles(eq(vaultToken), Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(responseEnreplacedyExpected);
    mockMvc.perform(MockMvcRequestBuilders.get("/v2/ss/approle").header("vault-token", vaultToken).header("Content-Type", "application/json;charset=UTF-8")).andExpect(status().isOk()).andExpect(content().string(containsString(responseMessage.toString())));
}

17 Source : SelfSupportControllerTest.java
with Apache License 2.0
from tmobile

@Test
public void test_readAppRoles() throws Exception {
    // Mock response
    String responseMessage = "sample response";
    ResponseEnreplacedy<String> responseEnreplacedyExpected = ResponseEnreplacedy.status(HttpStatus.OK).body(responseMessage);
    when(selfSupportService.readAppRoles(Mockito.any())).thenReturn(responseEnreplacedyExpected);
    mockMvc.perform(MockMvcRequestBuilders.get("/v2/ss/approle/role").header("vault-token", "5PDrOhsy4ig8L3EpsJZSLAMg").header("Content-Type", "application/json;charset=UTF-8")).andExpect(status().isOk()).andExpect(content().string(containsString(responseMessage)));
}

17 Source : SelfSupportControllerTest.java
with Apache License 2.0
from tmobile

@Test
public void test_getSafeNames() throws Exception {
    String responseJson = "{\"shared\":[\"safe5\",\"safe6\"],\"users\":[\"safe3\",\"safe4\"],\"apps\":[\"safe1\",\"safe2\"]}";
    ResponseEnreplacedy<String> responseEnreplacedyExpected = ResponseEnreplacedy.status(HttpStatus.OK).body(responseJson);
    UserDetails userDetails = getMockUser(false);
    when(selfSupportService.getAllSafeNames(userDetails)).thenReturn(responseEnreplacedyExpected);
    mockMvc.perform(MockMvcRequestBuilders.get("/v2/ss/sdb/names").requestAttr("UserDetails", userDetails).header("vault-token", "5PDrOhsy4ig8L3EpsJZSLAMg").header("Content-Type", "application/json;charset=UTF-8")).andExpect(status().isOk()).andExpect(content().string(containsString(responseJson)));
}

17 Source : SelfSupportControllerTest.java
with Apache License 2.0
from tmobile

@Test
public void test_getSafe() throws Exception {
    String responseJson = "{  \"keys\": [    \"mysafe01\"  ]}";
    ResponseEnreplacedy<String> responseEnreplacedyExpected = ResponseEnreplacedy.status(HttpStatus.OK).body(responseJson);
    UserDetails userDetails = getMockUser(false);
    when(selfSupportService.getSafe(userDetails, "users/safe1")).thenReturn(responseEnreplacedyExpected);
    mockMvc.perform(MockMvcRequestBuilders.get("/v2/ss/sdb?path=users/safe1").requestAttr("UserDetails", userDetails).header("vault-token", "5PDrOhsy4ig8L3EpsJZSLAMg").header("Content-Type", "application/json;charset=UTF-8")).andExpect(status().isOk()).andExpect(content().string(containsString(responseJson)));
}

17 Source : SelfSupportControllerTest.java
with Apache License 2.0
from tmobile

@Test
public void test_getAllSafes() throws Exception {
    String response = "{\n" + "  \"shared\": [],\n" + "  \"users\": [],\n" + "  \"apps\": [\n" + "    \"test1\",\n" + "    \"test2\"\n" + "  ]\n" + "}";
    ResponseEnreplacedy<String> responseEnreplacedyExpected = ResponseEnreplacedy.status(HttpStatus.OK).body(response);
    UserDetails userDetails = getMockUser(false);
    when(selfSupportService.getAllSafes(eq(userDetails), eq("5PDrOhsy4ig8L3EpsJZSLAMg"), eq("5PDrOhsy4ig8L3EpsJZSLAMg"))).thenReturn(responseEnreplacedyExpected);
    mockMvc.perform(MockMvcRequestBuilders.get("/v2/ss/sdb/allsafes").header("vault-token", "5PDrOhsy4ig8L3EpsJZSLAMg").header("Content-Type", "application/json;charset=UTF-8")).andExpect(status().isOk());
}

17 Source : SelfSupportControllerTest.java
with Apache License 2.0
from tmobile

@Test
public void test_readSecretIdAccessors() throws Exception {
    String role_name = "testapprole01";
    String vaultToken = "5PDrOhsy4ig8L3EpsJZSLAMg";
    String role_id_response = "{\n" + "  \"keys\": [\n" + "    \"accesssor-for-generated-role-id\"\n" + "  ]\n" + "}";
    StringBuilder responseMessage = new StringBuilder(role_id_response);
    ResponseEnreplacedy<String> responseEnreplacedyExpected = ResponseEnreplacedy.status(HttpStatus.OK).body(responseMessage.toString());
    when(selfSupportService.readSecretIdAccessors(eq(vaultToken), Mockito.any(), Mockito.any())).thenReturn(responseEnreplacedyExpected);
    mockMvc.perform(MockMvcRequestBuilders.get("/v2/ss/approle/" + role_name + "/accessors").header("vault-token", vaultToken).header("Content-Type", "application/json;charset=UTF-8")).andExpect(status().isOk()).andExpect(content().string(containsString(responseMessage.toString())));
}

17 Source : SelfSupportControllerTest.java
with Apache License 2.0
from tmobile

@Test
public void test_readAppRoleDetails() throws Exception {
    String role_name = "testapprole01";
    String vaultToken = "5PDrOhsy4ig8L3EpsJZSLAMg";
    String role_id_response = "{\n" + "  \"appRole\": {\n" + "    \"role_name\": \"testapprole01\",\n" + "    \"policies\": [\n" + "      \"string\"\n" + "    ],\n" + "    \"bind_secret_id\": true,\n" + "    \"secret_id_num_uses\": \"0\",\n" + "    \"secret_id_ttl\": \"0\",\n" + "    \"token_num_uses\": 0,\n" + "    \"token_ttl\": 0,\n" + "    \"token_max_ttl\": 0\n" + "  },\n" + "  \"role_id\": \"generated_role_id\",\n" + "  \"accessorIds\": [\n" + "    \"accesssor-for-generated-role-id\"\n" + "  ],\n" + "  \"appRoleMetadata\": {\n" + "    \"path\": \"metadata/approle/testapprole01\",\n" + "    \"data\": {\n" + "      \"name\": \"myvaultapprole\",\n" + "      \"createdBy\": \"testuser1\"\n" + "    }\n" + "  }\n" + "}";
    StringBuilder responseMessage = new StringBuilder(role_id_response);
    ResponseEnreplacedy<String> responseEnreplacedyExpected = ResponseEnreplacedy.status(HttpStatus.OK).body(responseMessage.toString());
    when(selfSupportService.readAppRoleDetails(eq(vaultToken), Mockito.any(), Mockito.any())).thenReturn(responseEnreplacedyExpected);
    mockMvc.perform(MockMvcRequestBuilders.get("/v2/ss/approle/" + role_name).header("vault-token", vaultToken).header("Content-Type", "application/json;charset=UTF-8")).andExpect(status().isOk()).andExpect(content().string(containsString(responseMessage.toString())));
}

17 Source : UserControllerTest.java
with GNU General Public License v3.0
from spring-framework-guru

@Test
public void testGetUserName() throws Exception {
    this.mockMvc.perform(MockMvcRequestBuilders.get("/users")).andExpect(status().isOk()).andExpect(MockMvcResultMatchers.content().string(containsString("John"))).andDo(doreplacedent("users/getUserByName"));
}

17 Source : HelloControllerTest.java
with MIT License
from Poseiden

@Test
public void should_return_hello_msg() throws Exception {
    this.unAuthMockMvc.perform(MockMvcRequestBuilders.get("/hello").accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andExpect(content().string(equalTo("Greetings from Spring Project Initial With Gradle!")));
}

17 Source : SignupControllerTests.java
with MIT License
from PacktPublishing

/*
    @Before
        public void setUp() {
         mvc = MockMvcBuilders.standaloneSetup(new IndexController()).build();
    }
     */
@Test
public void test_signup_form() throws Exception {
    mockMvc.perform(MockMvcRequestBuilders.get("/signup/form")).andExpect(status().isOk()).andExpect(view().name("signup/form")).andExpect(model().attributeExists("signupForm")).andExpect(content().string(containsString("Calendar User Signup"))).andDo(print());
}

17 Source : EmployeeController2Test.java
with Apache License 2.0
from kaimz

@Test
public void listAll() throws Exception {
    mvc.perform(MockMvcRequestBuilders.get("/emp")).andExpect(// 期待返回状态吗码200
    status().isOk()).andDo(// 打印返回的 http response 信息
    print());
}

17 Source : SpringMockTest.java
with GNU General Public License v3.0
from jpmorganchase

@Test
public void testMockGet() throws Exception {
    mockMvc.perform(MockMvcRequestBuilders.get("/scenario/mockGet", ""));
    replacedertTrue(true);
}

17 Source : InviteUserControllerTest.java
with MIT License
from InnovateUKGitHub

@Test
public void inviteInternalNewUser() throws Exception {
    InviteUserForm expectedUserForm = new InviteUserForm();
    mockMvc.perform(MockMvcRequestBuilders.get("/admin/invite-user")).andExpect(status().isOk()).andExpect(view().name("admin/invite-new-user")).andExpect(model().attribute("form", expectedUserForm));
}

17 Source : ApplicationProcurementMilestoneControllerTest.java
with MIT License
from InnovateUKGitHub

@Test
public void getByApplicationIdAndOrganisationId() throws Exception {
    long applicationId = 1L;
    long organisationId = 2L;
    List<ApplicationProcurementMilestoneResource> resource = newApplicationProcurementMilestoneResource().withDeliverable("Deliverable").build(1);
    when(applicationProcurementMilestoneService.getByApplicationIdAndOrganisationId(applicationId, organisationId)).thenReturn(serviceSuccess(resource));
    mockMvc.perform(MockMvcRequestBuilders.get("/application-procurement-milestone/application/{applicationId}/organisation/{organisationId}", applicationId, organisationId)).andExpect(status().isOk()).andExpect(jsonPath("$.[0].deliverable", is("Deliverable")));
    verify(applicationProcurementMilestoneService).getByApplicationIdAndOrganisationId(applicationId, organisationId);
}

17 Source : ImageTest.java
with GNU General Public License v3.0
from fogbow

private RequestBuilder createRequestBuilder(String urlTemplate, HttpHeaders headers, String body) {
    return MockMvcRequestBuilders.get(urlTemplate).headers(headers).accept(MediaType.APPLICATION_JSON).content(body).contentType(MediaType.APPLICATION_JSON);
}

17 Source : CreateProjectTest.java
with Apache License 2.0
from EdgeGallery

@Test
@WithMockUser(roles = "DEVELOPER_TENANT")
public void testGetProjectByIdFailed2() throws Exception {
    String url = String.format("/mec/developer/v1/projects/%s?userId=%s", "5cb37730-09c5-42e5-a638-6e1a3b8836b9", userId);
    mvc.perform(MockMvcRequestBuilders.get(url).contentType(MediaType.APPLICATION_JSON_UTF8).accept(MediaType.APPLICATION_JSON_UTF8));
}

17 Source : CreateProjectTest.java
with Apache License 2.0
from EdgeGallery

@Test
@WithMockUser(roles = "DEVELOPER_TENANT")
public void testGetProjectByIdFailed1() throws Exception {
    String url = String.format("/mec/developer/v1/projects/%s?userId=%s", "111111111111111", userId);
    mvc.perform(MockMvcRequestBuilders.get(url).contentType(MediaType.APPLICATION_JSON_UTF8).accept(MediaType.APPLICATION_JSON_UTF8));
}

17 Source : DefaultFallbackControllerTest.java
with Apache License 2.0
from dromara

@Test
public void testFallback() throws Exception {
    this.mockMvc.perform(MockMvcRequestBuilders.get("/fallback/hystrix")).andExpect(status().isOk()).andExpect(jsonPath("$.code", is(SoulResultEnum.HYSTRIX_PLUGIN_FALLBACK.getCode()))).andExpect(jsonPath("$.message", is(SoulResultEnum.HYSTRIX_PLUGIN_FALLBACK.getMsg()))).andReturn();
}

17 Source : DefaultFallbackControllerTest.java
with Apache License 2.0
from dromara

@Test
public void testResilience4jFallback() throws Exception {
    this.mockMvc.perform(MockMvcRequestBuilders.get("/fallback/resilience4j")).andExpect(status().isOk()).andExpect(jsonPath("$.code", is(SoulResultEnum.RESILIENCE4J_PLUGIN_FALLBACK.getCode()))).andExpect(jsonPath("$.message", is(SoulResultEnum.RESILIENCE4J_PLUGIN_FALLBACK.getMsg()))).andReturn();
}

17 Source : CpcRestIntegrationTest.java
with Creative Commons Zero v1.0 Universal
from CMSgov

@Test
void testNoSecurityGetCpcFile() throws Exception {
    mockMvc.perform(MockMvcRequestBuilders.get("/cpc/file/uuid")).andExpect(status().is(403));
}

17 Source : CpcRestIntegrationTest.java
with Creative Commons Zero v1.0 Universal
from CMSgov

@Test
void testNoSecurityUnprocessedCpcFiles() throws Exception {
    mockMvc.perform(MockMvcRequestBuilders.get("/cpc/unprocessed-files")).andExpect(status().is(403));
}

17 Source : WikiControllerTest.java
with MIT License
from cloudogu

@Test
public void findByIdNotFound() throws Exception {
    WikiId wikiId = new WikiId("4xQfahsId3", "master");
    when(wikiRepository.findById(wikiId)).thenReturn(Optional.empty());
    mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/repositories/4xQfahsId3/branches/master").contentType("application/json")).andExpect(status().isNotFound());
}

17 Source : RepositoryControllerTest.java
with MIT License
from cloudogu

@Test
public void findByIdNotFound() throws Exception {
    RepositoryId id = RepositoryId.valueOf("4xQfahsId3");
    when(repositoryRepository.findById(id)).thenReturn(Optional.empty());
    mockMvc.perform(MockMvcRequestBuilders.get("/api/v1/repositories/4xQfahsId3").contentType("application/json")).andExpect(status().isNotFound());
}

See More Examples