CategoryPriceNavigationXStreamProvider implements XStreamProvider<PriceTierTree> { private XStream provide() { if (this.xStream == null) { XStream xStream = new XStream(new DomDriver()); xStream.addPermission(AnyTypePermission.ANY); xStream.alias("price-navigation", PriceTierTreeImpl.class); xStream.aliasField("currencies", PriceTierTreeImpl.class, "priceMap"); xStream.alias("currency", Map.Entry.class); xStream.alias("name", String.class); xStream.alias("price-tiers", List.class); xStream.alias("price-tier", PriceTierNode.class); xStream.registerConverter(new MapConverter(xStream.getMapper(), "currency", "name", "price-tiers"), 10001); xStream.addDefaultImplementation(PriceTierNodeImpl.class, PriceTierNode.class); this.xStream = xStream; } return this.xStream; }  @Override PriceTierTree fromXML(final String xml); @Override PriceTierTree fromXML(final InputStream is); @Override String toXML(final PriceTierTree object);  }
@Test public void testProvide() throws Exception { final XStreamProvider<PriceTierTree> provider = new CategoryPriceNavigationXStreamProvider(); final String xml = new Scanner(new File("src/test/resources/price_tier_example.xml")).useDelimiter("\\Z").next(); final PriceTierTree tierTree = provider.fromXML(xml); assertNotNull(tierTree); final List<PriceTierNode> eur = tierTree.getPriceTierNodes("EUR"); assertNotNull(eur); assertEquals(5, eur.size()); assertTrue(new BigDecimal(0).compareTo(eur.get(0).getFrom()) == 0); assertTrue(new BigDecimal(100).compareTo(eur.get(0).getTo()) == 0); assertTrue(new BigDecimal(1000).compareTo(eur.get(4).getFrom()) == 0); assertTrue(new BigDecimal(200000).compareTo(eur.get(4).getTo()) == 0); final String xmlStr = provider.toXML(tierTree); assertNotNull(xmlStr); final PriceTierTree tierTree2 = provider.fromXML(xmlStr); assertNotNull(tierTree2); final List<PriceTierNode> eur2 = tierTree2.getPriceTierNodes("EUR"); assertNotNull(eur2); assertEquals(5, eur2.size()); assertTrue(new BigDecimal(0).compareTo(eur2.get(0).getFrom()) == 0); assertTrue(new BigDecimal(100).compareTo(eur2.get(0).getTo()) == 0); assertTrue(new BigDecimal(1000).compareTo(eur2.get(4).getFrom()) == 0); assertTrue(new BigDecimal(200000).compareTo(eur2.get(4).getTo()) == 0); }