comment irptest

This commit is contained in:
CaiHQ 2022-05-05 13:44:15 +08:00
parent 1a79df1478
commit 09dd8618d9

View File

@ -0,0 +1,127 @@
package org.bdware.bdserver;
import com.google.gson.Gson;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.bdware.doip.core.exception.IrpClientException;
import org.bdware.doip.core.model.handleRecord.DoHandleRecord;
import org.bdware.doip.core.model.handleRecord.DoipServiceHandleRecord;
import org.bdware.doip.core.model.handleRecord.HandleRecordBase;
import org.bdware.doip.core.utils.GlobalConfigurations;
import org.bdware.doip.endpoint.irpClient.InternalIrpClient;
import org.bdware.doip.endpoint.irpClient.IrpClient;
import org.junit.Before;
import org.junit.Test;
public class IRPTest {
private static final Logger LOGGER = LogManager.getLogger(IRPTest.class);
IrpClient client;
@Before
public void createTestClient() {
GlobalConfigurations.LHS_Address = "http://127.0.0.1:18007/";
client = new InternalIrpClient(null, "86.5000.470/dou.SUPER", GlobalConfigurations.LHS_Address);
}
@Test
public void testReslove() {
HandleRecordBase handleRecordBase = null;
try {
handleRecordBase = client.resolve("86.5000.470/doip.iZWUqzwFtY_bdw");
} catch (IrpClientException e) {
e.printStackTrace();
}
LOGGER.info(new Gson().toJson(handleRecordBase));
}
@Test
public void testRegister() {
DoHandleRecord doHr = new DoHandleRecord(GlobalConfigurations.User_Handle, "null");
DoipServiceHandleRecord doipServiceHandleRecord = new DoipServiceHandleRecord("1", "2", "3", "4", "5");
String handle = "86.5000.470/do.yWkNN8otdv_bdw";
// doHr.handle = handle;
try {
handle = client.register(doipServiceHandleRecord);
LOGGER.debug(handle);
//test resolve
HandleRecordBase handleRecordBase = client.resolve(handle);
LOGGER.info(new Gson().toJson(handleRecordBase));
} catch (IrpClientException e) {
e.printStackTrace();
}
}
@Test
public void testUnregister() {
String handle = "86.5000.470/do.A0gOqH2hup_bdw";
String resp = client.unRegister(handle);
LOGGER.info(resp);
}
@Test
public void testReRegister() {
DoHandleRecord doHr = new DoHandleRecord(GlobalConfigurations.User_Handle, "12345");
String handle = "86.5000.470/do.Y1LnYqyH5F_bdw";
doHr.handle = handle;
try {
handle = client.reRegister(doHr);
LOGGER.debug(handle);
//test resolve
HandleRecordBase handleRecordBase = client.resolve(handle);
LOGGER.debug(new Gson().toJson(handleRecordBase));
} catch (IrpClientException e) {
e.printStackTrace();
}
}
@Test
public void pumpDataIntoLhs() {
DoHandleRecord doHr = new DoHandleRecord(GlobalConfigurations.User_Handle, "null");
DoipServiceHandleRecord doipServiceHandleRecord = new DoipServiceHandleRecord("1", "2", "3", "4", "5");
String handle;
// doHr.handle = handle;
try {
for (int i = 0; i < 20; i++) {
handle = client.register(doipServiceHandleRecord);
LOGGER.info(handle);
handle = client.register(doHr);
LOGGER.info(handle);
}
// handle = client.register(doipServiceHandleRecord);
// logger.debug(handle);
// //test resolve
// HandleRecordBase handleRecordBase = client.resolve(handle);
// logger.info(new Gson().toJson(handleRecordBase));
} catch (IrpClientException e) {
e.printStackTrace();
}
}
// @Test
// public void updateUserHandleRecord(){
// if (Security.getProvider("BC") == null) {
// Security.addProvider(new BouncyCastleProvider());
// }
//
// try {
// GlobalCertifications.loadKeysFromJKS("keys/dou.SUPER.keystore", GlobalConfigurations.certPassword);
// } catch (Exception e) {
// e.printStackTrace();
// }
//
// GlobalIrpClient.useGeneralIrpClient(GlobalCertifications.localKeypair
// , GlobalConfigurations.User_Handle
// , GlobalConfigurations.LHS_Address);
//
// UserHandleRecord usr = new UserHandleRecord(JWK.getJWKFormatPK(GlobalCertifications.getGlobalKeypair().getPublic()),"SUPER USER");
// usr.handle = "86.5000.470/dou.SUPER";
// try {
// String out = client.reRegister(usr);
// logger.debug(out);
// logger.debug("Resolution: " + client.resolve(usr.handle));
// } catch (IrpClientException e) {
// e.printStackTrace();
// }
// }
}