SentinelUpdateController { @VisibleForTesting protected SetinelTbl convert2SentinelTbl(SentinelModel sentinelModel) { StringBuilder sb = new StringBuilder(); for(HostPort hostPort : sentinelModel.getSentinels()) { sb.append(hostPort.getHost()).append(':').append(hostPort.getPort()).append(','); } String sentinels = sb.deleteCharAt(sb.length() - 1).toString(); SetinelTbl proto = new SetinelTbl(); proto.setSetinelAddress(sentinels); proto.setDeleted(false); proto.setSetinelDescription(sentinelModel.getDesc()); proto.setDcId(dcService.find(sentinelModel.getDcName()).getId()); return proto; }  @RequestMapping(value = "/rebalance/sentinels/{dcName}/{numOfClusters}", method = RequestMethod.POST) RetMessage reBalanceSentinels(@PathVariable String dcName, @PathVariable int numOfClusters); @RequestMapping(value = "/rebalance/sentinels/force/{dcName}/{numOfClusters}", method = RequestMethod.POST) RetMessage reBalanceSentinelsForce(@PathVariable String dcName, @PathVariable int numOfClusters); @RequestMapping(value = "/sentinels", method = RequestMethod.POST) RetMessage addSentinel(@RequestBody SentinelModel sentinelModel); @RequestMapping(value = "/sentinels/{sentinelId}", method = RequestMethod.DELETE) RetMessage deleteSentinel(@PathVariable Long sentinelId); @RequestMapping(value = "/sentinels/{sentinelId}", method = RequestMethod.PATCH) RetMessage rehealSentinel(@PathVariable Long sentinelId); @RequestMapping(value = "/rebalance/sentinels/{dcName}", method = RequestMethod.POST) RetMessage reBalanceSentinels(@PathVariable String dcName, @RequestBody(required = false) List<String> clusterNames); @RequestMapping(value = "/sentinels/usage", method = RequestMethod.GET) RetMessage sentinelUsage(); @RequestMapping(value = "/sentinel/address", method = RequestMethod.PUT) RetMessage updateSentinelAddr(@RequestBody SentinelModel model); @RequestMapping(value = "/sentinel/monitor/{clusterName}", method = RequestMethod.DELETE) RetMessage removeSentinelMonitor(@PathVariable String clusterName);  }
@Test public void testConvert2SentinelTbl() throws Exception { when(dcService.find(anyString())).thenReturn(new DcTbl().setId(1)); SentinelModel sentinelModel = new SentinelModel().setDcName("JQ") .setDesc("test").setSentinels(Arrays.asList(new HostPort("127.0.0.1", 6379), new HostPort("127.0.0.1", 6380), new HostPort("127.0.0.1", 6381))); SetinelTbl setinelTbl = controller.convert2SentinelTbl(sentinelModel); Assert.assertEquals(1, setinelTbl.getDcId()); Assert.assertEquals("test", setinelTbl.getSetinelDescription()); Assert.assertEquals("127.0.0.1:6379,127.0.0.1:6380,127.0.0.1:6381", setinelTbl.getSetinelAddress()); }