コード例 #1
1
  @Test
  public void should_create_entity_dao() throws Exception {
    PropertyMeta idMeta =
        PropertyMetaTestBuilder //
            .completeBean(Void.class, Long.class)
            .field("id")
            .build();

    EntityMeta entityMeta = new EntityMeta();
    entityMeta.setClusteredEntity(false);
    entityMeta.setTableName("cf");
    entityMeta.setIdMeta(idMeta);
    entityMeta.setIdClass(Long.class);
    entityMeta.setPropertyMetas(new HashMap<String, PropertyMeta>());

    factory.createDaosForEntity(
        cluster, keyspace, configContext, entityMeta, entityDaosMap, wideRowDaosMap);

    ThriftGenericEntityDao entityDao = entityDaosMap.get("cf");

    assertThat(entityDao).isNotNull();
    assertThat(entityDao.getColumnFamily()).isEqualTo("cf");
    assertThat(Whitebox.getInternalState(entityDao, "policy")).isSameAs(consistencyPolicy);
    assertThat(Whitebox.getInternalState(entityDao, "cluster")).isSameAs(cluster);
    assertThat(Whitebox.getInternalState(entityDao, "keyspace")).isSameAs(keyspace);
    assertThat(Whitebox.getInternalState(entityDao, "columnNameSerializer"))
        .isSameAs(COMPOSITE_SRZ);

    Pair<Class<Long>, Class<String>> rowAndValueClases =
        Whitebox.getInternalState(entityDao, "rowkeyAndValueClasses");
    assertThat(rowAndValueClases.left).isSameAs(Long.class);
    assertThat(rowAndValueClases.right).isSameAs(String.class);
  }
コード例 #2
0
  @Test
  public void should_create_object_type_clustered_entity_dao() throws Exception {

    PropertyMeta idMeta =
        PropertyMetaTestBuilder.valueClass(CompoundKey.class)
            .compClasses(Integer.class, String.class, UUID.class)
            .field("id")
            .type(PropertyType.EMBEDDED_ID)
            .build();

    PropertyMeta pm =
        PropertyMetaTestBuilder.valueClass(UserBean.class).type(PropertyType.SIMPLE).build();

    EntityMeta entityMeta = new EntityMeta();
    entityMeta.setClusteredEntity(true);
    entityMeta.setIdMeta(idMeta);
    entityMeta.setTableName("cf");
    entityMeta.setPropertyMetas(ImmutableMap.of("id", idMeta, "pm", pm));
    entityMeta.setAllMetasExceptIdMeta(Arrays.asList(pm));
    entityMeta.setFirstMeta(pm);

    factory.createClusteredEntityDao(cluster, keyspace, configContext, entityMeta, wideRowDaosMap);

    ThriftGenericWideRowDao clusteredEntityDao = wideRowDaosMap.get("cf");

    Pair<Class<Integer>, Class<String>> rowAndValueClases =
        Whitebox.getInternalState(clusteredEntityDao, "rowkeyAndValueClasses");
    assertThat(rowAndValueClases.left).isSameAs(Integer.class);
    assertThat(rowAndValueClases.right).isSameAs(String.class);
  }
コード例 #3
0
  @Test
  public void should_build_entity_dao() throws Exception {
    PropertyMeta idMeta =
        PropertyMetaTestBuilder //
            .completeBean(Void.class, Long.class)
            .field("id")
            .build();

    EntityMeta entityMeta = new EntityMeta();
    entityMeta.setClusteredEntity(false);
    entityMeta.setTableName("cf");
    entityMeta.setIdMeta(idMeta);
    entityMeta.setIdClass(Long.class);
    entityMeta.setPropertyMetas(new HashMap<String, PropertyMeta>());

    entityMetaMap.put(CompleteBean.class, entityMeta);

    builder.buildDao(cluster, keyspace, entityMetaMap, configContext, false);
    verify(daoFactory)
        .createDaosForEntity(
            eq(cluster),
            eq(keyspace),
            eq(configContext),
            eq(entityMeta),
            any(Map.class),
            any(Map.class));
  }
コード例 #4
0
  @Test
  public void should_create_value_less_clustered_entity_dao() throws Exception {

    PropertyMeta idMeta =
        PropertyMetaTestBuilder.valueClass(CompoundKey.class)
            .compClasses(Integer.class, String.class, UUID.class)
            .field("id")
            .type(PropertyType.EMBEDDED_ID)
            .build();

    EntityMeta entityMeta = new EntityMeta();
    entityMeta.setClusteredEntity(true);
    entityMeta.setIdMeta(idMeta);
    entityMeta.setTableName("cf");
    entityMeta.setPropertyMetas(ImmutableMap.of("id", idMeta));

    factory.createClusteredEntityDao(cluster, keyspace, configContext, entityMeta, wideRowDaosMap);

    ThriftGenericWideRowDao clusteredEntityDao = wideRowDaosMap.get("cf");

    assertThat(clusteredEntityDao).isNotNull();
    assertThat(clusteredEntityDao.getColumnFamily()).isEqualTo("cf");
    assertThat(Whitebox.getInternalState(clusteredEntityDao, "policy")).isSameAs(consistencyPolicy);
    assertThat(Whitebox.getInternalState(clusteredEntityDao, "cluster")).isSameAs(cluster);
    assertThat(Whitebox.getInternalState(clusteredEntityDao, "keyspace")).isSameAs(keyspace);
    assertThat(Whitebox.getInternalState(clusteredEntityDao, "columnNameSerializer"))
        .isSameAs(COMPOSITE_SRZ);

    Pair<Class<Integer>, Class<String>> rowAndValueClasses =
        Whitebox.getInternalState(clusteredEntityDao, "rowkeyAndValueClasses");
    assertThat(rowAndValueClasses.left).isSameAs(Integer.class);
    assertThat(rowAndValueClasses.right).isSameAs(String.class);
  }