Package info.archinnov.achilles.internal.metadata.holder

Examples of info.archinnov.achilles.internal.metadata.holder.PropertyMeta


    }

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

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

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

        def1 = ColumnDefinitionBuilder.buildColumnDef("keyspace", "table", "id", DataType.bigint());
        def2 = ColumnDefinitionBuilder.buildColumnDef("keyspace", "table", "value", DataType.text());

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

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

        CompleteBean actual = entityMapper.mapRowToEntityWithPrimaryKey(entityMeta, row, propertiesMap, MANAGED);

        assertThat(actual).isSameAs(entity);
        verify(idMeta.forValues()).setValueToField(entity, id);
        verify(valueMeta.forValues()).setValueToField(entity, "value");
    }
View Full Code Here


    @Test
    public void should_map_row_to_entity_with_primary_key() throws Exception {
        ClusteredEntity entity = new ClusteredEntity();
        EmbeddedKey embeddedKey = new EmbeddedKey();
        PropertyMeta idMeta = mock(PropertyMeta.class, RETURNS_DEEP_STUBS);

        when(idMeta.structure().isEmbeddedId()).thenReturn(true);

        Map<String, PropertyMeta> propertiesMap = new HashMap<>();

        when(row.getColumnDefinitions()).thenReturn(columnDefs);
        when(columnDefs.iterator()).thenReturn(Arrays.<Definition>asList().iterator());
        when(entityMeta.forOperations().instanciate()).thenReturn(entity);
        when(entityMeta.getIdMeta()).thenReturn(idMeta);
        when(idMeta.forRowExtraction().extractCompoundPrimaryKeyFromRow(row, entityMeta, MANAGED)).thenReturn(embeddedKey);

        ClusteredEntity actual = entityMapper.mapRowToEntityWithPrimaryKey(entityMeta, row, propertiesMap, MANAGED);

        assertThat(actual).isSameAs(entity);
        verify(idMeta.forValues()).setValueToField(entity, embeddedKey);
    }
View Full Code Here

    private CompleteBean entity = new CompleteBean();

    @Test
    public void should_build_interceptor_with_eager_fields_already_loaded() throws Exception {

        PropertyMeta idMeta = PropertyMetaTestBuilder.completeBean(Void.class, String.class).propertyName("id").build();

        EntityMeta meta = mock(EntityMeta.class, RETURNS_DEEP_STUBS);
        when(meta.getIdMeta()).thenReturn(idMeta);
        when(meta.getClassName()).thenReturn("classname");
        when(meta.getGetterMetas()).thenReturn(new HashMap<Method, PropertyMeta>());
        when(meta.getSetterMetas()).thenReturn(new HashMap<Method, PropertyMeta>());

        when(context.<CompleteBean>getEntityClass()).thenReturn(CompleteBean.class);
        when(context.getEntityMeta()).thenReturn(meta);
        when(context.getPrimaryKey()).thenReturn(entity.getId());

        ProxyInterceptor<CompleteBean> interceptor = ProxyInterceptorBuilder.builder(context, entity)
                .alreadyLoaded(Sets.newHashSet(idMeta.getGetter())).build();

        assertThat(interceptor.getEntityOperations()).isSameAs(context);
        assertThat(interceptor.getTarget()).isSameAs(entity);
        assertThat(interceptor.getPrimaryKey()).isEqualTo(entity.getId());
        assertThat(interceptor.getAlreadyLoaded()).containsOnly(idMeta.getGetter());
    }
View Full Code Here

    }

    @Test
    public void should_build_interceptor_with_no_eager_fields() throws Exception {

        PropertyMeta idMeta = PropertyMetaTestBuilder.completeBean(Void.class, String.class).propertyName("id").build();

        EntityMeta meta = mock(EntityMeta.class, RETURNS_DEEP_STUBS);
        when(meta.getIdMeta()).thenReturn(idMeta);
        when(meta.getClassName()).thenReturn("classname");
        when(meta.getGetterMetas()).thenReturn(new HashMap<Method, PropertyMeta>());
View Full Code Here

  }

    @Test
    public void should_exception_when_static_column_on_non_clustered_entity() throws Exception {
        //Given
        PropertyMeta idMeta = mock(PropertyMeta.class, RETURNS_DEEP_STUBS);
        PropertyMeta pm = mock(PropertyMeta.class, RETURNS_DEEP_STUBS);
        EntityMeta entityMeta = mock(EntityMeta.class, RETURNS_DEEP_STUBS);
        when(entityMeta.getPropertyMetas().values()).thenReturn(Arrays.asList(pm));
        when(pm.structure().isStaticColumn()).thenReturn(true);
        when(entityMeta.getClassName()).thenReturn("myEntity");
        when(idMeta.structure().isClustered()).thenReturn(false);

        //When //Then
        exception.expect(AchillesBeanMappingException.class);
View Full Code Here

    }

    @Test
    public void should_exception_when_clustered_counter_entity_has_only_static_columns() throws Exception {
        //Given
        PropertyMeta idMeta = mock(PropertyMeta.class, RETURNS_DEEP_STUBS);
        PropertyMeta pm1 = mock(PropertyMeta.class, RETURNS_DEEP_STUBS);
        PropertyMeta pm2 = mock(PropertyMeta.class, RETURNS_DEEP_STUBS);
        EntityMeta entityMeta = mock(EntityMeta.class, RETURNS_DEEP_STUBS);
        when(entityMeta.getPropertyMetas().values()).thenReturn(Arrays.asList(pm1,pm2));
        when(entityMeta.getAllMetasExceptId().size()).thenReturn(2);
        when(entityMeta.getClassName()).thenReturn("myEntity");
        when(entityMeta.structure().isClusteredCounter()).thenReturn(true);
        when(idMeta.structure().isClustered()).thenReturn(true);
        when(pm1.structure().isStaticColumn()).thenReturn(true);
        when(pm2.structure().isStaticColumn()).thenReturn(true);
        when(pm1.structure().isCounter()).thenReturn(true);
        when(pm2.structure().isCounter()).thenReturn(true);

        //When //Then
        exception.expect(AchillesBeanMappingException.class);
        exception.expectMessage("The entity class 'myEntity' is a clustered counter and thus cannot have only static counter column");
View Full Code Here

    @Test
    public void should_build_proxy_with_all_fields_loaded() throws Exception {

        long primaryKey = RandomUtils.nextLong(0,Long.MAX_VALUE);
        PropertyMeta pm = mock(PropertyMeta.class, RETURNS_DEEP_STUBS);
        PropertyMeta counterMeta = mock(PropertyMeta.class, RETURNS_DEEP_STUBS);
        Object value = new Object();

        CompleteBean entity = CompleteBeanTestBuilder.builder().id(primaryKey).name("name").buid();
        proxifier = spy(proxifier);

        doReturn(interceptor).when(proxifier).buildInterceptor(eq(context), eq(entity), anySetOf(Method.class));
        when(context.getEntityMeta()).thenReturn(entityMeta);
        when(entityMeta.getIdMeta()).thenReturn(idMeta);
        when(entityMeta.getAllMetasExceptCounters()).thenReturn(Arrays.asList(pm));
        when(entityMeta.getAllCounterMetas()).thenReturn(Arrays.asList(counterMeta));
        when(pm.forValues().getValueFromField(entity)).thenReturn(value);
        when(context.getConfigContext()).thenReturn(configContext);
        when(factory.createProxyClass(entity.getClass(), configContext)).thenReturn((Class) entity.getClass());
        when(instantiator.instantiate(Mockito.<Class<Factory>>any())).thenReturn(realProxy);

        Object proxy = proxifier.buildProxyWithAllFieldsLoadedExceptCounters(entity, context);

        assertThat(proxy).isNotNull();
        assertThat(proxy).isInstanceOf(Factory.class);
        Factory factory = (Factory) proxy;

        assertThat(factory.getCallbacks()).hasSize(1);
        assertThat(factory.getCallback(0)).isInstanceOf(ProxyInterceptor.class);

        verify(pm.forValues()).getValueFromField(entity);
        verify(pm.forValues()).setValueToField(realProxy, value);
        verify(counterMeta.forValues()).setValueToField(entity,null);
    }
View Full Code Here

        validator.validateNoDuplicatePropertyName(context);
    }

    @Test
    public void should_exception_when_duplicate_cql3_name() throws Exception {
        PropertyMeta name = valueClass(String.class).cqlColumnName("name").type(SIMPLE).build();
        PropertyMeta duplicatedName = valueClass(String.class).cqlColumnName("name").type(SIMPLE).build();
        Map<String, PropertyMeta> propertyMetas = ImmutableMap.of("name1", name, "name2", duplicatedName);
        when(context.getCurrentPropertyName()).thenReturn("name");
        when(context.getCurrentCQL3ColumnName()).thenReturn("name");
        when(context.getPropertyMetas()).thenReturn(propertyMetas);
        when(context.<CompleteBean>getCurrentEntityClass()).thenReturn(CompleteBean.class);
View Full Code Here

  @Test
  public void should_exclude_by_types() throws Exception {
    PropertyTypeExclude exclude = new PropertyTypeExclude(COUNTER, SIMPLE);

    PropertyMeta pm1 = PropertyMetaTestBuilder.valueClass(String.class).entityClassName("entity").propertyName("pm1")
        .type(SET).build();

    PropertyMeta pm2 = PropertyMetaTestBuilder.valueClass(String.class).entityClassName("entity").propertyName("pm2")
        .type(SIMPLE).build();

    PropertyMeta pm3 = PropertyMetaTestBuilder.valueClass(String.class).entityClassName("entity").propertyName("pm3")
        .type(MAP).build();

    assertThat(Collections2.filter(Arrays.asList(pm1, pm2), exclude)).containsOnly(pm1);
    assertThat(Collections2.filter(Arrays.asList(pm1, pm3), exclude)).containsOnly(pm1, pm3);
  }
View Full Code Here

    @Test
    public void should_bind_for_insert_with_simple_id() throws Exception {
        long primaryKey = RandomUtils.nextLong(0,Long.MAX_VALUE);
        long age = RandomUtils.nextLong(0,Long.MAX_VALUE);
        String name = "name";
        PropertyMeta nameMeta = mock(PropertyMeta.class, RETURNS_DEEP_STUBS);
        PropertyMeta ageMeta = mock(PropertyMeta.class, RETURNS_DEEP_STUBS);

        when(overrider.getWriteLevel(context)).thenReturn(ALL);
        when(entityMeta.forOperations().getPrimaryKey(entity)).thenReturn(primaryKey);
        when(idMeta.structure().isEmbeddedId()).thenReturn(false);
        when(idMeta.forTranscoding().encodeToCassandra(primaryKey)).thenReturn(primaryKey);
        when(nameMeta.forTranscoding().getAndEncodeValueForCassandra(entity)).thenReturn(name);
        when(ageMeta.forTranscoding().getAndEncodeValueForCassandra(entity)).thenReturn(age);

        when(context.getSerialConsistencyLevel()).thenReturn(fromNullable(ConsistencyLevel.LOCAL_SERIAL));

        when(ps.bind(Matchers.anyVararg())).thenReturn(bs);
View Full Code Here

TOP

Related Classes of info.archinnov.achilles.internal.metadata.holder.PropertyMeta

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.