ApplicationWsDelegate { public void addInstance( String applicationName, String parentInstancePath, Instance instance ) throws ApplicationWsException { this.logger.finer( "Adding an instance to the application " + applicationName + "..." ); WebResource path = this.resource.path( UrlConstants.APP ).path( applicationName ).path( "instances" ); if( parentInstancePath != null ) path = path.queryParam( "instance-path", parentInstancePath ); ClientResponse response = this.wsClient.createBuilder( path ) .accept( MediaType.APPLICATION_JSON ).type( MediaType.APPLICATION_JSON ) .post( ClientResponse.class, instance ); handleResponse( response ); this.logger.finer( String.valueOf( response.getStatusInfo())); } ApplicationWsDelegate( WebResource resource, WsClient wsClient ); void changeInstanceState( String applicationName, InstanceStatus newStatus, String instancePath ); void setDescription( String applicationName, String newDesc ); void deployAndStartAll( String applicationName, String instancePath ); void stopAll( String applicationName, String instancePath ); void undeployAll( String applicationName, String instancePath ); List<Instance> listChildrenInstances( String applicationName, String instancePath, boolean all ); void addInstance( String applicationName, String parentInstancePath, Instance instance ); void removeInstance( String applicationName, String instancePath ); void resynchronize( String applicationName ); List<Component> listAllComponents( String applicationName ); List<Component> findComponentChildren( String applicationName, String componentName ); List<Component> findComponentAncestors( String applicationName, String componentName ); void bindApplication( String applicationName, String boundTplName, String boundApp ); List<String> listAllCommands( String applicationName );  }
@Test public void testAddInstance_root_success() throws Exception { Assert.assertEquals( 2, this.app.getRootInstances().size()); Instance newInstance = new Instance( "vm-mail" ).component( this.app.getMySqlVm().getComponent()); this.client.getApplicationDelegate().addInstance( this.app.getName(), null, newInstance ); Collection<Instance> rootInstances = this.app.getRootInstances(); Assert.assertEquals( 3, rootInstances.size()); for( Instance rootInstance : rootInstances ) { Assert.assertNotNull( rootInstance.getName(), rootInstance.getComponent()); Assert.assertEquals( rootInstance.getName(), Constants.TARGET_INSTALLER, rootInstance.getComponent().getInstallerName()); } }
@Test( expected = ApplicationWsException.class ) public void testAddInstance_root_failure() throws Exception { Assert.assertEquals( 2, this.app.getRootInstances().size()); Instance existingInstance = new Instance( this.app.getMySqlVm().getName()); this.client.getApplicationDelegate().addInstance( this.app.getName(), null, existingInstance ); }
@Test public void testAddInstance_child_success() throws Exception { Instance newMysql = new Instance( "mysql-2" ).component( this.app.getMySql().getComponent()); newMysql.overriddenExports.put("mysql.port", "3307"); newMysql.overriddenExports.put("test", "test"); Assert.assertEquals( 1, this.app.getTomcatVm().getChildren().size()); Assert.assertFalse( this.app.getTomcatVm().getChildren().contains( newMysql )); this.client.getApplicationDelegate().addInstance( this.app.getName(), InstanceHelpers.computeInstancePath( this.app.getTomcatVm()), newMysql ); Assert.assertEquals( 2, this.app.getTomcatVm().getChildren().size()); List<String> paths = new ArrayList<> (); for( Instance inst : this.app.getTomcatVm().getChildren()) { Assert.assertEquals( inst.getName(), "puppet", inst.getComponent().getInstallerName()); paths.add( InstanceHelpers.computeInstancePath( inst )); } String rootPath = InstanceHelpers.computeInstancePath( this.app.getTomcatVm()); Assert.assertTrue( paths.contains( rootPath + "/" + newMysql.getName())); Assert.assertTrue( paths.contains( rootPath + "/" + this.app.getTomcat().getName())); }
@Test public void testAddInstance_child_incompleteComponent() throws Exception { String mySqlComponentName = this.app.getMySql().getComponent().getName(); Instance newMysql = new Instance( "mysql-2" ).component( new Component( mySqlComponentName )); Assert.assertEquals( 1, this.app.getTomcatVm().getChildren().size()); Assert.assertFalse( this.app.getTomcatVm().getChildren().contains( newMysql )); this.client.getApplicationDelegate().addInstance( this.app.getName(), InstanceHelpers.computeInstancePath( this.app.getTomcatVm()), newMysql ); Assert.assertEquals( 2, this.app.getTomcatVm().getChildren().size()); List<String> paths = new ArrayList<> (); for( Instance inst : this.app.getTomcatVm().getChildren()) paths.add( InstanceHelpers.computeInstancePath( inst )); String rootPath = InstanceHelpers.computeInstancePath( this.app.getTomcatVm()); Assert.assertTrue( paths.contains( rootPath + "/" + newMysql.getName())); Assert.assertTrue( paths.contains( rootPath + "/" + this.app.getTomcat().getName())); }
@Test( expected = ApplicationWsException.class ) public void testAddInstance_child_failure() throws Exception { Instance newWar = new Instance( "war-2" ).component( this.app.getWar().getComponent()); Assert.assertEquals( 1, this.app.getTomcatVm().getChildren().size()); Assert.assertFalse( this.app.getTomcatVm().getChildren().contains( newWar )); this.client.getApplicationDelegate().addInstance( this.app.getName(), InstanceHelpers.computeInstancePath( this.app.getTomcatVm()), newWar ); }
@Test( expected = ApplicationWsException.class ) public void testAddInstance_inexstingApplication() throws Exception { Instance newMysql = new Instance( "mysql-2" ).component( this.app.getMySql().getComponent()); this.client.getApplicationDelegate().addInstance( "inexisting", InstanceHelpers.computeInstancePath( this.app.getTomcatVm()), newMysql ); }
@Test( expected = ApplicationWsException.class ) public void testAddInstance_inexstingParentInstance() throws Exception { Instance newMysql = new Instance( "mysql-2" ).component( this.app.getMySql().getComponent()); this.client.getApplicationDelegate().addInstance( "inexisting", "/bip/bip", newMysql ); }