[RM] Bug NTGDictionaryValidator correction
MODIFY
BackEnd/Service/service-ntg/src/main/java/com/exactpro/sf/configuration/dictionary/impl/NTGDictionaryValidator.java
BackEnd/Service/service-ntg/src/main/java/com/exactpro/sf/configuration/dictionary/impl/NTGDictionaryValidator.java
/******************************************************************************
- * Copyright 2009-2018 Exactpro (Exactpro Systems Limited)
+ * Copyright 2009-2020 Exactpro (Exactpro Systems Limited)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -40,6 +40,7 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import static com.exactpro.sf.common.messages.structures.StructureUtils.getAttributeValue;
import static com.exactpro.sf.services.MessageHelper.FIELD_MESSAGE_TYPE;
@@ -68,7 +69,7 @@ public class NTGDictionaryValidator extends AbstractDictionaryValidator {
private static final String UINT8 = "UInt8";
private static final String UINT16 = "UInt16";
private static final String UINT32 = "UInt32";
- private static final String UINT64 = "UInt64";
+ private static final String UINT64 = "Uint64";
private static final ImmutableBiMap<JavaType, String> POSSIBLE_ATTRIBUTE_TYPE_FOR_FIELD_TYPE = ImmutableBiMap.<JavaType, String>builder()
.put(JavaType.JAVA_LANG_SHORT, UINT8)
@@ -425,31 +426,33 @@ public class NTGDictionaryValidator extends AbstractDictionaryValidator {
IFieldStructure field, String attributeType) {
JavaType fieldType = field.getJavaType();
-
+ String errorMessage = null;
+ if (fieldType == JavaType.JAVA_LANG_INTEGER) {
+ if (!attributeType.equals(UINT8) && !attributeType.equals(UINT16)) {
+ errorMessage = String.format("Use [%s, %s] for Type attribute with current field's type or change field's type to [%s] to use with current Type attribute value",
+ UINT8, UINT16, POSSIBLE_ATTRIBUTE_TYPE_FOR_FIELD_TYPE.inverse().get(attributeType));
+ }
+ } else {
String possibleType = POSSIBLE_ATTRIBUTE_TYPE_FOR_FIELD_TYPE.get(fieldType);
-
- if (possibleType == null || !possibleType.equals(attributeType)) {
-
- String errorMessage;
+ if (!Objects.equals(possibleType, attributeType)) {
if (fieldType == JavaType.JAVA_LANG_BYTE) {
-
String fieldTypeInStringFormat = field.getJavaType().toString();
-
- errorMessage = String.format("Attribute <strong>\"Type\"</strong> value [%s] doesn't match the field type [%s]. Field type [%s] cannot be matched to any unsigned type. Possible value for field type is [%s]",
- attributeType, fieldTypeInStringFormat, fieldTypeInStringFormat, POSSIBLE_ATTRIBUTE_TYPE_FOR_FIELD_TYPE.inverse().get(attributeType));
+ errorMessage = String.format("Field's type [%s] cannot be matched to any unsigned type. Use [%s] for field's type with current Type attribute",
+ fieldTypeInStringFormat, POSSIBLE_ATTRIBUTE_TYPE_FOR_FIELD_TYPE.inverse().get(attributeType));
} else {
-
- errorMessage = String.format("Attribute <strong>\"Type\"</strong> value [%s] doesn't match the field type [%s]. Possible value for attribute type is [%s]. Possible value for field type is [%s]",
- attributeType, field.getJavaType().toString(), possibleType, POSSIBLE_ATTRIBUTE_TYPE_FOR_FIELD_TYPE.inverse().get(attributeType));
+ errorMessage = String.format("Use [%s] for Type attribute with current field's type or change field's type to [%s] to use with current Type attribute value",
+ POSSIBLE_ATTRIBUTE_TYPE_FOR_FIELD_TYPE.get(fieldType), POSSIBLE_ATTRIBUTE_TYPE_FOR_FIELD_TYPE.inverse().get(attributeType));
+ }
+ }
}
+ if (errorMessage != null) {
errors.add(
new DictionaryValidationError(message == null ? null : message.getName(), field.getName(),
errorMessage,
DictionaryValidationErrorLevel.FIELD, DictionaryValidationErrorType.ERR_ATTRIBUTES));
}
}
-
}

MODIFY
BackEnd/Service/service-ntg/src/test/java/com/exactpro/sf/configuration/dictionary/TestNTGDictionaryValidator.java
BackEnd/Service/service-ntg/src/test/java/com/exactpro/sf/configuration/dictionary/TestNTGDictionaryValidator.java
/******************************************************************************
- * Copyright 2009-2018 Exactpro (Exactpro Systems Limited)
+ * Copyright 2009-2020 Exactpro (Exactpro Systems Limited)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -49,14 +49,14 @@ public class TestNTGDictionaryValidator extends AbstractTest {
List<DictionaryValidationError> errors = validator.validate(dictionary, true, null);
String[] expectedErrors = {
- "DictionaryValidationError[message=Logon,field=MessageVersion,error=Attribute <strong>\"Type\"</strong> value [UInt8] doesn't match the field type [JAVA_LANG_BYTE]. Field type [JAVA_LANG_BYTE] cannot be matched to any unsigned type. Possible value for field type is [JAVA_LANG_SHORT],level=FIELD,type=ERR_ATTRIBUTES]",
- "DictionaryValidationError[message=Reject,field=RejectCode,error=Attribute <strong>\"Type\"</strong> value [UInt32] doesn't match the field type [JAVA_LANG_INTEGER]. Possible value for attribute type is [UInt16]. Possible value for field type is [JAVA_LANG_LONG],level=FIELD,type=ERR_ATTRIBUTES]",
+ "DictionaryValidationError[message=Logon,field=MessageVersion,error=Field's type [JAVA_LANG_BYTE] cannot be matched to any unsigned type. Use [JAVA_LANG_SHORT] for field's type with current Type attribute,level=FIELD,type=ERR_ATTRIBUTES]",
+ "DictionaryValidationError[message=Reject,field=RejectCode,error=Use [UInt8, UInt16] for Type attribute with current field's type or change field's type to [JAVA_LANG_LONG] to use with current Type attribute value,level=FIELD,type=ERR_ATTRIBUTES]",
"DictionaryValidationError[message=Reject,field=<null>,error=Message <strong>\"Reject\"</strong> doesn't contain IsAdmin attribute,level=MESSAGE,type=ERR_ATTRIBUTES]",
"DictionaryValidationError[message=AnotherTestMessage,field=OrderType,error=Attribute <strong>\"Length\"</strong> has incorrect value = [8]. Must be one of [1, 2, 4],level=FIELD,type=ERR_ATTRIBUTES]",
- "DictionaryValidationError[message=AnotherTestMessage,field=OrderType,error=Attribute <strong>\"Type\"</strong> value [UInt64] doesn't match the field type [JAVA_LANG_INTEGER]. Possible value for attribute type is [UInt16]. Possible value for field type is [JAVA_MATH_BIG_DECIMAL],level=FIELD,type=ERR_ATTRIBUTES]",
+ "DictionaryValidationError[message=AnotherTestMessage,field=OrderType,error=Use [UInt8, UInt16] for Type attribute with current field's type or change field's type to [JAVA_MATH_BIG_DECIMAL] to use with current Type attribute value,level=FIELD,type=ERR_ATTRIBUTES]",
"DictionaryValidationError[message=AnotherTestMessage,field=AnotherOrderType,error=Attribute <strong>\"Length\"</strong> has incorrect value = [1]. Must be one of [4, 8],level=FIELD,type=ERR_ATTRIBUTES]",
- "DictionaryValidationError[message=AnotherTestMessage,field=AnotherOrderType,error=Attribute <strong>\"Type\"</strong> value [UInt64] doesn't match the field type [JAVA_LANG_LONG]. Possible value for attribute type is [UInt32]. Possible value for field type is [JAVA_MATH_BIG_DECIMAL],level=FIELD,type=ERR_ATTRIBUTES]",
- "DictionaryValidationError[message=AnotherTestMessage,field=AnotherOrderType,error=Attribute <strong>\"Type\"</strong> value [UInt64] has length different from the attribute <strong>\"Length\"</strong> value = [1],level=FIELD,type=ERR_ATTRIBUTES]",
+ "DictionaryValidationError[message=AnotherTestMessage,field=AnotherOrderType,error=Use [UInt32] for Type attribute with current field's type or change field's type to [JAVA_MATH_BIG_DECIMAL] to use with current Type attribute value,level=FIELD,type=ERR_ATTRIBUTES]",
+ "DictionaryValidationError[message=AnotherTestMessage,field=AnotherOrderType,error=Attribute <strong>\"Type\"</strong> value [Uint64] has length different from the attribute <strong>\"Length\"</strong> value = [1],level=FIELD,type=ERR_ATTRIBUTES]",
"DictionaryValidationError[message=TestMessage,field=ClOrdID,error=Attribute <strong>Format</strong> must have one of the next values [A,D] for field with type [java.lang.String] but has [S],level=FIELD,type=ERR_ATTRIBUTES]",
"DictionaryValidationError[message=TestMessage,field=OrderType,error=Offset attribute is incorrect. actual - 50; expected - 54,level=FIELD,type=ERR_ATTRIBUTES]",
"DictionaryValidationError[message=<null>,field=<null>,error=Message <strong>\"Heartbeat\"</strong> is missing in dictionary,level=DICTIONARY,type=ERR_REQUIRED_FIELD]",

MODIFY
BackEnd/Service/service-ntg/src/test/plugin/cfg/dictionaries/ntg_errors.xml
BackEnd/Service/service-ntg/src/test/plugin/cfg/dictionaries/ntg_errors.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- ~ Copyright 2009-2018 Exactpro (Exactpro Systems Limited)
+ ~ Copyright 2009-2020 Exactpro (Exactpro Systems Limited)
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
<field defaultvalue="0" type="java.lang.Integer" name="OrderType">
<attribute type="java.lang.Integer" name="Length">8</attribute>
<attribute type="java.lang.Integer" name="Offset">54</attribute>
- <attribute type="java.lang.String" name="Type">UInt64</attribute>
+ <attribute type="java.lang.String" name="Type">Uint64</attribute>
</field>
<field defaultvalue="1" type="java.lang.Long" name="AnotherOrderType">
<attribute type="java.lang.Integer" name="Length">1</attribute>
<attribute type="java.lang.Integer" name="Offset">62</attribute>
- <attribute type="java.lang.String" name="Type">UInt64</attribute>
+ <attribute type="java.lang.String" name="Type">Uint64</attribute>
</field>
</message>
</messages>

[RM] Bug #71201. NTGDictionaryValidator correction

Change-Id: I40df24f602673e08092ee9b6a7a2828b80c0e7d1