use of com.auth0.client.mgmt.filter.UsersImportOptions in project auth0-java by auth0.
the class JobsEntityTest method shouldThrowOnRequestUsersImportWithNullConnectionId.
@Test
public void shouldThrowOnRequestUsersImportWithNullConnectionId() {
exception.expect(IllegalArgumentException.class);
exception.expectMessage("'connection id' cannot be null!");
File usersFile = mock(File.class);
when(usersFile.exists()).thenReturn(true);
UsersImportOptions options = mock(UsersImportOptions.class);
api.jobs().importUsers(null, usersFile, options);
}
use of com.auth0.client.mgmt.filter.UsersImportOptions in project auth0-java by auth0.
the class JobsEntityTest method shouldThrowOnRequestUsersImportWithNullUsersFile.
@Test
public void shouldThrowOnRequestUsersImportWithNullUsersFile() {
exception.expect(IllegalArgumentException.class);
exception.expectMessage("'users file' cannot be null!");
UsersImportOptions options = mock(UsersImportOptions.class);
api.jobs().importUsers("con_123456789", null, options);
}
use of com.auth0.client.mgmt.filter.UsersImportOptions in project auth0-java by auth0.
the class JobsEntityTest method shouldRequestUsersImportWithOptions.
@Test
public void shouldRequestUsersImportWithOptions() throws Exception {
UsersImportOptions options = new UsersImportOptions();
options.withExternalId("ext_id123");
options.withUpsert(true);
options.withSendCompletionEmail(false);
File usersFile = new File(MGMT_JOB_POST_USERS_IMPORTS_INPUT);
Request<Job> request = api.jobs().importUsers("con_123456789", usersFile, options);
assertThat(request, is(notNullValue()));
server.jsonResponse(MGMT_JOB_POST_USERS_IMPORTS, 200);
Job response = request.execute();
RecordedRequest recordedRequest = server.takeRequest();
assertThat(recordedRequest, hasMethodAndPath("POST", "/api/v2/jobs/users-imports"));
assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
String ctHeader = recordedRequest.getHeader("Content-Type");
assertThat(ctHeader, startsWith("multipart/form-data"));
String[] ctParts = ctHeader.split("multipart/form-data; boundary=");
RecordedMultipartRequest recordedMultipartRequest = new RecordedMultipartRequest(recordedRequest);
assertThat(recordedMultipartRequest.getPartsCount(), is(5));
assertThat(recordedMultipartRequest.getBoundary(), is(notNullValue()));
assertThat(recordedMultipartRequest.getBoundary(), is(ctParts[1]));
// Connection ID
KeyValuePart connectionIdParam = recordedMultipartRequest.getKeyValuePart("connection_id");
assertThat(connectionIdParam, is(notNullValue()));
assertThat(connectionIdParam.getValue(), is("con_123456789"));
// External ID
KeyValuePart externalIdParam = recordedMultipartRequest.getKeyValuePart("external_id");
assertThat(externalIdParam, is(notNullValue()));
assertThat(externalIdParam.getValue(), is("ext_id123"));
// Upsert
KeyValuePart upsertParam = recordedMultipartRequest.getKeyValuePart("upsert");
assertThat(upsertParam, is(notNullValue()));
assertThat(upsertParam.getValue(), is("true"));
// Send Completion Email
KeyValuePart sendCompletionEmailParam = recordedMultipartRequest.getKeyValuePart("send_completion_email");
assertThat(sendCompletionEmailParam, is(notNullValue()));
assertThat(sendCompletionEmailParam.getValue(), is("false"));
// Users JSON
FilePart jsonFile = recordedMultipartRequest.getFilePart("users");
assertThat(jsonFile, is(notNullValue()));
String utf8Contents = new String(Files.readAllBytes(usersFile.toPath()));
assertThat(jsonFile.getContentType(), is("text/json"));
assertThat(jsonFile.getFilename(), is("job_post_users_imports_input.json"));
assertThat(jsonFile.getValue(), is(utf8Contents));
assertThat(response, is(notNullValue()));
}
Aggregations