package org.synyx.minos.skillz.service;

import static org.junit.Assert.*;

import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.ArrayList;

import org.apache.commons.io.IOUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.synyx.minos.skillz.domain.Level;


/**
 * Test for {@code PdfDocbookCreatorImpl}.
 * 
 * @author Markus Knittig - knittig@synyx.de
 */
public class PdfDocbookCreatorIntegrationTest extends AbstractDocbookCreatorIntegrationTest {

    private PdfDocbookCreatorImpl docbookCreator;
    private File pdf;
    private OutputStream outputStream;

    @Autowired
    private FopXsltService fopXsltService;


    @Override
    @Before
    public void setUp() throws Exception {

        super.setUp();
        docbookCreator = new PdfDocbookCreatorImpl(docbookTemplateService, fopXsltService);
        pdf = File.createTempFile("test", "pdf");
        outputStream = new FileOutputStream(pdf);
    }


    @After
    public void tearDown() throws Exception {

        outputStream.close();
        pdf.delete();
    }


    @Test
    public void createsPdfWithOwnXSL() throws Exception {

        long lastModified = pdf.lastModified();

        Thread.sleep(1500);
        docbookCreator.streamPdf(IOUtils.toString(new ClassPathResource("/projectteam.xml").getInputStream()),
                new ClassPathResource("/projectteam2fo.xsl").getFile(), outputStream);
        outputStream.flush();

        assertTrue(pdf.lastModified() > lastModified);

    }


    @Test
    public void createPdf() throws Exception {

        long lastModified = pdf.lastModified();

        Thread.sleep(1500);
        docbookCreator.streamPdf(resume, new ArrayList<Level>(), outputStream);
        outputStream.flush();

        assertTrue(pdf.lastModified() > lastModified);
    }

}

@@ -38,155 +38,8 @@
 e;%0A%0A
-import static org.junit.Assert.*;%0A%0Aimport java.io.File;%0Aimport java.io.FileOutputStream;%0Aimport java.io.OutputStream;%0Aimport java.util.ArrayList;%0A%0A
 impo
@@ -72,16 +72,17 @@
 OUtils;%0A
+%0A
 import o
@@ -97,23 +97,31 @@
 .After;%0A
+%0A
 import 
+static 
 org.juni
@@ -126,16 +126,28 @@
 nit.
-Befor
+Assert.assertTru
 e;%0A
+%0A
 impo
@@ -159,20 +159,22 @@
 g.junit.
-Test
+Before
 ;%0Aimport
@@ -182,59 +182,20 @@
 org.
-springframework.beans.factory.annotation.Autowired;
+junit.Test;%0A
 %0Aimp
@@ -245,16 +245,17 @@
 source;%0A
+%0A
 import o
@@ -291,16 +291,129 @@
 Level;%0A%0A
+import java.io.File;%0Aimport java.io.FileOutputStream;%0Aimport java.io.OutputStream;%0A%0Aimport java.util.ArrayList;%0A%0A
 %0A/**%0A * 
@@ -454,17 +454,16 @@
 mpl%7D.%0A *
- 
 %0A * @aut
@@ -466,16 +466,17 @@
 @author 
+ 
 Markus K
@@ -716,68 +716,8 @@
 m;%0A%0A
-    @Autowired%0A    private FopXsltService fopXsltService;%0A%0A%0A
     
@@ -725,20 +725,16 @@
 Override
-%0A   
  @Before
@@ -879,23 +879,154 @@
 ice,
- fopXsltService
+%0A                new FopXsltServiceImpl(%0A                    new ClassPathResource(%22/resume-template/maven/src/docbkx-stylesheet/fo/docbook.xsl%22))
 );%0A 
@@ -1511,36 +1511,32 @@
 )),%0A            
-    
 new ClassPathRes
@@ -1676,17 +1676,16 @@
 ified);%0A
-%0A
     %7D%0A%0A%0A
@@ -1991,11 +1991,10 @@
 ;%0A    %7D%0A
-%0A
 %7D%0A

test fixed #4419