*******************************************************************************/
package fr.gouv.finances.dgfip.xemelios.controls.connector.adapters.pes;
+import static org.junit.Assert.assertEquals;
+
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
-import static org.junit.Assert.*;
-
import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
@Before
public void setUp() throws Exception {
- Logger rootLogger = Logger.getRootLogger();
+ final Logger rootLogger = Logger.getRootLogger();
rootLogger.addAppender(new ConsoleAppender(new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN)));
rootLogger.setLevel(Level.DEBUG);
-
- pesosConnector = new PesControlConnector() {
+
+ this.pesosConnector = new PesControlConnector() {
@Override
- protected void extractPesConfiguration(File confFolder) throws Exception {
+ protected void extractPesConfiguration(final File confFolder) throws Exception {
// rien à faire, on est pas dans le JAR
return;
}
@Override
protected void extractVersionInformations() throws IOException {
- controlVersion = controlEngineVersion = coreVersion = "test";
+ this.controlVersion = this.controlEngineVersion = this.coreVersion = "test";
}
-
-
+
};
- pesosConnector.setControlProgressListener(new ControlProgressListener() {
+ this.pesosConnector.setControlProgressListener(new ControlProgressListener() {
@Override
public void stopWaiting() {
}
@Override
- public void notifyImportInterrupted(boolean hide) {
+ public void notifyImportInterrupted(final boolean hide) {
}
@Override
- public void notifyImportFinished(Triplet triplet) {
+ public void notifyImportFinished(final Triplet triplet) {
}
});
- pesosConnector.initialize(new File(System.getProperty("configuration.path")));// pas de répertoire temp car la conf n'est pas extraite
-
- params = new HashMap<String, Object>();
- params.put("idPost", "062075");
- params.put("codCol", "566");
- params.put("idColl", "21620413100017");
- params.put("finJur", "");
- params.put("codBud", "00");
- params.put("nomencl", "M14"); // values can be M14, M21, M22, M31, M52, M61, M71
- params.put("typnomencl", "Nature"); // values can be Nature, Fonction, Nature-ref-fonct
- params.put("votop", Boolean.FALSE);
- params.put("dureedgp", new Integer(30));
- params.put("coltva", Boolean.TRUE);
- params.put("servTVA", new String[] {}); // list of services
- params.put("servADM", new String[] {});
- params.put("codProd", new String[] { "69", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "100", "101",
- "102", "103", "104", "105", "106", "107", "248", "300", "302", "305", "306", "307", "308" }); // String array of product codes
+ this.pesosConnector.initialize(new File(System.getProperty("configuration.path")));// pas de répertoire temp car la conf n'est pas extraite
+
+ this.params = new HashMap<String, Object>();
+ this.params.put("idPost", "062075");
+ this.params.put("codCol", "566");
+ this.params.put("idColl", "21620413100017");
+ this.params.put("finJur", "");
+ this.params.put("codBud", "00");
+ this.params.put("nomencl", "M14"); // values can be M14, M21, M22, M31, M52, M61, M71
+ this.params.put("typnomencl", "Nature"); // values can be Nature, Fonction, Nature-ref-fonct
+ this.params.put("votop", Boolean.FALSE);
+ this.params.put("dureedgp", new Integer(30));
+ this.params.put("coltva", Boolean.TRUE);
+ this.params.put("servTVA", new String[] {}); // list of services
+ this.params.put("servADM", new String[] {});
+ this.params.put("codProd", new String[] { "69", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "100", "101", "102", "103", "104", "105", "106", "107", "248",
+ "300", "302", "305", "306", "307", "308" }); // String array of product codes
}
- private ControlResult runTest(File fPesIn) throws Exception {
- File fPesOut = File.createTempFile("pes", "xml");
- File fPesRep = File.createTempFile("pes", "xml");
+ private ControlResult runTest(final File fPesIn) throws Exception {
+ final File fPesOut = File.createTempFile("pes", "xml");
+ final File fPesRep = File.createTempFile("pes", "xml");
System.out.println(fPesIn + " => PES Out : " + fPesOut + " ; REP Out : " + fPesRep);
- return pesosConnector.processControl(fPesIn, fPesOut, fPesRep, params);
+ return this.pesosConnector.processControl(fPesIn, fPesOut, fPesRep, this.params);
}
@Test(expected = ParameterNeededException.class)
public void testParamNeeded() throws Exception {
- HashMap<String, Object> pClone = (HashMap<String, Object>) params.clone();
+ final HashMap<String, Object> pClone = (HashMap<String, Object>) this.params.clone();
pClone.remove("nomencl");
- pesosConnector.processControl(null, null, null, pClone);
+ this.pesosConnector.processControl(null, null, null, pClone);
}
-
+
@Test
public void testFileWithoutEncoding() throws Exception {
- File fPesIn = new File(testFilePath, "NOENCODING.XML");
- ControlResult result = runTest(fPesIn);
+ final File fPesIn = new File(this.testFilePath, "NOENCODING.XML");
+ final ControlResult result = this.runTest(fPesIn);
assertEquals(ControlResult.INVALID_ENCODING, result);
}
@Test
public void testDblCheck() throws Exception {
- testPesValid();
- testPesValid();
+ this.testPesValid();
+ this.testPesValid();
}
@Test
public void testPesValid() throws Exception {
- File fPesIn = new File(testFilePath, "DEPOK.XML");
- ControlResult result = runTest(fPesIn);
+ final File fPesIn = new File(this.testFilePath, "DEPOK.XML");
+ final ControlResult result = this.runTest(fPesIn);
assertEquals(ControlResult.VALID, result);
}
+ @Test
+ public void testErrorPesos() throws Exception {
+ final File fPesIn = new File(this.testFilePath, "PESALR221720180500017TRESORERIE_DE_M20130425142650.XML");
+ final ControlResult result = this.runTest(fPesIn);
+
+ assertEquals(ControlResult.NOT_XML, result);
+ }
+
+ @Test
+ public void testErrorPesosTU1() throws Exception {
+ final File fPesIn = new File(this.testFilePath, "fich.xml");
+ final ControlResult result = this.runTest(fPesIn);
+
+ assertEquals(ControlResult.NOT_XML, result);
+ }
+
+ @Test
+ public void testErrorPesosTU2() throws Exception {
+ final File fPesIn = new File(this.testFilePath, "PES_DEP_exemple_1000_TVA.xml");
+ final ControlResult result = this.runTest(fPesIn);
+
+ assertEquals(ControlResult.CONTROL_ERROR, result);
+ }
+
@Test
public void testErrControl() throws Exception {
- File fPesIn = new File(testFilePath, "DEPKO_CTRL.XML");
- ControlResult result = runTest(fPesIn);
+ final File fPesIn = new File(this.testFilePath, "DEPKO_CTRL.XML");
+ final ControlResult result = this.runTest(fPesIn);
assertEquals(ControlResult.CONTROL_ERROR, result);
}
@Test
public void testErrNotXML() throws Exception {
- File fPesIn = new File(testFilePath, "DEPKO_STR.XML");
- ControlResult result = runTest(fPesIn);
+ final File fPesIn = new File(this.testFilePath, "DEPKO_STR.XML");
+ final ControlResult result = this.runTest(fPesIn);
assertEquals(result, ControlResult.NOT_XML);
}
@Test
public void testErrEncoding() throws Exception {
- File fPesIn = new File(testFilePath, "DEPKO_ENC.XML");
- ControlResult result = runTest(fPesIn);
+ final File fPesIn = new File(this.testFilePath, "DEPKO_ENC.XML");
+ final ControlResult result = this.runTest(fPesIn);
assertEquals(result, ControlResult.INVALID_ENCODING);
}
@Test
public void testErrSchema() throws Exception {
- File fPesIn = new File(testFilePath, "DEPKO_SCH.XML");
- ControlResult result = runTest(fPesIn);
+ final File fPesIn = new File(this.testFilePath, "DEPKO_SCH.XML");
+ final ControlResult result = this.runTest(fPesIn);
assertEquals(result, ControlResult.INVALID_SCHEMA);
}