ComponentData extendedComponentData = this.componentNameToComponentData.get( data.extendedComponentName ); if( extendedComponentData != null ) data.object.extendComponent( extendedComponentData.object ); else this.errors.addAll( data.error( ErrorCode.CO_INEXISTING_COMPONENT, component( data.extendedComponentName )));
@Test public void testFindInstanceResourcesDirectory_withCycle() throws Exception { final File appDir = this.folder.newFolder(); final Component c1 = new Component( "c1" ); final Component c2 = new Component( "c2" ); final Component c3 = new Component( "c3" ); c1.extendComponent( c2 ); c2.extendComponent( c3 ); c3.extendComponent( c1 ); Assert.assertFalse( ResourceUtils.findInstanceResourcesDirectory( appDir, c1 ).exists()); Assert.assertFalse( ResourceUtils.findInstanceResourcesDirectory( appDir, c2 ).exists()); Assert.assertFalse( ResourceUtils.findInstanceResourcesDirectory( appDir, c3 ).exists()); Map<?,?> map = ResourceUtils.storeInstanceResources( appDir, new Instance( "i" ).component( c3 )); Assert.assertEquals( 0, map.size()); }
@Test public void testFindAllExtendingComponents_cycle() { Component c1 = new Component( "c1" ); Component c2 = new Component( "c2" ); Component c3 = new Component( "c3" ); c3.extendComponent( c2 ); c2.extendComponent( c1 ); Collection<Component> extending = ComponentHelpers.findAllExtendingComponents( c3 ); Assert.assertEquals( 0, extending.size()); extending = ComponentHelpers.findAllExtendingComponents( c2 ); Assert.assertEquals( 1, extending.size()); Assert.assertTrue( extending.contains( c3 )); extending = ComponentHelpers.findAllExtendingComponents( c1 ); Assert.assertEquals( 2, extending.size()); Assert.assertTrue( extending.contains( c2 )); Assert.assertTrue( extending.contains( c3 )); c1.extendComponent( c3 ); Assert.assertEquals( 2, ComponentHelpers.findAllExtendingComponents( c1 ).size()); Assert.assertEquals( 2, ComponentHelpers.findAllExtendingComponents( c2 ).size()); Assert.assertEquals( 2, ComponentHelpers.findAllExtendingComponents( c3 ).size()); }
@Test public void testFindAllExtendedComponents_cycle() { Component c1 = new Component( "c1" ); Component c2 = new Component( "c2" ); Component c3 = new Component( "c3" ); c3.extendComponent( c2 ); c2.extendComponent( c1 ); Collection<Component> extended = ComponentHelpers.findAllExtendedComponents( c1 ); Assert.assertEquals( 1, extended.size()); extended = ComponentHelpers.findAllExtendedComponents( c2 ); Assert.assertEquals( 2, extended.size()); Assert.assertTrue( extended.contains( c1 )); Assert.assertTrue( extended.contains( c2 )); extended = ComponentHelpers.findAllExtendedComponents( c3 ); Assert.assertEquals( 3, extended.size()); Assert.assertTrue( extended.contains( c1 )); Assert.assertTrue( extended.contains( c2 )); Assert.assertTrue( extended.contains( c3 )); c1.extendComponent( c3 ); Assert.assertEquals( 3, ComponentHelpers.findAllExtendedComponents( c1 ).size()); Assert.assertEquals( 3, ComponentHelpers.findAllExtendedComponents( c2 ).size()); Assert.assertEquals( 3, ComponentHelpers.findAllExtendedComponents( c3 ).size()); }
Component c4 = new Component( "c4" ).installerName( Constants.TARGET_INSTALLER ); c1.extendComponent( c2 ); c2.extendComponent( c3 ); c3.extendComponent( c4 ); Assert.assertEquals( 0, RuntimeModelValidator.validate( c4 ).size()); c4.extendComponent( c1 ); Iterator<ModelError> iterator = RuntimeModelValidator.validate( c1 ).iterator(); Assert.assertEquals( ErrorCode.RM_CYCLE_IN_COMPONENTS_INHERITANCE, iterator.next().getErrorCode()); Assert.assertFalse( iterator.hasNext()); c1.extendComponent( c1 ); iterator = RuntimeModelValidator.validate( c1 ).iterator(); Assert.assertEquals( ErrorCode.RM_CYCLE_IN_COMPONENTS_INHERITANCE, iterator.next().getErrorCode());
@Test public void testFindAllComponents_extended() { ApplicationTemplate app = ComplexApplicationFactory1.newApplication(); app.getGraphs().getRootComponents().clear(); Component root1 = new Component( "root1" ).installerName( Constants.TARGET_INSTALLER ); Component root2 = new Component( "root2" ); Component root3 = new Component( "root3" ); Assert.assertEquals( 0, ComponentHelpers.findAllComponents( app ).size()); app.getGraphs().getRootComponents().add( root1 ); Assert.assertEquals( 1, ComponentHelpers.findAllComponents( app ).size()); root2.extendComponent( root1 ); Assert.assertEquals( 2, ComponentHelpers.findAllComponents( app ).size()); root3.extendComponent( root2 ); Assert.assertEquals( 3, ComponentHelpers.findAllComponents( app ).size()); app.getGraphs().getRootComponents().add( root2 ); app.getGraphs().getRootComponents().add( root3 ); Assert.assertEquals( 3, ComponentHelpers.findAllComponents( app ).size()); Component childComponent = new Component( "child" ).installerName( "script" ); root3.addChild( childComponent ); Assert.assertEquals( 4, ComponentHelpers.findAllComponents( app ).size()); }
comp.extendComponent( parent );
@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 ); }
serverWithApp.addExportedVariable( new ExportedVariable( "url", "something" )); serverWithAnotherApp.extendComponent( serverWithApp );
component.extendComponent( extendedComponent ); component.addExportedVariable( new ExportedVariable( "extended.v", "nop" ));
@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()); }
root.addChild( serverWithAnotherApp ); root.addChild( serverWithApp ); serverWithAnotherApp.extendComponent( serverWithApp );
@Test public void testFindInstanceResourcesDirectory_success() throws Exception { final File appDir = this.folder.newFolder(); final Component c1 = new Component( "c1" ); final Component c2 = new Component( "c2" ); final File expectedFile = new File( appDir, Constants.PROJECT_DIR_GRAPH + File.separator + c1.getName()); Assert.assertEquals( expectedFile, ResourceUtils.findInstanceResourcesDirectory( appDir, c1 )); Assert.assertNotSame( expectedFile, ResourceUtils.findInstanceResourcesDirectory( appDir, c2 )); c2.extendComponent( c1 ); Assert.assertEquals( expectedFile, ResourceUtils.findInstanceResourcesDirectory( appDir, c2 )); Instance instance = new Instance( "whatever" ).component( c2 ); Assert.assertEquals( expectedFile, ResourceUtils.findInstanceResourcesDirectory( appDir, instance )); }
tomcat8.extendComponent( tomcat );