@Test
public void embedCss() throws Exception {

  // This test ensures that the stylesheet code is added inline from the
  // links provided to the stylesheets.
  File tmp = new File( "target/test/resource/solution/system/tmp" );
  tmp.mkdirs();
  final String solutionPath = PentahoSystem.getApplicationContext().getSolutionPath( "system/tmp/test.css" );
  final File file = new File( solutionPath );
  try {
    FileUtils.writeStringToFile(file, ".fakeClass{}");
    final Map<Integer, byte[]> pages = new HashMap<>();
    pages
      .put( 0, "<link type=\"text/css\" rel=\"stylesheet\" href=\"/pentaho/getImage?image=test.css\">".getBytes() );
    // File does not exist so the link will not be replaced with inline styles
    pages
      .put( 1, "<link type=\"text/css\" rel=\"stylesheet\" href=\"/pentaho/getImage?image=nofile.css\">".getBytes() );
    final String res;
    try ( ByteArrayOutputStream baos = new ByteArrayOutputStream() ) {
      PaginationControlWrapper.write( baos, new ReportContentImpl( 1, pages ) );
      res = new String( baos.toByteArray(), "UTF-8" );
    }
    // Ensure the pages contain the encoded sylesheet content for test.css and
    // that the nofile.css link is still there since no file exists.
    assertTrue( res.contains( "var pages = [ 'Jmx0O3N0eWxlJmd0OwouZmFrZUNsYXNze30KJmx0Oy9zdHlsZSZndDs=', \n" +
            "'Jmx0O2xpbmsgdHlwZT0mcXVvdDt0ZXh0L2NzcyZxdW90OyByZWw9JnF1b3Q7c3R5bGVzaGVldCZxdW90OyBocmVmPSZxdW90Oy9wZW50YWhvL2dldEltYWdlP2ltYWdlPW5vZmlsZS5jc3MmcXVvdDsmZ3Q7' ];" ) );
    assertFalse( res.contains( "link" ) );
    assertTrue( res.contains( "style" ) );
  } finally {
    file.delete();
    tmp.delete();
  }
}