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.rest.web;
21  
22  import static org.junit.Assert.assertEquals;
23  import static org.mockito.Mockito.mock;
24  import static org.mockito.Mockito.when;
25  
26  import java.util.HashSet;
27  import java.util.List;
28  import java.util.Map;
29  
30  import javax.ws.rs.core.Response;
31  
32  import org.junit.Test;
33  import org.neo4j.graphdb.DynamicRelationshipType;
34  import org.neo4j.graphdb.RelationshipType;
35  import org.neo4j.kernel.AbstractGraphDatabase;
36  import org.neo4j.server.database.Database;
37  import org.neo4j.server.rest.web.DatabaseMetadataService;
38  import org.neo4j.server.rest.domain.JsonHelper;
39  import org.neo4j.server.rest.domain.JsonParseException;
40  
41  public class DatabaseMetadataServiceTest {
42      @Test
43      public void shouldAdvertiseRelationshipTyoesThatCurrentlyExistInTheDatabase() throws JsonParseException {
44          HashSet<RelationshipType> fakeRelationshipTypes = new HashSet<RelationshipType>();
45          fakeRelationshipTypes.add(DynamicRelationshipType.withName("a"));
46          fakeRelationshipTypes.add(DynamicRelationshipType.withName("b"));
47          fakeRelationshipTypes.add(DynamicRelationshipType.withName("c"));
48          
49          Database database = mock(Database.class);
50          AbstractGraphDatabase graph = mock(AbstractGraphDatabase.class);
51          database.graph = graph;
52          when(database.graph.getRelationshipTypes()).thenReturn(fakeRelationshipTypes);
53          DatabaseMetadataService service  = new DatabaseMetadataService(database);
54          
55          Response response = service.getRelationshipTypes();
56          
57          assertEquals(200, response.getStatus());
58          List<Map<String, Object>> jsonList = JsonHelper.jsonToList(response.getEntity().toString());
59          assertEquals(3, jsonList.size());
60      }
61  }
62