@Test public void testMessage_instanceChanged() throws Exception { MsgNotifInstanceChanged msg = new MsgNotifInstanceChanged( "app2", new Instance( "instance1" )); checkBasics( msg, MsgNotifInstanceChanged.class ); }
@Test public void testMessage_instanceRemoved() throws Exception { MsgNotifInstanceRemoved msg = new MsgNotifInstanceRemoved( "app2", new Instance( "instance1" )); checkBasics( msg, MsgNotifInstanceRemoved.class ); }
@Test public void testMessage_updateProbeConfiguration() throws Exception { MsgCmdUpdateProbeConfiguration msg = new MsgCmdUpdateProbeConfiguration( "/inst", null ); checkBasics( msg, MsgCmdUpdateProbeConfiguration.class ); msg = new MsgCmdUpdateProbeConfiguration( new Instance( "inst" ), new HashMap<String,byte[]>( 0 )); checkBasics( msg, MsgCmdUpdateProbeConfiguration.class ); }
@Test public void testFindInstanceDirectoryOnAgent() { File f = InstanceHelpers.findInstanceDirectoryOnAgent( new Instance( "inst" ) .component( new Component( "c" ).installerName( "my-plugin" ))); File tempDir = new File( System.getProperty( "java.io.tmpdir" )); Assert.assertTrue( f.getAbsolutePath().startsWith( tempDir.getAbsolutePath())); Assert.assertTrue( f.getAbsolutePath().contains( "inst" )); Assert.assertTrue( f.getAbsolutePath().contains( "my-plugin" )); }
@Test public void testFindPrefixesForExportedVariables_withInstanceVariablesOnly() { Instance instance = new Instance( "inst" ).component( new Component( "comp" )); instance.overriddenExports.put( "comp.ip", "" ); instance.overriddenExports.put( "comp.split.property", "" ); instance.overriddenExports.put( "comp.port", "8000" ); instance.overriddenExports.put( "facet.desc", "some description" ); Set<String> prefixes = VariableHelpers.findPrefixesForExportedVariables( instance ); Assert.assertEquals( 2, prefixes.size()); Assert.assertTrue( prefixes.contains( "comp" )); Assert.assertTrue( prefixes.contains( "facet" )); }
@Test public void testMessage_heartbeat() throws Exception { MsgNotifHeartbeat msg = new MsgNotifHeartbeat( "app1", "instance1", "127.0.0.1" ); checkBasics( msg, MsgNotifHeartbeat.class ); msg = new MsgNotifHeartbeat( "app1", new Instance( "instance2" ), "192.168.0.11" ); checkBasics( msg, MsgNotifHeartbeat.class ); }
@Test public void testMessage_removeInstance() throws Exception { MsgCmdRemoveInstance msg = new MsgCmdRemoveInstance( "/inst1" ); checkBasics( msg, MsgCmdRemoveInstance.class ); msg = new MsgCmdRemoveInstance( new Instance( "root" )); checkBasics( msg, MsgCmdRemoveInstance.class ); }
@Test public void testInstances() { List<Instance> instances = new ArrayList<> (); for( int i=0; i<10; i++ ) { Instance inst = new Instance( "inst-" + i ).component( new Component( "comp" )); instances.add( inst ); } Assert.assertEquals( 0, RuntimeModelValidator.validate( instances ).size()); }
@Test public void testStoreInstanceResources_inexistingDirectory() throws Exception { Instance instance = new Instance( "whatever" ).component( new Component( "comp" )); Map<?,?> map = ResourceUtils.storeInstanceResources( new File( "file/does/not/exist" ), instance ); Assert.assertEquals( 0, map.size()); }
@Test public void testStoreInstanceResources_notADirectory() throws Exception { final File appDir = this.folder.newFolder(); final String componentName = "my-component"; final File componentDirectory = new File( appDir, Constants.PROJECT_DIR_GRAPH + File.separator + componentName ); Assert.assertTrue( componentDirectory.getParentFile().mkdirs()); Assert.assertTrue( componentDirectory.createNewFile()); Instance instance = new Instance( "whatever" ).component( new Component( componentName )); Map<?,?> map = ResourceUtils.storeInstanceResources( appDir, instance ); Assert.assertEquals( 0, map.size()); }
@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 testHashCode() { Assert.assertTrue( new Import( "inst", "comp" ).hashCode() > 0 ); Assert.assertTrue( new Import( new Instance()).hashCode() > 0 ); }
@Test public void testFindPrefixesForExportedVariables_withVariable() { Instance instance = new Instance( "inst" ).component( new Component( "comp" )); Set<String> prefixes = VariableHelpers.findPrefixesForExportedVariables( instance ); Assert.assertEquals( 0, prefixes.size()); }
@Test public void testHaveSamePath() { Instance instance1 = new Instance( "inst1" ); Assert.assertTrue( InstanceHelpers.haveSamePath( instance1, instance1 )); Instance instance2 = new Instance( "inst2" ); Assert.assertFalse( InstanceHelpers.haveSamePath( instance1, instance2 )); instance2.setName( "inst1" ); Assert.assertTrue( InstanceHelpers.haveSamePath( instance1, instance2 )); }
@Test public void testOneInstance() throws Exception { Graphs graphs = buildGraphs(); Component vmComponent = ComponentHelpers.findComponent( graphs, "VM" ); Assert.assertNotNull( vmComponent ); Instance inst = new Instance( "inst" ).component( vmComponent ); compareInstances( graphs, Arrays.asList( inst ), false, false ); }
@Test public void testOneInstanceWithComments() throws Exception { Graphs graphs = buildGraphs(); Component vmComponent = ComponentHelpers.findComponent( graphs, "VM" ); Assert.assertNotNull( vmComponent ); Instance inst = new Instance( "inst" ).component( vmComponent ); compareInstances( graphs, Arrays.asList( inst ), true, false ); }
@Test public void testComputeInstancePath() { Instance instance1 = new Instance(); Assert.assertEquals( "/", InstanceHelpers.computeInstancePath( instance1 )); instance1.setName( "inst1" ); Assert.assertEquals( "/inst1", InstanceHelpers.computeInstancePath( instance1 )); Instance instance2 = new Instance( "inst2" ); Assert.assertEquals( "/inst2", InstanceHelpers.computeInstancePath( instance2 )); instance1.getChildren().add( instance2 ); instance2.setParent( instance1 ); Assert.assertEquals( "/inst1", InstanceHelpers.computeInstancePath( instance1 )); Assert.assertEquals( "/inst1/inst2", InstanceHelpers.computeInstancePath( instance2 )); }
@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 testIsTarget() { Instance inst = new Instance( "i" ); Assert.assertFalse( InstanceHelpers.isTarget( inst )); inst.setComponent( new Component( "comp" ).installerName( "whatever" )); Assert.assertFalse( InstanceHelpers.isTarget( inst )); inst.getComponent().setInstallerName( Constants.TARGET_INSTALLER ); Assert.assertTrue( InstanceHelpers.isTarget( inst )); }