Package org.cassandraunit.type

Examples of org.cassandraunit.type.GenericType


        columnFamily.setKeyType(ComparatorType.UTF8TYPE);
        columnFamily.setDefaultColumnValueType(ComparatorType.UTF8TYPE);

        /* row1 */
        RowModel row = new RowModel();
        row.setKey(new GenericType("rowWithTimestampedColumn", GenericTypeEnum.UTF_8_TYPE));

        /* column1 */
        ColumnModel column1 = new ColumnModel();
        column1.setName(new GenericType("columnWithTimestamp",GenericTypeEnum.UTF_8_TYPE));
        column1.setTimestamp(new Long(2020L));
        row.getColumns().add(column1);

        columnFamily.getRows().add(row);
        keyspace.getColumnFamilies().add(columnFamily);
View Full Code Here


        columnFamily.setComparatorTypeAlias("(reversed=true)");
        columnFamily.setDefaultColumnValueType(ComparatorType.BYTESTYPE);

    /* row1 */
        RowModel row1 = new RowModel();
        row1.setKey(new GenericType("row1", GenericTypeEnum.UTF_8_TYPE));

    /* column1 */
        ColumnModel column1 = new ColumnModel();
        column1.setName(new GenericType("c", GenericTypeEnum.UTF_8_TYPE));
        column1.setValue(new GenericType("c", GenericTypeEnum.UTF_8_TYPE));
        row1.getColumns().add(column1);

    /* column2 */
        ColumnModel column2 = new ColumnModel();
        column2.setName(new GenericType("b", GenericTypeEnum.UTF_8_TYPE));
        column2.setValue(new GenericType("b", GenericTypeEnum.UTF_8_TYPE));
        row1.getColumns().add(column2);

    /* column3 */
        ColumnModel column3 = new ColumnModel();
        column3.setName(new GenericType("a", GenericTypeEnum.UTF_8_TYPE));
        column3.setValue(new GenericType("a", GenericTypeEnum.UTF_8_TYPE));
        row1.getColumns().add(column3);

        columnFamily.getRows().add(row1);
        keyspace.getColumnFamilies().add(columnFamily);
        when(mockDataSet.getKeyspace()).thenReturn(keyspace);
View Full Code Here

        columnFamily.setComparatorTypeAlias("(LongType(reversed=true),UTF8Type,IntegerType(reversed=true))");
        columnFamily.setDefaultColumnValueType(ComparatorType.BYTESTYPE);

    /* row1 */
        RowModel row1 = new RowModel();
        row1.setKey(new GenericType("row1", GenericTypeEnum.UTF_8_TYPE));

        GenericTypeEnum[] columnNameTypes = {GenericTypeEnum.LONG_TYPE, GenericTypeEnum.UTF_8_TYPE, GenericTypeEnum.INTEGER_TYPE};

    /* column1 */
        ColumnModel column1 = new ColumnModel();
        column1.setName(new GenericType(new String[] { "12", "aa", "11" }, columnNameTypes));
        column1.setValue(new GenericType("v6", GenericTypeEnum.UTF_8_TYPE));
        row1.getColumns().add(column1);

    /* column2 */
        ColumnModel column2 = new ColumnModel();
        column2.setName(new GenericType(new String[] { "12", "ab", "12" }, columnNameTypes));
        column2.setValue(new GenericType("v5", GenericTypeEnum.UTF_8_TYPE));
        row1.getColumns().add(column2);

    /* column3 */
        ColumnModel column3 = new ColumnModel();
        column3.setName(new GenericType(new String[] { "12", "ab", "11" }, columnNameTypes));
        column3.setValue(new GenericType("v4", GenericTypeEnum.UTF_8_TYPE));
        row1.getColumns().add(column3);

    /* column4 */
        ColumnModel column4 = new ColumnModel();
        column4.setName(new GenericType(new String[] { "11", "aa", "11" }, columnNameTypes));
        column4.setValue(new GenericType("v3", GenericTypeEnum.UTF_8_TYPE));
        row1.getColumns().add(column4);

    /* column5 */
        ColumnModel column5 = new ColumnModel();
        column5.setName(new GenericType(new String[] { "11", "ab", "12" }, columnNameTypes));
        column5.setValue(new GenericType("v2", GenericTypeEnum.UTF_8_TYPE));
        row1.getColumns().add(column5);

    /* column6 */
        ColumnModel column6 = new ColumnModel();
        column6.setName(new GenericType(new String[] { "11", "ab", "11" }, columnNameTypes));
        column6.setValue(new GenericType("v1", GenericTypeEnum.UTF_8_TYPE));
        row1.getColumns().add(column6);

        columnFamily.getRows().add(row1);
        keyspace.getColumnFamilies().add(columnFamily);
        when(mockDataSet.getKeyspace()).thenReturn(keyspace);
View Full Code Here

        columnFamily.setKeyType(ComparatorType.UTF8TYPE);
        columnFamily.setDefaultColumnValueType(ComparatorType.BYTESTYPE);

        /* row1 */
        RowModel row = new RowModel();
        row.setKey(new GenericType("row1", GenericTypeEnum.UTF_8_TYPE));

        /* column1 */
        ColumnModel column1 = new ColumnModel();
        column1.setName(new GenericType("a", GenericTypeEnum.UTF_8_TYPE));
        column1.setValue(new GenericType("aGVsbG8gd29ybGQh", GenericTypeEnum.BYTES_TYPE));
        row.getColumns().add(column1);

        /* column2 */
        ColumnModel column2 = new ColumnModel();
        column2.setName(new GenericType("b", GenericTypeEnum.UTF_8_TYPE));
        String value2 = "V2VsY29tZSB0byBBcGFjaGUgQ2Fzc2FuZHJhDQoNClRoZSBBcGFjaGUgQ2Fzc2FuZHJhIGRhdGFiYXNlIGlzIHRoZSByaWdodCBjaG9pY2Ugd2hlbiB5b3UgbmVlZCBzY2FsYWJpbGl0eSBhbmQgaGln" +
                "aCBhdmFpbGFiaWxpdHkgd2l0aG91dCBjb21wcm9taXNpbmcgcGVyZm9ybWFuY2UuIExpbmVhciBzY2FsYWJpbGl0eSBhbmQgcHJvdmVuIGZhdWx0LXRvbGVyYW5jZSBvbiBjb21tb2RpdHkgaGFyZHdh" +
                "cmUgb3IgY2xvdWQgaW5mcmFzdHJ1Y3R1cmUgbWFrZSBpdCB0aGUgcGVyZmVjdCBwbGF0Zm9ybSBmb3IgbWlzc2lvbi1jcml0aWNhbCBkYXRhLiBDYXNzYW5kcmEncyBzdXBwb3J0IGZvciByZXBsaWNh" +
                "dGluZyBhY3Jvc3MgbXVsdGlwbGUgZGF0YWNlbnRlcnMgaXMgYmVzdC1pbi1jbGFzcywgcHJvdmlkaW5nIGxvd2VyIGxhdGVuY3kgZm9yIHlvdXIgdXNlcnMgYW5kIHRoZSBwZWFjZSBvZiBtaW5kIG9m" +
                "IGtub3dpbmcgdGhhdCB5b3UgY2FuIHN1cnZpdmUgcmVnaW9uYWwgb3V0YWdlcy4=";
        column2.setValue(new GenericType(value2, GenericTypeEnum.BYTES_TYPE));
        row.getColumns().add(column2);

        columnFamily.getRows().add(row);
        keyspace.getColumnFamilies().add(columnFamily);

View Full Code Here

    verifyExtration("uuid(13816710-1dd2-11b2-879a-782bcb80ff6a)", "13816710-1dd2-11b2-879a-782bcb80ff6a",
        GenericTypeEnum.UUID_TYPE);
  }

  private void verifyExtration(String valueToExtract, String extractedValueToHave, GenericTypeEnum typeToHave) {
    GenericType extractedValue = TypeExtractor.extract(valueToExtract, null);
    assertThat(extractedValue, is(notNullValue()));
    assertThat(extractedValue.getType(), is(typeToHave));
    assertThat(extractedValue.getValue(), is(extractedValueToHave));
  }
View Full Code Here

  @Test
  public void shouldExtractDefaultUTF8Type() {
    ComparatorType defaultValueType = ComparatorType.UTF8TYPE;
    String valueToExtract = "myutf8value";
    GenericType extractedValue = TypeExtractor.extract(valueToExtract, defaultValueType);
    assertThat(extractedValue, is(notNullValue()));
    assertThat(extractedValue.getType(), is(GenericTypeEnum.UTF_8_TYPE));
    assertThat(extractedValue.getValue(), is("myutf8value"));
  }
View Full Code Here

  @Test
  public void shouldExtractDefaultLongType() {
    ComparatorType defaultValueType = ComparatorType.LONGTYPE;
    String valueToExtract = "12";
    GenericType extractedValue = TypeExtractor.extract(valueToExtract, defaultValueType);
    assertThat(extractedValue, is(notNullValue()));
    assertThat(extractedValue.getType(), is(GenericTypeEnum.LONG_TYPE));
    assertThat(extractedValue.getValue(), is("12"));
  }
View Full Code Here

     */
    private SuperColumnModel mapXmlSuperColumnToSuperColumnModel(List<ColumnMetadata> columnMetaData, SuperColumn xmlSuperColumn,
                                                                 ComparatorType comparatorType, ComparatorType subComparatorType, ComparatorType defaultColumnValueType) {
        SuperColumnModel superColumnModel = new SuperColumnModel();

        superColumnModel.setName(new GenericType(xmlSuperColumn.getName(), GenericTypeEnum.fromValue(comparatorType
                .getTypeName())));

        superColumnModel.setColumns(mapXmlColumnsToColumnsModel(columnMetaData, xmlSuperColumn.getColumn(), subComparatorType, null,
                defaultColumnValueType));
        return superColumnModel;
View Full Code Here

    private ColumnModel mapXmlColumnToColumnModel(ColumnMetadata metaData, Column xmlColumn, ComparatorType comparatorType,
                                                  GenericTypeEnum[] typesBelongingCompositeTypeForComparatorType, ComparatorType defaultColumnValueType) {
        ColumnModel columnModel = new ColumnModel();

        if (comparatorType == null) {
            columnModel.setName(new GenericType(xmlColumn.getName(), GenericTypeEnum.BYTES_TYPE));
        } else if (ComparatorType.COMPOSITETYPE.getTypeName().equals(comparatorType.getTypeName())) {
            /* composite type */
            try {
                columnModel.setName(new GenericType(StringUtils.split(xmlColumn.getName(), ":"),
                        typesBelongingCompositeTypeForComparatorType));
            } catch (IllegalArgumentException e) {
                throw new ParseException(xmlColumn.getName()
                        + " doesn't fit with the schema declaration of your composite type");
            }
        } else {
            /* simple type */
            columnModel.setName(new GenericType(xmlColumn.getName(), GenericTypeEnum.fromValue(comparatorType
                    .getTypeName())));
        }

        if (defaultColumnValueType != null
                && ComparatorType.COUNTERTYPE.getClassName().equals(defaultColumnValueType.getClassName())
                && TypeExtractor.containFunctions(xmlColumn.getValue())) {
            throw new ParseException("Impossible to override Column value into a Counter column family");
        }

        GenericType columnValue = null;
        if (xmlColumn.getValue() != null) {
            if (metaData != null && !TypeExtractor.containFunctions(xmlColumn.getValue())) {
                GenericTypeEnum genTypeEnum = GenericTypeEnum.valueOf(metaData.getValidationClass().name());
                columnValue = new GenericType(xmlColumn.getValue(), genTypeEnum);
            } else {
                columnValue = TypeExtractor.extract(xmlColumn.getValue(), defaultColumnValueType);
            }
        }
        columnModel.setValue(columnValue);
View Full Code Here

    private static String[] availableTypeFunctionArray = new String[]{"bytes(", "integer(", "lexicaluuid(", "long(",
            "utf8(", "timeuuid(", "uuid(", "ascii(", "boolean(", "date(", "double(", "float(", "countercolumn("};

    public static GenericType extract(String valueToExtract, ComparatorType defaultValueType) {
        String extractedValue = null;
        GenericType genericType = null;
        if (containFunctions(valueToExtract)) {
            /* there is a type function defined */
            String typeFunction = StringUtils.substringBefore(valueToExtract, startTypeFunction);
            String rightSideWithLastParenthesis = StringUtils.substringAfter(valueToExtract, typeFunction + startTypeFunction);
            extractedValue = StringUtils.removeEnd(rightSideWithLastParenthesis,endTypeFunction);
            genericType = new GenericType(extractedValue, GenericTypeEnum.fromValue(typeFunction + "type"));
        } else {
            /* there is no type function defined */
            extractedValue = valueToExtract;
            if (defaultValueType == null) {
                genericType = new GenericType(extractedValue, GenericTypeEnum.BYTES_TYPE);
            } else {
                genericType = new GenericType(extractedValue, GenericTypeEnum.fromValue(defaultValueType.getTypeName()));
            }
        }
        return genericType;
    }
View Full Code Here

TOP

Related Classes of org.cassandraunit.type.GenericType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.