WorkloadParser { public Workload parse(Reader reader) throws IOException { ObjectMapper mapper = MapperFactory.initMapper(); JsonNode root = mapper.readTree(reader); return parseWorkload(mapper, root); }  Workload parse(Reader reader); void parse(Writer writer, Workload workload);  }
@Test public void parseConfiguration01() throws JsonProcessingException, IOException { WorkloadParser parser = new WorkloadParser(); Reader reader = new StringReader(ResourcesUtils.loadAsString("workloads/config01.json")); Workload config = parser.parse(reader); assertNotNull(config); assertEquals(config.getIndiceTypes().size(), 1); IndexTypeMetadata meta = config.getIndiceTypes().get(0); assertEquals(meta.getIndexName(), "NAME"); assertEquals(meta.getTypeName(), "TYPE"); ReflectionAssert.assertReflectionEquals(fields, meta.getFields(), ReflectionComparatorMode.LENIENT_ORDER); }
@Test public void parseConfiguration02() throws IOException { WorkloadParser parser = new WorkloadParser(); Reader reader = new StringReader(ResourcesUtils.loadAsString("workloads/config02.json")); Workload config = parser.parse(reader); assertNotNull(config); assertEquals(config.getVersion(), WorkloadConstants.CURRENT_VERSION); }
@Test public void parseIndexType() throws IOException { IndexTypeMetadata indexType = new IndexTypeMetadata("INDEX", "TYPE", fields); StringWriter writer = new StringWriter(); Workload config = new Workload(WorkloadConstants.CURRENT_VERSION, MetadataConstants.DEFAULT_META_BY_TYPE, Arrays.asList(indexType)); WorkloadParser parser = new WorkloadParser(); parser.parse(writer, config); String json = writer.toString(); LOGGER.info("\n{}", json); StringReader reader = new StringReader(json); Workload parsedConfig = parser.parse(reader); ReflectionAssert.assertReflectionEquals(config, parsedConfig, ReflectionComparatorMode.LENIENT_ORDER); }