Search in sources :

Example 1 with WebServer

use of org.neo4j.server.web.WebServer in project neo4j by neo4j.

the class DBMSModuleTest method shouldRegisterAtRootByDefault.

@Test
public void shouldRegisterAtRootByDefault() throws Exception {
    WebServer webServer = mock(WebServer.class);
    Config config = mock(Config.class);
    CommunityNeoWebServer neoServer = mock(CommunityNeoWebServer.class);
    when(neoServer.getBaseUri()).thenReturn(new URI("http://localhost:7575"));
    when(neoServer.getWebServer()).thenReturn(webServer);
    when(config.get(GraphDatabaseSettings.auth_enabled)).thenReturn(true);
    when(config.get(ServerSettings.http_paths_blacklist)).thenReturn(emptyList());
    var module = new DBMSModule(webServer, config, () -> new DiscoverableURIs.Builder().build(), NullLogProvider.getInstance());
    module.start();
    verify(webServer).addJAXRSClasses(anyList(), anyString(), isNull());
}
Also used : WebServer(org.neo4j.server.web.WebServer) CommunityNeoWebServer(org.neo4j.server.CommunityNeoWebServer) Config(org.neo4j.configuration.Config) CommunityNeoWebServer(org.neo4j.server.CommunityNeoWebServer) URI(java.net.URI) Test(org.junit.jupiter.api.Test)

Example 2 with WebServer

use of org.neo4j.server.web.WebServer in project neo4j by neo4j.

the class DBMSModuleTest method shouldNotRegisterUserServiceWhenAuthDisabled.

@SuppressWarnings("unchecked")
@Test
public void shouldNotRegisterUserServiceWhenAuthDisabled() throws Exception {
    WebServer webServer = mock(WebServer.class);
    Config config = mock(Config.class);
    CommunityNeoServer neoServer = mock(CommunityNeoServer.class);
    when(neoServer.baseUri()).thenReturn(new URI("http://localhost:7575"));
    when(neoServer.getWebServer()).thenReturn(webServer);
    when(config.get(GraphDatabaseSettings.auth_enabled)).thenReturn(false);
    DBMSModule module = new DBMSModule(webServer, config);
    module.start();
    verify(webServer).addJAXRSClasses(anyList(), anyString(), anyCollection());
    verify(webServer, never()).addJAXRSClasses(Matchers.argThat(new ArgumentMatcher<List<String>>() {

        @Override
        public boolean matches(Object argument) {
            List<String> argumentList = (List<String>) argument;
            return argumentList.contains(UserService.class.getName());
        }

        @Override
        public void describeTo(Description description) {
            description.appendText("<List containing " + UserService.class.getName() + ">");
        }
    }), anyString(), anyCollection());
}
Also used : Description(org.hamcrest.Description) CommunityNeoServer(org.neo4j.server.CommunityNeoServer) WebServer(org.neo4j.server.web.WebServer) UserService(org.neo4j.server.rest.dbms.UserService) Config(org.neo4j.kernel.configuration.Config) ArgumentMatcher(org.mockito.ArgumentMatcher) List(java.util.List) Matchers.anyList(org.mockito.Matchers.anyList) Matchers.anyString(org.mockito.Matchers.anyString) URI(java.net.URI) Test(org.junit.Test)

Example 3 with WebServer

use of org.neo4j.server.web.WebServer in project neo4j by neo4j.

the class ManagementApiModuleTest method shouldRegisterASingleUri.

@Test
public void shouldRegisterASingleUri() throws Exception {
    WebServer webServer = mock(WebServer.class);
    CommunityNeoServer neoServer = mock(CommunityNeoServer.class);
    when(neoServer.baseUri()).thenReturn(new URI("http://localhost:7575"));
    when(neoServer.getWebServer()).thenReturn(webServer);
    Map<String, String> params = new HashMap();
    String managementPath = "/db/manage";
    params.put(ServerSettings.management_api_path.name(), managementPath);
    Config config = Config.embeddedDefaults(params);
    when(neoServer.getConfig()).thenReturn(config);
    ManagementApiModule module = new ManagementApiModule(webServer, config);
    module.start();
    verify(webServer).addJAXRSClasses(any(List.class), anyString(), anyCollection());
}
Also used : CommunityNeoServer(org.neo4j.server.CommunityNeoServer) WebServer(org.neo4j.server.web.WebServer) HashMap(java.util.HashMap) Config(org.neo4j.kernel.configuration.Config) List(java.util.List) Matchers.anyString(org.mockito.Matchers.anyString) URI(java.net.URI) Test(org.junit.Test)

Example 4 with WebServer

use of org.neo4j.server.web.WebServer in project neo4j by neo4j.

the class RESTApiModuleTest method shouldRegisterASingleUri.

@Test
public void shouldRegisterASingleUri() throws Exception {
    // Given
    WebServer webServer = mock(WebServer.class);
    Map<String, String> params = new HashMap();
    String path = "/db/data";
    params.put(ServerSettings.rest_api_path.name(), path);
    Config config = Config.embeddedDefaults(params);
    Dependencies deps = new Dependencies();
    deps.satisfyDependency(new UsageData(mock(JobScheduler.class)));
    Database db = mock(Database.class);
    // When
    RESTApiModule module = new RESTApiModule(webServer, config, deps, NullLogProvider.getInstance());
    module.start();
    // Then
    verify(webServer).addJAXRSClasses(any(List.class), anyString(), anyCollection());
}
Also used : UsageData(org.neo4j.udc.UsageData) WebServer(org.neo4j.server.web.WebServer) HashMap(java.util.HashMap) Config(org.neo4j.kernel.configuration.Config) Database(org.neo4j.server.database.Database) List(java.util.List) Matchers.anyString(org.mockito.Matchers.anyString) Dependencies(org.neo4j.kernel.impl.util.Dependencies) Test(org.junit.Test)

Example 5 with WebServer

use of org.neo4j.server.web.WebServer in project neo4j by neo4j.

the class ThirdPartyJAXRSModuleTest method shouldReportThirdPartyPackagesAtSpecifiedMount.

@Test
void shouldReportThirdPartyPackagesAtSpecifiedMount() throws Exception {
    // Given
    WebServer webServer = mock(WebServer.class);
    CommunityNeoWebServer neoServer = mock(CommunityNeoWebServer.class);
    when(neoServer.getBaseUri()).thenReturn(new URI("http://localhost:7575"));
    when(neoServer.getWebServer()).thenReturn(webServer);
    Config config = mock(Config.class);
    List<ThirdPartyJaxRsPackage> jaxRsPackages = new ArrayList<>();
    String path = "/third/party/package";
    jaxRsPackages.add(new ThirdPartyJaxRsPackage("org.example.neo4j", path));
    when(config.get(ServerSettings.third_party_packages)).thenReturn(jaxRsPackages);
    // When
    ThirdPartyJAXRSModule module = new ThirdPartyJAXRSModule(webServer, config, NullLogProvider.getInstance());
    module.start();
    // Then
    verify(webServer).addJAXRSPackages(any(List.class), anyString(), any());
}
Also used : WebServer(org.neo4j.server.web.WebServer) CommunityNeoWebServer(org.neo4j.server.CommunityNeoWebServer) CommunityNeoWebServer(org.neo4j.server.CommunityNeoWebServer) Config(org.neo4j.configuration.Config) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) URI(java.net.URI) ThirdPartyJaxRsPackage(org.neo4j.server.configuration.ThirdPartyJaxRsPackage) Test(org.junit.jupiter.api.Test)

Aggregations

WebServer (org.neo4j.server.web.WebServer)6 List (java.util.List)5 URI (java.net.URI)4 Test (org.junit.Test)3 Test (org.junit.jupiter.api.Test)3 Matchers.anyString (org.mockito.Matchers.anyString)3 Config (org.neo4j.configuration.Config)3 Config (org.neo4j.kernel.configuration.Config)3 HashMap (java.util.HashMap)2 CommunityNeoServer (org.neo4j.server.CommunityNeoServer)2 CommunityNeoWebServer (org.neo4j.server.CommunityNeoWebServer)2 ArrayList (java.util.ArrayList)1 Description (org.hamcrest.Description)1 ArgumentMatcher (org.mockito.ArgumentMatcher)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 Matchers.anyList (org.mockito.Matchers.anyList)1 Dependencies (org.neo4j.kernel.impl.util.Dependencies)1 ThirdPartyJaxRsPackage (org.neo4j.server.configuration.ThirdPartyJaxRsPackage)1 Database (org.neo4j.server.database.Database)1 UserService (org.neo4j.server.rest.dbms.UserService)1