Software Engineering Asked on December 22, 2021
An interesting question I’ve stumbled upon:
Let’s assume a java application creates a data model, converts this data to a json object with two fields and uploads it to a server:
{
"FirstName": "Foo",
"LastName": "Bar"
}
Now a different technology, say js, php, etc on the server needs to process the data.
Both sides are well tested against a set of unit tests but naturally integration across different languages and technologies is hard to be tested in depth.
Is there a known principle or technique that can validate the data on both ends? I mean lets say there is a contract that says that LastName
must not, by any chance be <2 chars in size. This is a business rule which is a hard constraint on the data.
Now the java implementation has a bug or simply overlooked the requirement for LastName
. Both sides complete unit tests but they fail hard during integration.
Is there some technique that allows to specify such rules across languages? I am not talking about runtime rejection of malformed data but rather ensure consistency on both sides of an application.
JSON Schema has validator implementations in more than 17 languages. Which probably makes it the most cross-language object validation methodology. The implementations do vary a bit in completeness though.
Answered by naught101 on December 22, 2021
Integration Testing
You succinctly describe the root issue here, namely lack of integration testing.
Both sides complete unit tests but they fail hard during integration.
The team building the Java application forgot to include validation and unit tests for when LastName
is less than two characters.
The team building the PHP application, on the other hand, remembered to include the validation and unit tests.
Luckily, the QA team knew about the LastName
requirement and added the name Jin-u O
in their integration testing suite. When they called an API operation in the Java application using that name, expecting a 400-level validation error, they instead got a 200 and the test failed.
Is integration testing easy? Absolutely not. But it's definitely worth it if you've got the time and resources to test your applications against an objective set of criteria.
Answered by Dan Wilson on December 22, 2021
The phrase I've come across for this is single source of truth
:
In information systems design and theory, single source of truth (SSOT) is the practice of structuring information models and associated data schema such that every data element is stored exactly once. Any possible linkages to this data element (possibly in other areas of the relational schema or even in distant federated databases) are by reference only. Because all other locations of the data just refer back to the primary "source of truth" location, updates to the data element in the primary location propagate to the entire system without the possibility of a duplicate value somewhere being forgotten.
Software can be generated as noted above:
In software design, the same schema, business logic and other components are often repeated in multiple different contexts, while each version refers to itself as "Source Code". To address this problem, the concepts of SSoT can also be applied to software development principals using processes like recursive transcompiling to iteratively turn a single source of truth into many different kinds of source code, which will match each other structurally because they are all derived from the same SSoT.
Specifically, some cross language specifications include:
Projects such as Apache Thrift normalize this:
Apache Thrift allows you to define data types and service interfaces in a simple definition file. Taking that file as input, the compiler generates code to be used to easily build RPC clients and servers that communicate seamlessly across programming languages. Instead of writing a load of boilerplate code to serialize and transport your objects and invoke remote methods, you can get right down to business.
References
Answered by Paul Sweatte on December 22, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP