test
This commit is contained in:
snoop 2017-06-23 20:09:02 +09:00
parent 4d2f8b8cff
commit 6d46f4745e
2 changed files with 103 additions and 0 deletions

View File

@ -85,4 +85,13 @@ public class NoAuthProbeDAOTest {
}
@Test
public void findOne() {
NoAuthProbe noAuthProbe = this.noAuthProbeDAO.findOne(1L);
Assert.assertNotEquals(noAuthProbe, null);
}
}

View File

@ -0,0 +1,94 @@
package com.loafle.overflow.proxy.db;
import com.loafle.overflow.AppConfig;
import com.loafle.overflow.JdbcConfiguration;
import com.loafle.overflow.module.domain.dao.DomainDAO;
import com.loafle.overflow.module.domain.model.Domain;
import com.loafle.overflow.module.noauthprobe.dao.NoAuthProbeDAO;
import com.loafle.overflow.module.noauthprobe.model.NoAuthProbe;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.*;
/**
* Created by root on 17. 6. 23.
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {AppConfig.class, JdbcConfiguration.class})
public class DBProxyTest {
@Autowired
private DomainDAO domainDAO;
@Autowired
private NoAuthProbeDAO noAuthProbeDAO;
@Test
public void RelfetMehotds() {
JpaRepository jpa = this.noAuthProbeDAO;
Method[] mArray = jpa.getClass().getMethods();
for (Method m : mArray) {
if( m.getName().equals("findOne")) {
System.out.println(m.getParameterTypes());
}
}
}
@Test
public void RelfectMethod() throws InvocationTargetException, IllegalAccessException {
JpaRepository jpa = this.noAuthProbeDAO;
Method m = getMethod(jpa.getClass(), "findOne");
Assert.assertNotEquals(m, null);
// Domain domain = new Domain();
//
// domain.setName("snoop's domain");
List<Object> valueList = new ArrayList<Object>();
valueList.add(1L);
Object o = m.invoke(jpa, valueList.toArray(new Object[valueList.size()]));
System.out.println(o);
}
public Method getMethod(Class jpa, String methodName) {
if (jpa == null) {
return null;
}
Method m = null;
try {
m = jpa.getMethod(methodName, java.io.Serializable.class);
} catch (NoSuchMethodException e) {
System.out.println("super");
return getMethod(jpa.getSuperclass(), methodName);
}
return m;
}
}