Java Code Examples for play.test.Helpers#route()
The following examples show how to use
play.test.Helpers#route() .
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: BadgeAssertionControllerTest.java From sunbird-lms-service with MIT License | 6 votes |
@Test public void revokeAssertionFailureTest() { PowerMockito.mockStatic(RequestInterceptor.class); when(RequestInterceptor.verifyRequestData(Mockito.anyObject())) .thenReturn("{userId} uuiuhcf784508 8y8c79-fhh"); Map<String, Object> requestMap = new HashMap<>(); Map<String, Object> innerMap = new HashMap<>(); innerMap.put(BadgingJsonKey.ASSERTION_ID, "assertionId"); innerMap.put(BadgingJsonKey.RECIPIENT_ID, "userIdorcontentId"); innerMap.put(BadgingJsonKey.RECIPIENT_TYPE, "user"); requestMap.put(JsonKey.REQUEST, innerMap); String data = mapToJson(requestMap); JsonNode json = Json.parse(data); RequestBuilder req = new RequestBuilder() .bodyJson(json) .uri("/v1/issuer/badge/assertion/delete") .method("DELETE"); Result result = Helpers.route(application, req); assertEquals(400, result.status()); }
Example 2
Source File: LocationControllerTest.java From sunbird-lms-service with MIT License | 6 votes |
@Test public void testCreateLocationWithoutType() { Map<String, Object> requestMap = new HashMap<>(); Map<String, Object> locationData = new HashMap<>(); locationData.put(JsonKey.NAME, LOCATION_NAME); locationData.put(JsonKey.CODE, LOCATION_CODE); requestMap.put(JsonKey.REQUEST, locationData); String data = TestUtil.mapToJson(requestMap); JsonNode json = Json.parse(data); RequestBuilder req = new RequestBuilder().bodyJson(json).uri(CREATE_LOCATION_URL).method("POST"); //req.headers(headerMap); Result result = Helpers.route(application,req); assertEquals(400, result.status()); }
Example 3
Source File: ClientControllerTest.java From sunbird-lms-service with MIT License | 6 votes |
@Test @Ignore public void testupdateClientKey() { PowerMockito.mockStatic(RequestInterceptor.class); when(RequestInterceptor.verifyRequestData(Mockito.anyObject())) .thenReturn("{userId} uuiuhcf784508 8y8c79-fhh"); Map<String, Object> requestMap = new HashMap<>(); Map<String, Object> innerMap = new HashMap<>(); innerMap.put("x-authenticated-client-token", "ap"); innerMap.put("x-authenticated-client-id", "123"); requestMap.put(JsonKey.REQUEST, innerMap); String data = mapToJson(requestMap); JsonNode json = Json.parse(data); RequestBuilder req = new RequestBuilder().bodyJson(json).uri("/v1/client/key/update").method("PATCH"); Result result = Helpers.route(application, req); assertEquals(200, result.status()); }
Example 4
Source File: DbOperationControllerTest.java From sunbird-lms-service with MIT License | 6 votes |
@Test public void testupdate() { PowerMockito.mockStatic(RequestInterceptor.class); when(RequestInterceptor.verifyRequestData(Mockito.anyObject())) .thenReturn("{userId} uuiuhcf784508 8y8c79-fhh"); Map<String, Object> requestMap = new HashMap<>(); Map<String, Object> innerMap = new HashMap<>(); innerMap.put(ENTITY_NAME, entityName); innerMap.put(INDEXED, true); Map<String, Object> payLoad = new HashMap<>(); payLoad.put(JsonKey.USER_ID, "usergt78y4ry85464"); payLoad.put(JsonKey.ID, "ggudy8d8ydyy8ddy9"); innerMap.put(PAYLOAD, payLoad); requestMap.put(JsonKey.REQUEST, innerMap); String data = mapToJson(requestMap); JsonNode json = Json.parse(data); RequestBuilder req = new RequestBuilder().bodyJson(json).uri("/v1/object/update").method("POST"); /*//req.headers(headerMap);*/ Result result = Helpers.route(application,req); assertEquals(200, result.status()); }
Example 5
Source File: BulkUploadControllerTest.java From sunbird-lms-service with MIT License | 6 votes |
@Test public void testUploadLocationWithProperData() { PowerMockito.mockStatic(RequestInterceptor.class); when(RequestInterceptor.verifyRequestData(Mockito.anyObject())) .thenReturn("{userId} uuiuhcf784508 8y8c79-fhh"); Map<String, Object> requestMap = new HashMap<>(); Map<String, Object> innerMap = new HashMap<>(); innerMap.put(JsonKey.DATA, "sampleStream".getBytes(Charset.defaultCharset())); innerMap.put(GeoLocationJsonKey.LOCATION_TYPE, "State"); requestMap.put(JsonKey.REQUEST, innerMap); String data = mapToJson(requestMap); JsonNode json = Json.parse(data); RequestBuilder req = new RequestBuilder().bodyJson(json).uri("/v1/bulk/location/upload").method("POST"); Result result = Helpers.route(application, req); assertEquals(200, result.status()); }
Example 6
Source File: DbOperationControllerTest.java From sunbird-lms-service with MIT License | 6 votes |
@Test public void testCreateWithWrongEntityName() { PowerMockito.mockStatic(RequestInterceptor.class); when(RequestInterceptor.verifyRequestData(Mockito.anyObject())) .thenReturn("{userId} uuiuhcf784508 8y8c79-fhh"); Map<String, Object> requestMap = new HashMap<>(); Map<String, Object> innerMap = new HashMap<>(); innerMap.put(ENTITY_NAME, entityName + "-wrong"); innerMap.put(INDEXED, true); Map<String, Object> payLoad = new HashMap<>(); payLoad.put(JsonKey.USER_ID, "usergt78y4ry8"); payLoad.put(JsonKey.ID, "ggudy8d8ydyy8ddy9"); innerMap.put(PAYLOAD, payLoad); requestMap.put(JsonKey.REQUEST, innerMap); String data = mapToJson(requestMap); JsonNode json = Json.parse(data); RequestBuilder req = new RequestBuilder().bodyJson(json).uri("/v1/object/create").method("POST"); /*//req.headers(headerMap);*/ Result result = Helpers.route(application,req); assertEquals(200, result.status()); }
Example 7
Source File: LocationControllerTest.java From sunbird-lms-service with MIT License | 6 votes |
@Test public void testUpdateLocation() { Map<String, Object> requestMap = new HashMap<>(); Map<String, Object> requestBody = new HashMap<>(); requestBody.put(JsonKey.NAME, LOCATION_NAME); requestBody.put(JsonKey.CODE, LOCATION_CODE); requestBody.put(JsonKey.ID, LOCATION_ID); requestMap.put(JsonKey.REQUEST, requestBody); String data = TestUtil.mapToJson(requestMap); JsonNode json = Json.parse(data); RequestBuilder req = new RequestBuilder().bodyJson(json).uri(UPDATE_LOCATION_URL).method("PATCH"); //req.headers(headerMap); Result result = Helpers.route(application,req); assertEquals(200, result.status()); }
Example 8
Source File: EmailServiceControllerTest.java From sunbird-lms-service with MIT License | 6 votes |
@Test public void testsendMail() { PowerMockito.mockStatic(RequestInterceptor.class); when(RequestInterceptor.verifyRequestData(Mockito.anyObject())) .thenReturn("{userId} uuiuhcf784508 8y8c79-fhh"); Map<String, Object> requestMap = new HashMap<>(); Map<String, Object> innerMap = new HashMap<>(); innerMap.put(JsonKey.ORG_NAME, "org123"); innerMap.put(JsonKey.SUBJECT, "subject"); innerMap.put(JsonKey.BODY, "body"); List<String> recepeintsEmails = new ArrayList<>(); recepeintsEmails.add("abc"); List<String> receipeintUserIds = new ArrayList<>(); receipeintUserIds.add("user001"); innerMap.put("recipientEmails", recepeintsEmails); innerMap.put("recipientUserIds", receipeintUserIds); requestMap.put(JsonKey.REQUEST, innerMap); String data = mapToJson(requestMap); JsonNode json = Json.parse(data); RequestBuilder req = new RequestBuilder().bodyJson(json).uri("/v1/notification/email").method("POST"); //req.headers(headerMap); Result result = Helpers.route(application,req); assertEquals(200, result.status()); }
Example 9
Source File: DbOperationControllerTest.java From sunbird-lms-service with MIT License | 6 votes |
@Test public void testgetMetrics() { PowerMockito.mockStatic(RequestInterceptor.class); when(RequestInterceptor.verifyRequestData(Mockito.anyObject())) .thenReturn("{userId} uuiuhcf784508 8y8c79-fhh"); Map<String, Object> requestMap = new HashMap<>(); Map<String, Object> innerMap = new HashMap<>(); innerMap.put(ENTITY_NAME, entityName); List<String> requiredFields = new ArrayList<>(); requiredFields.add("userid"); innerMap.put(REQUIRED_FIELDS, requiredFields); Map<String, Object> filters = new HashMap<>(); filters.put(JsonKey.USER_ID, "usergt78y4ry85464"); innerMap.put(JsonKey.FILTERS, filters); innerMap.put(JsonKey.ID, "ggudy8d8ydyy8ddy9"); requestMap.put(JsonKey.REQUEST, innerMap); String data = mapToJson(requestMap); JsonNode json = Json.parse(data); RequestBuilder req = new RequestBuilder().bodyJson(json).uri("/v1/object/metrics").method("POST"); //req.headers(headerMap); Result result = Helpers.route(application,req); assertEquals(200, result.status()); }
Example 10
Source File: FileStorageControllerTest.java From sunbird-lms-service with MIT License | 6 votes |
@Test public void testuploadFileService() { PowerMockito.mockStatic(RequestInterceptor.class); when(RequestInterceptor.verifyRequestData(Mockito.anyObject())) .thenReturn("{userId} uuiuhcf784508 8y8c79-fhh"); Map<String, Object> requestMap = new HashMap<>(); Map<String, Object> innerMap = new HashMap<>(); innerMap.put(JsonKey.DATA, "uploadFILEData".getBytes()); requestMap.put(JsonKey.REQUEST, innerMap); String data = mapToJson(requestMap); JsonNode json = Json.parse(data); RequestBuilder req = new RequestBuilder().bodyJson(json).uri("/v1/file/upload").method("POST"); //req.headers(headerMap); Result result = Helpers.route(application,req); assertEquals(200, result.status()); }
Example 11
Source File: ApplicationConfigControllerTest.java From sunbird-lms-service with MIT License | 5 votes |
@Test public void testupdateSystemSettingsFailure() { PowerMockito.mockStatic(RequestInterceptor.class); when(RequestInterceptor.verifyRequestData(Mockito.anyObject())) .thenReturn("{userId} uuiuhcf784508 8y8c79-fhh"); Map<String, Object> requestMap = new HashMap<>(); Map<String, Object> innerMap = new HashMap<>(); List<String> list = new ArrayList( Arrays.asList( PropertiesCache.getInstance() .getProperty("system_settings_properties") .split(","))); if (list.size() > 0) { innerMap.put(list.get(0), list.get(0)); requestMap.put(JsonKey.REQUEST, innerMap); String data = mapToJson(requestMap); JsonNode json = Json.parse(data); RequestBuilder req = new RequestBuilder().bodyJson(json).uri("/v1/system/settings/set").method("POST"); /*req.headers(headerMap);*/ Result result = Helpers.route(application, req); assertEquals(400, result.status()); } }
Example 12
Source File: LocationControllerTest.java From sunbird-lms-service with MIT License | 5 votes |
@Test public void testDeleteLocation() { RequestBuilder req = new RequestBuilder().uri(DELETE_LOCATION_URL + "/" + LOCATION_ID).method("DELETE"); //req.headers(headerMap); Result result = Helpers.route(application,req); assertEquals(200, result.status()); }
Example 13
Source File: OrganisationMetricsControllerTest.java From sunbird-lms-service with MIT License | 5 votes |
@Test public void testorgConsumptionReport() { PowerMockito.mockStatic(RequestInterceptor.class); when(RequestInterceptor.verifyRequestData(Mockito.anyObject())) .thenReturn("{userId} uuiuhcf784508 8y8c79-fhh"); RequestBuilder req = new RequestBuilder() .uri("/v1/dashboard/consumption/org/orgId/export?period=7d") .method("GET"); //req.headers(headerMap); Result result = Helpers.route(application,req); assertEquals(200, result.status()); }
Example 14
Source File: NotesControllerTest.java From sunbird-lms-service with MIT License | 5 votes |
@Test public void testUpdateNoteSuccess() { Map<String, Object> requestMap = new HashMap<>(); requestMap.put( JsonKey.REQUEST, getCreateNoteRequest(USER_ID, COURSE_ID, CONTENT_ID, NOTE, TITLE)); String data = mapToJson(requestMap); JsonNode json = Json.parse(data); RequestBuilder req = new RequestBuilder().bodyJson(json).uri("/v1/note/update/" + NOTE_ID).method("PATCH"); //req.headers(headerMap); Result result = Helpers.route(application,req); assertEquals(200, result.status()); }
Example 15
Source File: DbOperationControllerTest.java From sunbird-lms-service with MIT License | 5 votes |
@Test public void testAll() { testCreate(); testCreateWithWrongEntityName(); testupdate(); testread(); testreadAll(); testsearch(); testdelete(); PowerMockito.mockStatic(RequestInterceptor.class); when(RequestInterceptor.verifyRequestData(Mockito.anyObject())) .thenReturn("{userId} uuiuhcf784508 8y8c79-fhh"); Map<String, Object> requestMap = new HashMap<>(); Map<String, Object> innerMap = new HashMap<>(); innerMap.put(ENTITY_NAME, entityName); List<String> requiredFields = new ArrayList<>(); requiredFields.add("userid"); innerMap.put(REQUIRED_FIELDS, requiredFields); Map<String, Object> filters = new HashMap<>(); filters.put(JsonKey.USER_ID, "usergt78y4ry85464"); innerMap.put(JsonKey.FILTERS, filters); innerMap.put(JsonKey.ID, "ggudy8d8ydyy8ddy9"); requestMap.put(JsonKey.REQUEST, innerMap); String data = mapToJson(requestMap); JsonNode json = Json.parse(data); RequestBuilder req = new RequestBuilder().bodyJson(json).uri("/v1/object/search").method("POST"); /*//req.headers(headerMap);*/ Result result = Helpers.route(application,req); assertEquals(200, result.status()); }
Example 16
Source File: HealthControllerTest.java From sunbird-lms-service with MIT License | 5 votes |
@Test public void testgetHealth() { PowerMockito.mockStatic(RequestInterceptor.class); when(RequestInterceptor.verifyRequestData(Mockito.anyObject())) .thenReturn("{userId} uuiuhcf784508 8y8c79-fhh"); RequestBuilder req = new RequestBuilder().uri("/v1/health").method("GET"); //req.headers(headerMap); Result result = Helpers.route(application,req); assertEquals(200, result.status()); }
Example 17
Source File: BulkUploadControllerTest.java From sunbird-lms-service with MIT License | 5 votes |
@Test public void testGetUploadStatus() { Http.RequestBuilder req = new Http.RequestBuilder() .uri("/v1/upload/status/pid") .method("GET"); Result result = Helpers.route(application, req); Assert.assertEquals( 200, result.status()); }
Example 18
Source File: SystemSettingsControllerTest.java From sunbird-lms-service with MIT License | 5 votes |
@Test public void testSetSystemSettingFailureWithoutField() { JsonNode json = createSetSystemSettingRequest("defaultRootOrgId", null, "org123"); RequestBuilder req = new RequestBuilder().bodyJson(json).uri("/v1/system/settings/set").method("POST"); //req.headers(headerMap); Result result = Helpers.route(application,req); assertEquals(400, result.status()); }
Example 19
Source File: FeedControllerTest.java From sunbird-lms-service with MIT License | 5 votes |
@Test public void testGetUserFeed() { PowerMockito.mockStatic(FeedRequestValidator.class); PowerMockito.when( FeedRequestValidator.userIdValidation(Mockito.anyString(), Mockito.anyString())) .thenReturn(true) .thenReturn(false); Http.RequestBuilder req = new Http.RequestBuilder().uri("/v1/user/feed/1234567890").method("GET"); Result result = Helpers.route(application, req); assertEquals(200, result.status()); }
Example 20
Source File: OrganisationControllerTest.java From sunbird-lms-service with MIT License | 5 votes |
public Result performTest(String url, String method, Map map) { String data = mapToJson(map); Http.RequestBuilder req; if (StringUtils.isNotBlank(data)) { JsonNode json = Json.parse(data); req = new Http.RequestBuilder().bodyJson(json).uri(url).method(method); } else { req = new Http.RequestBuilder().uri(url).method(method); } // req.headers(new Http.Headers(headerMap)); Result result = Helpers.route(application, req); return result; }