Package info.archinnov.achilles.test.integration.entity

Examples of info.archinnov.achilles.test.integration.entity.CompleteBean


    assertThat(bean.getVersion().get()).isEqualTo(5L);
  }

  @Test
  public void should_get_counter_from_refreshed_entity() throws Exception {
    CompleteBean bean = builder().randomId().buid();
    bean = manager.insert(bean);

    Counter version = bean.getVersion();
    version.incr(5L);

    manager.update(bean);

    assertThat(version.get()).isEqualTo(5L);

    manager.refresh(bean);

    assertThat(bean.getVersion().get()).isEqualTo(5L);
  }
View Full Code Here


    private PersistenceManager manager = resource.getPersistenceManager();

    @Test
    public void should_return_entities_for_indexed_query() throws Exception {
        CompleteBean entity1 = CompleteBeanTestBuilder.builder().randomId().name("DuyHai").buid();
        CompleteBean entity2 = CompleteBeanTestBuilder.builder().randomId().name("John DOO").buid();

        manager.insert(entity1);
        manager.insert(entity2);

        IndexCondition condition = new IndexCondition("name", "John DOO");
        List<CompleteBean> actual = manager.indexedQuery(CompleteBean.class, condition).get();

        assertThat(actual).hasSize(1);

        CompleteBean found1 = actual.get(0);
        assertThat(found1).isNotNull();

    }
View Full Code Here

    @Test
    public void should_return_empty_list_instead_of_null_for_field_annotated_with_emptyIfNullCollection() throws Exception {
        //Given
        Long id = RandomUtils.nextLong(0,Long.MAX_VALUE);

        final CompleteBean proxy = manager.getProxy(CompleteBean.class, id);

        //When
        final List<String> friends = proxy.getFriends();

        //Then
        assertThat(friends).isNotNull().isEmpty();
    }
View Full Code Here

    private PersistenceManager manager = resource.getPersistenceManager();

    @Test
    public void should_return_rows_for_native_query() throws Exception {
        CompleteBean entity1 = builder().randomId().name("DuyHai").age(35L)
                .addFriends("foo", "bar").addFollowers("George", "Paul").addPreference(1, "FR")
                .addPreference(2, "Paris").addPreference(3, "75014").version(CounterBuilder.incr(15L)).buid();

        CompleteBean entity2 = builder().randomId().name("John DOO").age(35L)
                .addFriends("qux", "twix").addFollowers("Isaac", "Lara").addPreference(1, "US")
                .addPreference(2, "NewYork").version(CounterBuilder.incr(17L)).buid();

        manager.insert(entity1);
        manager.insert(entity2);

        RegularStatement statement = select("name", "age_in_years", "friends", "followers", "preferences")
                .from("CompleteBean").where(in("id", entity1.getId(), entity2.getId()));

        List<TypedMap> actual = manager.nativeQuery(statement).get();

        assertThat(actual).hasSize(2);
View Full Code Here

        assertThat(preferences2.get(2)).isEqualTo("NewYork");
    }

    @Test
    public void should_return_rows_for_native_query_with_bound_values() throws Exception {
        CompleteBean entity = builder().randomId().name("DuyHai").buid();
        manager.insert(entity);

        RegularStatement statement = select("name").from("CompleteBean").where(eq("id", bindMarker()));

        List<TypedMap> actual = manager.nativeQuery(statement, entity.getId()).get();

        assertThat(actual).hasSize(1);

        TypedMap row = actual.get(0);
View Full Code Here

    }

    @Test
    public void should_execute_native_query_with_CAS() throws Exception {
        //Given
        CompleteBean entity = builder().randomId().name("DuyHai").label("label").buid();

        manager.insert(entity);

        final Insert statement = insertInto("CompleteBean").ifNotExists().value("id", bindMarker("id")).value("name", bindMarker("name"));

        final AtomicBoolean error = new AtomicBoolean(false);
        final AtomicReference<CASResult> result = new AtomicReference<>(null);

        CASResultListener listener = new CASResultListener() {
            @Override
            public void onCASSuccess() {

            }

            @Override
            public void onCASError(CASResult casResult) {
                error.getAndSet(true);
                result.getAndSet(casResult);
            }
        };

        //When
        manager.nativeQuery(statement,OptionsBuilder.casResultListener(listener),entity.getId(),"DuyHai").execute();

        //Then
        assertThat(error.get()).isTrue();
        assertThat(result.get()).isNotNull();

        final TypedMap currentValues = result.get().currentValues();

        assertThat(currentValues.<Long>getTyped("id")).isEqualTo(entity.getId());
        assertThat(currentValues.<String>getTyped("name")).isEqualTo(entity.getName());
        assertThat(currentValues.<String>getTyped("label")).isEqualTo(entity.getLabel());
    }
View Full Code Here

        assertThat(currentValues.<String>getTyped("label")).isEqualTo(entity.getLabel());
    }

    @Test
    public void should_return_count_for_native_query() throws Exception {
        CompleteBean entity = builder().randomId().name("DuyHai").buid();

        manager.insert(entity);

        RegularStatement statement = select().countAll().from("CompleteBean").where(eq("id", entity.getId()));

        Long count = (Long) manager.nativeQuery(statement).first().get("count");

        assertThat(count).isEqualTo(1L);
    }
View Full Code Here

        assertThat(count).isEqualTo(1L);
    }

    @Test
    public void should_return_ttl_and_timestamp_for_native_query() throws Exception {
        CompleteBean entity = builder().randomId().name("DuyHai").age(32L).buid();

        Long timestamp = (System.currentTimeMillis() + 1234500) * 1000;

        manager.insert(entity, OptionsBuilder.withTtl(1000).withTimestamp(timestamp));

        RegularStatement statement = select().fcall("ttl", column("name")).fcall("writetime",column("age_in_years"))
                .from("CompleteBean").where(eq("id",entity.getId()));

        Map<String, Object> result = manager.nativeQuery(statement).first();

        assertThat((Integer) result.get("ttl(name)")).isLessThanOrEqualTo(1000);
        assertThat(result.get("writetime(age_in_years)")).isEqualTo(timestamp);
View Full Code Here

        assertThat(result.get("unixTimestampOf(date)")).isNotNull().isInstanceOf(Long.class);
    }

    @Test
    public void should_return_iterator_for_native_query() throws Exception {
        CompleteBean entity1 = builder().randomId().name("DuyHai").buid();
        CompleteBean entity2 = builder().randomId().name("Paul").buid();
        CompleteBean entity3 = builder().randomId().name("George").buid();
        CompleteBean entity4 = builder().randomId().name("John").buid();
        CompleteBean entity5 = builder().randomId().name("Helen").buid();

        manager.insert(entity1);
        manager.insert(entity2);
        manager.insert(entity3);
        manager.insert(entity4);
View Full Code Here

        assertThat(iterator.hasNext()).isFalse();
    }

    @Test
    public void should_return_entities_for_typed_query_with_select_star() throws Exception {
        CompleteBean entity1 = builder().randomId().name("DuyHai").age(35L)
                .addFriends("foo", "bar").addFollowers("George", "Paul").addPreference(1, "FR")
                .addPreference(2, "Paris").addPreference(3, "75014").buid();

        CompleteBean entity2 = builder().randomId().name("John DOO").age(34L)
                .addFriends("qux", "twix").addFollowers("Isaac", "Lara").addPreference(1, "US")
                .addPreference(2, "NewYork").buid();

        manager.insert(entity1);
        manager.insert(entity2);

        RegularStatement statement = select().from("CompleteBean").limit(3);

        List<CompleteBean> actual = manager.typedQuery(CompleteBean.class, statement).get();

        assertThat(actual).hasSize(2);

        CompleteBean found1 = actual.get(0);
        CompleteBean found2 = actual.get(1);

        Factory factory1 = (Factory) found1;
        @SuppressWarnings("unchecked")
        ProxyInterceptor<CompleteBean> interceptor1 = (ProxyInterceptor<CompleteBean>) factory1.getCallback(0);

        CompleteBean target1 = (CompleteBean) interceptor1.getTarget();

        assertThat(target1.getLabel()).isNull();
        assertThat(target1.getWelcomeTweet()).isNull();

        Factory factory2 = (Factory) found1;
        @SuppressWarnings("unchecked")
        ProxyInterceptor<CompleteBean> interceptor2 = (ProxyInterceptor<CompleteBean>) factory2.getCallback(0);

        CompleteBean target2 = (CompleteBean) interceptor2.getTarget();

        assertThat(target2.getLabel()).isNull();
        assertThat(target2.getWelcomeTweet()).isNull();

        if (found1.getId().equals(entity1.getId())) {
            CompleteBean reference = entity1;

            assertThat(Factory.class.isAssignableFrom(found1.getClass())).isTrue();
            assertThat(found1.getId()).isEqualTo(reference.getId());
            assertThat(found1.getName()).isEqualTo(reference.getName());
            assertThat(found1.getAge()).isEqualTo(reference.getAge());
            assertThat(found1.getFriends()).containsAll(reference.getFriends());
            assertThat(found1.getFollowers()).containsAll(reference.getFollowers());
            assertThat(found1.getPreferences().get(1)).isEqualTo("FR");
            assertThat(found1.getPreferences().get(2)).isEqualTo("Paris");
            assertThat(found1.getPreferences().get(3)).isEqualTo("75014");

            reference = entity2;

            assertThat(Factory.class.isAssignableFrom(found2.getClass())).isTrue();
            assertThat(found2.getId()).isEqualTo(reference.getId());
            assertThat(found2.getName()).isEqualTo(reference.getName());
            assertThat(found2.getAge()).isEqualTo(reference.getAge());
            assertThat(found2.getFriends()).containsAll(reference.getFriends());
            assertThat(found2.getFollowers()).containsAll(reference.getFollowers());
            assertThat(found2.getPreferences().get(1)).isEqualTo("US");
            assertThat(found2.getPreferences().get(2)).isEqualTo("NewYork");
        } else {
            CompleteBean reference = entity2;

            assertThat(Factory.class.isAssignableFrom(found1.getClass())).isTrue();
            assertThat(found1.getId()).isEqualTo(reference.getId());
            assertThat(found1.getName()).isEqualTo(reference.getName());
            assertThat(found1.getFriends()).containsAll(reference.getFriends());
            assertThat(found1.getFollowers()).containsAll(reference.getFollowers());
            assertThat(found1.getPreferences().get(1)).isEqualTo("US");
            assertThat(found1.getPreferences().get(2)).isEqualTo("NewYork");

            reference = entity1;

            assertThat(Factory.class.isAssignableFrom(found2.getClass())).isTrue();
            assertThat(found2.getId()).isEqualTo(reference.getId());
            assertThat(found2.getName()).isEqualTo(reference.getName());
            assertThat(found2.getFriends()).containsAll(reference.getFriends());
            assertThat(found2.getFollowers()).containsAll(reference.getFollowers());
            assertThat(found2.getPreferences().get(1)).isEqualTo("FR");
            assertThat(found2.getPreferences().get(2)).isEqualTo("Paris");
            assertThat(found2.getPreferences().get(3)).isEqualTo("75014");
        }
    }
View Full Code Here

TOP

Related Classes of info.archinnov.achilles.test.integration.entity.CompleteBean

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.