Search in sources :

Example 26 with JaxRsResponse

use of org.neo4j.doc.server.rest.JaxRsResponse in project neo4j-documentation by neo4j.

the class PagedTraverserDocIT method shouldRespondWith400OnNegativeLeaseTime.

@Test
public void shouldRespondWith400OnNegativeLeaseTime() {
    theStartNode = createLinkedList(SHORT_LIST_LENGTH, server.getDatabase());
    int negativeLeaseTime = -9;
    JaxRsResponse response = RestRequest.req().post(functionalTestHelper.nodeUri(theStartNode.getId()) + "/paged/traverse/node?leaseTime=" + String.valueOf(negativeLeaseTime), traverserDescription());
    assertEquals(400, response.getStatus());
}
Also used : JaxRsResponse(org.neo4j.doc.server.rest.JaxRsResponse) Test(org.junit.Test)

Example 27 with JaxRsResponse

use of org.neo4j.doc.server.rest.JaxRsResponse in project neo4j-documentation by neo4j.

the class PagedTraverserDocIT method shouldRespondWith400OnScriptErrors.

@Test
public void shouldRespondWith400OnScriptErrors() {
    GlobalJavascriptInitializer.initialize(ScriptExecutionMode.SANDBOXED);
    theStartNode = createLinkedList(1, server.getDatabase());
    JaxRsResponse response = RestRequest.req().post(functionalTestHelper.nodeUri(theStartNode.getId()) + "/paged/traverse/node?pageSize=50", "{" + "\"prune_evaluator\":{\"language\":\"builtin\",\"name\":\"none\"}," + "\"return_filter\":{\"language\":\"javascript\",\"body\":\"position.getClass()" + ".getClassLoader();\"}," + "\"order\":\"depth_first\"," + "\"relationships\":{\"type\":\"NEXT\",\"direction\":\"out\"}" + "}");
    assertEquals(400, response.getStatus());
}
Also used : JaxRsResponse(org.neo4j.doc.server.rest.JaxRsResponse) Test(org.junit.Test)

Example 28 with JaxRsResponse

use of org.neo4j.doc.server.rest.JaxRsResponse in project neo4j-documentation by neo4j.

the class PagedTraverserDocIT method shouldHaveTransportEncodingChunkedOnResponseHeader.

@Test
public void shouldHaveTransportEncodingChunkedOnResponseHeader() {
    // given
    theStartNode = createLinkedList(VERY_LONG_LIST_LENGTH, server.getDatabase());
    // when
    JaxRsResponse response = createStreamingPagedTraverserWithTimeoutInMinutesAndPageSize(60, 1000);
    // then
    assertEquals(201, response.getStatus());
    assertEquals("application/json; charset=UTF-8; stream=true", response.getHeaders().getFirst("Content-Type"));
    assertThat(response.getHeaders().getFirst("Transfer-Encoding"), containsString("chunked"));
}
Also used : JaxRsResponse(org.neo4j.doc.server.rest.JaxRsResponse) Test(org.junit.Test)

Example 29 with JaxRsResponse

use of org.neo4j.doc.server.rest.JaxRsResponse in project neo4j-documentation by neo4j.

the class PagedTraverserDocIT method shouldExpireTraverserWithNonDefaultTimeout.

@Documented("Paged traverser timeout.\n\n" + "The default timeout for a paged traverser is 60\n" + "seconds, but depending on the application larger or smaller timeouts\n" + "might be appropriate. This can be set by adding a +leaseTime+ query\n" + "parameter with the number of seconds the paged traverser should last.")
@Test
public void shouldExpireTraverserWithNonDefaultTimeout() {
    theStartNode = createLinkedList(SHORT_LIST_LENGTH, server.getDatabase());
    URI traverserLocation = createPagedTraverserWithTimeoutInMinutes(10).getLocation();
    clock.forward(11, TimeUnit.MINUTES);
    JaxRsResponse response = new RestRequest(traverserLocation).get();
    assertEquals(404, response.getStatus());
}
Also used : RestRequest(org.neo4j.doc.server.rest.RestRequest) JaxRsResponse(org.neo4j.doc.server.rest.JaxRsResponse) URI(java.net.URI) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test)

Example 30 with JaxRsResponse

use of org.neo4j.doc.server.rest.JaxRsResponse in project neo4j-documentation by neo4j.

the class SecurityRulesDocIT method aComplexWildcardUriPathShould401OnAccessToProtectedSubPath.

@Test
@Title("Using complex wildcards to target security rules")
@Documented("In this example, a security rule is registered to deny access to all URIs matching a complex pattern.\n" + "The config looks like this:\n" + "\n" + "@@config\n" + "\n" + "with the rule source code of:\n" + "\n" + "@@failingRuleWithComplexWildcardPath")
public void aComplexWildcardUriPathShould401OnAccessToProtectedSubPath() throws Exception {
    String mountPoint = "/protected/wildcard_replacement/x/y/z/something/else/more_wildcard_replacement/a/b/c" + "/final/bit";
    server = CommunityServerBuilder.server().withDefaultDatabaseTuning().withThirdPartyJaxRsPackage("org.dummy.doc.web.service", mountPoint).withSecurityRules(PermanentlyFailingSecurityRuleWithComplexWildcardPath.class.getCanonicalName()).usingDataDir(folder.directory(name.getMethodName()).getAbsolutePath()).build();
    server.start();
    gen.get().docHeadingLevel(1);
    gen.get().addSnippet("config", "\n[source,properties]\n----\ndbms.security.http_authorization_classes=my.rules" + ".PermanentlyFailingSecurityRuleWithComplexWildcardPath\n----\n");
    gen.get().addTestSourceSnippets(PermanentlyFailingSecurityRuleWithComplexWildcardPath.class, "failingRuleWithComplexWildcardPath");
    gen.get().setSection("ops");
    functionalTestHelper = new FunctionalTestHelper(server);
    JaxRsResponse clientResponse = gen.get().expectedStatus(401).expectedType(MediaType.APPLICATION_JSON_TYPE).expectedHeader("WWW-Authenticate").get(trimTrailingSlash(functionalTestHelper.baseUri()) + mountPoint + "/more/stuff").response();
    assertEquals(401, clientResponse.getStatus());
}
Also used : FunctionalTestHelper(org.neo4j.doc.server.helpers.FunctionalTestHelper) Matchers.containsString(org.hamcrest.Matchers.containsString) JaxRsResponse(org.neo4j.doc.server.rest.JaxRsResponse) Documented(org.neo4j.kernel.impl.annotations.Documented) Test(org.junit.Test) Title(org.neo4j.test.TestData.Title)

Aggregations

Test (org.junit.Test)38 JaxRsResponse (org.neo4j.doc.server.rest.JaxRsResponse)38 RestRequest (org.neo4j.doc.server.rest.RestRequest)17 Matchers.containsString (org.hamcrest.Matchers.containsString)16 FunctionalTestHelper (org.neo4j.doc.server.helpers.FunctionalTestHelper)9 PrettyJSON (org.neo4j.doc.server.rest.PrettyJSON)8 Documented (org.neo4j.kernel.impl.annotations.Documented)6 URI (java.net.URI)4 Map (java.util.Map)4 Title (org.neo4j.test.TestData.Title)3 File (java.io.File)2 FileUtils.readTextFile (org.neo4j.io.fs.FileUtils.readTextFile)2 NeoServer (org.neo4j.server.NeoServer)2 Client (com.sun.jersey.api.client.Client)1 CommunityWebContainerBuilder (org.neo4j.doc.server.helpers.CommunityWebContainerBuilder)1 ListenSocketAddress (org.neo4j.helpers.ListenSocketAddress)1 BadInputException (org.neo4j.server.rest.repr.BadInputException)1