diff --git a/test/bats/test-timescaledb-bridge/timescaledb-bridge-test.bats b/test/bats/test-timescaledb-bridge/timescaledb-bridge-test.bats index 8e1d3ff5..4e59e71e 100644 --- a/test/bats/test-timescaledb-bridge/timescaledb-bridge-test.bats +++ b/test/bats/test-timescaledb-bridge/timescaledb-bridge-test.bats @@ -10,10 +10,12 @@ POSTGRES_POD=acid-cluster-0 POSTGRES_USERNAME=ngb POSTGRES_DATABASE=tsdb POSTGRES_SECRET=ngb.acid-cluster.credentials.postgresql.acid.zalan.do +ENTITY=/tmp/entity.txt ATTRIBUTES_PROPERTY=/tmp/property.txt ATTRIBUTES_PROPERTY2=/tmp/property2.txt ATTRIBUTES_RELATIONSHIP=/tmp/relationship.txt ATTRIBUTES_TOPIC=iff.ngsild.attributes +ENTITIES_TOPIC=iff.ngsild.entities KAFKA_BOOTSTRAP=my-cluster-kafka-bootstrap:9092 RANDOMID=$(tr -dc A-Za-z0-9 ${ATTRIBUTES_PROPERTY} "entityId": "${URN}", "name": "${STATE}", "type": "${PROPERTY}", - "https://uri.etsi.org/ngsi-ld/hasValue": "${VALUE}", + "attributeValue": "${VALUE}", "nodeType": "@id", - "index": 0} + "datasetId": "@none" +} EOF cat << EOF > ${ATTRIBUTES_PROPERTY2} @@ -50,7 +53,7 @@ cat << EOF > ${ATTRIBUTES_PROPERTY2} "entityId": "${URN4}", "name": "${STATE}", "type": "${PROPERTY}", - "https://uri.etsi.org/ngsi-ld/hasValue": "${VALUE2}", + "attributeValue": "${VALUE2}", "nodeType": "@value", "valueType": "http://www.w3.org/2001/XMLSchema#string", "index": 0 @@ -63,25 +66,32 @@ cat << EOF > ${ATTRIBUTES_RELATIONSHIP} "entityId": "${URN2}", "name": "${REL}", "type": "${RELATIONSHIP}", - "https://uri.etsi.org/ngsi-ld/hasObject": "${URN3}", + "attributeValue": "${URN3}", "nodeType": "@id", "index": 0 } EOF -cat << EOF > ${TSDB_EXPECTED} +cat << EOF > ${ENTITY} { - "id": "${IDSTATE}", - "entityId": "${URN}", - "name": "${STATE}", - "type": "${PROPERTY}", - "https://uri.etsi.org/ngsi-ld/hasValue": "${VALUE2}", - "nodeType": "@value", - "valueType": "http://www.w3.org/2001/XMLSchema#string", - "index": 0 + "id": "${URN}", + "type": "https://example.com/type" } EOF +# cat << EOF > ${TSDB_EXPECTED} +# { +# "id": "${IDSTATE}", +# "entityId": "${URN}", +# "name": "${STATE}", +# "type": "${PROPERTY}", +# "https://uri.etsi.org/ngsi-ld/hasValue": "${VALUE2}", +# "nodeType": "@value", +# "valueType": "http://www.w3.org/2001/XMLSchema#string", +# "index": 0 +# } +# EOF + # send data to kafka bridge # $1: file to send # $2: kafka topic @@ -94,12 +104,22 @@ send_to_kafka_bridge() { get_datapoints() { urn=$1 targetfile=$2 - echo 'select json_agg(t) from public.entityhistory as t where t."entityId" = ' \'"$urn"\' ';' | \ + echo 'select json_agg(t) from public.attributes as t where t."entityId" = ' \'"$urn"\' ';' | \ PGPASSWORD=${POSTGRES_PASSWORD} psql -t -h localhost -U ${POSTGRES_USERNAME} -d ${POSTGRES_DATABASE} -A | \ jq -S 'map(del(.modifiedAt, .observedAt))' >"$targetfile" } +# receive entity datapoints +# $1: payload to post +get_entity_datapoints() { + urn=$1 + targetfile=$2 + echo 'select json_agg(t) from public.entities as t where t."id" = ' \'"$urn"\' ';' | \ + PGPASSWORD=${POSTGRES_PASSWORD} psql -t -h localhost -U ${POSTGRES_USERNAME} -d ${POSTGRES_DATABASE} -A | \ + jq -S 'map(del(.modifiedAt, .observedAt))' >"$targetfile" +} + # check s # $1: retrieved tsdb objects # $2: expected tsdb objects @@ -111,9 +131,13 @@ check_tsdb_sample1() { "attributeId": "https://industry-fusion.com/types/v0.9/state", "attributeType": "https://uri.etsi.org/ngsi-ld/Property", "datasetId": "@none", + "deleted": false, "entityId": "$URN", - "index": 0, + "id": "$IDSTATE", + "lang": null, "nodeType": "@id", + "parentId": null, + "unitType": null, "value": "state", "valueType": null } @@ -132,9 +156,13 @@ check_tsdb_sample2() { "attributeId": "https://industry-fusion.com/types/v0.9/relationship", "attributeType": "https://uri.etsi.org/ngsi-ld/Relationship", "datasetId": "@none", + "deleted": false, "entityId": "$URN", - "index": 0, + "id": "$IDREL", + "lang": null, "nodeType": "@id", + "parentId": null, + "unitType": null, "value": "$URN3", "valueType": null } @@ -150,9 +178,13 @@ check_tsdb_sample3() { "attributeId": "https://industry-fusion.com/types/v0.9/state", "attributeType": "https://uri.etsi.org/ngsi-ld/Property", "datasetId": "@none", + "deleted": false, "entityId": "$URN4", - "index": 0, + "id": "$IDSTATE2", + "lang": null, "nodeType": "@value", + "parentId": null, + "unitType": null, "value": "$VALUE2", "valueType": "http://www.w3.org/2001/XMLSchema#string" } @@ -160,6 +192,23 @@ check_tsdb_sample3() { EOF } + +# check entity +# $1: retrieved tsdb objects +# $2: expected tsdb objects +check_tsdb_sample4() { + URN=$2 + cat << EOF | diff "$1" - >&3 +[ + { + "deleted": false, + "id": "$URN", + "type": "https://example.com/type" + } +] +EOF +} + setup() { # shellcheck disable=SC2086 [ "$DEBUG" = "true" ] || (exec ${SUDO} kubefwd -n ${IFFNAMESPACE} -l "app.kubernetes.io/name in (kafka)" svc) & @@ -207,4 +256,16 @@ teardown(){ echo "# Now checking result." run check_tsdb_sample3 "$TSDB_RESULT" "$URN4" [ "$status" -eq "0" ] +} + +@test "verify timescaledb-bridge is forwarding entity" { + $SKIP + echo "# Sending property to Kafka" + send_to_kafka_bridge ${ENTITY} ${ENTITIES_TOPIC} + sleep 2 + get_entity_datapoints "$URN" "${TSDB_RESULT}" + cat "${TSDB_RESULT}" + echo "# Now checking result." + run check_tsdb_sample4 "$TSDB_RESULT" "$URN" + [ "$status" -eq "0" ] } \ No newline at end of file