View Javadoc
1   /**
2    * Copyright (c) 2018 BITPlan GmbH
3    *
4    * http://www.bitplan.com
5    *
6    * This file is part of the Opensource project at:
7    * https://github.com/BITPlan/com.bitplan.simplegraph
8    *
9    * Licensed under the Apache License, Version 2.0 (the "License");
10   * you may not use this file except in compliance with the License.
11   * You may obtain a copy of the License at
12   *
13   *     http://www.apache.org/licenses/LICENSE-2.0
14   *
15   * Unless required by applicable law or agreed to in writing, software
16   * distributed under the License is distributed on an "AS IS" BASIS,
17   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18   * See the License for the specific language governing permissions and
19   * limitations under the License.
20   */
21  package com.bitplan.simplegraph.excel;
22  
23  import static org.junit.Assert.assertEquals;
24  
25  import java.io.File;
26  import java.util.List;
27  import java.util.Map;
28  import java.util.logging.Logger;
29  
30  import org.apache.poi.ss.usermodel.Workbook;
31  import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
32  import org.apache.tinkerpop.gremlin.structure.Graph;
33  import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory;
34  import org.junit.Test;
35  
36  import com.bitplan.simplegraph.core.SimpleNode;
37  import com.bitplan.simplegraph.core.TestTinkerPop3;
38  
39  /**
40   * test the excel system
41   * 
42   * @author wf
43   *
44   */
45  public class TestExcelSystem {
46    public static boolean debug = false;
47    protected static Logger LOGGER = Logger
48        .getLogger("com.bitplan.simplegraph.excel");
49  
50    String testAirRouteFileName = "../simplegraph-excel/air-routes.xlsx";
51    String testModernFileName="../simplegraph-excel/modern.xlsx";
52  
53    @Test
54    public void testCreateExcelAirRoutes() throws Exception {
55      ExcelSystem es = new ExcelSystem();
56      Graph graph = TestTinkerPop3.getAirRoutes();
57      GraphTraversalSource g = graph.traversal();
58      // es.setDebug(true);
59      Workbook wb = es.createWorkBook(g);
60      assertEquals(6, wb.getNumberOfSheets());
61      es.save(wb, testAirRouteFileName);
62    }
63    
64    @Test
65    public void testCreateExcelModern() throws Exception {
66      ExcelSystem es = new ExcelSystem();
67      Graph graph = TinkerFactory.createModern();
68      GraphTraversalSource g = graph.traversal();
69      // es.setDebug(true);
70      Workbook wb = es.createWorkBook(g);
71      assertEquals(4, wb.getNumberOfSheets());
72      es.save(wb, testModernFileName);
73    }
74  
75    @Test
76    public void testReadExcel() throws Exception {
77      ExcelSystem es = new ExcelSystem();
78      es.connect();
79      File testFile = new File(testModernFileName);
80      es.moveTo(testFile.toURI().toString());
81      debug=true;
82      if (debug)
83        es.forAll(SimpleNode.printDebug);
84      long nodeCount = es.g().V().count().next().longValue();
85      assertEquals(17,nodeCount);
86      List<Map<String, Object>> sheetMapList = es.g().V().has("sheetname").valueMap("sheetname").toList();
87      assertEquals(4,sheetMapList.size()); 
88      assertEquals(12,es.g().V().has("row").count().next().longValue());
89      assertEquals(4,es.g().V().has("row").out("sheet").dedup().count().next().longValue());
90    }
91  
92  }