Package org.cassandraunit.dataset

Examples of org.cassandraunit.dataset.DataSet


        return mockDataSet;
    }

    public static DataSet getMockDataSetWithReversedComparatorOnSimpleType() {
        DataSet mockDataSet = mock(DataSet.class);
        KeyspaceModel keyspace = new KeyspaceModel();
        keyspace.setName("reversedKeyspace");
        keyspace.getColumnFamilies();

    /* column family */
        ColumnFamilyModel columnFamily = new ColumnFamilyModel();
        columnFamily.setName("columnFamilyWithReversedComparatorOnSimpleType");
        columnFamily.setKeyType(ComparatorType.UTF8TYPE);
        columnFamily.setComparatorType(ComparatorType.UTF8TYPE);
        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);
        when(mockDataSet.getColumnFamilies()).thenReturn(keyspace.getColumnFamilies());

        return mockDataSet;
    }
View Full Code Here


    }

    @Test(expected = ParseException.class)
    public void shouldNotGetCounterColumnFamilyBecauseThereIsFunctionOverridingDefaultValueType() {
        DataSet dataSet = new ClassPathXmlDataSet("xml/dataSetBadCounterColumnFamilyWithFunction.xml");
        dataSet.getKeyspace();
    }
View Full Code Here

        assertThat(actualColumn.getValue().getType(), is(GenericTypeEnum.BYTES_TYPE));
    }

    @Test
    public void shouldGetAJsonDataSetWithDefinedValuesAndData() {
        DataSet dataSet = new ClassPathJsonDataSet("json/dataSetDefinedValues.json");
        assertThat(dataSet, notNullValue());

        KeyspaceModel actualKeyspace = dataSet.getKeyspace();
        assertThat(actualKeyspace, notNullValue());
        assertThat(actualKeyspace.getName(), is("beautifulDefinedKeyspaceName"));
        assertThat(actualKeyspace.getReplicationFactor(), is(1));
        assertThat(actualKeyspace.getStrategy(), is(StrategyModel.SIMPLE_STRATEGY));

        assertThat(dataSet.getColumnFamilies(), notNullValue());
        assertThat(dataSet.getColumnFamilies().size(), is(4));

        ColumnFamilyModel actualColumnFamily1 = dataSet.getColumnFamilies().get(0);
        assertThat(actualColumnFamily1, notNullValue());
        assertThat(actualColumnFamily1.getName(), is("columnFamily1"));
        assertThat(actualColumnFamily1.getKeyType().getTypeName(), is(ComparatorType.UTF8TYPE.getTypeName()));
        assertThat(actualColumnFamily1.getComparatorType().getTypeName(), is(ComparatorType.UTF8TYPE.getTypeName()));
        assertThat(actualColumnFamily1.getSubComparatorType(), is(nullValue()));
        assertThat(actualColumnFamily1.getComment(), is("amazing comment"));
        assertThat(actualColumnFamily1.getCompactionStrategy(), is("LeveledCompactionStrategy"));
        assertThat(actualColumnFamily1.getCompactionStrategyOptions().get(0).getName(), is("sstable_size_in_mb"));
        assertThat(actualColumnFamily1.getCompactionStrategyOptions().get(0).getValue(), is("10"));
        assertThat(actualColumnFamily1.getGcGraceSeconds(), is(9999));
        assertThat(actualColumnFamily1.getMaxCompactionThreshold(), is(31));
        assertThat(actualColumnFamily1.getMinCompactionThreshold(), is(3));
        assertThat(actualColumnFamily1.getReadRepairChance(), is(0.1d));
        assertThat(actualColumnFamily1.getReplicationOnWrite(), is(Boolean.FALSE));

        List<RowModel> actualRows1 = actualColumnFamily1.getRows();
        assertThat(actualRows1, notNullValue());
        assertThat(actualRows1.size(), is(1));

        RowModel actualRow11 = actualRows1.get(0);
        assertThat(actualRow11, notNullValue());
        assertThat(actualRow11.getKey().getValue(), is("key01"));
        assertThat(actualRow11.getKey().getType(), is(GenericTypeEnum.UTF_8_TYPE));

        List<ColumnModel> actualColumns11 = actualRow11.getColumns();
        assertThat(actualColumns11, notNullValue());
        assertThat(actualColumns11.size(), is(1));

        ColumnModel actualColumn111 = actualColumns11.get(0);
        assertThat(actualColumn111, notNullValue());
        assertThat(actualColumn111.getName().getValue(), is("columnName1"));
        assertThat(actualColumn111.getName().getType(), is(GenericTypeEnum.UTF_8_TYPE));
        assertThat(actualColumn111.getValue().getValue(), is("columnValue1"));
        assertThat(actualColumn111.getValue().getType(), is(GenericTypeEnum.UTF_8_TYPE));

        ColumnFamilyModel actualColumnFamily2 = dataSet.getColumnFamilies().get(1);
        assertThat(actualColumnFamily2, notNullValue());
        assertThat(actualColumnFamily2.getName(), is("columnFamily2"));
        assertThat(actualColumnFamily2.getKeyType().getTypeName(), is(ComparatorType.UTF8TYPE.getTypeName()));
        assertThat(actualColumnFamily2.getComparatorType().getTypeName(), is(ComparatorType.UTF8TYPE.getTypeName()));
        assertThat(actualColumnFamily2.getSubComparatorType().getTypeName(), is(ComparatorType.UTF8TYPE.getTypeName()));
View Full Code Here

        dataSet.getKeyspace();
    }

    @Test
    public void shouldGetAColumnFamilyWithSecondaryIndex() {
        DataSet dataSet = new ClassPathXmlDataSet("xml/dataSetWithSecondaryIndex.xml");
        ColumnMetadataModel acutalColumnMetadataModel = dataSet.getColumnFamilies().get(0).getColumnsMetadata().get(0);
        assertThat(acutalColumnMetadataModel.getColumnName().getValue(), is("columnWithIndexAndUTF8ValidationClass"));
        assertThat(acutalColumnMetadataModel.getColumnIndexType(), is(ColumnIndexType.KEYS));
        assertThat(acutalColumnMetadataModel.getValidationClass(), is(ComparatorType.UTF8TYPE));

        ColumnMetadataModel actualColumnMetadataModel1 = dataSet.getColumnFamilies().get(0).getColumnsMetadata().get(1);
        assertThat(actualColumnMetadataModel1.getColumnName().getValue(), is("columnWithIndexAndIndexNameAndUTF8ValidationClass"));
        assertThat(actualColumnMetadataModel1.getColumnIndexType(), is(ColumnIndexType.KEYS));
        assertThat(actualColumnMetadataModel1.getValidationClass(), is(ComparatorType.UTF8TYPE));
        assertThat(actualColumnMetadataModel1.getIndexName(), is("indexNameOfTheIndex"));

        ColumnMetadataModel actualColumnMetadataModel2 = dataSet.getColumnFamilies().get(0).getColumnsMetadata().get(2);
        assertThat(actualColumnMetadataModel2.getColumnName().getValue(), is("columnWithUTF8ValidationClass"));
        assertThat(actualColumnMetadataModel2.getColumnIndexType(), nullValue());
        assertThat(actualColumnMetadataModel2.getValidationClass(), is(ComparatorType.UTF8TYPE));
    }
View Full Code Here

        return mockDataSet;
    }

    public static DataSet getMockDataSetWithReversedComparatorOnCompositeTypes() {
        DataSet mockDataSet = mock(DataSet.class);
        KeyspaceModel keyspace = new KeyspaceModel();
        keyspace.setName("reversedKeyspace");
        keyspace.getColumnFamilies();

    /* column family */
        ColumnFamilyModel columnFamily = new ColumnFamilyModel();
        columnFamily.setName("columnFamilyWithReversedCompOnCompositeTypes");
        columnFamily.setKeyType(ComparatorType.UTF8TYPE);
        columnFamily.setComparatorType(ComparatorType.COMPOSITETYPE);
        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);
        when(mockDataSet.getColumnFamilies()).thenReturn(keyspace.getColumnFamilies());

        return mockDataSet;
    }
View Full Code Here

        assertThat(actualColumnMetadataModel2.getValidationClass(), is(ComparatorType.UTF8TYPE));
    }

    @Test
    public void shouldGetAColumnFamilyWithCompositeType() throws Exception {
        DataSet dataSet = new ClassPathXmlDataSet("xml/dataSetWithCompositeType.xml");
        assertThatKeyspaceModelWithCompositeTypeIsOk(dataSet);
    }
View Full Code Here

        assertThat(actualColumn2111.getValue().getType(), is(GenericTypeEnum.LONG_TYPE));
    }

    @Test
    public void shouldGetAStandardCounterColumnFamily() {
        DataSet dataSet = new ClassPathJsonDataSet("json/dataSetDefinedValues.json");
        List<RowModel> actualRows = dataSet.getColumnFamilies().get(2).getRows();
        assertThat(actualRows, notNullValue());
        assertThat(actualRows.size(), is(1));

        RowModel actualRow1 = actualRows.get(0);
        assertThat(actualRow1, notNullValue());
View Full Code Here

        return mockDataSet;
    }

    public static DataSet getMockDataSetWithBinaryData() {
        DataSet mockDataSet = mock(DataSet.class);
        KeyspaceModel keyspace = new KeyspaceModel();
        keyspace.setName("binaryKeyspace");
        keyspace.getColumnFamilies();

        /* column family */
        ColumnFamilyModel columnFamily = new ColumnFamilyModel();
        columnFamily.setName("columnFamilyWithBinaryData");
        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);

        when(mockDataSet.getKeyspace()).thenReturn(keyspace);
        when(mockDataSet.getColumnFamilies()).thenReturn(keyspace.getColumnFamilies());

        return mockDataSet;
    }
View Full Code Here



    @Test(expected = ParseException.class)
    public void shouldNotGetAColumnFamilyWithCompositeType() throws Exception {
        DataSet dataSet = new ClassPathXmlDataSet("xml/dataSetWithBadCompositeType.xml");
        dataSet.getKeyspace();
    }
View Full Code Here

        assertThat(actualColumn11.getValue().getType(), is(GenericTypeEnum.COUNTER_TYPE));
    }

    @Test
    public void shouldGetASuperCounterColumnFamily() {
        DataSet dataSet = new ClassPathJsonDataSet("json/dataSetDefinedValues.json");
        assertThat(dataSet.getColumnFamilies().get(3), notNullValue());
        assertThat(dataSet.getColumnFamilies().get(3).getName(), is("superCounterColumnFamily"));

        List<RowModel> actualRows = dataSet.getColumnFamilies().get(3).getRows();
        assertThat(actualRows, notNullValue());
        assertThat(actualRows.size(), is(1));

        RowModel actualRow = actualRows.get(0);
        assertThat(actualRow, notNullValue());
View Full Code Here

TOP

Related Classes of org.cassandraunit.dataset.DataSet

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.