Evolve { String addVersionAndRtlAttributeToTranslations(String translatedCourse, String locale, boolean isRTL) { ObjectMapper objectMapper = new ObjectMapper(); JsonNode jsonNode = objectMapper.readTreeUnchecked(translatedCourse); JsonNode translations = jsonNode.get("_translations"); if (jsonNode == null || !jsonNode.isObject()) { throw new RuntimeException("there must be a _translations object node"); } ObjectNode translationsObjectNode = (ObjectNode) translations; translationsObjectNode.put("_version", locale); translationsObjectNode.put("_rtl", isRTL); return objectMapper.writeValueAsStringUnchecked(jsonNode); } Evolve(RestTemplate restTemplate); Stream<Course> getCourses(); String getTranslationsByCourseId(String courseId); void createCourseTranslationsById(String courseId, String translatedCourse, String locale, boolean isRTL);  }
@Test public void addVersionAndRtlAttributeToTranslations() throws IOException { String withoutAttribute = "{\n" + " \"_translations\": {\n" + " \"5e3e1805bb23502ffd28796c\": {\n" + " \"_id\": \"5e3e1805bb23502ffd28796c\"\n" + " }\n" + " }\n" + "}\n"; String wihtAttribute = new Evolve(null).addVersionAndRtlAttributeToTranslations(withoutAttribute, "fr-FR", false); Assert.assertEquals("{\"_translations\":{\"5e3e1805bb23502ffd28796c\":{\"_id\":\"5e3e1805bb23502ffd28796c\"},\"_version\":\"fr-FR\",\"_rtl\":false}}", wihtAttribute); }