mirror of
https://gitee.com/willfree/min-dev-java.git
synced 2026-10-04 19:42:01 +08:00
add test: IdentifierWrapper
This commit is contained in:
1 parent
e0f36a740e
commit
2d4a57beeb
5 files changed
+189
-11
No files matched your search
@@ -1,7 +1,6 @@
|
||||
package component;
|
||||
|
||||
import org.junit.Test;
|
||||
import util.ByteHelper;
|
||||
import util.StringHelper;
|
||||
|
||||
/*
|
||||
|
||||
@@ -0,0 +1,170 @@
|
||||
package component;
|
||||
|
||||
import encoding.*;
|
||||
import org.junit.Test;
|
||||
import util.ByteHelper;
|
||||
|
||||
/*
|
||||
* @Author: Wang Feng
|
||||
* @Description:
|
||||
* @Version: 1.0.0
|
||||
* @Date: 16:04 2021/3/29
|
||||
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
*/
|
||||
public class IdentifierWrapperTest {
|
||||
|
||||
@Test
|
||||
public void TestCreateCustomIdentifierByString() throws ComponentException {
|
||||
String str="/min/pku/王锋";
|
||||
VlInt tlvType=new VlInt(199);
|
||||
IdentifierWrapper got=new IdentifierWrapper(tlvType,str);
|
||||
System.out.println(got.isValid());
|
||||
System.out.println(got.toUri());
|
||||
System.out.println(got.getIdentifier().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestCreateCustomIdentifierByComponents() throws ComponentException {
|
||||
IdentifierComponentContainer components=new IdentifierComponentContainer();
|
||||
String[] componentStrings="/min/pku/王锋".split("/");
|
||||
// System.out.println(componentStrings.toString());
|
||||
for (int i = 1; i < componentStrings.length; i++) {
|
||||
System.out.println(componentStrings[i]);
|
||||
components.addElement(new IdentifierComponent(componentStrings[i]));
|
||||
}
|
||||
VlInt tlvType=new VlInt(110);
|
||||
IdentifierWrapper got=new IdentifierWrapper(tlvType,components);
|
||||
System.out.println(got.isValid());
|
||||
System.out.println(got.toUri());
|
||||
System.out.println(got.getIdentifier().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestCreateCustomIdentifierByBlock() throws BlockException, ComponentException {
|
||||
byte[] buf=new byte[8000];
|
||||
buf[0]=100;
|
||||
buf[1]= ByteHelper.uint8ToByte(241);
|
||||
System.arraycopy(ByteHelper.uint16ToByteArray(7996),0,buf,2,2);
|
||||
VlInt tlvType=new VlInt(103);
|
||||
Block block=new Block(new VlInt(101),new VlInt(8000),buf,true);
|
||||
IdentifierWrapper got=new IdentifierWrapper(tlvType,block);
|
||||
System.out.println(got.isValid());
|
||||
System.out.println(got.toUri());
|
||||
System.out.println(got.getIdentifier().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestCreateCommonIdentifierByString() throws ComponentException {
|
||||
String str="/min/pku/王锋";
|
||||
IdentifierWrapper got=new IdentifierWrapper().createCommonIdentifierByString(str);
|
||||
System.out.println(got.isValid());
|
||||
System.out.println(got.toUri());
|
||||
System.out.println(got.getIdentifier().size());
|
||||
System.out.println(got.getTlvType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestCreateCommonIdentifierByComponents() throws ComponentException {
|
||||
IdentifierComponentContainer components=new IdentifierComponentContainer();
|
||||
String[] componentStrings="/min/pku/王锋".split("/");
|
||||
// System.out.println(componentStrings.toString());
|
||||
for (int i = 1; i < componentStrings.length; i++) {
|
||||
System.out.println(componentStrings[i]);
|
||||
components.addElement(new IdentifierComponent(componentStrings[i]));
|
||||
}
|
||||
IdentifierWrapper got=new IdentifierWrapper().createCommonIdentifierByComponents(components);
|
||||
System.out.println(got.isValid());
|
||||
System.out.println(got.toUri());
|
||||
System.out.println(got.getIdentifier().size());
|
||||
System.out.println(got.getTlvType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestCreateContentDataIdentifierByStringg() throws ComponentException {
|
||||
String str="/min/pku/王锋";
|
||||
IdentifierWrapper got=new IdentifierWrapper().createContentDataIdentifierByString(str);
|
||||
System.out.println(got.isValid());
|
||||
System.out.println(got.toUri());
|
||||
System.out.println(got.getIdentifier().size());
|
||||
System.out.println(got.getTlvType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestCreateContentDataIdentifierByComponents() throws ComponentException {
|
||||
IdentifierComponentContainer components=new IdentifierComponentContainer();
|
||||
String[] componentStrings="/min/pku/王锋".split("/");
|
||||
// System.out.println(componentStrings.toString());
|
||||
for (int i = 1; i < componentStrings.length; i++) {
|
||||
System.out.println(componentStrings[i]);
|
||||
components.addElement(new IdentifierComponent(componentStrings[i]));
|
||||
}
|
||||
IdentifierWrapper got=new IdentifierWrapper().createContentDataIdentifierByComponents(components);
|
||||
System.out.println(got.isValid());
|
||||
System.out.println(got.toUri());
|
||||
System.out.println(got.getIdentifier().size());
|
||||
System.out.println(got.getTlvType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestIdentifierWrapper_WireEncode() throws ComponentException, EncoderException, BlockException {
|
||||
byte[] buf=new byte[8000];
|
||||
buf[0]=100;
|
||||
buf[1]= ByteHelper.uint8ToByte(241);
|
||||
System.arraycopy(ByteHelper.uint16ToByteArray(7996),0,buf,2,2);
|
||||
|
||||
VlInt tlvType=new VlInt(103);
|
||||
Block block=new Block(new VlInt(101),new VlInt(8000),buf,true);
|
||||
IdentifierWrapper got=new IdentifierWrapper(tlvType,block);
|
||||
|
||||
System.out.println(got.isValid());
|
||||
System.out.println(got.toUri());
|
||||
System.out.println(got.getIdentifier().size());
|
||||
System.out.println(got.getTlvType());
|
||||
|
||||
Encoder encoder=new Encoder();
|
||||
encoder.encoderReset(new SizeT(Encoder.MaxPacketSize),new SizeT(0));
|
||||
got.wireEncode(encoder);
|
||||
byte[] rawBuf=encoder.getBuffer();
|
||||
Block rawBlock=new Block(rawBuf,false);
|
||||
IdentifierWrapper gt=new IdentifierWrapper();
|
||||
gt.wireDecode(rawBlock);
|
||||
System.out.println(gt.isValid());
|
||||
System.out.println(gt.toUri());
|
||||
System.out.println(gt.getIdentifier().size());
|
||||
System.out.println(gt.getTlvType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestCreateContentDataIdentifierByBlock() throws BlockException, ComponentException {
|
||||
byte[] buf=new byte[8000];
|
||||
buf[0]=100;
|
||||
buf[1]= ByteHelper.uint8ToByte(241);
|
||||
System.arraycopy(ByteHelper.uint16ToByteArray(7996),0,buf,2,2);
|
||||
VlInt tlvType=new VlInt(103);
|
||||
Block block=new Block(new VlInt(101),new VlInt(8000),buf,true);
|
||||
IdentifierWrapper got=new IdentifierWrapper().createContentDataIdentifierByBlock(block);
|
||||
System.out.println(got.isValid());
|
||||
System.out.println(got.toUri());
|
||||
System.out.println(got.getIdentifier().size());
|
||||
System.out.println(got.getTlvType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestCreateInterestDataIdentifierByStringg() throws ComponentException {
|
||||
String str="/min/pku/王";
|
||||
IdentifierWrapper got=new IdentifierWrapper().createContentInterestIdentifierByString(str);
|
||||
System.out.println(got.isValid());
|
||||
System.out.println(got.toUri());
|
||||
System.out.println(got.getIdentifier().size());
|
||||
System.out.println(got.getTlvType());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestCreateIdentifierWrapperByTypeAndIdentifier() throws ComponentException {
|
||||
Identifier identifier=new Identifier("/min/pku/王");
|
||||
for (int i = 100; i < 200; i++) {
|
||||
IdentifierWrapper got=new IdentifierWrapper(new VlInt(i),identifier);
|
||||
System.out.println(got.toUri());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user