@Test public void testZoneidListMinusOne() throws ResourceAllocationException { // If zoneId List has only one parameter -1, then zone ids list should be null. registerTemplateCmd = new RegisterTemplateCmd(); registerTemplateCmd.zoneIds = new ArrayList<>(); registerTemplateCmd.zoneIds.add(-1L); Assert.assertNull(registerTemplateCmd.getZoneIds()); } @Test
@Test public void testZoneidPresentZoneidListAbsent() throws ResourceAllocationException { registerTemplateCmd = new RegisterTemplateCmd(); registerTemplateCmd.zoneIds = null; registerTemplateCmd.zoneId = 1L; Assert.assertEquals((Long)1L,registerTemplateCmd.getZoneIds().get(0)); } }
@Test public void testZoneidListMoreThanMinusOne() throws ResourceAllocationException { try { registerTemplateCmd = new RegisterTemplateCmd(); registerTemplateCmd.zoneIds = new ArrayList<>(); registerTemplateCmd.zoneIds.add(-1L); registerTemplateCmd.zoneIds.add(1L); registerTemplateCmd.execute(); } catch (ServerApiException e) { if (e.getErrorCode() != ApiErrorCode.PARAM_ERROR) { Assert.fail("Parameter zoneids cannot combine all zones (-1) option with other zones"); } } } @Test
@Test public void testZoneidAndZoneIdListBothPresent() throws ResourceAllocationException { try { registerTemplateCmd = new RegisterTemplateCmd(); registerTemplateCmd.zoneId = -1L; registerTemplateCmd.zoneIds = new ArrayList<>(); registerTemplateCmd.zoneIds.add(-1L); registerTemplateCmd.execute(); } catch (ServerApiException e) { if(e.getErrorCode() != ApiErrorCode.PARAM_ERROR) { Assert.fail("Api should fail when both zoneid and zoneids are passed"); } } }
@Test public void testZoneidMinusOne() throws ResourceAllocationException { // If zoneId is passed as -1, then zone ids list should be null. registerTemplateCmd = new RegisterTemplateCmd(); registerTemplateCmd.zoneId = -1L; Assert.assertNull(registerTemplateCmd.getZoneIds()); }
@Test public void testZoneidAndZoneIdListEmpty() throws ResourceAllocationException { try { registerTemplateCmd = new RegisterTemplateCmd(); registerTemplateCmd.execute(); } catch (ServerApiException e) { if(e.getErrorCode() != ApiErrorCode.PARAM_ERROR) { Assert.fail("Api should fail when both zoneid and zoneids aren't passed"); } } }