/** * Finds an instance by name. * @param rootInstance a root instance * @param instancePath the instance path * @return an instance, or null if it was not found */ public static Instance findInstanceByPath( Instance rootInstance, String instancePath ) { Application tempApplication = new Application( new ApplicationTemplate()); if( rootInstance != null ) tempApplication.getRootInstances().add( rootInstance ); return findInstanceByPath( tempApplication, instancePath ); }
@Test public void testEqualsAndHashCode_3() { ApplicationTemplate app1 = new ApplicationTemplate(); ApplicationTemplate app2 = new ApplicationTemplate( "app" ).version( "whatever" ); HashSet<ApplicationTemplate> set = new HashSet<>( 2 ); set.add( app1 ); set.add( app2 ); Assert.assertEquals( 2, set.size()); }
@Test public void testEqualsAndHashCode_4() { ApplicationTemplate app1 = new ApplicationTemplate( "app" ).version( "v1" ); ApplicationTemplate app2 = new ApplicationTemplate( "app" ).version( "v3" ); HashSet<ApplicationTemplate> set = new HashSet<>( 2 ); set.add( app1 ); set.add( app2 ); Assert.assertEquals( 2, set.size()); }
@Test public void testEqualsAndHashCode_2() { ApplicationTemplate app1 = new ApplicationTemplate(); app1.setName( "app" ); ApplicationTemplate app2 = new ApplicationTemplate(); app2.setName( "app" ); HashSet<ApplicationTemplate> set = new HashSet<>( 2 ); set.add( app1 ); set.add( app2 ); Assert.assertEquals( 1, set.size()); }
@Test public void testEqualsAndHashCode_1() { ApplicationTemplate app1 = new ApplicationTemplate(); app1.setName( "app" ); app1.setVersion( "snapshot" ); ApplicationTemplate app2 = new ApplicationTemplate(); app2.setName( "app" ); app2.setVersion( "snapshot" ); HashSet<ApplicationTemplate> set = new HashSet<>( 2 ); set.add( app1 ); set.add( app2 ); Assert.assertEquals( 1, set.size()); }
@Test public void testEqualsAndHashCode_1() { Application app1 = new Application( new TestApplicationTemplate()); app1.setName( "app" ); Application app2 = new Application( new ApplicationTemplate()); app2.setName( "app" ); HashSet<Application> set = new HashSet<>( 2 ); set.add( app1 ); set.add( app2 ); Assert.assertEquals( 1, set.size()); }
@Test public void testEquals() { ApplicationTemplate app = new ApplicationTemplate( "app" ); Assert.assertFalse( app.equals( null )); Assert.assertFalse( app.equals( new ApplicationTemplate())); Assert.assertFalse( app.equals( new ApplicationTemplate( "app" ).version( "something" ))); Assert.assertFalse( app.equals( new Object())); Assert.assertEquals( app, app ); Assert.assertEquals( app, new ApplicationTemplate( "app" )); }
@Test public void testGetAllInstances() { Application app = new Application( new ApplicationTemplate()); Instance[] rootInstances = new Instance[ 8 ]; for( int i=0; i<rootInstances.length; i++ ) { rootInstances[ i ] = new Instance( "i-" + i ); InstanceHelpers.insertChild( rootInstances[ i ], new Instance( "child-" + i )); } app.getRootInstances().addAll( Arrays.asList( rootInstances )); List<Instance> allInstances = InstanceHelpers.getAllInstances( app ); Assert.assertEquals( rootInstances.length * 2, allInstances.size()); for( Instance rootInstance : rootInstances ) Assert.assertTrue( rootInstance.getName(), allInstances.contains( rootInstance )); }
@Test public void testChain() { Application app = new Application( new ApplicationTemplate()).name( "ins" ).description( "desc" ); Assert.assertEquals( "ins", app.getName()); Assert.assertEquals( "desc", app.getDescription()); }
@Test public void testTags() { ApplicationTemplate app = new ApplicationTemplate(); Assert.assertEquals( 0, app.getTags().size()); app.addTag( "toto" ); Assert.assertEquals( 1, app.getTags().size()); Assert.assertEquals( "toto", app.getTags().iterator().next()); Set<String> newTags = new HashSet<> (); newTags.add( "titi" ); newTags.add( "tutu" ); app.setTags( newTags ); Assert.assertEquals( newTags, app.getTags()); } }
@Test public void testEquals() { Application app = new Application( "app", new ApplicationTemplate()); Assert.assertFalse( app.equals( null )); Assert.assertFalse( app.equals( new Application( app.getTemplate()))); Assert.assertFalse( app.equals( new Object())); Assert.assertEquals( app, app ); Assert.assertEquals( app, new Application( "app", app.getTemplate())); Assert.assertEquals( app, new Application( "app", new ApplicationTemplate( "whatever" ))); }
@Test public void testFindIcon_nullConfigDirectory() throws Exception { // In case we try to get an icon while the DM is reconfigured ApplicationTemplate tpl = new ApplicationTemplate( "app" ).version( "v1" ); Assert.assertNull( IconUtils.findIcon( tpl )); } }
@Test public void testFindIcon_tpl() throws Exception { File appDir = this.folder.newFolder(); ApplicationTemplate tpl = new ApplicationTemplate( "app" ).version( "v1" ).directory( appDir ); File descDir = new File( appDir, Constants.PROJECT_DIR_DESC ); Assert.assertTrue( descDir.mkdirs()); File trickFile = new File( descDir, "file.txt" ); Assert.assertTrue( trickFile.createNewFile()); Assert.assertNull( IconUtils.findIcon( tpl )); File singleJpgFile = new File( descDir, "whatever.jpg" ); Assert.assertTrue( singleJpgFile.createNewFile()); Assert.assertEquals( singleJpgFile, IconUtils.findIcon( tpl )); File defaultFile = new File( descDir, "application.sVg" ); Assert.assertTrue( defaultFile.createNewFile()); Assert.assertEquals( defaultFile, IconUtils.findIcon( tpl )); Assert.assertNull( IconUtils.findIcon( new ApplicationTemplate( "app" ).version( "" ))); Assert.assertNull( IconUtils.findIcon( new ApplicationTemplate( "app" ).version( "" ))); Assert.assertNull( IconUtils.findIcon( new ApplicationTemplate( "app" ).version( "v2" ))); }
@Test public void testFindAllComponents_simple() { ApplicationTemplate app = new ApplicationTemplate(); Assert.assertEquals( 0, ComponentHelpers.findAllComponents( app ).size()); Graphs graphs = new Graphs(); app.setGraphs( graphs ); Component comp1 = new Component( "comp1" ); graphs.getRootComponents().add( comp1 ); Assert.assertEquals( 1, ComponentHelpers.findAllComponents( app ).size()); comp1.addChild( new Component( "comp-2" )); Assert.assertEquals( 2, ComponentHelpers.findAllComponents( app ).size()); Component comp3 = new Component( "comp_3" ); graphs.getRootComponents().add( comp3 ); comp3.addChild( new Component( "comp-2" )); Assert.assertEquals( 3, ComponentHelpers.findAllComponents( app ).size()); }
@Test public void testDm() throws Exception { // The messaging client is never null ReconfigurableClientDm client = new ReconfigurableClientDm(); Assert.assertNotNull( client.getMessagingClient()); // Invoke other method, no matter in which order client.setMessageQueue( new RoboconfMessageQueue()); Assert.assertFalse( client.hasValidClient()); Assert.assertFalse( client.isConnected()); client.deleteMessagingServerArtifacts( new Application( "app", new ApplicationTemplate())); client.propagateAgentTermination( null, null ); }
@Test public void testInvalidChildInstance_2() throws Exception { Component vmComponent = new Component( "VM" ).installerName( "target" ); Component tomcatComponent = new Component( "Tomcat" ).installerName( "puppet" ); Graphs graphs = new Graphs(); graphs.getRootComponents().add( vmComponent ); // We cannot instantiate a VM under a VM Instance vmInstance = new Instance("vm" ).component( vmComponent ); Instance tomcatInstance = new Instance("tomcat" ).component( tomcatComponent ); InstanceHelpers.insertChild( vmInstance, tomcatInstance ); ApplicationTemplate app = new ApplicationTemplate( "app" ).version( "2.4" ).graphs( graphs ); app.getRootInstances().add( vmInstance ); Iterator<ModelError> iterator = RuntimeModelValidator.validate( app ).iterator(); Assert.assertEquals( ErrorCode.RM_INVALID_INSTANCE_PARENT, iterator.next().getErrorCode()); Assert.assertFalse( iterator.hasNext()); }
@Test public void testCrap() { Instance inst = new Instance(); Assert.assertNull( inst.toString()); Assert.assertNotNull( inst.name( "azerty" ).toString()); Component comp = new Component(); Assert.assertNull( comp.toString()); Assert.assertNotNull( comp.name( "azerty" ).toString()); Application app = new Application( new ApplicationTemplate()); Assert.assertNull( app.toString()); Assert.assertNotNull( app.name( "azerty" ).toString()); Assert.assertTrue( 0 < PreferenceKeyCategory.values().length ); } }
@Test public void testChain() { ApplicationTemplate app = new ApplicationTemplate().name( "ins" ).description( "desc" ).version( "snapshot" ).graphs( new Graphs()); Assert.assertEquals( "ins", app.getName()); Assert.assertEquals( "desc", app.getDescription()); Assert.assertEquals( "snapshot", app.getVersion()); Assert.assertNotNull( app.getGraphs()); }
private void saveAndCompare( ApplicationDescriptor desc ) throws Exception { File f = this.folder.newFile(); ApplicationTemplate tpl = new ApplicationTemplate( desc.getTemplateName()).version( desc.getTemplateVersion()); Application app = new Application( desc.getName(), tpl ).description( desc.getDescription()); ApplicationDescriptor.save( f, app ); ApplicationDescriptor desc2 = ApplicationDescriptor.load( f ); Assert.assertEquals( desc.getDescription(), desc2.getDescription()); Assert.assertEquals( desc.getName(), desc2.getName()); Assert.assertEquals( desc.getTemplateName(), desc2.getTemplateName()); Assert.assertEquals( desc.getTemplateVersion(), desc2.getTemplateVersion()); } }
@Test public void testSetNameWithAccents() { ApplicationTemplate app = new ApplicationTemplate( "avé dés àcçents" ); Assert.assertEquals( "ave des accents", app.getName()); Assert.assertEquals( "avé dés àcçents", app.getDisplayName()); app.setName( " " ); Assert.assertEquals( "", app.getName()); Assert.assertEquals( "", app.getDisplayName()); app.setName( null ); Assert.assertNull( app.getName()); Assert.assertNull( app.getDisplayName()); app.setName( " âêû éèà " ); Assert.assertEquals( "aeu eea", app.getName()); Assert.assertEquals( "âêû éèà", app.getDisplayName()); }