Package org.apache.ibatis.domain.blog

Examples of org.apache.ibatis.domain.blog.Author


    }
  }

  @Test
  public void shouldSetAndGetProperties() {
    MetaObject object = SystemMetaObject.forObject(new Author());
    object.setValue("email", "test");
    assertEquals("test", object.getValue("email"));

  }
View Full Code Here


  }

  @Test
  public void shouldVerifyPropertyTypes() {
    MetaObject object = SystemMetaObject.forObject(new Author());
    assertEquals(6, object.getSetterNames().length);
    assertEquals(int.class, object.getGetterType("id"));
    assertEquals(String.class, object.getGetterType("username"));
    assertEquals(String.class, object.getGetterType("password"));
    assertEquals(String.class, object.getGetterType("email"));
View Full Code Here

    assertNull(metaMap.getValue("phone.home"));
  }

  @Test
  public void shouldNotUseObjectWrapperFactoryByDefault() {
    MetaObject meta = SystemMetaObject.forObject(new Author());
    assertTrue(!meta.getObjectWrapper().getClass().equals(CustomBeanWrapper.class));
  }
View Full Code Here

    assertTrue(!meta.getObjectWrapper().getClass().equals(CustomBeanWrapper.class));
  }

  @Test
  public void shouldUseObjectWrapperFactoryWhenSet() {
    MetaObject meta = MetaObject.forObject(new Author(), SystemMetaObject.DEFAULT_OBJECT_FACTORY, new CustomBeanWrapperFactory());
    assertTrue(meta.getObjectWrapper().getClass().equals(CustomBeanWrapper.class));
   
    // Make sure the old default factory is in place and still works
    meta = SystemMetaObject.forObject(new Author());
    assertFalse(meta.getObjectWrapper().getClass().equals(CustomBeanWrapper.class));
  }
View Full Code Here

  }

  @Test
  public void testThatNestedQueryItemsAreRetrievedFromCache() throws Exception {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    final Author author;
    try {
      final AuthorMapper authorMapper = sqlSession.getMapper(AuthorMapper.class);
      author = authorMapper.selectAuthor(101);
     
      // ensure that author is cached
      final Author cachedAuthor = authorMapper.selectAuthor(101);
      assertThat("cached author", author, sameInstance(cachedAuthor));
    } finally {
      sqlSession.close();
    }
View Full Code Here

  }
 
  @Test
  public void testThatNestedQueryItemsAreRetrievedIfNotInCache() throws Exception {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    Author author = null;
    try {
      final BlogMapper blogMapper = sqlSession.getMapper(BlogMapper.class);
      author = blogMapper.selectBlog(1).getAuthor();
     
      // ensure that nested author within blog is cached
      assertNotNull("blog author", blogMapper.selectBlog(1).getAuthor());
      assertNotNull("blog author", blogMapper.selectBlogUsingConstructor(1).getAuthor());
    } finally {
      sqlSession.close();
    }

    // open a new session
    sqlSession = sqlSessionFactory.openSession();   
    try {
      final AuthorMapper authorMapper = sqlSession.getMapper(AuthorMapper.class);
      Author cachedAuthor = authorMapper.selectAuthor(101);

      // ensure that nested author within blog is cached
      assertThat("blog author", cachedAuthor, sameInstance(author));
     
    } finally {
View Full Code Here

  @Test
  public void shouldInsertAuthorWithSelectKey() {
    SqlSession session = sqlSessionFactory.openSession();
    try {
      BoundAuthorMapper mapper = session.getMapper(BoundAuthorMapper.class);
      Author author = new Author(-1, "cbegin", "******", "cbegin@nowhere.com", "N/A", Section.NEWS);
      int rows = mapper.insertAuthor(author);
      assertEquals(1, rows);
      session.rollback();
    } finally {
      session.close();
View Full Code Here

  @Test
  public void shouldInsertAuthorWithSelectKeyAndDynamicParams() {
    SqlSession session = sqlSessionFactory.openSession();
    try {
      BoundAuthorMapper mapper = session.getMapper(BoundAuthorMapper.class);
      Author author = new Author(-1, "cbegin", "******", "cbegin@nowhere.com", "N/A", Section.NEWS);
      int rows = mapper.insertAuthorDynamic(author);
      assertEquals(1, rows);
      assertFalse(-1 == author.getId()); // id must be autogenerated
      Author author2 = mapper.selectAuthor(author.getId());
      assertNotNull(author2);
      assertEquals(author.getEmail(), author2.getEmail());
      session.rollback();
    } finally {
      session.close();
    }
  }
View Full Code Here

      BoundBlogMapper mapper = session.getMapper(BoundBlogMapper.class);
      Blog blog = mapper.selectBlogUsingConstructorWithResultMapAndProperties(1);
      assertEquals(1, blog.getId());
      assertEquals("Jim Business", blog.getTitle());
      assertNotNull("author should not be null", blog.getAuthor());
      Author author = blog.getAuthor();
      assertEquals(101, author.getId());
      assertEquals("jim@ibatis.apache.org", author.getEmail());
      assertEquals("jim", author.getUsername());
      List<Post> posts = blog.getPosts();
      assertTrue("posts should not be empty", posts != null);
      assertEquals(2, posts.size());
    } finally {
      session.close();
View Full Code Here

  @Test
  public void shouldSelectOneAuthor() {
    SqlSession session = sqlSessionFactory.openSession();
    try {
      BoundAuthorMapper mapper = session.getMapper(BoundAuthorMapper.class);
      Author author = mapper.selectAuthor(101);
      assertEquals(101, author.getId());
      assertEquals("jim", author.getUsername());
      assertEquals("********", author.getPassword());
      assertEquals("jim@ibatis.apache.org", author.getEmail());
      assertEquals("", author.getBio());
    } finally {
      session.close();
    }
  }
View Full Code Here

TOP

Related Classes of org.apache.ibatis.domain.blog.Author

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.