RabbitMqUtils { public static String buildExchangeName( MessagingContext ctx ) { String exchangeName; if( ctx.getKind() == RecipientKind.DM ) exchangeName = buildExchangeNameForTheDm( ctx.getDomain()); else if( ctx.getKind() == RecipientKind.INTER_APP ) exchangeName = buildExchangeNameForInterApp( ctx.getDomain()); else exchangeName = RabbitMqUtils.buildExchangeNameForAgent( ctx.getDomain(), ctx.getApplicationName()); return exchangeName; } private  RabbitMqUtils(); static void configureFactory( ConnectionFactory factory, Map<String,String> configuration ); static void closeConnection( Channel channel ); static void declareApplicationExchanges( String domain, String applicationName, Channel channel ); static void declareGlobalExchanges( String domain, Channel channel ); static String buildExchangeNameForAgent( String domain, String applicationName ); static String buildExchangeNameForTheDm( String domain ); static String buildExchangeNameForInterApp( String domain ); static String buildExchangeName( MessagingContext ctx );  }
@Test public void testBuildExchangeName() { MessagingContext ctx = new MessagingContext( RecipientKind.DM, "domain", "app1" ); Assert.assertEquals( "domain." + EXCHANGE_DM, RabbitMqUtils.buildExchangeName( ctx )); ctx = new MessagingContext( RecipientKind.DM, "domain", "app2" ); Assert.assertEquals( "domain." + EXCHANGE_DM, RabbitMqUtils.buildExchangeName( ctx )); ctx = new MessagingContext( RecipientKind.INTER_APP, "domain", "app1" ); Assert.assertEquals( "domain." + EXCHANGE_INTER_APP, RabbitMqUtils.buildExchangeName( ctx )); ctx = new MessagingContext( RecipientKind.INTER_APP, "domain", "facet", ThoseThat.IMPORT, "app1" ); Assert.assertEquals( "domain." + EXCHANGE_INTER_APP, RabbitMqUtils.buildExchangeName( ctx )); ctx = new MessagingContext( RecipientKind.AGENTS, "domain", "facet", ThoseThat.IMPORT, "app1" ); Assert.assertEquals( "domain.app1.agents", RabbitMqUtils.buildExchangeName( ctx )); ctx = new MessagingContext( RecipientKind.AGENTS, "domain1", "facet", ThoseThat.EXPORT, "app2" ); Assert.assertEquals( "domain1.app2.agents", RabbitMqUtils.buildExchangeName( ctx )); }