@Override public Application deserialize( JsonParser parser, DeserializationContext context ) throws IOException { ObjectCodec oc = parser.getCodec(); JsonNode node = oc.readTree( parser ); Application application; JsonNode n; if(( n = node.get( APP_INST_TPL_NAME )) != null ) { ApplicationTemplate appTemplate = new ApplicationTemplate(); appTemplate.setName( n.textValue()); n = node.get( APP_INST_TPL_VERSION ); if( n != null ) appTemplate.setVersion( n.textValue()); n = node.get( APP_INST_TPL_EEP ); if( n != null ) appTemplate.setExternalExportsPrefix( n.textValue()); application = new Application( appTemplate ); } else { application = new Application( null ); } if(( n = node.get( DISPLAY_NAME )) != null ) application.setName( n.textValue()); else if(( n = node.get( NAME )) != null ) application.setName( n.textValue()); if(( n = node.get( DESC )) != null ) application.setDescription( n.textValue()); return application; } }
/** * 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() { Application app1 = new Application( new TestApplicationTemplate()); Application app2 = new Application( "app", app1.getTemplate()); HashSet<Application> set = new HashSet<>( 2 ); set.add( app1 ); set.add( app2 ); Assert.assertEquals( 2, set.size()); }
@Test public void testEqualsAndHashCode_2() { Application app1 = new Application( new TestApplicationTemplate()); app1.setName( "app" ); Application app2 = new Application( app1.getTemplate()); app2.setName( "app" ); HashSet<Application> 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 testFindAllComponents_appInstance() { ApplicationTemplate tpl = ComplexApplicationFactory1.newApplication(); Application app = new Application( tpl ); Assert.assertEquals( 10, ComponentHelpers.findAllComponents( app ).size()); app = new Application( null ); Assert.assertEquals( 0, ComponentHelpers.findAllComponents( app ).size()); }
@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 testExternalExports() { TestApplicationTemplate tpl = new TestApplicationTemplate(); Application app = new Application( tpl ); Assert.assertEquals( app.getExternalExports(), tpl.externalExports ); tpl.externalExports.put( "something", "here" ); Assert.assertEquals( app.getExternalExports(), tpl.externalExports ); }
@Test public void testFindIcon_app() throws Exception { File appDir = this.folder.newFolder(); File descDir = new File( appDir, Constants.PROJECT_DIR_DESC ); Assert.assertTrue( descDir.mkdirs()); File trickFile = new File( descDir, "directory.jpg" ); Assert.assertTrue( trickFile.mkdirs()); Application app = new Application( "app", new TestApplicationTemplate()).directory( appDir ); Assert.assertNull( IconUtils.findIcon( app )); File singleJpgFile = new File( descDir, "whatever.jpg" ); Assert.assertTrue( singleJpgFile.createNewFile()); Assert.assertEquals( singleJpgFile, IconUtils.findIcon( app )); File defaultFile = new File( descDir, "application.sVg" ); Assert.assertTrue( defaultFile.createNewFile()); Assert.assertEquals( defaultFile, IconUtils.findIcon( app )); }
@Test public void testAssociations() { ApplicationTemplate tpl = new ApplicationTemplate(); Assert.assertEquals( 0, tpl.getAssociatedApplications().size()); Application app1 = new Application( "1", tpl ); Assert.assertEquals( 1, tpl.getAssociatedApplications().size()); Application app2 = new Application( "2", tpl ); Assert.assertEquals( 2, tpl.getAssociatedApplications().size()); app1.removeAssociationWithTemplate(); Assert.assertEquals( 1, tpl.getAssociatedApplications().size()); app2.removeAssociationWithTemplate(); Assert.assertEquals( 0, tpl.getAssociatedApplications().size()); // Limits app1.removeAssociationWithTemplate(); Application app3 = new Application( null ); app3.removeAssociationWithTemplate(); // No exception }
@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 testFindIconUrl() throws Exception { // Create fake icons ApplicationTemplate tpl = new ApplicationTemplate( "tpl" ).version( "v1" ).directory( this.folder.newFolder()); File descDir = new File( tpl.getDirectory(), Constants.PROJECT_DIR_DESC ); Assert.assertTrue( descDir.mkdirs()); Assert.assertTrue( new File( descDir, "tp.jpg" ).createNewFile()); Application app = new Application( "app", tpl ).directory( this.folder.newFolder()); descDir = new File( app.getDirectory(), Constants.PROJECT_DIR_DESC ); Assert.assertTrue( descDir.mkdirs()); Assert.assertTrue( new File( descDir, "whatever.jpg" ).createNewFile()); // Check the URLs Assert.assertEquals( "/tpl/v1/tp.jpg", IconUtils.findIconUrl( tpl )); Assert.assertEquals( "/app/whatever.jpg", IconUtils.findIconUrl( app )); // And we delete the icon Utils.deleteFilesRecursively( descDir ); Assert.assertEquals( "", IconUtils.findIconUrl( app )); }
@Test public void testShortcuts() { Application app = new Application( null ); Assert.assertNull( app.getGraphs()); Assert.assertNotNull( app.getExternalExports()); Assert.assertEquals( 0, app.getExternalExports().size()); app = new TestApplication(); Assert.assertNotNull( app.getGraphs()); Assert.assertNotNull( app.getExternalExports()); }
@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 test_N_InstantiationsWithConflict() throws Exception { // The graph 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 ); // The file to read File f = TestUtils.findTestFile( "/configurations/invalid/instanceof-name-conflict-with-count.instances" ); FromInstanceDefinition fromDef = new FromInstanceDefinition( f.getParentFile()); Collection<Instance> rootInstances = fromDef.buildInstances( graphs, f ); Assert.assertEquals( 1, fromDef.getErrors().size()); Assert.assertEquals( ErrorCode.CO_CONFLICTING_INFERRED_INSTANCE, fromDef.getErrors().iterator().next().getErrorCode()); // The assertions Application app = new Application( new ApplicationTemplate()); app.getRootInstances().addAll( rootInstances ); Assert.assertEquals( 5, rootInstances.size()); // Should be 6, but there two have the same path. // So, one is overriding the other. }
@Test public void testFindAllScopedInstances() { Instance root = new Instance( "root" ).component( new Component( "Root" ).installerName( Constants.TARGET_INSTALLER )); Instance server = new Instance( "server" ).component( new Component( "Server" ).installerName( Constants.TARGET_INSTALLER )); Instance app1 = new Instance( "app1" ).component( new Component( "Application" ).installerName( "whatever" )); Instance app2 = new Instance( "app2" ).component( new Component( "Application" ).installerName( Constants.TARGET_INSTALLER )); Instance server2 = new Instance( "server2" ).component( new Component( "Server" ).installerName( "whatever" )); InstanceHelpers.insertChild( root, server ); InstanceHelpers.insertChild( root, server2 ); InstanceHelpers.insertChild( server, app1 ); InstanceHelpers.insertChild( server2, app2 ); Application app = new Application( "test", new ApplicationTemplate()); app.getRootInstances().add( root ); List<Instance> instances = InstanceHelpers.findAllScopedInstances( app ); Assert.assertEquals( 3, instances.size()); Assert.assertTrue( instances.contains( root )); Assert.assertTrue( instances.contains( server )); Assert.assertTrue( instances.contains( app2 )); }
@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 ); }
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 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 testSetNameWithAccents() { Application app = new Application( "avé dés àcçents", new TestApplicationTemplate()); 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()); } }