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

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


        batch.batchNativeStatement(statement);

        batch.endBatch();

        //When
        final CompleteBean found = manager.find(CompleteBean.class, id);

        //Then
        assertThat(found.getName()).isEqualTo(name);
    }
View Full Code Here


  public void should_initialize_lazy_properties() throws Exception {
    Tweet tweet = new Tweet();
    tweet.setId(UUIDGen.getTimeUUID());
    tweet.setContent("welcome");

    CompleteBean entity = CompleteBeanTestBuilder.builder().randomId().name("name").label("label").age(45L)
        .addFriends("foo", "bar").welcomeTweet(tweet).version(CounterBuilder.incr(11L)).buid();

    manager.insert(entity);

    CompleteBean foundEntity = manager.find(CompleteBean.class, entity.getId());

    CompleteBean rawEntity = manager.initAndRemoveProxy(foundEntity);

    assertThat(rawEntity.getName()).isEqualTo("name");
    assertThat(rawEntity.getLabel()).isEqualTo("label");
    assertThat(rawEntity.getAge()).isEqualTo(45L);
    assertThat(rawEntity.getFriends()).containsExactly("foo", "bar");
    assertThat(rawEntity.getWelcomeTweet().getContent()).isEqualTo("welcome");
    assertThat(rawEntity.getVersion()).isInstanceOf(InternalCounterImpl.class);
    assertThat(rawEntity.getVersion().get()).isEqualTo(11L);
  }
View Full Code Here

    assertThat(rawEntity.getVersion().get()).isEqualTo(11L);
  }

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

    entity = manager.insert(entity);

    entity.getVersion().incr(2L);

        manager.update(entity);

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

    CompleteBean foundEntity = manager.typedQuery(CompleteBean.class,statement,entity.getId()).getFirst();

    CompleteBean rawEntity = manager.initAndRemoveProxy(foundEntity);

    assertThat(rawEntity.getVersion()).isInstanceOf(InternalCounterImpl.class);
    assertThat(rawEntity.getVersion().get()).isEqualTo(2L);
  }
View Full Code Here

    private PersistenceManager manager = resource.getPersistenceManager();

    @Test
    public void should_return_rows_for_native_query_async() 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);


        final RegularStatement statement = select("name","age_in_years","friends","followers","preferences")
                .from("CompleteBean").where(eq("id", bindMarker("id")));

        final CountDownLatch latch = new CountDownLatch(1);
        final AtomicReference<Object> successSpy = new AtomicReference<>();
        FutureCallback<Object> successCallBack = new FutureCallback<Object>() {
            @Override
            public void onSuccess(Object result) {
                successSpy.getAndSet(result);
                latch.countDown();
            }

            @Override
            public void onFailure(Throwable t) {
                latch.countDown();
            }
        };

        final AchillesFuture<List<TypedMap>> future1 = manager.nativeQuery(statement, entity1.getId()).asyncGet(successCallBack);
        final AchillesFuture<List<TypedMap>> future2 = manager.nativeQuery(statement, entity2.getId()).asyncGet();

        final List<TypedMap> typedMaps1 = future1.get();
        assertThat(typedMaps1).hasSize(1);
        TypedMap typedMap1 = typedMaps1.get(0);
View Full Code Here

        assertThat(exceptionSpy.get()).isNotNull().isInstanceOf(InvalidQueryException.class);
    }

    @Test
    public void should_return_async_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

    }


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

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

        manager.insert(paul);
        manager.insert(john);

        final CountDownLatch latch = new CountDownLatch(2);
        final AtomicReference<Object> successSpy1 = new AtomicReference<>();
        final AtomicReference<Object> successSpy2 = new AtomicReference<>();

        FutureCallback<Object> successCallBack1 = new FutureCallback<Object>() {
            @Override
            public void onSuccess(Object result) {
                successSpy1.getAndSet(result);
                latch.countDown();
            }

            @Override
            public void onFailure(Throwable t) {
                latch.countDown();
            }
        };

        FutureCallback<Object> successCallBack2 = new FutureCallback<Object>() {
            @Override
            public void onSuccess(Object result) {
                successSpy2.getAndSet(result);
                latch.countDown();
            }

            @Override
            public void onFailure(Throwable t) {
                latch.countDown();
            }
        };

        final RegularStatement selectStar = select().from("CompleteBean").where(eq("id", bindMarker("id")));
        final List<CompleteBean> list1 = manager.typedQuery(CompleteBean.class, selectStar, paul.getId()).asyncGet(successCallBack1).get();
        final CompleteBean foundJohn = manager.typedQuery(CompleteBean.class, selectStar, john.getId()).asyncGetFirst(successCallBack2).get();

        assertThat(list1).hasSize(1);

        CompleteBean foundPaul = list1.get(0);

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

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

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

        assertThat(realPaul.getName()).isEqualTo(paul.getName());
        assertThat(realPaul.getAge()).isEqualTo(paul.getAge());
        assertThat(realPaul.getFriends()).containsAll(paul.getFriends());
        assertThat(realPaul.getFollowers()).containsAll(paul.getFollowers());
        assertThat(realPaul.getPreferences().get(1)).isEqualTo("FR");
        assertThat(realPaul.getPreferences().get(2)).isEqualTo("Paris");
        assertThat(realPaul.getPreferences().get(3)).isEqualTo("75014");

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

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

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

        assertThat(realJohn.getName()).isEqualTo(john.getName());
        assertThat(realJohn.getAge()).isEqualTo(john.getAge());
        assertThat(realJohn.getFriends()).containsAll(john.getFriends());
        assertThat(realJohn.getFollowers()).containsAll(john.getFollowers());
        assertThat(realJohn.getPreferences().get(1)).isEqualTo("US");
        assertThat(realJohn.getPreferences().get(2)).isEqualTo("NewYork");

        latch.await();
        Thread.sleep(100);
        assertThat(successSpy1.get()).isNotNull().isInstanceOf(List.class);
        assertThat(successSpy2.get()).isNotNull().isInstanceOf(CompleteBean.class).isNotInstanceOf(Factory.class);
View Full Code Here

    }

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

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

        manager.insert(paul);
        manager.insert(john);

        final CountDownLatch latch = new CountDownLatch(2);
        final AtomicReference<Object> successSpy1 = new AtomicReference<>();
        final AtomicReference<Object> successSpy2 = new AtomicReference<>();

        FutureCallback<Object> successCallBack1 = new FutureCallback<Object>() {
            @Override
            public void onSuccess(Object result) {
                successSpy1.getAndSet(result);
                latch.countDown();
            }

            @Override
            public void onFailure(Throwable t) {
                latch.countDown();
            }
        };

        FutureCallback<Object> successCallBack2 = new FutureCallback<Object>() {
            @Override
            public void onSuccess(Object result) {
                successSpy2.getAndSet(result);
                latch.countDown();
            }

            @Override
            public void onFailure(Throwable t) {
                latch.countDown();
            }
        };

        final RegularStatement selectStar = select().from("CompleteBean").where(eq("id", bindMarker("id")));

        final AchillesFuture<CompleteBean> futurePaul = manager.rawTypedQuery(CompleteBean.class, selectStar, paul.getId()).asyncGetFirst(successCallBack1);
        final AchillesFuture<CompleteBean> futureJohn = manager.rawTypedQuery(CompleteBean.class, selectStar, john.getId()).asyncGetFirst(successCallBack2);

        CompleteBean foundPaul = futurePaul.get();

        assertThat(foundPaul.getName()).isEqualTo(paul.getName());
        assertThat(foundPaul.getAge()).isEqualTo(paul.getAge());
        assertThat(foundPaul.getFriends()).containsAll(paul.getFriends());
        assertThat(foundPaul.getFollowers()).containsAll(paul.getFollowers());
        assertThat(foundPaul.getPreferences().get(1)).isEqualTo("FR");
        assertThat(foundPaul.getPreferences().get(2)).isEqualTo("Paris");
        assertThat(foundPaul.getPreferences().get(3)).isEqualTo("75014");
        assertThat(foundPaul.getVersion()).isNull();

        CompleteBean foundJohn = futureJohn.get();
        assertThat(foundJohn.getName()).isEqualTo(john.getName());
        assertThat(foundJohn.getAge()).isEqualTo(john.getAge());
        assertThat(foundJohn.getFriends()).containsAll(john.getFriends());
        assertThat(foundJohn.getFollowers()).containsAll(john.getFollowers());
        assertThat(foundJohn.getPreferences().get(1)).isEqualTo("US");
        assertThat(foundJohn.getPreferences().get(2)).isEqualTo("NewYork");
        assertThat(foundJohn.getVersion()).isNull();

        latch.await();
        Thread.sleep(100);
        assertThat(successSpy1.get()).isNotNull().isInstanceOf(CompleteBean.class).isNotInstanceOf(Factory.class);
        assertThat(successSpy2.get()).isNotNull().isInstanceOf(CompleteBean.class).isNotInstanceOf(Factory.class);
View Full Code Here


    @Test
    public void should_not_order_batch_statements_for_insert() throws Exception {
        //Given
        CompleteBean entity = CompleteBeanTestBuilder.builder().randomId().buid();
        Batch batch = manager.createBatch();

        //When
        batch.startBatch();

        entity.setName("name3");
        batch.insert(entity);
        entity.setName("name1");
        batch.insert(entity);

        batch.endBatch();
        //Then

        CompleteBean actual = manager.find(CompleteBean.class, entity.getId());

        assertThat(actual.getName()).isEqualTo("name3");
    }
View Full Code Here

    }

    @Test
    public void should_not_order_batch_statements_for_update() throws Exception {
        //Given
        CompleteBean entity = CompleteBeanTestBuilder.builder().randomId().buid();
        Batch batch = manager.createBatch();

        CompleteBean managed = manager.insert(entity);

        //When
        batch.startBatch();

        managed.setName("name3");
        batch.update(managed);
        managed.setName("name1");
        batch.update(managed);

        batch.endBatch();

        //Then
        manager.refresh(managed);

        assertThat(managed.getName()).isEqualTo("name3");
    }
View Full Code Here

            exceptionCaught = true;
        }

        assertThat(exceptionCaught).isTrue();

        CompleteBean newBean = new CompleteBean();
        newBean.setId(id);
        newBean.setName("name");

        manager.insert(newBean);

        newBean = manager.find(CompleteBean.class, newBean.getId());

        assertThat(newBean).isNotNull();
        assertThat(newBean.getName()).isEqualTo("name");
    }
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.