View Javadoc

    1   /**
    2    * Copyright (c) 2002-2011 "Neo Technology,"
    3    * Network Engine for Objects in Lund AB [http://neotechnology.com]
    4    *
    5    * This file is part of Neo4j.
    6    *
    7    * Neo4j is free software: you can redistribute it and/or modify
    8    * it under the terms of the GNU General Public License as published by
    9    * the Free Software Foundation, either version 3 of the License, or
    10   * (at your option) any later version.
    11   *
    12   * This program is distributed in the hope that it will be useful,
    13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15   * GNU General Public License for more details.
    16   *
    17   * You should have received a copy of the GNU General Public License
    18   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    19   */
    20  package org.neo4j.server.modules;
    21
    22  import static org.mockito.Matchers.any;
    23  import static org.mockito.Mockito.mock;
    24  import static org.mockito.Mockito.verify;
    25  import static org.mockito.Mockito.when;
    26
    27  import java.net.URI;
    28  import java.util.HashMap;
    29
    30  import javax.management.ObjectName;
    31
    32  import org.apache.commons.configuration.MapConfiguration;
    33  import org.junit.Test;
    34  import org.neo4j.jmx.Kernel;
    35  import org.neo4j.kernel.AbstractGraphDatabase;
    36  import org.neo4j.server.NeoServerWithEmbeddedWebServer;
    37  import org.neo4j.server.database.Database;
    38  import org.neo4j.server.web.WebServer;
    39  import org.rrd4j.core.RrdDb;
    40
    41
    42  public class WebAdminModuleTest {
    43      @Test
    44      public void shouldRegisterASingleUri() throws Exception {
    45          WebServer webServer = mock(WebServer.class);
    46
    47          NeoServerWithEmbeddedWebServer neoServer = mock(NeoServerWithEmbeddedWebServer.class);
    48          when(neoServer.baseUri()).thenReturn(new URI("http://localhost:7575"));
    49          when(neoServer.getWebServer()).thenReturn(webServer);
    50
    51          Database db = mock(Database.class);
    52          db.graph = (mock(AbstractGraphDatabase.class));
    53          Kernel mockKernel = mock(Kernel.class);
    54          ObjectName mockObjectName = mock(ObjectName.class);
    55          when(mockKernel.getMBeanQuery()).thenReturn(mockObjectName);
    56          when(db.graph.getManagementBean(Kernel.class)).thenReturn(mockKernel);
    57
    58          when(neoServer.getDatabase()).thenReturn(db);
    59          when( neoServer.getConfiguration() ).thenReturn( new MapConfiguration( new HashMap<Object, Object>() ) );
    60
    61          WebAdminModule module = new WebAdminModule();
    62          module.start( neoServer );
    63
    64          verify( db ).setRrdDb( any( RrdDb.class ) );
    65      }
    66  }