[RM] Feature Add dictionary attribute test for XmlDictionaryStructureWriter
MODIFY
FrontEnd/SailfishFrontEnd/src/main/java/com/exactpro/sf/testwebgui/structures/XmlDictionaryStructureWriter.java
FrontEnd/SailfishFrontEnd/src/main/java/com/exactpro/sf/testwebgui/structures/XmlDictionaryStructureWriter.java
/*******************************************************************************
- * Copyright 2009-2019 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.
@@ -67,10 +67,8 @@ public class XmlDictionaryStructureWriter {
}
}
-
Fields fields = new Fields();
Messages messages = new Messages();
-
// Fields adding
Map<ModifiableFieldStructure, Field> structureFieldMap = new LinkedHashMap<>();
@@ -114,7 +112,6 @@ public class XmlDictionaryStructureWriter {
messageReferenceMap.put(message, (ModifiableMessageStructure)messageStructure.getReference());
}
-
structureMessageMap.put(messageStructure, message);
for(ModifiableFieldStructure fieldStructure : messageStructure.getImplFields().values()) {

ADD
FrontEnd/SailfishFrontEnd/src/test/java/com/exactpro/sf/testwebgui/structures/XmlDictionaryStructureWriterTest.java
+/*******************************************************************************
+ * 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ ******************************************************************************/
+package com.exactpro.sf.testwebgui.structures;
+
+import com.exactpro.sf.common.impl.messages.xml.configuration.JavaType;
+import com.exactpro.sf.common.messages.structures.IAttributeStructure;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Map;
+
+import static com.google.common.collect.Sets.newHashSet;
+
+public class XmlDictionaryStructureWriterTest {
+
+ private static final Path BASE_DIR = Paths.get((System.getProperty("basedir") == null) ? "." : System.getProperty("basedir")).toAbsolutePath().normalize();
+ private static final String FILE_PATH = BASE_DIR + File.separator + "src" + File.separator + "test" + File.separator + "resources" + File.separator + "dictionary_attributes.xml";
+
+ private static final String FIRST_ATTRIBUTE_NAME = "String";
+ private static final String SECOND_ATTRIBUTE_NAME = "Integer";
+ private static final String THIRD_ATTRIBUTE_NAME = "Boolean";
+
+ @Test
+ public void testDictionaryAttributesWriting() throws IOException {
+
+ File dictionary = new File(FILE_PATH);
+
+ ModifiableDictionaryStructure dictionaryStructure = getDictionaryStructure(dictionary);
+
+ ModifiableDictionaryStructure dictionaryStructureAfterWriting;
+ File tempFile = null;
+ try {
+
+ tempFile = File.createTempFile("dictionary", ".xml");
+
+ XmlDictionaryStructureWriter.write(dictionaryStructure, tempFile);
+
+ dictionaryStructureAfterWriting = getDictionaryStructure(tempFile);
+ } finally {
+
+ if (tempFile != null) {
+ tempFile.delete();
+ }
+ }
+ Map<String, IAttributeStructure> attributes = dictionaryStructureAfterWriting.getAttributes();
+
+ Assert.assertEquals(newHashSet(FIRST_ATTRIBUTE_NAME, SECOND_ATTRIBUTE_NAME, THIRD_ATTRIBUTE_NAME), attributes.keySet());
+
+ Assert.assertEquals(attributes.get(FIRST_ATTRIBUTE_NAME).getType(), JavaType.JAVA_LANG_STRING);
+ Assert.assertEquals(attributes.get(FIRST_ATTRIBUTE_NAME).getValue(), "AttributeValue");
+
+ Assert.assertEquals(attributes.get(SECOND_ATTRIBUTE_NAME).getType(), JavaType.JAVA_LANG_INTEGER);
+ Assert.assertEquals(Integer.valueOf(attributes.get(SECOND_ATTRIBUTE_NAME).getValue()), Integer.valueOf(5112020));
+
+ Assert.assertEquals(attributes.get(THIRD_ATTRIBUTE_NAME).getType(), JavaType.JAVA_LANG_BOOLEAN);
+ Assert.assertEquals(Boolean.valueOf(attributes.get(THIRD_ATTRIBUTE_NAME).getValue()), true);
+ }
+
+ private ModifiableDictionaryStructure getDictionaryStructure(File dictionary) throws IOException {
+ ModifiableXmlDictionaryStructureLoader loader = new ModifiableXmlDictionaryStructureLoader();
+ try (InputStream inputStream = new FileInputStream(dictionary)) {
+ return loader.load(inputStream);
+ }
+ }
+
+}
\ No newline at end of file

ADD
FrontEnd/SailfishFrontEnd/src/test/resources/dictionary_attributes.xml
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ 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.
+ ~ You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
+<dictionary name="DictionaryAttributes" xmlns="http://exactprosystems.com/dictionary">
+ <attribute name="String" type="java.lang.String">AttributeValue</attribute>
+ <attribute name="Integer" type="java.lang.Integer">5112020</attribute>
+ <attribute name="Boolean" type="java.lang.Boolean">True</attribute>
+ <fields>
+ <field name="String" id="String" type="java.lang.String"/>
+ <field name="Integer" id="Integer" type="java.lang.Integer"/>
+ </fields>
+ <messages>
+ <message name="Parent" id="ParentId">
+ <attribute name="AttributeA" type="java.lang.String">ValueA</attribute>
+ <field name="FieldA" reference="String"/>
+ </message>
+ <message name="ChildA" id="ChildAId" reference="ParentId">
+ <attribute name="AttributeB" type="java.lang.String">ValueB</attribute>
+ <field name="FieldB" reference="Integer"/>
+ </message>
+ <message name="ChildB" id="ChildBId" reference="ChildAId">
+ <attribute name="AttributeC" type="java.lang.String">ValueC</attribute>
+ <attribute name="AttributeA" type="java.lang.Long">1</attribute>
+ <field name="FieldC" reference="String"/>
+ <field name="FieldA" reference="Integer"/>
+ <field name="FieldD" reference="ParentId"/>
+ </message>
+ </messages>
+</dictionary>
\ No newline at end of file

[RM] Feature #71413. Add dictionary attribute test for XmlDictionaryStructureWriter

Change-Id: Ia54bc9468601e72699e3121774ce4a8b37f63510