Skip to content
This repository was archived by the owner on Nov 22, 2023. It is now read-only.

Move examples from rosetta translate to translate demo

Hugo Hills edited this page Jul 20, 2022 · 14 revisions

This page contains instructions on how to migrate rosetta-translate unit tests to translate-demo examples. A few utilities have been created to help.

Set Up

Migration

1. Create empty input files for a translate-demo example

The data used to create examples in translate-demo are stored in a folder src/test/resources/example-generation/inputs. Within that folder the examples are organised into category folder (e.g. single-cardinality) and example name folder (e.g. example 4).

  • Decide on categoryName (e.g. single-cardinality) and exampleSuffix (e.g. 4, used in the example name, example-4)
  • In Intellij, open utility class ExampleTemplateGenerator, set categoryName and exampleSuffix, run the main
    • Note: ExampleTemplateGenerator run configuration should have working dir of $MODULE_DIR$
  • Template (or empty) xml, xsd, rosetta and md files will be created in a folder structure inside the inputs folder

2. Copy unit test files from rosetta-translate

The rosetta-translate project has many unit tests that can be migrated into translate-demo examples. Choose a unit test (based on the provided spreadsheet), and copy over the files into the template files created in step 1.

Rosetta, xml, xsd files can be found in rosetta-translate, inside the folder /rosetta-translate/src/test/resources/xml.

2.1 Copy rosetta code

  • Find the relevant unit test rosetta in rosetta-translate
  • Copy the unit test rosetta code, excluding the top level element (e.g. Top4), as this is named Root in the template
  • Once copied into translate-demo inputs example file (e.g. example-4.rosetta):
    • Format code (intending, naming etc)
    • Update synonyms source to template value (e.g. change Bank_A to SINGLE_CARDINALITY_EXAMPLE_4)

2.2 Copy xsd content

  • Find the relevant unit test xsd in rosetta-translate.
  • Copy the unit test xsd content, excluding schema tag into translate-demo inputs xsd file (e.g. example-4.xsd)

2.3 Copy xml content

  • Find the relevant unit test xml in rosetta-translate.
  • Copy the xml content into translate-demo inputs xml file (e.g. example-4.xml)
  • Clean up old element schema attributes

2.4 Write short description of test into empty md file

  • Look at the unit test / example and write a short description in the translate-demo inputs md file (e.g. example-4.md)

3. Generate examples from inputs folder

Use the utility to generate the required structure, config file to display the examples in the Rosetta application. The utility also generates unit tests (and expectations) for each example.

3.1 Run utility to set up example in Rosetta application

  • In Intellij, open ExampleGenerator, and run to create all config and units tests for examples specified in the inputs folder
    • Note: ExampleGenerator run configuration should have working dir of $MODULE_DIR$

3.2 Generate Java classes from the example rosetta code

  • Run maven plugins "resources:copy-resources xtext:generate -f pom.xml" to generate classes
    • Note: set up maven command in Intellij run configuration
  • Code should now compile, and unit tests should run

3.3 Generate unit test expectations

  • Run unit tests and generate expectations by running all tests with update flags set
  • Set up run all unit tests run configuration in Intellij with env vars:
    • TEST_WRITE_BASE_PATH=/Users/hugohills/dev/github/rosetta-models/translate-demo/rosetta-source/src/main/resources;WRITE_EXPECTATIONS=true;CREATE_EXPECTATION_FILES=true
  • Unit test json expectations should be created.

4. Commit and push

  • Add all unversioned files and commit and push all changes.