Search in sources :

Example 1 with LogStream

use of com.auth0.json.mgmt.logstreams.LogStream in project auth0-java by auth0.

the class LogStreamsEntityTest method shouldUpdateLogStream.

@Test
public void shouldUpdateLogStream() throws Exception {
    LogStream logStream = getLogStream("log stream", null);
    logStream.setStatus("paused");
    Request<LogStream> request = api.logStreams().update("123", logStream);
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_LOG_STREAM, 200);
    LogStream response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("PATCH", "/api/v2/log-streams/123"));
    assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
    assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
    Map<String, Object> body = bodyFromRequest(recordedRequest);
    assertThat(body.size(), is(3));
    assertThat(body, hasEntry("name", "log stream"));
    assertThat(body, hasEntry("status", "paused"));
    assertThat(body, hasEntry("sink", logStream.getSink()));
    assertThat(response, is(notNullValue()));
    assertThat(response, hasProperty("id", is(notNullValue())));
    assertThat(response, hasProperty("name", is(notNullValue())));
    assertThat(response, hasProperty("type", is(notNullValue())));
    assertThat(response, hasProperty("status", is(notNullValue())));
    assertThat(response, hasProperty("sink", is(notNullValue())));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) LogStream(com.auth0.json.mgmt.logstreams.LogStream) Test(org.junit.Test)

Example 2 with LogStream

use of com.auth0.json.mgmt.logstreams.LogStream in project auth0-java by auth0.

the class LogStreamsEntityTest method getLogStream.

private LogStream getLogStream(String name, String type) {
    LogStream logStream = new LogStream(type);
    logStream.setName(name);
    Map<String, Object> sink = new HashMap<>();
    sink.put("httpEndpoint", "https://me.org");
    sink.put("httpAuthorization", "abc123");
    sink.put("httpContentFormat", "JSONLINES");
    sink.put("httpContentType", "application/json");
    logStream.setSink(sink);
    return logStream;
}
Also used : HashMap(java.util.HashMap) LogStream(com.auth0.json.mgmt.logstreams.LogStream)

Example 3 with LogStream

use of com.auth0.json.mgmt.logstreams.LogStream in project auth0-java by auth0.

the class LogStreamsEntityTest method shouldThrowOnUpdateLogStreamWithNullId.

@Test
public void shouldThrowOnUpdateLogStreamWithNullId() {
    exception.expect(IllegalArgumentException.class);
    exception.expectMessage("'log stream id' cannot be null!");
    api.logStreams().update(null, new LogStream());
}
Also used : LogStream(com.auth0.json.mgmt.logstreams.LogStream) Test(org.junit.Test)

Example 4 with LogStream

use of com.auth0.json.mgmt.logstreams.LogStream in project auth0-java by auth0.

the class LogStreamsEntityTest method shouldGetLogStream.

@Test
public void shouldGetLogStream() throws Exception {
    Request<LogStream> request = api.logStreams().get("123");
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MockServer.MGMT_LOG_STREAM, 200);
    LogStream response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("GET", "/api/v2/log-streams/123"));
    assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
    assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
    assertThat(response, is(notNullValue()));
    assertThat(response, hasProperty("id", is(notNullValue())));
    assertThat(response, hasProperty("name", is(notNullValue())));
    assertThat(response, hasProperty("type", is(notNullValue())));
    assertThat(response, hasProperty("status", is(notNullValue())));
    assertThat(response, hasProperty("sink", is(notNullValue())));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) LogStream(com.auth0.json.mgmt.logstreams.LogStream) Test(org.junit.Test)

Example 5 with LogStream

use of com.auth0.json.mgmt.logstreams.LogStream in project auth0-java by auth0.

the class LogStreamsEntityTest method shouldCreateLogStream.

@Test
public void shouldCreateLogStream() throws Exception {
    LogStream logStream = getLogStream("log stream", "http");
    Request<LogStream> request = api.logStreams().create(logStream);
    assertThat(request, is(notNullValue()));
    server.jsonResponse(MGMT_LOG_STREAM, 200);
    LogStream response = request.execute();
    RecordedRequest recordedRequest = server.takeRequest();
    assertThat(recordedRequest, hasMethodAndPath("POST", "/api/v2/log-streams"));
    assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
    assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
    Map<String, Object> body = bodyFromRequest(recordedRequest);
    assertThat(body.size(), is(3));
    assertThat(body, hasEntry("name", "log stream"));
    assertThat(body, hasEntry("type", "http"));
    assertThat(body, hasEntry("sink", logStream.getSink()));
    assertThat(response, is(notNullValue()));
    assertThat(response, hasProperty("id", is(notNullValue())));
    assertThat(response, hasProperty("name", is(notNullValue())));
    assertThat(response, hasProperty("type", is(notNullValue())));
    assertThat(response, hasProperty("status", is(notNullValue())));
    assertThat(response, hasProperty("sink", is(notNullValue())));
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) LogStream(com.auth0.json.mgmt.logstreams.LogStream) Test(org.junit.Test)

Aggregations

LogStream (com.auth0.json.mgmt.logstreams.LogStream)6 Test (org.junit.Test)5 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)4 HashMap (java.util.HashMap)1 List (java.util.List)1