Search in sources :

Example 1 with MyInt

use of com.beanit.asn1bean.compiler.modules.module1.MyInt in project jasn1 by openmuc.

the class ModulesTest method encodingDecoding.

@Test
public void encodingDecoding() throws IOException {
    ReverseByteArrayOutputStream berOS = new ReverseByteArrayOutputStream(1000);
    MyDate1 dateOfHire = new MyDate1();
    dateOfHire.value = "19710917".getBytes(UTF_8);
    dateOfHire.encode(berOS, true);
    MyInt2 myInt2Encode = new MyInt2(2);
    berOS.reset();
    myInt2Encode.encode(berOS, true);
    MyInt2 myInt2Decode = new MyInt2();
    byte[] code = HexString.toBytes("a303020102");
    InputStream is = new ByteArrayInputStream(code);
    myInt2Decode.decode(is, true);
    assertEquals(myInt2Decode.value.intValue(), 2);
    PersonnelRecord pr = new PersonnelRecord();
    Name name = new Name();
    name.setGivenName(new BerVisibleString("givenName".getBytes(UTF_8)));
    name.setFamilyName(new BerVisibleString("familyName".getBytes(UTF_8)));
    name.setInitial(new BerVisibleString("initial".getBytes(UTF_8)));
    pr.setName(name);
    pr.setTitle(new BerVisibleString("title".getBytes(UTF_8)));
    pr.setNumber(new EmployeeNumberZ(1));
    pr.setDateOfHire(new Date("23121981".getBytes(UTF_8)));
    pr.setNameOfSpouse(name);
    ChildInformation child = new ChildInformation();
    child.setName(new Name("child name".getBytes(UTF_8)));
    child.setDateOfBirth(new Date("12121912".getBytes(UTF_8)));
    PersonnelRecord.Children children = new PersonnelRecord.Children();
    List<ChildInformation> childInformation = children.getChildInformation();
    childInformation.add(child);
    childInformation.add(child);
    pr.setTestBitString(new MyBitString(new byte[] { (byte) 0x80, (byte) 0xff }, 10));
    pr.setTest(new MyInt(3));
    TestChoice testChoice = new TestChoice();
    testChoice.setChoiceElement1(child);
    pr.setTest2(testChoice);
    pr.setTest3(testChoice);
    pr.setTest4(testChoice);
    pr.setTest5(testChoice);
    pr.setTest6(testChoice);
    TestSequenceOf testSequenceOf = new TestSequenceOf();
    List<BerInteger> berIntegers = testSequenceOf.getBerInteger();
    for (int i = 0; i < 10; i++) {
        berIntegers.add(new BerInteger(i));
    }
    pr.setTestSequenceOf(testSequenceOf);
    PersonnelRecord.TestSequenceOf2 testSequenceOf2 = new PersonnelRecord.TestSequenceOf2();
    List<PersonnelRecord.TestSequenceOf2.SEQUENCE> sequences = testSequenceOf2.getSEQUENCE();
    for (int i = 0; i < 10; i++) {
        PersonnelRecord.TestSequenceOf2.SEQUENCE sequence = new PersonnelRecord.TestSequenceOf2.SEQUENCE();
        sequence.setTest1(new BerInteger(i++));
        sequence.setTest2(new BerInteger(i));
        sequences.add(sequence);
    }
    pr.setTestSequenceOf2(testSequenceOf2);
    BerEmbeddedPdv berEmbeddedPdv = new BerEmbeddedPdv();
    pr.setEmbeddedPdv(berEmbeddedPdv);
}
Also used : PersonnelRecord(com.beanit.asn1bean.compiler.modules.module1.PersonnelRecord) EmployeeNumberZ(com.beanit.asn1bean.compiler.modules.module2.EmployeeNumberZ) ReverseByteArrayOutputStream(com.beanit.asn1bean.ber.ReverseByteArrayOutputStream) Name(com.beanit.asn1bean.compiler.modules.module1.Name) BerEmbeddedPdv(com.beanit.asn1bean.ber.types.BerEmbeddedPdv) BerVisibleString(com.beanit.asn1bean.ber.types.string.BerVisibleString) MyBitString(com.beanit.asn1bean.compiler.modules.module1.MyBitString) ChildInformation(com.beanit.asn1bean.compiler.modules.module1.ChildInformation) TestSequenceOf(com.beanit.asn1bean.compiler.modules.module1.TestSequenceOf) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) TestChoice(com.beanit.asn1bean.compiler.modules.module1.TestChoice) BerInteger(com.beanit.asn1bean.ber.types.BerInteger) Date(com.beanit.asn1bean.compiler.modules.module1.Date) MyDate1(com.beanit.asn1bean.compiler.modules.module1.MyDate1) ByteArrayInputStream(java.io.ByteArrayInputStream) MyInt(com.beanit.asn1bean.compiler.modules.module1.MyInt) MyInt2(com.beanit.asn1bean.compiler.modules.module1.MyInt2) Test(org.junit.jupiter.api.Test)

Example 2 with MyInt

use of com.beanit.asn1bean.compiler.modules.module1.MyInt in project jasn1 by openmuc.

the class ModulesTest method encodingDecoding.

@Test
public void encodingDecoding() throws IOException {
    ReverseByteArrayOutputStream berOS = new ReverseByteArrayOutputStream(1000);
    MyDate1 dateOfHire = new MyDate1();
    // MyDate1 dateOfHire = new MyDate1("19710917");
    dateOfHire.value = new String("19710917").getBytes();
    dateOfHire.encode(berOS, true);
    MyInt2 myInt2Encode = new MyInt2(2);
    berOS.reset();
    myInt2Encode.encode(berOS, true);
    MyInt2 myInt2Decode = new MyInt2();
    byte[] code = HexConverter.fromShortHexString("a303020102");
    InputStream is = new ByteArrayInputStream(code);
    myInt2Decode.decode(is, true);
    Assert.assertEquals(myInt2Decode.value.intValue(), 2);
    PersonnelRecord pr = new PersonnelRecord();
    Name name = new Name();
    name.setGivenName(new BerVisibleString("givenName".getBytes()));
    name.setFamilyName(new BerVisibleString("familyName".getBytes()));
    name.setInitial(new BerVisibleString("initial".getBytes()));
    pr.setName(name);
    pr.setTitle(new BerVisibleString("title".getBytes()));
    pr.setNumber(new EmployeeNumberZ(1));
    pr.setDateOfHire(new Date("23121981".getBytes()));
    pr.setNameOfSpouse(name);
    ChildInformation child = new ChildInformation();
    child.setName(new Name("child name".getBytes()));
    child.setDateOfBirth(new Date("12121912".getBytes()));
    PersonnelRecord.Children children = new PersonnelRecord.Children();
    List<ChildInformation> childInformation = children.getChildInformation();
    childInformation.add(child);
    childInformation.add(child);
    pr.setTestBitString(new MyBitString(new byte[] { (byte) 0x80, (byte) 0xff }, 10));
    pr.setTest(new MyInt(3));
    TestChoice testChoice = new TestChoice();
    testChoice.setChoiceElement1(child);
    pr.setTest2(testChoice);
    pr.setTest3(testChoice);
    pr.setTest4(testChoice);
    pr.setTest5(testChoice);
    pr.setTest6(testChoice);
    TestSequenceOf testSequenceOf = new TestSequenceOf();
    List<BerInteger> berIntegers = testSequenceOf.getBerInteger();
    for (int i = 0; i < 10; i++) {
        berIntegers.add(new BerInteger(i));
    }
    pr.setTestSequenceOf(testSequenceOf);
    TestSequenceOf2 testSequenceOf2 = new TestSequenceOf2();
    List<SEQUENCE> sequences = testSequenceOf2.getSEQUENCE();
    for (int i = 0; i < 10; i++) {
        SEQUENCE sequence = new SEQUENCE();
        sequence.setTest1(new BerInteger(i++));
        sequence.setTest2(new BerInteger(i));
        sequences.add(sequence);
    }
    pr.setTestSequenceOf2(testSequenceOf2);
    BerEmbeddedPdv berEmbeddedPdv = new BerEmbeddedPdv();
    pr.setEmbeddedPdv(berEmbeddedPdv);
    System.out.println("PersonnelRecord.toString():\n" + pr);
}
Also used : BerVisibleString(org.openmuc.jasn1.ber.types.string.BerVisibleString) MyBitString(org.openmuc.jasn1.compiler.modules.module1.MyBitString) PersonnelRecord(org.openmuc.jasn1.compiler.modules.module1.PersonnelRecord) EmployeeNumberZ(org.openmuc.jasn1.compiler.modules.module2.EmployeeNumberZ) ReverseByteArrayOutputStream(org.openmuc.jasn1.ber.ReverseByteArrayOutputStream) Name(org.openmuc.jasn1.compiler.modules.module1.Name) BerEmbeddedPdv(org.openmuc.jasn1.ber.types.BerEmbeddedPdv) SEQUENCE(org.openmuc.jasn1.compiler.modules.module1.PersonnelRecord.TestSequenceOf2.SEQUENCE) BerVisibleString(org.openmuc.jasn1.ber.types.string.BerVisibleString) MyBitString(org.openmuc.jasn1.compiler.modules.module1.MyBitString) ChildInformation(org.openmuc.jasn1.compiler.modules.module1.ChildInformation) TestSequenceOf(org.openmuc.jasn1.compiler.modules.module1.TestSequenceOf) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) TestChoice(org.openmuc.jasn1.compiler.modules.module1.TestChoice) BerInteger(org.openmuc.jasn1.ber.types.BerInteger) TestSequenceOf2(org.openmuc.jasn1.compiler.modules.module1.PersonnelRecord.TestSequenceOf2) Date(org.openmuc.jasn1.compiler.modules.module1.Date) MyDate1(org.openmuc.jasn1.compiler.modules.module1.MyDate1) ByteArrayInputStream(java.io.ByteArrayInputStream) MyInt(org.openmuc.jasn1.compiler.modules.module1.MyInt) MyInt2(org.openmuc.jasn1.compiler.modules.module1.MyInt2) Test(org.junit.Test)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 ReverseByteArrayOutputStream (com.beanit.asn1bean.ber.ReverseByteArrayOutputStream)1 BerEmbeddedPdv (com.beanit.asn1bean.ber.types.BerEmbeddedPdv)1 BerInteger (com.beanit.asn1bean.ber.types.BerInteger)1 BerVisibleString (com.beanit.asn1bean.ber.types.string.BerVisibleString)1 ChildInformation (com.beanit.asn1bean.compiler.modules.module1.ChildInformation)1 Date (com.beanit.asn1bean.compiler.modules.module1.Date)1 MyBitString (com.beanit.asn1bean.compiler.modules.module1.MyBitString)1 MyDate1 (com.beanit.asn1bean.compiler.modules.module1.MyDate1)1 MyInt (com.beanit.asn1bean.compiler.modules.module1.MyInt)1 MyInt2 (com.beanit.asn1bean.compiler.modules.module1.MyInt2)1 Name (com.beanit.asn1bean.compiler.modules.module1.Name)1 PersonnelRecord (com.beanit.asn1bean.compiler.modules.module1.PersonnelRecord)1 TestChoice (com.beanit.asn1bean.compiler.modules.module1.TestChoice)1 TestSequenceOf (com.beanit.asn1bean.compiler.modules.module1.TestSequenceOf)1 EmployeeNumberZ (com.beanit.asn1bean.compiler.modules.module2.EmployeeNumberZ)1 Test (org.junit.Test)1 Test (org.junit.jupiter.api.Test)1 ReverseByteArrayOutputStream (org.openmuc.jasn1.ber.ReverseByteArrayOutputStream)1