66
77import static org .assertj .core .api .Assertions .assertThat ;
88
9- import com .fasterxml .jackson .databind .JsonNode ;
109import com .fasterxml .jackson .databind .node .ArrayNode ;
1110import com .fasterxml .jackson .databind .node .JsonNodeFactory ;
1211import com .fasterxml .jackson .databind .node .ObjectNode ;
1312import io .cucumber .java .en .Given ;
1413import io .cucumber .java .en .Then ;
1514import java .util .List ;
1615import java .util .Map ;
16+ import lombok .extern .slf4j .Slf4j ;
1717import org .openmuc .jdlms .ObisCode ;
1818import org .opensmartgridplatform .adapter .ws .schema .smartmetering .configuration .ConfigurationFlag ;
1919import org .opensmartgridplatform .adapter .ws .schema .smartmetering .configuration .ConfigurationFlags ;
2424import org .opensmartgridplatform .dlms .interfaceclass .attribute .DataAttribute ;
2525import org .springframework .beans .factory .annotation .Autowired ;
2626
27+ @ Slf4j
2728public class SimulatedConfigurationObjectSteps {
2829
2930 private static final int CLASS_ID = InterfaceClass .DATA .id ();
@@ -35,8 +36,9 @@ public class SimulatedConfigurationObjectSteps {
3536
3637 @ Autowired private JsonObjectCreator jsonObjectCreator ;
3738
38- @ Given ("device simulation of {string} with configuration object" )
39- public void deviceSimulationOfConfigurationObject (
39+ @ Given (
40+ "device simulation of {string} with configuration object values in structure type value attribute" )
41+ public void deviceSimulationOfConfigurationObjectValuesInStructureTypeValueAttribute (
4042 final String deviceIdentification , final Map <String , String > settings ) {
4143
4244 this .deviceSimulatorSteps .deviceSimulationOfEquipmentIdentifier (deviceIdentification );
@@ -49,16 +51,52 @@ public void deviceSimulationOfConfigurationObject(
4951 CLASS_ID , OBIS_CODE , ATTRIBUTE_ID_VALUE , attributeValue , OBJECT_DESCRIPTION );
5052 }
5153
52- @ Then ("device simulation of {string} should be with configuration object" )
53- public void deviceSimulationOfShouldBeWithConfigurationObject (
54+ @ Given (
55+ "device simulation of {string} with configuration object values in bitstring type value attribute" )
56+ public void deviceSimulationOfConfigurationObjectValuesInBitstringTypeValueAttribute (
5457 final String deviceIdentification , final Map <String , String > settings ) {
5558
59+ this .deviceSimulatorSteps .deviceSimulationOfEquipmentIdentifier (deviceIdentification );
60+
61+ final ConfigurationObject configurationObject =
62+ ConfigurationObjectFactory .fromParameterMap (settings );
63+ final ObjectNode attributeValue =
64+ this .createBitstringForConfigurationObject (configurationObject , new JsonNodeFactory (false ));
65+ this .deviceSimulatorSteps .setDlmsAttributeValue (
66+ CLASS_ID , OBIS_CODE , ATTRIBUTE_ID_VALUE , attributeValue , OBJECT_DESCRIPTION );
67+ }
68+
69+ @ Then (
70+ "device simulation should have values in a bitstring type value attribute of the configuration object" )
71+ public void
72+ deviceSimulationShouldHaveValuesInABitstringTypeValueAttributeOfTheConfigurationObject (
73+ final Map <String , String > settings ) {
74+
75+ final ConfigurationObject expectedConfigurationObject =
76+ ConfigurationObjectFactory .fromParameterMap (settings );
77+ final ObjectNode expectedValue =
78+ this .createBitstringForConfigurationObject (
79+ expectedConfigurationObject , new JsonNodeFactory (false ));
80+
81+ this .assertDlmsAttributeValue (expectedValue );
82+ }
83+
84+ @ Then (
85+ "device simulation should have values in a structure type value attribute of the configuration object" )
86+ public void
87+ deviceSimulationShouldHaveValuesInAStructureTypeValueAttributeOfTheConfigurationObject (
88+ final Map <String , String > settings ) {
89+
5690 final ConfigurationObject expectedConfigurationObject =
5791 ConfigurationObjectFactory .fromParameterMap (settings );
5892 final ObjectNode expectedValue =
5993 this .createStructureForConfigurationObject (
6094 expectedConfigurationObject , new JsonNodeFactory (false ));
6195
96+ this .assertDlmsAttributeValue (expectedValue );
97+ }
98+
99+ private void assertDlmsAttributeValue (final ObjectNode expectedValue ) {
62100 final ObjectNode actualValue =
63101 this .deviceSimulatorSteps .getDlmsAttributeValue (
64102 CLASS_ID , OBIS_CODE , ATTRIBUTE_ID_VALUE , OBJECT_DESCRIPTION );
@@ -71,22 +109,35 @@ private ObjectNode createStructureForConfigurationObject(
71109
72110 final ObjectNode structureForConfigurationObject = jsonNodeFactory .objectNode ();
73111 this .jsonObjectCreator .setTypeNode (structureForConfigurationObject , "structure" );
112+
74113 final ArrayNode configurationObjectElements = jsonNodeFactory .arrayNode ();
114+
75115 configurationObjectElements .add (
76116 this .createGprsOperationModeForConfigurationObject (
77117 configurationObject .getGprsOperationMode (), jsonNodeFactory ));
78- configurationObjectElements .add (
79- this .createFlagsForConfigurationObject (
80- configurationObject .getConfigurationFlags (), jsonNodeFactory ));
118+
119+ final String flagsString = this .createFlagString (configurationObject .getConfigurationFlags ());
120+ final ObjectNode flagsForConfigurationObject =
121+ this .jsonObjectCreator .createAttributeValue ("bit-string" , flagsString , jsonNodeFactory );
122+ configurationObjectElements .add (flagsForConfigurationObject );
123+
81124 structureForConfigurationObject .set ("value" , configurationObjectElements );
82125
83126 return structureForConfigurationObject ;
84127 }
85128
129+ private ObjectNode createBitstringForConfigurationObject (
130+ final ConfigurationObject configurationObject , final JsonNodeFactory jsonNodeFactory ) {
131+
132+ final String flagsString = this .createFlagString (configurationObject .getConfigurationFlags ());
133+
134+ return this .jsonObjectCreator .createAttributeValue ("bit-string" , flagsString , jsonNodeFactory );
135+ }
136+
86137 private ObjectNode createGprsOperationModeForConfigurationObject (
87138 final GprsOperationModeType gprsOperationMode , final JsonNodeFactory jsonNodeFactory ) {
88139
89- String textValue ;
140+ final String textValue ;
90141 if (gprsOperationMode == GprsOperationModeType .ALWAYS_ON ) {
91142 textValue = "1" ;
92143 } else if (gprsOperationMode == GprsOperationModeType .TRIGGERED ) {
@@ -97,9 +148,7 @@ private ObjectNode createGprsOperationModeForConfigurationObject(
97148 return this .jsonObjectCreator .createAttributeValue ("enumerate" , textValue , jsonNodeFactory );
98149 }
99150
100- private JsonNode createFlagsForConfigurationObject (
101- final ConfigurationFlags configurationFlags , final JsonNodeFactory jsonNodeFactory ) {
102-
151+ private String createFlagString (final ConfigurationFlags configurationFlags ) {
103152 final int bitStringLength = 16 ;
104153 final char [] flags = new char [bitStringLength ];
105154 for (int i = 0 ; i < bitStringLength ; i ++) {
@@ -114,7 +163,6 @@ private JsonNode createFlagsForConfigurationObject(
114163 }
115164 }
116165 }
117- return this .jsonObjectCreator .createAttributeValue (
118- "bit-string" , new String (flags ), jsonNodeFactory );
166+ return new String (flags );
119167 }
120168}
0 commit comments