@Test public void throwsExceptionIfOutputFileNameIsMissingInTemplateFile() throws MOGLiPluginException { // prepare test final String artefactName = "testArtefact"; createTestArtefact(artefactName); final VelocityGeneratorResultData resultData = buildVelocityGeneratorResultData(null, "temp", "Content", false); prepareResultData(resultData); // call functionality under test try { velocityClassBasedGenerator.doYourJob(); } catch (MOGLiPluginException e) { assertStringContains(e.getMessage(), VelocityGeneratorResultData.NO_TARGET_FILE_NAME); return; } fail("Expected exception not thrown!"); }
@Test public void findsMainTemplate() { // prepare test final File artefactDir = new File( infrastructure.getPluginInputDir(), VelocityClassBasedFileMakerStarter.ARTEFACT_JAVABEAN); // call functionality under test String mainTemplate = null; try { mainTemplate = velocityClassBasedGenerator.findMainTemplate(artefactDir); } catch (MOGLiPluginException e) { fail(e.getMessage()); } // verify test result assertEquals("Main Template filename", MAIN_TEMPLATE, mainTemplate); }
@Test public void throwsExceptionIfMainTemplateIsNotFound() { // prepare test final File artefactDir = new File( infrastructure.getPluginInputDir(), VelocityClassBasedFileMakerStarter.ARTEFACT_JAVABEAN); final File mainTemplateFile = new File(artefactDir, MAIN_TEMPLATE); mainTemplateFile.delete(); // call functionality under test try { velocityClassBasedGenerator.findMainTemplate(artefactDir); fail("Expected exception not thrown!"); } catch (MOGLiPluginException e) { assertStringContains(e.getMessage(), TemplateUtil.NO_MAIN_TEMPLATE_FOUND); // cleanup FileUtil.deleteDirWithContent(generatorPluginInputDir); } }
@Test public void throwsExceptionIfConditionFileWasNotFound() throws MOGLiPluginException { // prepare test final File validatorFile = new File( velocityClassBasedGenerator.getInfrastructure().getPluginInputDir(), MetaInfoValidationUtil.FILENAME_VALIDATION); MOGLiFileUtil.createNewFileWithContent( validatorFile, "|MetaInfo| MetaInfoTestName1 |is| optional |for| attributes |in| ModelName |.|" + FileUtil.getSystemLineSeparator() + "|MetaInfo| MetaInfoTestName4 |is valid to occur| 1-2 |time(s) for| attributes |in| ModelName |if| notExistingConditionFile.txt |is true.|"); // call functionality under test try { velocityClassBasedGenerator.getMetaInfoValidatorList(); fail("Expected exception not thrown!"); } catch (MOGLiPluginException e) { assertStringContains(e.getMessage(), "Expected condition file does not exist: "); assertStringContains(e.getMessage(), "notExistingConditionFile.txt"); } }