Skip to content

Commit

Permalink
Update all feature files to 1.5.8
Browse files Browse the repository at this point in the history
* Update uri_serializer, uri_deserializer, uuid_serializer, uuid_deserializer, uattributes_validator, uri_validator to 1.5.8 spec (uuid_validator updated in previous PR)
  • Loading branch information
matthewd0123 committed Jul 31, 2024
1 parent 31dc933 commit 7de7c70
Show file tree
Hide file tree
Showing 13 changed files with 456 additions and 774 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,20 @@

package org.eclipse.uprotocol;

import com.google.gson.Gson;
import com.google.protobuf.ByteString;
import com.google.protobuf.Descriptors;
import com.google.protobuf.Message;
import com.google.protobuf.Descriptors.EnumValueDescriptor;
import com.google.protobuf.Descriptors.FieldDescriptor;
import com.google.protobuf.InvalidProtocolBufferException;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import com.google.protobuf.util.JsonFormat;

import org.json.JSONArray;
import org.json.JSONObject;
Expand Down Expand Up @@ -152,40 +156,17 @@ public static JSONObject convertMessageToJSON(Message message) {
}

public static Map<String, Object> convertMessageToMap(Message message) {
Map<String, Object> result = new HashMap<>();
Map<String, Object> map;
JsonFormat.Printer printer = JsonFormat.printer().includingDefaultValueFields().preservingProtoFieldNames();
Gson gson = new Gson();

List<FieldDescriptor> allFields = message.getDescriptorForType().getFields();
for (FieldDescriptor field : allFields) {
String fieldName = field.getName();
Object defaultOrSetValue = message.getField(field);
Object value = getattr(message, field, defaultOrSetValue);
if (value instanceof EnumValueDescriptor) {
value = ((EnumValueDescriptor) value).getNumber();
}

if (value instanceof ByteString) {
value = ((ByteString) value).toStringUtf8();
}

if (value instanceof Message) {
result.put(fieldName, convertMessageToMap((Message) value));
} else if (field.isRepeated()) {
List<Object> repeated = new ArrayList<>();
for (Object subMsg : (List<Object>) value) {
if (subMsg instanceof Message) {
repeated.add(convertMessageToMap((Message) subMsg));
} else {
repeated.add(subMsg);
}
}
result.put(fieldName, repeated);

} else if (field.isRequired() || field.isOptional()) {
result.put(fieldName, value);
}
try {
String jsonString = printer.print(message);
map = gson.fromJson(jsonString, Map.class);
} catch (InvalidProtocolBufferException ex) {
map = new HashMap<>();
}

return result;
return map;
}

public static Object getattr(Message message, FieldDescriptor field, Object defaultValue) {
Expand Down
14 changes: 11 additions & 3 deletions test_manager/features/steps/tck_step_implementations.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,11 @@ def create_sdk_data(context, sdk_name: str, command: str):
sdk_name, "initialize_transport", context.ue_tracker[int(ue_number) - 1][2]
)
context.logger.info(f"Response Json {command} -> {response_json}")
assert_that(int(response_json["data"]["code"]), equal_to(UCode.OK))

try:
assert_that(int(response_json["data"]["code"]), equal_to(UCode.OK))
except ValueError:
assert_that(response_json["data"]["code"], equal_to("OK"))

context.logger.info(f"{sdk_name} connected to Test Manager...")

Expand Down Expand Up @@ -319,7 +323,7 @@ def verify_uuid_received_properties(context):
if len(expected_value) > 0:
if field in int_type_fields:
expected_value: int = int(expected_value)
assert_that(deserialized_uuid[field], equal_to(expected_value))
assert_that(int(deserialized_uuid[field]), equal_to(expected_value))
except AssertionError as ae:
raise AssertionError(f"Assertion error. {ae}")

Expand Down Expand Up @@ -358,8 +362,12 @@ def send_command_request(context, command: str):
def receive_status(context, field_name: str, expected_value: str):
try:
actual_value: str = context.response_data[field_name]
expected_value_string = expected_value
expected_value: int = getattr(UCode, expected_value)
assert_that(expected_value, equal_to(int(actual_value)))
try:
assert_that(expected_value, equal_to(int(actual_value)))
except ValueError:
assert_that(expected_value_string, equal_to(actual_value))
except AssertionError:
raise AssertionError(
f"Assertion error. Expected is {expected_value} but " f"received {context.response_data[field_name]}"
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 7de7c70

Please sign in to comment.