Package com.pv.mf.db.mock

Source Code of com.pv.mf.db.mock.MockBuilderTest

package com.pv.mf.db.mock;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.pv.mf.db.mock.impl.MockBuilderFactory;
import com.pv.mf.db.mock.impl.SelectBuilder;
import com.pv.mf.db.mock.impl.UpdateBuilder;
import com.pv.mf.db.mock.test.db.model.User;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"/mockbuilder-test-ctx.xml" })
public class MockBuilderTest {
  

  
   @Autowired
   private MockBuilderFactory _annotationFactory;
  
   ////
   ////
  
   @Test
   public void buildSelect_MultiObject() {
     
      SelectBuilder builder = (SelectBuilder)_annotationFactory.select();
      User user = builder.mock(User.class);
     
      builder.columns(user.getId(), user.getUserName());
      builder.and(user.getId(), 1L);
     
//      user = builder.mock(User.class);
//     
//      builder.execute();
     
      Assert.assertEquals("pvxuser", user.getUserName());
   }
  
   @Test
   public void save() {
      String name = "test_user";
     
      UpdateBuilder builder = (UpdateBuilder)_annotationFactory.update();
      User user = builder.mock(User.class);
     
//      builder.and(user.getUserName(), name);
//      builder.and(user.getPassword(), "test_password");
     
      user.setUserName(name);
      user.setPassword("test_password");
     
      builder.execute();
     
      getUserByName(name);
   }
  
   public void getUserByName(String name) {
     
      SelectBuilder builder = (SelectBuilder)_annotationFactory.select();
      User user = builder.mock(User.class);
     
      builder.columns(user.getId(), user.getUserName());
      builder.and(user.getUserName(), name);
     
      user = builder.get(User.class);
     
      Assert.assertEquals(name, user.getUserName());
   }
  

}
TOP

Related Classes of com.pv.mf.db.mock.MockBuilderTest

TOP
Copyright © 2018 www.massapi.com. 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.