@Test public void testWriteInstances_notEmpty() throws Exception { Component component = new Component( "comp" ); Instance instance = new Instance( "inst" ).component( component ).status( InstanceStatus.DEPLOYING ).channel( "c" ); instance.overriddenExports.put( "check", "true" ); instance.data.put( "something", "else" ); File targetFile = this.folder.newFile(); RuntimeModelIo.writeInstances( targetFile, Arrays.asList( instance )); Assert.assertTrue( targetFile.exists()); Assert.assertTrue( 0 < targetFile.length()); }
@Test public void testChain() { Instance inst = new Instance().name( "ins" ).status( InstanceStatus.DEPLOYING ).component( null ).parent( null ); Assert.assertEquals( 0, inst.channels.size()); Assert.assertEquals( "ins", inst.getName()); Assert.assertEquals( InstanceStatus.DEPLOYING, inst.getStatus()); Assert.assertNull( inst.getComponent()); Assert.assertNull( inst.getParent()); Assert.assertEquals( 1, inst.channel( "woo" ).channels.size()); Assert.assertEquals( 2, inst.channel( "yeah" ).channels.size()); Assert.assertEquals( 2, inst.channel( "woo" ).channels.size()); }
@Test public void testDuplicateInstance_singleInstance() { Instance original = new Instance( "inst" ).channel( "chan" ).component( new Component( "comp" )); original.overriddenExports.put( "test", "test" ); original.overriddenExports.put( "A.port", "8012" ); original.data.put( "some", "data" ); original.getImports().put( "facet-name", new ArrayList<Import> ()); original.setStatus( InstanceStatus.DEPLOYED_STARTED ); Instance copy = InstanceHelpers.replicateInstance( original ); Assert.assertEquals( original.getName(), copy.getName()); Assert.assertEquals( original.channels, copy.channels ); Assert.assertEquals( original.overriddenExports.size(), copy.overriddenExports.size()); Assert.assertEquals( "test", copy.overriddenExports.get( "test" )); Assert.assertEquals( "8012", copy.overriddenExports.get( "A.port" )); Assert.assertEquals( 0, copy.getImports().size()); Assert.assertEquals( original.getComponent(), copy.getComponent()); Assert.assertEquals( InstanceStatus.NOT_DEPLOYED, copy.getStatus()); }
@Test public void testOneInstanceWithChildren() throws Exception { Graphs graphs = buildGraphs(); Component vmComponent = ComponentHelpers.findComponent( graphs, "VM" ); Assert.assertNotNull( vmComponent ); Component tomcatComponent = ComponentHelpers.findComponent( graphs, "Tomcat" ); Assert.assertNotNull( tomcatComponent ); Component warComponent = ComponentHelpers.findComponent( graphs, "WAR" ); Assert.assertNotNull( warComponent ); Instance vm = new Instance( "i-vm" ).component( vmComponent ); Instance tomcat = new Instance( "i-tomcat" ).component( tomcatComponent ); Instance war = new Instance( "i-war" ).component( warComponent ); tomcat.overriddenExports.put( "Tomcat.port", "9004" ); InstanceHelpers.insertChild( vm, tomcat ); InstanceHelpers.insertChild( tomcat, war ); vm.channel( "channel1" ).channel( "channel2" ); war.data.put( "prop1", "value1" ); war.data.put( "prop2", "value2" ); compareInstances( graphs, Arrays.asList( vm ), false, true ); }
@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 ); }
Instance original_1 = new Instance( "inst-1" ).channel( "chan" ).component( new Component( "comp-1" )); original_1.overriddenExports.put( "test", "test" ); original_1.overriddenExports.put( "A.port", "8012" ); Instance original_2 = new Instance( "inst-2" ).channel( "chan" ).component( new Component( "comp-2" )); original_2.overriddenExports.put( "port", "8012" ); Instance original_22 = new Instance( "inst-22" ).channel( "chan" ).component( new Component( "comp-78" )); Instance original_3 = new Instance( "inst-3" ).channel( "chan" ).component( new Component( "comp-3" )); original_3.overriddenExports.put( "ip", "localhost" );