model
This commit is contained in:
@@ -1,115 +1,115 @@
|
||||
package com.loafle;
|
||||
|
||||
|
||||
import com.loafle.overflow.db.api.DBGrpc;
|
||||
import com.loafle.overflow.db.api.DBInput;
|
||||
import com.loafle.overflow.db.api.DBOutput;
|
||||
import io.grpc.ManagedChannel;
|
||||
import io.grpc.ManagedChannelBuilder;
|
||||
import io.grpc.StatusRuntimeException;
|
||||
import org.codehaus.jackson.map.ObjectMapper;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class TestClient {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(TestClient.class.getName());
|
||||
|
||||
private final ManagedChannel channel;
|
||||
private final DBGrpc.DBBlockingStub dbStub;
|
||||
|
||||
public TestClient() {
|
||||
channel = ManagedChannelBuilder.forAddress("127.0.0.1", 50006).usePlaintext(true).build();
|
||||
dbStub = DBGrpc.newBlockingStub(channel);
|
||||
}
|
||||
|
||||
|
||||
public void shutdown() throws InterruptedException {
|
||||
channel.shutdown().awaitTermination(5, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
|
||||
public void execute() {
|
||||
|
||||
try {
|
||||
Member m = new Member();
|
||||
m.setId(Long.parseLong("2"));
|
||||
m.setName("geek");
|
||||
m.setCompany("loafle");
|
||||
m.setDigest("bbbbbbbbb");
|
||||
m.setPwSalt("salktttt");
|
||||
m.setEmail("insanity@loafle.com");
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
DBInput request = DBInput.newBuilder()
|
||||
.setTargetDao("member")
|
||||
.setMethod("findByEmail")
|
||||
.putParams("com.loafle.overflow.member.model.Member", mapper.writeValueAsString(m))
|
||||
//.putParams("id", "1")
|
||||
.build();
|
||||
DBOutput response;
|
||||
try {
|
||||
response = dbStub.exec(request);
|
||||
} catch (StatusRuntimeException e) {
|
||||
logger.log(Level.WARNING, "RPC failed: {0}", e.getStatus());
|
||||
return;
|
||||
}
|
||||
logger.log(Level.INFO, response.getResult());
|
||||
}catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRPCServer() {
|
||||
TestClient client = new TestClient();
|
||||
try {
|
||||
client.execute();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
client.shutdown();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void testClassName() throws ClassNotFoundException, IOException {
|
||||
|
||||
String testRes = "[{\"ip\":3232235882,\"port\":5432,\"targetType\":\"DATABASE\",\"vendorName\":\"PostgreSQL 9.5.0\",\"kinds\":\"PostgreSQL2222\",\"version\":\"9.5.0\",\"createDate\":-62135596800000,\"portType\":\"TCP\",\"member\":{\"id\":1,\"email\":\"\",\"pwSalt\":\"\",\"digest\":\"\",\"name\":\"\",\"company\":\"\",\"phone\":\"\",\"authorizedDate\":0}},{\"ip\":3232235882,\"port\":5432,\"targetType\":\"DATABASE\",\"vendorName\":\"PostgreSQL 9.5.0\",\"kinds\":\"PostgreSQL3333\",\"version\":\"9.5.0\",\"createDate\":-62135596800000,\"portType\":\"TCP\",\"member\":{\"id\":1,\"email\":\"\",\"pwSalt\":\"\",\"digest\":\"\",\"name\":\"\",\"company\":\"\",\"phone\":\"\",\"authorizedDate\":0}},{\"ip\":3232235882,\"port\":5432,\"targetType\":\"DATABASE\",\"vendorName\":\"PostgreSQL 9.5.0\",\"kinds\":\"PostgreSQL4444\",\"version\":\"9.5.0\",\"createDate\":-62135596800000,\"portType\":\"TCP\",\"member\":{\"id\":1,\"email\":\"\",\"pwSalt\":\"\",\"digest\":\"\",\"name\":\"\",\"company\":\"\",\"phone\":\"\",\"authorizedDate\":0}},{\"ip\":3232235882,\"port\":5432,\"targetType\":\"DATABASE\",\"vendorName\":\"PostgreSQL 9.5.0\",\"kinds\":\"PostgreSQL5555\",\"version\":\"9.5.0\",\"createDate\":-62135596800000,\"portType\":\"TCP\",\"member\":{\"id\":1,\"email\":\"\",\"pwSalt\":\"\",\"digest\":\"\",\"name\":\"\",\"company\":\"\",\"phone\":\"\",\"authorizedDate\":0}},{\"ip\":3232235882,\"port\":5432,\"targetType\":\"DATABASE\",\"vendorName\":\"PostgreSQL 9.5.0\",\"kinds\":\"PostgreSQL6666\",\"version\":\"9.5.0\",\"createDate\":-62135596800000,\"portType\":\"TCP\",\"member\":{\"id\":1,\"email\":\"\",\"pwSalt\":\"\",\"digest\":\"\",\"name\":\"\",\"company\":\"\",\"phone\":\"\",\"authorizedDate\":0}}]";
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
Class<?> cls = Class.forName("[L" + "com.loafle.overflow.target.model.Target" + ";");
|
||||
// Class<?> cls = Class.forName("java.util.List<com.loafle.overflow.target.model.Target>");
|
||||
|
||||
Object obj = mapper.readValue(testRes, cls);
|
||||
|
||||
|
||||
List<Object> aa = Arrays.asList((Object[])obj);
|
||||
|
||||
System.out.println(aa.getClass());
|
||||
// List<Target> tl = (List<Target>)aa;
|
||||
|
||||
|
||||
// List<Target> aaa = (List<Target>)obj.;
|
||||
//package com.loafle;
|
||||
//
|
||||
//
|
||||
// for( Target t : aaa) {
|
||||
// System.out.println(t);
|
||||
//import com.loafle.overflow.db.api.DBGrpc;
|
||||
//import com.loafle.overflow.db.api.DBInput;
|
||||
//import com.loafle.overflow.db.api.DBOutput;
|
||||
//import io.grpc.ManagedChannel;
|
||||
//import io.grpc.ManagedChannelBuilder;
|
||||
//import io.grpc.StatusRuntimeException;
|
||||
//import org.codehaus.jackson.map.ObjectMapper;
|
||||
//import org.junit.Test;
|
||||
//
|
||||
//import java.io.IOException;
|
||||
//import java.util.Arrays;
|
||||
//import java.util.List;
|
||||
//import java.util.concurrent.TimeUnit;
|
||||
//import java.util.logging.Level;
|
||||
//import java.util.logging.Logger;
|
||||
//
|
||||
//public class TestClient {
|
||||
//
|
||||
// private static final Logger logger = Logger.getLogger(TestClient.class.getName());
|
||||
//
|
||||
// private final ManagedChannel channel;
|
||||
// private final DBGrpc.DBBlockingStub dbStub;
|
||||
//
|
||||
// public TestClient() {
|
||||
// channel = ManagedChannelBuilder.forAddress("127.0.0.1", 50006).usePlaintext(true).build();
|
||||
// dbStub = DBGrpc.newBlockingStub(channel);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public void shutdown() throws InterruptedException {
|
||||
// channel.shutdown().awaitTermination(5, TimeUnit.SECONDS);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public void execute() {
|
||||
//
|
||||
// try {
|
||||
// Member m = new Member();
|
||||
// m.setId(Long.parseLong("2"));
|
||||
// m.setName("geek");
|
||||
// m.setCompany("loafle");
|
||||
// m.setDigest("bbbbbbbbb");
|
||||
// m.setPwSalt("salktttt");
|
||||
// m.setEmail("insanity@loafle.com");
|
||||
//
|
||||
// ObjectMapper mapper = new ObjectMapper();
|
||||
//
|
||||
// DBInput request = DBInput.newBuilder()
|
||||
// .setTargetDao("member")
|
||||
// .setMethod("findByEmail")
|
||||
// .putParams("com.loafle.overflow.member.model.Member", mapper.writeValueAsString(m))
|
||||
// //.putParams("id", "1")
|
||||
// .build();
|
||||
// DBOutput response;
|
||||
// try {
|
||||
// response = dbStub.exec(request);
|
||||
// } catch (StatusRuntimeException e) {
|
||||
// logger.log(Level.WARNING, "RPC failed: {0}", e.getStatus());
|
||||
// return;
|
||||
// }
|
||||
// logger.log(Level.INFO, response.getResult());
|
||||
// }catch(Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
|
||||
}
|
||||
}
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void testRPCServer() {
|
||||
// TestClient client = new TestClient();
|
||||
// try {
|
||||
// client.execute();
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// } finally {
|
||||
// try {
|
||||
// client.shutdown();
|
||||
// } catch (InterruptedException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
//
|
||||
// @Test
|
||||
// public void testClassName() throws ClassNotFoundException, IOException {
|
||||
//
|
||||
// String testRes = "[{\"ip\":3232235882,\"port\":5432,\"targetType\":\"DATABASE\",\"vendorName\":\"PostgreSQL 9.5.0\",\"kinds\":\"PostgreSQL2222\",\"version\":\"9.5.0\",\"createDate\":-62135596800000,\"portType\":\"TCP\",\"member\":{\"id\":1,\"email\":\"\",\"pwSalt\":\"\",\"digest\":\"\",\"name\":\"\",\"company\":\"\",\"phone\":\"\",\"authorizedDate\":0}},{\"ip\":3232235882,\"port\":5432,\"targetType\":\"DATABASE\",\"vendorName\":\"PostgreSQL 9.5.0\",\"kinds\":\"PostgreSQL3333\",\"version\":\"9.5.0\",\"createDate\":-62135596800000,\"portType\":\"TCP\",\"member\":{\"id\":1,\"email\":\"\",\"pwSalt\":\"\",\"digest\":\"\",\"name\":\"\",\"company\":\"\",\"phone\":\"\",\"authorizedDate\":0}},{\"ip\":3232235882,\"port\":5432,\"targetType\":\"DATABASE\",\"vendorName\":\"PostgreSQL 9.5.0\",\"kinds\":\"PostgreSQL4444\",\"version\":\"9.5.0\",\"createDate\":-62135596800000,\"portType\":\"TCP\",\"member\":{\"id\":1,\"email\":\"\",\"pwSalt\":\"\",\"digest\":\"\",\"name\":\"\",\"company\":\"\",\"phone\":\"\",\"authorizedDate\":0}},{\"ip\":3232235882,\"port\":5432,\"targetType\":\"DATABASE\",\"vendorName\":\"PostgreSQL 9.5.0\",\"kinds\":\"PostgreSQL5555\",\"version\":\"9.5.0\",\"createDate\":-62135596800000,\"portType\":\"TCP\",\"member\":{\"id\":1,\"email\":\"\",\"pwSalt\":\"\",\"digest\":\"\",\"name\":\"\",\"company\":\"\",\"phone\":\"\",\"authorizedDate\":0}},{\"ip\":3232235882,\"port\":5432,\"targetType\":\"DATABASE\",\"vendorName\":\"PostgreSQL 9.5.0\",\"kinds\":\"PostgreSQL6666\",\"version\":\"9.5.0\",\"createDate\":-62135596800000,\"portType\":\"TCP\",\"member\":{\"id\":1,\"email\":\"\",\"pwSalt\":\"\",\"digest\":\"\",\"name\":\"\",\"company\":\"\",\"phone\":\"\",\"authorizedDate\":0}}]";
|
||||
//
|
||||
// ObjectMapper mapper = new ObjectMapper();
|
||||
// Class<?> cls = Class.forName("[L" + "com.loafle.overflow.target.model.Target" + ";");
|
||||
//// Class<?> cls = Class.forName("java.util.List<com.loafle.overflow.target.model.Target>");
|
||||
//
|
||||
// Object obj = mapper.readValue(testRes, cls);
|
||||
//
|
||||
//
|
||||
// List<Object> aa = Arrays.asList((Object[])obj);
|
||||
//
|
||||
// System.out.println(aa.getClass());
|
||||
//// List<Target> tl = (List<Target>)aa;
|
||||
//
|
||||
//
|
||||
//// List<Target> aaa = (List<Target>)obj.;
|
||||
////
|
||||
////
|
||||
//// for( Target t : aaa) {
|
||||
//// System.out.println(t);
|
||||
//// }
|
||||
//
|
||||
// }
|
||||
//}
|
||||
@@ -2,6 +2,7 @@ package com.loafle.overflow.module.member.dao;
|
||||
|
||||
import com.loafle.overflow.AppConfig;
|
||||
import com.loafle.overflow.JdbcConfiguration;
|
||||
import com.loafle.overflow.module.member.model.Member;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -24,8 +25,8 @@ public class MemberDAOTest {
|
||||
Member m = new Member();
|
||||
|
||||
m.setName("insanity2");
|
||||
m.setCompany("loafle");
|
||||
m.setDigest("bbbbbbbbb");
|
||||
m.setCompanyName("loafle");
|
||||
m.setPw("bbbbbbbbb");
|
||||
m.setPwSalt("salktttt");
|
||||
m.setPhone("000-000-0000");
|
||||
m.setEmail("insanity1@loafle.com");
|
||||
|
||||
@@ -1,15 +1,22 @@
|
||||
package com.loafle.overflow.target.dao;
|
||||
|
||||
import com.loafle.overflow.AppConfig;
|
||||
import com.loafle.overflow.JdbcConfiguration;
|
||||
import com.loafle.overflow.module.infra.Infra;
|
||||
import com.loafle.overflow.module.target.dao.TargetDAO;
|
||||
import com.loafle.overflow.module.target.model.Target;
|
||||
import com.loafle.overflow.module.probe.model.Probe;
|
||||
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 java.sql.Timestamp;
|
||||
import java.util.Date;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = {AppConfig.class, JdbcConfiguration.class})
|
||||
public class JPATargetDaoTest {
|
||||
|
||||
@Autowired
|
||||
@@ -28,6 +35,9 @@ public class JPATargetDaoTest {
|
||||
Probe p = new Probe();
|
||||
p.setId(1);
|
||||
|
||||
t.setInfra(i);
|
||||
t.setProbe(p);
|
||||
|
||||
Target ret = repo.save(t);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user