@Test public void shouldSetAppropriateDefaultsWhenNoneSpecified() throws Exception { final String testXmlString = "<types>" + " <type name=\"testType\" primitiveType=\"char\"/>" + "</types>"; final Map<String, Type> map = parseTestXmlWithMap("/types/type", testXmlString); // assert that testType is in map and name of Type is correct assertThat(map.get("testType").name(), is("testType")); // assert defaults for length, variableLength and presence final Type t = map.get("testType"); assertThat(t.presence(), is(Presence.REQUIRED)); final EncodedDataType d = (EncodedDataType)t; assertThat(d.length(), is(1)); assertThat(d.isVariableLength(), is(false)); }
@Test public void shouldHandleSettingAllAttributes() throws Exception { final String testXmlString = "<types>" + " <type name=\"testType\" presence=\"required\" primitiveType=\"char\" length=\"1\" " + "variableLength=\"false\"/>" + "</types>"; final Map<String, Type> map = parseTestXmlWithMap("/types/type", testXmlString); // assert that testType is in map and name of Type is correct final Type t = map.get("testType"); assertThat(t.name(), is("testType")); assertThat(t.presence(), is(Presence.REQUIRED)); final EncodedDataType d = (EncodedDataType)t; assertThat(d.primitiveType(), is(PrimitiveType.CHAR)); assertThat(d.length(), is(1)); assertThat(d.isVariableLength(), is(false)); }
/** * The encodedLength (in octets) of the list of EncodedDataTypes * * @return encodedLength of the compositeType */ public int encodedLength() { int offset = 0; for (final EncodedDataType t : containedTypeList) { if (t.isVariableLength()) { return Token.VARIABLE_LENGTH; } if (t.offsetAttribute() != -1) { offset = t.offsetAttribute(); } offset += t.encodedLength(); } return offset; }