Package org.cassandraunit.dataset

Examples of org.cassandraunit.dataset.DataSet


    }

    @Test
    public void shouldNotGetAXmlDataSetBecauseItIsInvalid() {
        try {
            DataSet dataSet = new ClassPathXmlDataSet("xml/dataSetInvalidDataSet.xml");
            dataSet.getKeyspace();
            fail();
        } catch (ParseException e) {
            /* nothing to do, it what we want */
            assertThat(e.getMessage(), containsString("org.xml.sax.SAXParseException"));
            assertThat(e.getMessage(), containsString("'columnFamily'"));
View Full Code Here


    }

    @Test
    public void shouldGetKeyspaceWithDefaultValues() {

        DataSet dataSet = new ClassPathXmlDataSet("xml/dataSetDefaultValues.xml");
        assertThat(dataSet.getKeyspace(), notNullValue());
        assertThat(dataSet.getKeyspace().getName(), notNullValue());
        assertThat(dataSet.getKeyspace().getName(), is("beautifulKeyspaceName"));
        assertThat(dataSet.getKeyspace().getReplicationFactor(), is(1));
        assertThat(dataSet.getKeyspace().getStrategy(), is(StrategyModel.SIMPLE_STRATEGY));

    }
View Full Code Here

* @author Marc Carre (#27)
*/
public class MockDataSetHelper {

  public static DataSet getMockDataSetWithDefaultValues() {
    DataSet mockDataSet = mock(DataSet.class);
    KeyspaceModel keyspace = contructDefaultValuesKeyspace();

    when(mockDataSet.getKeyspace()).thenReturn(keyspace);
    when(mockDataSet.getColumnFamilies()).thenReturn(keyspace.getColumnFamilies());
    return mockDataSet;
  }
View Full Code Here

    columnModel.setValue(new GenericType(value, GenericTypeEnum.BYTES_TYPE));
    return columnModel;
  }

  public static DataSet getMockDataSetWithDefinedValues() {
    DataSet mockDataSet = mock(DataSet.class);
    /* keyspace */
    KeyspaceModel keyspace = new KeyspaceModel();
    keyspace.setName("otherKeyspaceName");
    keyspace.setStrategy(StrategyModel.SIMPLE_STRATEGY);
    keyspace.setReplicationFactor(1);
    List<ColumnFamilyModel> columnFamilies = new ArrayList<ColumnFamilyModel>();

    /* column family 1 */
    ColumnFamilyModel beautifulColumnFamily = new ColumnFamilyModel();
    beautifulColumnFamily.setName("beautifulColumnFamilyName");
    beautifulColumnFamily.setType(ColumnType.SUPER);
    beautifulColumnFamily.setKeyType(ComparatorType.TIMEUUIDTYPE);
    beautifulColumnFamily.setComparatorType(ComparatorType.UTF8TYPE);
    beautifulColumnFamily.setSubComparatorType(ComparatorType.LONGTYPE);
    beautifulColumnFamily.setDefaultColumnValueType(ComparatorType.UTF8TYPE);

        beautifulColumnFamily.setComment("amazing comment");
        beautifulColumnFamily.setCompactionStrategy("LeveledCompactionStrategy");
        List<CompactionStrategyOptionModel> compactionStrategyOptions = new ArrayList<CompactionStrategyOptionModel>();
        compactionStrategyOptions.add(new CompactionStrategyOptionModel("sstable_size_in_mb", "10"));
        beautifulColumnFamily.setCompactionStrategyOptions(compactionStrategyOptions);
        beautifulColumnFamily.setGcGraceSeconds(9999);
        beautifulColumnFamily.setMaxCompactionThreshold(31);
        beautifulColumnFamily.setMinCompactionThreshold(3);
        beautifulColumnFamily.setReadRepairChance(0.1d);
        beautifulColumnFamily.setReplicationOnWrite(Boolean.FALSE);


    List<RowModel> rows = new ArrayList<RowModel>();

    /* row1 */
    RowModel row1 = new RowModel();
    row1.setKey(new GenericType("13816710-1dd2-11b2-879a-782bcb80ff6a", GenericTypeEnum.TIME_UUID_TYPE));
    List<SuperColumnModel> superColumns1 = new ArrayList<SuperColumnModel>();
    superColumns1.add(constructDefinedSuperColumnForMock(11));
    superColumns1.add(constructDefinedSuperColumnForMock(12));

    row1.setSuperColumns(superColumns1);
    rows.add(row1);

    /* row2 */
    RowModel row2 = new RowModel();
    row2.setKey(new GenericType("13818e20-1dd2-11b2-879a-782bcb80ff6a", GenericTypeEnum.TIME_UUID_TYPE));
    List<SuperColumnModel> superColumns2 = new ArrayList<SuperColumnModel>();
    superColumns2.add(constructDefinedSuperColumnForMock(21));
    superColumns2.add(constructDefinedSuperColumnForMock(22));
    superColumns2.add(constructDefinedSuperColumnForMock(23));

    row2.setSuperColumns(superColumns2);
    rows.add(row2);

    beautifulColumnFamily.setRows(rows);
    columnFamilies.add(beautifulColumnFamily);

    /* column family 2 */
    ColumnFamilyModel columnFamily2 = new ColumnFamilyModel();
    columnFamily2.setName("amazingColumnFamilyName");
    columnFamily2.setType(ColumnType.STANDARD);
    columnFamily2.setKeyType(ComparatorType.UTF8TYPE);
    columnFamily2.setComparatorType(ComparatorType.UTF8TYPE);
    columnFamily2.setDefaultColumnValueType(ComparatorType.UTF8TYPE);

    columnFamilies.add(columnFamily2);

    /* column family 3 with index */
    ColumnFamilyModel columnFamily3 = new ColumnFamilyModel();
    columnFamily3.setName("columnFamilyWithSecondaryIndex");
    columnFamily3.setType(ColumnType.STANDARD);
    columnFamily3.setKeyType(ComparatorType.UTF8TYPE);
    columnFamily3.setComparatorType(ComparatorType.UTF8TYPE);
    columnFamily3.setDefaultColumnValueType(ComparatorType.UTF8TYPE);
    columnFamily3.addColumnMetadata(new ColumnMetadataModel(
                newUtf8GenericType("columnWithSecondaryIndexAndValidationClassAsLongType"), ComparatorType.LONGTYPE, ColumnIndexType.KEYS, null));
    columnFamilies.add(columnFamily3);

        /* column family 4 with index */
        ColumnFamilyModel columnFamily4 = new ColumnFamilyModel();
        columnFamily4.setName("columnFamilyWithSecondaryIndexAndIndexName");
        columnFamily4.setType(ColumnType.STANDARD);
        columnFamily4.setKeyType(ComparatorType.UTF8TYPE);
        columnFamily4.setComparatorType(ComparatorType.UTF8TYPE);
        columnFamily4.setDefaultColumnValueType(ComparatorType.UTF8TYPE);
        columnFamily4.addColumnMetadata(new ColumnMetadataModel(
                newUtf8GenericType("columnWithSecondaryIndexAndValidationClassAsUTF8Type"), ComparatorType.UTF8TYPE, ColumnIndexType.KEYS,
                "columnWithSecondaryIndexHaveIndexNameAndValidationClassAsUTF8Type"));

        columnFamilies.add(columnFamily4);

        /* column family 5 with column validation class */
        ColumnFamilyModel columnFamily5 = new ColumnFamilyModel();
        columnFamily5.setName("columnFamilyWithColumnValidationClass");
        columnFamily5.setType(ColumnType.STANDARD);
        columnFamily5.setKeyType(ComparatorType.UTF8TYPE);
        columnFamily5.setComparatorType(ComparatorType.UTF8TYPE);
        columnFamily5.setDefaultColumnValueType(ComparatorType.UTF8TYPE);
        columnFamily5.addColumnMetadata(new ColumnMetadataModel(
                newUtf8GenericType("columnWithValidationClassAsUTF8Type"),
                ComparatorType.UTF8TYPE, null, null));

        columnFamilies.add(columnFamily5);

    keyspace.setColumnFamilies(columnFamilies);

    when(mockDataSet.getKeyspace()).thenReturn(keyspace);
    when(mockDataSet.getColumnFamilies()).thenReturn(keyspace.getColumnFamilies());
    return mockDataSet;
  }
View Full Code Here

    }

    @Test
    public void shouldGetKeyspaceWithDefinedValues() {
        DataSet dataSet = new ClassPathXmlDataSet("xml/dataSetDefinedValues.xml");
        assertThat(dataSet.getKeyspace(), notNullValue());
        assertThat(dataSet.getKeyspace().getName(), notNullValue());
        assertThat(dataSet.getKeyspace().getName(), is("otherKeyspaceName"));
        assertThat(dataSet.getKeyspace().getReplicationFactor(), is(2));
        assertThat(dataSet.getKeyspace().getStrategy(), is(StrategyModel.SIMPLE_STRATEGY));
    }
View Full Code Here

*/
public class ClasspathJsonDataSetTest {

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

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

        List<ColumnFamilyModel> actualColumnFamilies = dataSet.getColumnFamilies();
        assertThat(actualColumnFamilies, notNullValue());
        assertThat(actualColumnFamilies.size(), is(1));

        ColumnFamilyModel actualColumnFamily1 = actualColumnFamilies.get(0);
        assertThat(actualColumnFamily1, notNullValue());
View Full Code Here

    columnModel.setValue(new GenericType(value, GenericTypeEnum.UTF_8_TYPE));
    return columnModel;
  }

  public static DataSet getMockDataSetWithDefinedValuesSimple() {
    DataSet mockDataSet = mock(DataSet.class);
    /* keyspace */
    KeyspaceModel keyspace = new KeyspaceModel();
    keyspace.setName("otherKeyspaceName");
    keyspace.setStrategy(StrategyModel.SIMPLE_STRATEGY);
    keyspace.setReplicationFactor(1);
    List<ColumnFamilyModel> columnFamilies = new ArrayList<ColumnFamilyModel>();
    columnFamilies.add(constructColumnFamily1ForDefinedValueSimple());
    columnFamilies.add(constructColumnFamily2ForDefinedValueSimple());
    columnFamilies.add(constructColumnFamily3ForDefinedValueSimple());
    columnFamilies.add(constructColumnFamily4ForDefinedValueSimple());
    columnFamilies.add(constructColumnFamily5ForDefinedValueSimple());
    columnFamilies.add(constructColumnFamily6ForDefinedValueSimple());
    columnFamilies.add(constructColumnFamily7ForDefinedValueSimple());
    keyspace.setColumnFamilies(columnFamilies);

    when(mockDataSet.getKeyspace()).thenReturn(keyspace);
    when(mockDataSet.getColumnFamilies()).thenReturn(keyspace.getColumnFamilies());
    return mockDataSet;
  }
View Full Code Here

    return columnFamily;
  }

  public static DataSet getMockDataSetWithSuperColumn() {
    DataSet mockDataSet = mock(DataSet.class);
    /* keyspace */
    KeyspaceModel keyspace = new KeyspaceModel();
    keyspace.setName("beautifulKeyspaceName");
    List<ColumnFamilyModel> columnFamilies = new ArrayList<ColumnFamilyModel>();
    ColumnFamilyModel columnFamily = new ColumnFamilyModel();
    columnFamily.setName("beautifulColumnFamilyName");
    columnFamily.setType(ColumnType.SUPER);

    List<RowModel> rows = new ArrayList<RowModel>();

    RowModel row1 = new RowModel();
    row1.setKey(new GenericType("01", GenericTypeEnum.BYTES_TYPE));
    List<SuperColumnModel> superColumns1 = new ArrayList<SuperColumnModel>();

    SuperColumnModel superColumn11 = new SuperColumnModel();
    superColumn11.setName(new GenericType("11", GenericTypeEnum.BYTES_TYPE));
    List<ColumnModel> columns11 = new ArrayList<ColumnModel>();
    columns11.add(constructDefaultColumnForMock("1110", "1110"));
    columns11.add(constructDefaultColumnForMock("1120", "1120"));
    superColumn11.setColumns(columns11);
    superColumns1.add(superColumn11);

    SuperColumnModel superColumn12 = new SuperColumnModel();
    superColumn12.setName(new GenericType("12", GenericTypeEnum.BYTES_TYPE));
    List<ColumnModel> columns12 = new ArrayList<ColumnModel>();
    columns12.add(constructDefaultColumnForMock("1210", "1210"));
    columns12.add(constructDefaultColumnForMock("1220", "1220"));
    superColumn12.setColumns(columns12);
    superColumns1.add(superColumn12);

    row1.setSuperColumns(superColumns1);
    rows.add(row1);

    RowModel row2 = new RowModel();
    row2.setKey(new GenericType("02", GenericTypeEnum.BYTES_TYPE));
    List<SuperColumnModel> superColumns2 = new ArrayList<SuperColumnModel>();
    SuperColumnModel superColumn21 = new SuperColumnModel();
    superColumn21.setName(new GenericType("21", GenericTypeEnum.BYTES_TYPE));
    List<ColumnModel> columns21 = new ArrayList<ColumnModel>();
    columns21.add(constructDefaultColumnForMock("2110", "2110"));
    columns21.add(constructDefaultColumnForMock("2120", "2120"));
    superColumn21.setColumns(columns21);
    superColumns2.add(superColumn21);
    row2.setSuperColumns(superColumns2);

    rows.add(row2);

    columnFamily.setRows(rows);
    columnFamilies.add(columnFamily);
    keyspace.setColumnFamilies(columnFamilies);

    when(mockDataSet.getKeyspace()).thenReturn(keyspace);
    when(mockDataSet.getColumnFamilies()).thenReturn(keyspace.getColumnFamilies());
    return mockDataSet;
  }
View Full Code Here

        assertThat(dataSet.getKeyspace().getStrategy(), is(StrategyModel.SIMPLE_STRATEGY));
    }

    @Test
    public void shouldGetOneColumnFamilyWithDefaultValues() {
        DataSet dataSet = new ClassPathXmlDataSet("xml/dataSetDefaultValues.xml");
        assertThat(dataSet.getColumnFamilies(), notNullValue());
        assertThat(dataSet.getColumnFamilies().isEmpty(), is(false));

        ColumnFamilyModel actualColumnFamily = dataSet.getColumnFamilies().get(0);
        assertThat(actualColumnFamily, notNullValue());
        assertThat(actualColumnFamily.getName(), is("columnFamily1"));
        assertThat(actualColumnFamily.getType(), is(ColumnType.STANDARD));
        assertThat(actualColumnFamily.getKeyType().getClassName(),is(ComparatorType.BYTESTYPE.getClassName()));
        assertThat(actualColumnFamily.getComparatorType().getClassName(),is(ComparatorType.BYTESTYPE.getClassName()));
View Full Code Here

        assertThat(actualColumnFamily1.getSubComparatorType(), nullValue());
    }

    @Test(expected = ParseException.class)
    public void shouldNotGetAJsonDataSetStructureBecauseOfNull() {
        DataSet dataSet = new ClassPathJsonDataSet(null);
        dataSet.getKeyspace();
    }
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.