@Test public void testFindInstanceDirectoryOnAgent() { File f = InstanceHelpers.findInstanceDirectoryOnAgent( new Instance( "inst" ) .component( new Component( "c" ).installerName( "my-plugin" ))); File tempDir = new File( System.getProperty( "java.io.tmpdir" )); Assert.assertTrue( f.getAbsolutePath().startsWith( tempDir.getAbsolutePath())); Assert.assertTrue( f.getAbsolutePath().contains( "inst" )); Assert.assertTrue( f.getAbsolutePath().contains( "my-plugin" )); }
@Test public void testGraphs_notRoot() { Component comp1 = new Component( "comp1" ).installerName( Constants.TARGET_INSTALLER ); Component comp2 = new Component( "comp2" ).installerName( Constants.TARGET_INSTALLER ); comp1.addChild( comp2 ); Graphs graphs = new Graphs(); graphs.getRootComponents().add( comp2 ); Iterator<ModelError> iterator = RuntimeModelValidator.validate( graphs ).iterator(); Assert.assertEquals( ErrorCode.RM_NOT_A_ROOT_COMPONENT, iterator.next().getErrorCode()); Assert.assertFalse( iterator.hasNext()); }
@Test public void testPuppetValidation_twoModules() throws Exception { File appDir = this.folder.newFolder(); Component comp = new Component( "toto" ).installerName( "puppet" ); File directory = ResourceUtils.findInstanceResourcesDirectory( appDir, comp ); Assert.assertTrue( new File( directory, "roboconf_toto" ).mkdirs()); Assert.assertTrue( new File( directory, "roBoconf_titi" ).mkdirs()); List<ModelError> errors = RecipesValidator.validateComponentRecipes( appDir, comp ); Assert.assertEquals( 1, errors.size()); Assert.assertEquals( ErrorCode.REC_PUPPET_HAS_TOO_MANY_RBCF_MODULES, errors.get( 0 ).getErrorCode()); }
@Test public void testScriptValidation_success() throws Exception { File appDir = this.folder.newFolder(); Component comp = new Component( "toto" ).installerName( "script" ); File directory = ResourceUtils.findInstanceResourcesDirectory( appDir, comp ); Assert.assertTrue( new File( directory, RecipesValidator.SCRIPTS_DIR_NAME ).mkdirs()); Utils.writeStringInto( "\ntest", new File( directory, RecipesValidator.SCRIPTS_DIR_NAME + "/test.sh" )); Assert.assertEquals( 0, RecipesValidator.validateComponentRecipes( appDir, comp ).size()); }
@Test public void testScriptValidation_noScriptAtAll() throws Exception { File appDir = this.folder.newFolder(); Component comp = new Component( "toto" ).installerName( "script" ); File directory = ResourceUtils.findInstanceResourcesDirectory( appDir, comp ); Assert.assertTrue( new File( directory, RecipesValidator.SCRIPTS_DIR_NAME ).mkdirs()); Assert.assertEquals( 0, RecipesValidator.validateComponentRecipes( appDir, comp ).size()); }
@Test public void testPuppetValidation_validUpdatePp() throws Exception { File appDir = this.folder.newFolder(); Component comp = new Component( "toto" ).installerName( "puppet" ); File directory = ResourceUtils.findInstanceResourcesDirectory( appDir, comp ); Assert.assertTrue( new File( directory, "roboconf_toto/manifests" ).mkdirs()); File targetFile = new File( directory, "roboconf_toto/manifests/update.pp" ); File inputFile = TestUtils.findTestFile( "/recipes/update.pp" ); Utils.copyStream( inputFile, targetFile ); List<ModelError> errors = RecipesValidator.validateComponentRecipes( appDir, comp ); Assert.assertEquals( 0, errors.size()); }
@Test public void testPuppetValidation_onlyStartPp() throws Exception { File appDir = this.folder.newFolder(); Component comp = new Component( "toto" ).installerName( "puppet" ); File directory = ResourceUtils.findInstanceResourcesDirectory( appDir, comp ); Assert.assertTrue( new File( directory, "roboconf_toto/manifests" ).mkdirs()); File targetFile = new File( directory, "roboconf_toto/manifests/start.pp" ); File inputFile = TestUtils.findTestFile( "/recipes/invalid-update.pp" ); Utils.copyStream( inputFile, targetFile ); List<ModelError> errors = RecipesValidator.validateComponentRecipes( appDir, comp ); Assert.assertEquals( 0, errors.size()); }
private Graphs buildGraphs() { Graphs graphs = new Graphs(); Component vmComponent = new Component( "VM" ).installerName( "target" ); graphs.getRootComponents().add( vmComponent ); Component tomcatComponent = new Component( "Tomcat" ).installerName( "puppet" ); tomcatComponent.addExportedVariable( new ExportedVariable( "Tomcat.ip", null )); tomcatComponent.addExportedVariable( new ExportedVariable( "Tomcat.port", "8080" )); vmComponent.addChild( tomcatComponent ); Component warComponent = new Component( "WAR" ).installerName( "script" ); tomcatComponent.addChild( warComponent ); Assert.assertEquals( 0, RuntimeModelValidator.validate( graphs ).size()); return graphs; }
@Test public void testInstancesWithWrongImport() throws Exception { Graphs graphs = new Graphs(); graphs.getRootComponents().add( new Component( "VM" ).installerName( "target" )); File f = TestUtils.findTestFile( "/configurations/invalid/instances-with-inexisting-import.instances" ); FromInstanceDefinition fromDef = new FromInstanceDefinition( f.getParentFile()); fromDef.buildInstances( graphs, f ); Iterator<ParsingError> iterator = fromDef.getErrors().iterator(); Assert.assertEquals( ErrorCode.CO_UNREACHABLE_FILE, iterator.next().getErrorCode()); Assert.assertFalse( iterator.hasNext()); }
@Test public void testScriptValidation_noScriptsDirectory() throws Exception { File appDir = this.folder.newFolder(); Component comp = new Component( "toto" ).installerName( "script" ); File directory = ResourceUtils.findInstanceResourcesDirectory( appDir, comp ); Assert.assertTrue( directory.mkdirs()); Utils.writeStringInto( "", new File( directory, "test.sh" )); List<ModelError> errors = RecipesValidator.validateComponentRecipes( appDir, comp ); Assert.assertEquals( 1, errors.size()); Assert.assertEquals( ErrorCode.REC_SCRIPT_NO_SCRIPTS_DIR, errors.get( 0 ).getErrorCode()); }
@Test public void testPuppetValidation_invalidUpdatePp() throws Exception { File appDir = this.folder.newFolder(); Component comp = new Component( "toto" ).installerName( "puppet" ); File directory = ResourceUtils.findInstanceResourcesDirectory( appDir, comp ); Assert.assertTrue( new File( directory, "roboconf_toto/manifests" ).mkdirs()); File targetFile = new File( directory, "roboconf_toto/manifests/update.pp" ); File inputFile = TestUtils.findTestFile( "/recipes/invalid-update.pp" ); Utils.copyStream( inputFile, targetFile ); List<ModelError> errors = RecipesValidator.validateComponentRecipes( appDir, comp ); Assert.assertEquals( 1, errors.size()); Assert.assertEquals( ErrorCode.REC_PUPPET_MISSING_PARAM_IMPORT_DIFF, errors.get( 0 ).getErrorCode()); }
@Test public void testPuppetValidation_invalidInitPp() throws Exception { File appDir = this.folder.newFolder(); Component comp = new Component( "toto" ).installerName( "puppet" ); File directory = ResourceUtils.findInstanceResourcesDirectory( appDir, comp ); Assert.assertTrue( new File( directory, "roboconf_toto/manifests" ).mkdirs()); File targetFile = new File( directory, "roboconf_toto/manifests/init.pp" ); File inputFile = TestUtils.findTestFile( "/recipes/invalid-update.pp" ); Utils.copyStream( inputFile, targetFile ); List<ModelError> errors = RecipesValidator.validateComponentRecipes( appDir, comp ); Assert.assertEquals( 1, errors.size()); Assert.assertEquals( ErrorCode.REC_PUPPET_MISSING_PARAM_IMPORT_DIFF, errors.get( 0 ).getErrorCode()); }
@Test public void testPuppetValidation_missingRunningState() throws Exception { File appDir = this.folder.newFolder(); Component comp = new Component( "toto" ).installerName( "puppet" ); File directory = ResourceUtils.findInstanceResourcesDirectory( appDir, comp ); Assert.assertTrue( new File( directory, "roboconf_toto/manifests" ).mkdirs()); File targetFile = new File( directory, "roboconf_toto/manifests/start.pp" ); File inputFile = TestUtils.findTestFile( "/recipes/missing-running-state.pp" ); Utils.copyStream( inputFile, targetFile ); List<ModelError> errors = RecipesValidator.validateComponentRecipes( appDir, comp ); Assert.assertEquals( 1, errors.size()); Assert.assertEquals( ErrorCode.REC_PUPPET_MISSING_PARAM_RUNNING_STATE, errors.get( 0 ).getErrorCode()); }
@Test public void testEmptyRecipeDirectory() throws Exception { File appDir = this.folder.newFolder(); Component comp = new Component("toto").installerName("script"); File directory = ResourceUtils.findInstanceResourcesDirectory(appDir, comp); Assert.assertTrue(directory.mkdirs()); List<ModelError> errors = RecipesValidator.validateComponentRecipes(appDir, comp); Assert.assertEquals(0, errors.size()); }
@Test public void testPuppetValidation_noModule() throws Exception { File appDir = this.folder.newFolder(); Component comp = new Component( "toto" ).installerName( "puppet" ); File directory = ResourceUtils.findInstanceResourcesDirectory( appDir, comp ); Assert.assertTrue( directory.mkdirs()); List<ModelError> errors = RecipesValidator.validateComponentRecipes( appDir, comp ); Assert.assertEquals( 1, errors.size()); Assert.assertEquals( ErrorCode.REC_PUPPET_HAS_NO_RBCF_MODULE, errors.get( 0 ).getErrorCode()); }
@Test public void testPuppetValidation_oneModuleButWildCardImports() throws Exception { File appDir = this.folder.newFolder(); Component comp = new Component( "toto" ).installerName( "puppet" ); comp.addImportedVariable( new ImportedVariable( "Other.*", true, false )); File directory = ResourceUtils.findInstanceResourcesDirectory( appDir, comp ); Assert.assertTrue( new File( directory, "roboconf_toto" ).mkdirs()); List<ModelError> errors = RecipesValidator.validateComponentRecipes( appDir, comp ); Assert.assertEquals( 1, errors.size()); Assert.assertEquals( ErrorCode.REC_PUPPET_DISLIKES_WILDCARD_IMPORTS, errors.get( 0 ).getErrorCode()); }
@Test public void testFromGraphs_withInheritance() throws Exception { Graphs graphs = new Graphs(); Component cA = new Component( "A" ).installerName( Constants.TARGET_INSTALLER ); graphs.getRootComponents().add( cA ); cA.addExportedVariable( new ExportedVariable( "A.port", "9000" )); cA.addExportedVariable( new ExportedVariable( "A.ip", null )); Component cB = new Component( "B" ).installerName( Constants.TARGET_INSTALLER ); cB.extendComponent( cA ); graphs.getRootComponents().add( cB ); cB.addExportedVariable( new ExportedVariable( "A.port", "9000" )); cB.addExportedVariable( new ExportedVariable( "A.ip", null )); compareGraphs( graphs, false ); }
@Test public void testChain() { Component c = new Component( "c" ); Component comp = new Component().name( "ins" ).installerName( "my-installer" ); comp.extendComponent( c ); Assert.assertEquals( "ins", comp.getName()); Assert.assertEquals( "my-installer", comp.getInstallerName()); Assert.assertEquals( c, comp.getExtendedComponent()); }
@Test public void testMessage_addInstance() throws Exception { Instance child = new Instance( "child" ).channel( "channel 4" ).status( InstanceStatus.DEPLOYED_STOPPED ); child.component( new Component( "comp_child" ).installerName( "whatever" )); MsgCmdAddInstance msg = new MsgCmdAddInstance( child ); checkBasics( msg, MsgCmdAddInstance.class ); Instance root = new Instance( "root" ).status( InstanceStatus.DEPLOYED_STARTED ).channel( "channel1" ).channel( "channel2" ); root.component( new Component( "comp_root" ).installerName( "whatever" )); InstanceHelpers.insertChild( root, child ); msg = new MsgCmdAddInstance( child ); checkBasics( msg, MsgCmdAddInstance.class ); msg = new MsgCmdAddInstance( new Instance( "instance without component" )); checkBasics( msg, MsgCmdAddInstance.class ); }
@Test public void testIsTarget() { Instance inst = new Instance( "i" ); Assert.assertFalse( InstanceHelpers.isTarget( inst )); inst.setComponent( new Component( "comp" ).installerName( "whatever" )); Assert.assertFalse( InstanceHelpers.isTarget( inst )); inst.getComponent().setInstallerName( Constants.TARGET_INSTALLER ); Assert.assertTrue( InstanceHelpers.isTarget( inst )); }