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

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


  private PersistenceManager manager = resource.getPersistenceManager();

  @Test
  public void should_remove_proxy_from_entity() throws Exception {
    CompleteBean bean = CompleteBeanTestBuilder.builder().randomId().name("Jonathan").buid();
    Tweet tweet = TweetTestBuilder.tweet().randomId().content("tweet").buid();
    bean.setWelcomeTweet(tweet);

    bean = manager.insert(bean);

    bean = manager.removeProxy(bean);
View Full Code Here


    private Session session = manager.getNativeSession();

    @Test
    public void should_persist() throws Exception {

        CompleteBean entity = CompleteBeanTestBuilder.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();

        manager.insert(entity);

        Row row = session.execute("select name,age_in_years,friends,followers,preferences from completebean where id = "
                + entity.getId()).one();

        assertThat(row.getLong("age_in_years")).isEqualTo(35L);
        assertThat(row.getList("friends", String.class)).containsExactly("foo", "bar");
        assertThat(row.getSet("followers", String.class)).containsOnly("George", "Paul");

        Map<Integer, String> preferences = row.getMap("preferences", Integer.class, String.class);

        assertThat(preferences).containsKey(1);
        assertThat(preferences).containsKey(2);
        assertThat(preferences).containsKey(3);

        assertThat(preferences).containsValue("FR");
        assertThat(preferences).containsValue("Paris");
        assertThat(preferences).containsValue("75014");

        row = session.execute(
                "select counter_value from achilles_counter_table where fqcn = '"
                        + CompleteBean.class.getCanonicalName() + "' and primary_key='" + entity.getId()
                        + "' and property_name='version'").one();

        assertThat(row.getLong("counter_value")).isEqualTo(15L);

    }
View Full Code Here

    }

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

        manager.insert(entity);

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

        assertThat(found).isNotNull();
        assertThat(found.getId()).isEqualTo(entity.getId());
        assertThat(found.getFriends()).isNotNull().isEmpty();
        assertThat(found.getFollowers()).isNull();
        assertThat(found.getPreferences()).isNull();
    }
View Full Code Here

        assertThat(found.getPreferences()).isNull();
    }

    @Test
    public void should_overwrite_existing_values_on_persist() throws Exception {
        CompleteBean entity = CompleteBeanTestBuilder.builder().randomId().name("DuyHai")
                .addFriends("foo", "bar", "qux").addFollowers("John", "Helen").addPreference(1, "Paris")
                .addPreference(2, "Ile de France").addPreference(3, "FRANCE").buid();

        manager.insert(entity);

        entity.getFriends().clear();
        entity.getFollowers().clear();
        entity.getPreferences().clear();

        // Should clean collections & maps before persisting again
        manager.insert(entity);

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

        assertThat(entity.getFriends()).isNotNull().isEmpty();
        assertThat(entity.getFollowers()).isNull();
        assertThat(entity.getPreferences()).isNull();

    }
View Full Code Here

    }

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

        //When
        manager.insertOrUpdate(entity);

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

        //Then
        assertThat(found).isNotNull();
        assertThat(found.getName()).isEqualTo("DuyHai");

        //When
        found.setName("Paul");
        manager.insertOrUpdate(found);

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

        //Then
        assertThat(updated).isNotNull();
        assertThat(found.getName()).isEqualTo("Paul");
View Full Code Here

    }

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

        manager.insert(entity);

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

        assertThat(found).isNotNull();
        assertThat(found.getName()).isEqualTo("Jonathan");
    }
View Full Code Here

        assertThat(found.getName()).isEqualTo("Jonathan");
    }

    @Test
    public void should_update_modifications() throws Exception {
        CompleteBean entity = CompleteBeanTestBuilder.builder().randomId().name("Jonathan").age(40L)
                .addFriends("bob", "alice").addFollowers("Billy", "Stephen", "Jacky").addPreference(1, "US")
                .addPreference(2, "New York").buid();
        CompleteBean managed = manager.insert(entity);

        managed.setAge(100L);
        managed.getFriends().add("eve");
        managed.getPreferences().put(1, "FR");

        manager.update(managed);

        Row row = session.execute("select * from completebean where id=" + entity.getId()).one();

View Full Code Here

        assertThat(preferences.get(2)).isEqualTo("New York");
    }

    @Test
    public void should_delete_property_after_merge() throws Exception {
        CompleteBean entity = CompleteBeanTestBuilder.builder().randomId().name("Jonathan").age(40L)
                .addFriends("bob", "alice").addFollowers("Billy", "Stephen", "Jacky").addPreference(1, "US")
                .addPreference(2, "New York").buid();
        manager.insert(entity);

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

        found.setName(null);
        found.setFriends(null);
        found.setFollowers(null);
        found.setPreferences(null);

        manager.update(found);

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

        assertThat(found.getName()).isNull();
        assertThat(found.getFriends()).isNotNull().isEmpty();
        assertThat(found.getFollowers()).isNull();
        assertThat(found.getPreferences()).isNull();

    }
View Full Code Here

    }

    @Test
    public void should_exception_when_trying_to_modify_primary_key() throws Exception {
        CompleteBean entity = CompleteBeanTestBuilder.builder().randomId().name("Jonathan").age(40L)
                .addFriends("bob", "alice").addFollowers("Billy", "Stephen", "Jacky").addPreference(1, "US")
                .addPreference(2, "New York").buid();

        entity = manager.insert(entity);

        exception.expect(IllegalAccessException.class);
        exception.expectMessage("Cannot change primary key value for existing entity");

        entity.setId(RandomUtils.nextLong(0,Long.MAX_VALUE));
    }
View Full Code Here

        entity.setId(RandomUtils.nextLong(0,Long.MAX_VALUE));
    }

    @Test
    public void should_return_managed_entity_after_persist() throws Exception {
        CompleteBean entity = CompleteBeanTestBuilder.builder().randomId().buid();
        entity = manager.insert(entity);

        assertThat(entity).isInstanceOf(Factory.class);
    }
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.