Example usage for org.apache.cassandra.cql3 ColumnSpecification ColumnSpecification

List of usage examples for org.apache.cassandra.cql3 ColumnSpecification ColumnSpecification

Introduction

In this page you can find the example usage for org.apache.cassandra.cql3 ColumnSpecification ColumnSpecification.

Prototype

public ColumnSpecification(String ksName, String cfName, ColumnIdentifier name, AbstractType<?> type) 

Source Link

Usage

From source file:info.archinnov.achilles.entity.CQLEntityMapperTest.java

License:Apache License

@Test
public void should_map_row_to_entity() throws Exception {
    Long id = RandomUtils.nextLong();
    PropertyMeta idMeta = mock(PropertyMeta.class);
    PropertyMeta valueMeta = mock(PropertyMeta.class);

    when(idMeta.isEmbeddedId()).thenReturn(false);

    Map<String, PropertyMeta> propertiesMap = ImmutableMap.of("id", idMeta, "value", valueMeta);

    ColumnIdentifier iden1 = new ColumnIdentifier(UTF8Type.instance.decompose("id"), UTF8Type.instance);
    ColumnSpecification spec1 = new ColumnSpecification("keyspace", "id", iden1, LongType.instance);

    ColumnIdentifier iden2 = new ColumnIdentifier(UTF8Type.instance.decompose("value"), UTF8Type.instance);
    ColumnSpecification spec2 = new ColumnSpecification("keyspace", "value", iden2, UTF8Type.instance);

    def1 = Whitebox.invokeMethod(Definition.class, "fromTransportSpecification", spec1);
    def2 = Whitebox.invokeMethod(Definition.class, "fromTransportSpecification", spec2);

    when(row.getColumnDefinitions()).thenReturn(columnDefs);
    when(columnDefs.iterator()).thenReturn(Arrays.asList(def1, def2).iterator());

    when(entityMeta.getIdMeta()).thenReturn(idMeta);
    when(entityMeta.instanciate()).thenReturn(entity);
    when(cqlRowInvoker.invokeOnRowForFields(row, idMeta)).thenReturn(id);
    when(cqlRowInvoker.invokeOnRowForFields(row, valueMeta)).thenReturn("value");
    when(entityMeta.instanciate()).thenReturn(entity);

    CompleteBean actual = entityMapper.mapRowToEntityWithPrimaryKey(CompleteBean.class, entityMeta, row,
            propertiesMap, true);//from  ww  w . j a  va  2  s .  com

    assertThat(actual).isSameAs(entity);
    verify(idMeta).setValueToField(entity, id);
    verify(valueMeta).setValueToField(entity, "value");
}

From source file:info.archinnov.achilles.entity.operations.CQLNativeQueryMapperTest.java

License:Apache License

@Test
public void should_map_rows() throws Exception {
    Long id = RandomUtils.nextLong();
    String name = "name";

    ColumnIdentifier iden1 = new ColumnIdentifier(UTF8Type.instance.decompose("id"), UTF8Type.instance);
    ColumnSpecification spec1 = new ColumnSpecification("keyspace", "id", iden1, LongType.instance);

    ColumnIdentifier iden2 = new ColumnIdentifier(UTF8Type.instance.decompose(name), UTF8Type.instance);
    ColumnSpecification spec2 = new ColumnSpecification("keyspace", "name", iden2, UTF8Type.instance);

    def1 = Whitebox.invokeMethod(Definition.class, "fromTransportSpecification", spec1);
    def2 = Whitebox.invokeMethod(Definition.class, "fromTransportSpecification", spec2);

    when(row.getColumnDefinitions()).thenReturn(columnDefs);
    when(columnDefs.iterator()).thenReturn(Arrays.asList(def1, def2).iterator());

    when(cqlRowInvoker.invokeOnRowForType(row, Long.class, "id")).thenReturn(id);
    when(cqlRowInvoker.invokeOnRowForType(row, String.class, "name")).thenReturn(name);

    List<Map<String, Object>> result = mapper.mapRows(Arrays.asList(row));

    verify(cqlRowInvoker).invokeOnRowForType(row, Long.class, "id");
    verify(cqlRowInvoker).invokeOnRowForType(row, String.class, "name");

    assertThat(result).hasSize(1);/*from w ww  . j  a  v  a2 s .c  o  m*/
    Map<String, Object> line = result.get(0);

    assertThat(line).hasSize(2);
    assertThat(line.get("id")).isEqualTo(id);
    assertThat(line.get("name")).isEqualTo(name);

}

From source file:info.archinnov.achilles.entity.operations.CQLNativeQueryMapperTest.java

License:Apache License

@Test
public void should_map_rows_with_list() throws Exception {
    ArrayList<String> friends = new ArrayList<String>();

    ColumnIdentifier iden1 = new ColumnIdentifier(UTF8Type.instance.decompose("friends"), UTF8Type.instance);
    ColumnSpecification spec1 = new ColumnSpecification("keyspace", "friends", iden1,
            ListType.getInstance(UTF8Type.instance));

    def1 = Whitebox.invokeMethod(Definition.class, "fromTransportSpecification", spec1);

    when(row.getColumnDefinitions()).thenReturn(columnDefs);
    when(columnDefs.iterator()).thenReturn(Arrays.asList(def1).iterator());

    when(row.getList("friends", String.class)).thenReturn(friends);
    List<Map<String, Object>> result = mapper.mapRows(Arrays.asList(row));

    assertThat(result).hasSize(1);//w  w w.j  a  v  a2s  . c o  m
    Map<String, Object> line = result.get(0);

    assertThat(line).hasSize(1);
    assertThat(line.get("friends")).isSameAs(friends);
}

From source file:info.archinnov.achilles.entity.operations.CQLNativeQueryMapperTest.java

License:Apache License

@Test
public void should_map_rows_with_set() throws Exception {
    Set<String> followers = new HashSet<String>();

    ColumnIdentifier iden1 = new ColumnIdentifier(UTF8Type.instance.decompose("followers"), UTF8Type.instance);
    ColumnSpecification spec1 = new ColumnSpecification("keyspace", "followers", iden1,
            SetType.getInstance(UTF8Type.instance));

    def1 = Whitebox.invokeMethod(Definition.class, "fromTransportSpecification", spec1);

    when(row.getColumnDefinitions()).thenReturn(columnDefs);
    when(columnDefs.iterator()).thenReturn(Arrays.asList(def1).iterator());

    when(row.getSet("followers", String.class)).thenReturn(followers);
    List<Map<String, Object>> result = mapper.mapRows(Arrays.asList(row));

    assertThat(result).hasSize(1);//from  w  w  w.j a  va 2s. c om
    Map<String, Object> line = result.get(0);

    assertThat(line).hasSize(1);
    assertThat(line.get("followers")).isSameAs(followers);
}

From source file:info.archinnov.achilles.entity.operations.CQLNativeQueryMapperTest.java

License:Apache License

@Test
public void should_map_rows_with_map() throws Exception {
    Map<BigInteger, String> preferences = new HashMap<BigInteger, String>();

    ColumnIdentifier iden1 = new ColumnIdentifier(UTF8Type.instance.decompose("preferences"),
            UTF8Type.instance);/*from www . ja  va 2  s .  co  m*/
    ColumnSpecification spec1 = new ColumnSpecification("keyspace", "followers", iden1,
            MapType.getInstance(IntegerType.instance, UTF8Type.instance));

    def1 = Whitebox.invokeMethod(Definition.class, "fromTransportSpecification", spec1);

    when(row.getColumnDefinitions()).thenReturn(columnDefs);
    when(columnDefs.iterator()).thenReturn(Arrays.asList(def1).iterator());

    when(row.getMap("preferences", BigInteger.class, String.class)).thenReturn(preferences);
    List<Map<String, Object>> result = mapper.mapRows(Arrays.asList(row));

    assertThat(result).hasSize(1);
    Map<String, Object> line = result.get(0);

    assertThat(line).hasSize(1);
    assertThat(line.get("preferences")).isSameAs(preferences);
}

From source file:info.archinnov.achilles.entity.operations.CQLNativeQueryMapperTest.java

License:Apache License

@Test
public void should_return_empty_list_when_no_column() throws Exception {
    ColumnIdentifier iden1 = new ColumnIdentifier(UTF8Type.instance.decompose("id"), UTF8Type.instance);
    ColumnSpecification spec1 = new ColumnSpecification("keyspace", "id", iden1, LongType.instance);

    def1 = Whitebox.invokeMethod(Definition.class, "fromTransportSpecification", spec1);

    when(row.getColumnDefinitions()).thenReturn(null);

    List<Map<String, Object>> result = mapper.mapRows(Arrays.asList(row));
    assertThat(result).isEmpty();//from w  w  w.  j ava  2s.  c o  m

    verifyZeroInteractions(cqlRowInvoker);
}