예제 #1
0
 @Test
 public void testChangeNameOnExistingDataSources() throws Exception {
   sm.register("file", super.getAnyNonSpatialResource());
   DataSource ds = dsf.getDataSourceFromSQL("select * from file;");
   sm.rename(ds.getName(), "sql");
   DataSource ds2 = dsf.getDataSource("sql");
   assertEquals(ds.getName(), ds2.getName());
 }
예제 #2
0
 @Test
 public void testSQLSources() throws Exception {
   sm.register("testH", super.getAnyNonSpatialResource());
   sm.register("sql", "select * from testH;");
   DataSource ds = dsf.getDataSource("sql");
   assertEquals((ds.getSource().getType() & SourceManager.SQL), SourceManager.SQL);
   assertFalse(ds.isEditable());
 }
예제 #3
0
  @Test
  public void testNameAndID() {
    Map<String, Object> raw = new HashMap<String, Object>();
    raw.put("id", "abcdef");
    raw.put("name", "MyDS");

    DataSource dataSource = new DataSource(raw, mock(ApiClient.class));

    assertEquals(dataSource.getId(), raw.get("id"));
    assertEquals(dataSource.getName(), raw.get("name"));
  }
예제 #4
0
 @Test
 public void toJson() throws Exception {
   List<Student> ls = new ArrayList<>(data.StudentRepo().values());
   InputMeta testObj = new InputMeta(ls, data.ProjectRepo());
   String expected = testObj.getHottestProject();
   String allRaw = testObj.toJson();
   assertTrue(allRaw.contains("hottestProject"));
   String head = "\"hottestProject\": \"";
   int strBegin = allRaw.indexOf(head) + head.length();
   int strEnd = strBegin + expected.length();
   String got = allRaw.substring(strBegin, strEnd);
   assertTrue(expected.equals(got));
 }
예제 #5
0
  @Test
  public void testRemoveDataSources() throws Exception {
    sm.register("temp", super.getAnyNonSpatialResource());

    DataSource d = dsf.getDataSource("temp");
    sm.remove(d.getName());

    try {
      dsf.getDataSource("temp");
      fail();
    } catch (NoSuchTableException e) {
    }
  }
예제 #6
0
  @Test
  public void testRemoveCallsAPIEndpoint() {
    ServerBridge bridge = mock(ServerBridge.class);
    when(bridge.delete("datasources/a")).thenReturn("");

    ApiClient api = new ApiClient("abc");
    api.setServerBridge(bridge);

    Map<String, Object> raw = new HashMap<String, Object>();
    raw.put("id", "a");
    raw.put("name", "MyDS");

    DataSource dataSource = new DataSource(raw, api);
    dataSource.remove();

    verify(bridge).delete("datasources/a");
  }
예제 #7
0
  @Test
  public void testGetVariablesEmptyList() {
    ServerBridge bridge = mock(ServerBridge.class);
    when(bridge.get("datasources/a/variables")).thenReturn("[]");

    ApiClient api = new ApiClient("abc");
    api.setServerBridge(bridge);

    Map<String, Object> raw = new HashMap<String, Object>();
    raw.put("id", "a");
    raw.put("name", "MyDS");

    DataSource dataSource = new DataSource(raw, api);
    Variable[] variables = dataSource.getVariables();

    verify(bridge).get("datasources/a/variables");
    assertEquals(0, variables.length);
  }
예제 #8
0
  @Test
  public void testGetVariablesThreeVariables() {
    ServerBridge bridge = mock(ServerBridge.class);
    when(bridge.get("datasources/a/variables"))
        .thenReturn(
            "["
                + "{'id': 'a', 'name': 'A', 'unit': 'unitA', 'icon': 'iconA'},"
                + "{'id': 'b', 'name': 'B', 'unit': 'unitB', 'icon': 'iconB'},"
                + "{'id': 'c', 'name': 'C', 'unit': 'unitC', 'icon': 'iconC'}"
                + "]");

    ApiClient api = new ApiClient("abc");
    api.setServerBridge(bridge);

    Map<String, Object> raw = new HashMap<String, Object>();
    raw.put("id", "a");
    raw.put("name", "MyDS");

    DataSource dataSource = new DataSource(raw, api);
    Variable[] variables = dataSource.getVariables();

    verify(bridge).get("datasources/a/variables");
    assertEquals(3, variables.length);

    // Check IDs
    assertEquals("a", variables[0].getId());
    assertEquals("b", variables[1].getId());
    assertEquals("c", variables[2].getId());

    // Check names
    assertEquals("A", variables[0].getName());
    assertEquals("B", variables[1].getName());
    assertEquals("C", variables[2].getName());

    // Check units
    assertEquals("unitA", variables[0].getUnit());
    assertEquals("unitB", variables[1].getUnit());
    assertEquals("unitC", variables[2].getUnit());

    // Check icons
    assertEquals("iconA", variables[0].getIcon());
    assertEquals("iconB", variables[1].getIcon());
    assertEquals("iconC", variables[2].getIcon());
  }
예제 #9
0
 @Test
 public void testSecondNameWorksWithIndexes() throws Exception {
   String dsName = "test8";
   sm.register(dsName, super.getAnySpatialResource());
   String secondName = "secondName";
   DataSource ds = dsf.getDataSource(dsName);
   ds.open();
   String spatialFieldName =
       ds.getMetadata().getFieldName(MetadataUtilities.getSpatialFieldIndex(ds.getMetadata()));
   ds.close();
   sm.addName(dsName, secondName);
   dsf.getIndexManager()
       .buildIndex(dsName, spatialFieldName, IndexManager.RTREE_SPATIAL_INDEX, null);
   SpatialIndexQuery query =
       new DefaultSpatialIndexQuery(spatialFieldName, new Envelope(0, 0, 0, 0));
   assertNotNull(dsf.getIndexManager().getIndex(dsName, spatialFieldName));
   assertNotNull(dsf.getIndexManager().getIndexedFieldNames(dsName));
   assertNotNull(dsf.getIndexManager().queryIndex(dsName, query));
   assertNotNull(dsf.getIndexManager().getIndex(secondName, spatialFieldName));
   assertNotNull(dsf.getIndexManager().getIndexedFieldNames(secondName));
   assertNotNull(dsf.getIndexManager().queryIndex(secondName, query));
 }
예제 #10
0
 private void checkNames(String dsName, String secondName)
     throws DriverLoadException, NoSuchTableException, DataSourceCreationException,
         DriverException, AlreadyClosedException {
   assertEquals(sm.getSource(dsName), sm.getSource(secondName));
   DataSource ds1 = dsf.getDataSource(dsName);
   DataSource ds2 = dsf.getDataSource(secondName);
   ds1.open();
   Value[][] ds1c = getDataSourceContents(ds1);
   ds1.close();
   ds2.open();
   Value[][] ds2c = getDataSourceContents(ds2);
   ds2.close();
   assertTrue(equals(ds1c, ds2c));
 }
예제 #11
0
 @Test
 public void testOperationDataSourceName() throws Throwable {
   sm.register("temp", super.getAnyNonSpatialResource());
   DataSource d = dsf.getDataSourceFromSQL("select * from temp;");
   assertNotNull(dsf.getDataSource(d.getName()));
 }
 @Test
 public void testAllGeters() throws Exception {
   AllTypesObjectDriver testD = new AllTypesObjectDriver();
   DataSet test = testD.getTable("main");
   DataSource d = dsf.getDataSource("alltypes");
   d.open();
   assertTrue(
       ValueFactory.createValue(d.getBinary(0, 0))
           .equals(test.getFieldValue(0, 0))
           .getAsBoolean());
   assertTrue(
       ValueFactory.createValue(d.getBinary(0, "binary"))
           .equals(test.getFieldValue(0, 0))
           .getAsBoolean());
   assertTrue(
       ValueFactory.createValue(d.getBoolean(0, 1))
           .equals(test.getFieldValue(0, 1))
           .getAsBoolean());
   assertTrue(
       ValueFactory.createValue(d.getBoolean(0, "boolean"))
           .equals(test.getFieldValue(0, 1))
           .getAsBoolean());
   assertTrue(
       ValueFactory.createValue(d.getByte(0, 2)).equals(test.getFieldValue(0, 2)).getAsBoolean());
   assertTrue(
       ValueFactory.createValue(d.getByte(0, "byte"))
           .equals(test.getFieldValue(0, 2))
           .getAsBoolean());
   assertTrue(
       ValueFactory.createValue(d.getDate(0, 3)).equals(test.getFieldValue(0, 3)).getAsBoolean());
   assertTrue(
       ValueFactory.createValue(d.getDate(0, "date"))
           .equals(test.getFieldValue(0, 3))
           .getAsBoolean());
   assertTrue(
       ValueFactory.createValue(d.getDouble(0, 4))
           .equals(test.getFieldValue(0, 4))
           .getAsBoolean());
   assertTrue(
       ValueFactory.createValue(d.getDouble(0, "double"))
           .equals(test.getFieldValue(0, 4))
           .getAsBoolean());
   assertTrue(
       ValueFactory.createValue(d.getFloat(0, 5)).equals(test.getFieldValue(0, 5)).getAsBoolean());
   assertTrue(
       ValueFactory.createValue(d.getFloat(0, "float"))
           .equals(test.getFieldValue(0, 5))
           .getAsBoolean());
   assertTrue(
       ValueFactory.createValue(d.getInt(0, 6)).equals(test.getFieldValue(0, 6)).getAsBoolean());
   assertTrue(
       ValueFactory.createValue(d.getInt(0, "int"))
           .equals(test.getFieldValue(0, 6))
           .getAsBoolean());
   assertTrue(
       ValueFactory.createValue(d.getLong(0, 7)).equals(test.getFieldValue(0, 7)).getAsBoolean());
   assertTrue(
       ValueFactory.createValue(d.getLong(0, "long"))
           .equals(test.getFieldValue(0, 7))
           .getAsBoolean());
   assertTrue(
       ValueFactory.createValue(d.getShort(0, 8)).equals(test.getFieldValue(0, 8)).getAsBoolean());
   assertTrue(
       ValueFactory.createValue(d.getShort(0, "short"))
           .equals(test.getFieldValue(0, 8))
           .getAsBoolean());
   assertTrue(
       ValueFactory.createValue(d.getString(0, 9))
           .equals(test.getFieldValue(0, 9))
           .getAsBoolean());
   assertTrue(
       ValueFactory.createValue(d.getString(0, "string"))
           .equals(test.getFieldValue(0, 9))
           .getAsBoolean());
   assertTrue(
       ValueFactory.createValue(d.getTimestamp(0, 10))
           .equals(test.getFieldValue(0, 10))
           .getAsBoolean());
   assertTrue(
       ValueFactory.createValue(d.getTimestamp(0, "timestamp"))
           .equals(test.getFieldValue(0, 10))
           .getAsBoolean());
   assertTrue(
       ValueFactory.createValue(d.getTime(0, 11))
           .equals(test.getFieldValue(0, 11))
           .getAsBoolean());
   assertTrue(
       ValueFactory.createValue(d.getTime(0, "time"))
           .equals(test.getFieldValue(0, 11))
           .getAsBoolean());
   d.close();
 }
  @Test
  public void testSetters() throws Exception {
    DataSource d = dsf.getDataSource("alltypes");
    d.open();
    d.setBinary(0, 0, d.getFieldValue(1, 0).getAsBinary());
    d.setBinary(0, "binary", d.getFieldValue(1, 0).getAsBinary());
    d.setBoolean(0, 1, d.getFieldValue(1, 1).getAsBoolean());
    d.setBoolean(0, "boolean", d.getFieldValue(1, 1).getAsBoolean());
    d.setByte(0, 2, d.getFieldValue(1, 2).getAsByte());
    d.setByte(0, "byte", d.getFieldValue(1, 2).getAsByte());
    d.setDate(0, 3, d.getFieldValue(1, 3).getAsDate());
    d.setDate(0, "date", d.getFieldValue(1, 3).getAsDate());
    d.setDouble(0, 4, d.getFieldValue(1, 4).getAsDouble());
    d.setDouble(0, "double", d.getFieldValue(1, 4).getAsDouble());
    d.setFloat(0, 5, d.getFieldValue(1, 5).getAsFloat());
    d.setFloat(0, "float", d.getFieldValue(1, 5).getAsFloat());
    d.setInt(0, 6, d.getFieldValue(1, 6).getAsInt());
    d.setInt(0, "int", d.getFieldValue(1, 6).getAsInt());
    d.setLong(0, 7, d.getFieldValue(1, 7).getAsLong());
    d.setLong(0, "long", d.getFieldValue(1, 7).getAsLong());
    d.setShort(0, 8, d.getFieldValue(1, 8).getAsShort());
    d.setShort(0, "short", d.getFieldValue(1, 8).getAsShort());
    d.setString(0, 9, d.getFieldValue(1, 9).getAsString());
    d.setString(0, "string", d.getFieldValue(1, 9).getAsString());
    d.setTimestamp(0, "timestamp", d.getFieldValue(1, 10).getAsTimestamp());
    d.setTime(0, 11, d.getFieldValue(1, 11).getAsTime());
    d.setTime(0, "time", d.getFieldValue(1, 11).getAsTime());

    for (int i = 0; i < d.getMetadata().getFieldCount(); i++) {
      assertEquals(d.getFieldValue(0, i), d.getFieldValue(1, i));
    }
    d.close();
  }