Exemplo n.º 1
0
  /** Prints the sample collections that will be used in testing (for exporting purposes) */
  @Test(groups = "doc")
  @SuppressWarnings("unchecked")
  public void printSampleCollections() {
    String objective = "Sample Collections";
    System.out.println(String.format("Printing %s...", objective));

    for (DataType dataType : SAMPLE_COLLECTIONS.keySet()) {
      HashMap<DataType, Object> sampleValueMap =
          (HashMap<DataType, Object>) SAMPLE_COLLECTIONS.get(dataType);

      if (dataType.getName() == DataType.Name.MAP) {
        DataType typeArgument = sampleValueMap.keySet().iterator().next();
        HashMap<DataType, Object> sampleMap =
            (HashMap<DataType, Object>) sampleValueMap.get(typeArgument);

        Object mapKey = SAMPLE_DATA.get(typeArgument);
        Object mapValue = sampleMap.get(typeArgument);
        System.out.println(String.format("%1$-30s {%2$s : %3$s}", dataType, mapKey, mapValue));
      } else {
        DataType typeArgument = sampleValueMap.keySet().iterator().next();
        Object sampleValue = sampleValueMap.get(typeArgument);

        System.out.println(String.format("%1$-30s %2$s", dataType, sampleValue));
      }
    }

    System.out.println(String.format("\nEnd of %s\n\n", objective));
  }
Exemplo n.º 2
0
  /** Validate simple statement selects for all primitive data types */
  public void primitiveSelectTest() throws Throwable {
    String execute_string;
    Object value;
    Row row;
    for (DataType dataType : PRIMITIVE_SELECT_STATEMENTS.keySet()) {
      execute_string = PRIMITIVE_SELECT_STATEMENTS.get(dataType);
      row = session.execute(execute_string).one();

      value = SAMPLE_DATA.get(dataType);
      assertEquals(TestUtils.getValue(row, "k", dataType), value);
      assertEquals(TestUtils.getValue(row, "v", dataType), value);
    }
    assertEquals(SAMPLE_DATA.size(), 15);
    assertEquals(PRIMITIVE_SELECT_STATEMENTS.keySet().size(), SAMPLE_DATA.size());
  }
Exemplo n.º 3
0
  /** Generates the select statements that will be used in testing */
  private static HashMap<DataType, String> getPrimitiveSelectStatements() {
    HashMap<DataType, String> selectStatements = new HashMap<DataType, String>();

    for (DataType dataType : SAMPLE_DATA.keySet()) {
      selectStatements.put(dataType, String.format(BASIC_SELECT_FORMAT, dataType));
    }

    return selectStatements;
  }
Exemplo n.º 4
0
  /** Generates the insert statements that will be used in testing */
  private static Collection<String> getPrimitiveInsertStatements() {
    ArrayList<String> insertStatements = new ArrayList<String>();

    for (DataType dataType : SAMPLE_DATA.keySet()) {
      String value = helperStringifiedData(dataType);
      insertStatements.add(String.format(PRIMITIVE_INSERT_FORMAT, dataType, value));
    }

    return insertStatements;
  }
Exemplo n.º 5
0
  /** Generates the insert statements that will be used in testing */
  @SuppressWarnings("unchecked")
  private static Collection<String> getCollectionInsertStatements() {
    ArrayList<String> insertStatements = new ArrayList<String>();

    String tableName;
    String key;
    String value;
    for (DataType dataType : SAMPLE_COLLECTIONS.keySet()) {
      HashMap<DataType, Object> sampleValueMap =
          (HashMap<DataType, Object>) SAMPLE_COLLECTIONS.get(dataType);

      // Create tableName in form of: DataType_TypeArgument[_TypeArgument]
      tableName = helperGenerateTableName(dataType);

      if (dataType.getName() == DataType.Name.MAP) {
        List<DataType> typeArgument = dataType.getTypeArguments();

        key = helperStringifiedData(typeArgument.get(0));
        value = helperStringifiedData(typeArgument.get(1));

        insertStatements.add(String.format(MAP_INSERT_FORMAT, tableName, key, value));
      } else if (dataType.getName() == DataType.Name.LIST) {
        DataType typeArgument = sampleValueMap.keySet().iterator().next();
        key = helperStringifiedData(typeArgument);

        // Create the value to be a list of the same 5 elements
        value = "[";
        for (int i = 0; i < 5; i++) value += key + ',';
        value = value.substring(0, value.length() - 1) + ']';

        insertStatements.add(String.format(COLLECTION_INSERT_FORMAT, tableName, key, value));
      } else {
        DataType typeArgument = sampleValueMap.keySet().iterator().next();
        key = helperStringifiedData(typeArgument);
        value = '{' + key + '}';

        insertStatements.add(String.format(COLLECTION_INSERT_FORMAT, tableName, key, value));
      }
    }

    return insertStatements;
  }
Exemplo n.º 6
0
  /** Generates the select statements that will be used in testing */
  private static HashMap<DataType, String> getCollectionSelectStatements() {
    HashMap<DataType, String> selectStatements = new HashMap<DataType, String>();

    String tableName;
    for (DataType dataType : SAMPLE_COLLECTIONS.keySet()) {
      tableName = helperGenerateTableName(dataType);
      selectStatements.put(dataType, String.format(BASIC_SELECT_FORMAT, tableName));
    }

    return selectStatements;
  }
Exemplo n.º 7
0
  /** Prints the sample data that will be used in testing (for exporting purposes) */
  @Test(groups = "doc")
  public void printSampleData() {
    String objective = "Sample Data";
    System.out.println(String.format("Printing %s...", objective));

    for (DataType dataType : SAMPLE_DATA.keySet()) {
      Object sampleValue = SAMPLE_DATA.get(dataType);
      System.out.println(String.format("%1$-10s %2$s", dataType, sampleValue));
    }

    System.out.println(String.format("\nEnd of %s\n\n", objective));
  }
Exemplo n.º 8
0
  /** Test simple statement selects for all collection data types */
  @SuppressWarnings("unchecked")
  public void collectionSelectTest() throws Throwable {
    HashMap<DataType, Object> sampleValueMap;
    String execute_string;
    DataType typeArgument1;
    DataType typeArgument2;
    Row row;
    for (DataType dataType : COLLECTION_SELECT_STATEMENTS.keySet()) {
      execute_string = COLLECTION_SELECT_STATEMENTS.get(dataType);
      row = session.execute(execute_string).one();

      sampleValueMap = (HashMap<DataType, Object>) SAMPLE_COLLECTIONS.get(dataType);
      typeArgument1 = dataType.getTypeArguments().get(0);
      if (dataType.getName() == DataType.Name.MAP) {
        typeArgument2 = dataType.getTypeArguments().get(1);

        // Create a copy of the map that is being expected
        HashMap<DataType, Object> sampleMap =
            (HashMap<DataType, Object>) sampleValueMap.get(typeArgument1);
        Object mapKey = SAMPLE_DATA.get(sampleMap.keySet().iterator().next());
        Object mapValue = sampleMap.values().iterator().next();
        HashMap<Object, Object> expectedMap = new HashMap<Object, Object>();
        expectedMap.put(mapKey, mapValue);

        assertEquals(TestUtils.getValue(row, "k", typeArgument2), SAMPLE_DATA.get(typeArgument2));
        assertEquals(TestUtils.getValue(row, "v", dataType), expectedMap);
      } else {
        Object expectedValue = sampleValueMap.get(typeArgument1);

        assertEquals(TestUtils.getValue(row, "k", typeArgument1), SAMPLE_DATA.get(typeArgument1));
        assertEquals(TestUtils.getValue(row, "v", dataType), expectedValue);
      }
    }
    assertEquals(SAMPLE_COLLECTIONS.size(), 255);
    assertEquals(COLLECTION_SELECT_STATEMENTS.keySet().size(), SAMPLE_COLLECTIONS.size());
  }