mirror of
https://gitee.com/willfree/min-dev-java.git
synced 2026-10-04 19:42:01 +08:00
add test: KeyLocatorTest
This commit is contained in:
1 parent
025d2f1c62
commit
c8f0e35f1b
4 files changed
+136
-42
No files matched your search
@@ -0,0 +1,100 @@
|
||||
package component;
|
||||
|
||||
import encoding.*;
|
||||
import org.checkerframework.checker.units.qual.K;
|
||||
import org.junit.Test;
|
||||
import packet.PacketException;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/*
|
||||
* @Author: Wang Feng
|
||||
* @Description:
|
||||
* @Version: 1.0.0
|
||||
* @Date: 19:08 2021/3/31
|
||||
* @Copyright: MIN-Group;国家重大科技基础设施——未来网络北大实验室;深圳市信息论与未来网络重点实验室
|
||||
*/
|
||||
public class KeyLocatorTest {
|
||||
@Test
|
||||
public void TestCreateKeyLocatorByString() throws ComponentException {
|
||||
String str="/install/hello/王";
|
||||
KeyLocator got=new KeyLocator(str);
|
||||
System.out.println("keyLocator: "+got.getIdentifier().toUri());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestCreateKeyLocatorByBlock() throws EncoderException, ComponentException, BlockException {
|
||||
Encoder encoder=new Encoder();
|
||||
encoder.encoderReset(new SizeT(Encoder.MaxPacketSize),new SizeT(0));
|
||||
String str="/min/王/123/哈哈哈哈";
|
||||
IdentifierWrapper got=new IdentifierWrapper().createCommonIdentifierByString(str);
|
||||
System.out.println("type: "+got.getTlvType());
|
||||
got.wireEncode(encoder);
|
||||
byte[] rawBuf=encoder.getBuffer();
|
||||
System.out.println("buf: "+ Arrays.toString(rawBuf));
|
||||
// rawBuf[4]=101;
|
||||
byte[] buf2=new byte[rawBuf.length-2];
|
||||
System.arraycopy(rawBuf,2,buf2,0,rawBuf.length-2);
|
||||
System.out.println("buf2: "+ Arrays.toString(buf2));
|
||||
Block block=new Block(new VlInt(203),new VlInt(rawBuf.length-2),buf2,true);
|
||||
block.parseSubElements();
|
||||
System.out.println(block.getSubElements().getBlock(0).getType());
|
||||
// System.out.println(block.getSubElements().getBlock(1).getType());
|
||||
KeyLocator gotKey=new KeyLocator(block);
|
||||
System.out.println(gotKey.getIdentifier().toUri());
|
||||
System.out.println(gotKey.isValid());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestCreateKeyLocatorByComponents() throws ComponentException {
|
||||
IdentifierComponent component=new IdentifierComponent("min");
|
||||
IdentifierComponent component1=new IdentifierComponent("pku");
|
||||
IdentifierComponent component2=new IdentifierComponent("王");
|
||||
IdentifierComponentContainer gotComponent=new IdentifierComponentContainer();
|
||||
gotComponent.addElement(component);
|
||||
gotComponent.addElement(component1);
|
||||
gotComponent.addElement(component2);
|
||||
KeyLocator gotKey=new KeyLocator(gotComponent);
|
||||
System.out.println(gotKey.getIdentifier().toUri());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestCreateKeyLocatorByIdentifier() throws ComponentException, EncoderException {
|
||||
Identifier gotIdentifier=new Identifier("/min/pku/111");
|
||||
KeyLocator gotKey=new KeyLocator(gotIdentifier);
|
||||
System.out.println(gotKey.getIdentifier().toUri());
|
||||
|
||||
IdentifierComponent component=new IdentifierComponent("min");
|
||||
IdentifierComponent component1=new IdentifierComponent("pku");
|
||||
IdentifierComponent component2=new IdentifierComponent(111);
|
||||
IdentifierComponentContainer gotComponent=new IdentifierComponentContainer();
|
||||
gotComponent.addElement(component);
|
||||
gotComponent.addElement(component1);
|
||||
gotComponent.addElement(component2);
|
||||
KeyLocator gotKey1=new KeyLocator(gotComponent);
|
||||
System.out.println(gotKey1.getIdentifier().toUri());
|
||||
|
||||
Encoder encoder=new Encoder();
|
||||
encoder.encoderReset(new SizeT(Encoder.MaxPacketSize),new SizeT(0));
|
||||
gotKey.wireEncode(encoder);
|
||||
System.out.println(Arrays.toString(encoder.getBuffer()));
|
||||
|
||||
Encoder encoder1=new Encoder();
|
||||
encoder1.encoderReset(new SizeT(Encoder.MaxPacketSize),new SizeT(0));
|
||||
gotKey1.wireEncode(encoder1);
|
||||
System.out.println(Arrays.toString(encoder1.getBuffer()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void TestKeyLocator_WireDecode() throws ComponentException, BlockException, EncoderException, PacketException {
|
||||
Identifier gotIdentifier=new Identifier("/min/pku/111");
|
||||
KeyLocator gotKey=new KeyLocator(gotIdentifier);
|
||||
System.out.println(gotKey.getIdentifier().toUri());
|
||||
|
||||
Block block=new SelfEncodingBase().selfWireEncode(gotKey);
|
||||
|
||||
KeyLocator newK=new KeyLocator();
|
||||
newK.wireDecode(block);
|
||||
System.out.println(newK.getIdentifier().toUri());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user