OsBO { public String updateOs(OsData osData, String uuid) { TblOs tblOs; try { if (uuid != null && !uuid.isEmpty()) { tblOs = tblOsJpaController.findTblOsByUUID(uuid); } else { tblOs = tblOsJpaController.findTblOsByNameVersion(osData.getName(), osData.getVersion()); } if (tblOs == null) { throw new ASException(ErrorCode.WS_OS_DOES_NOT_EXIST, osData.getName(), osData.getVersion()); } tblOs.setDescription(osData.getDescription()); tblOsJpaController.edit(tblOs); } catch (ASException ase) { throw ase; } catch (Exception e) { log.error("Error during OS update.", e); throw new ASException(ErrorCode.WS_OS_UPDATE_ERROR, e.getClass().getSimpleName()); } return "true"; } OsBO(); List<OsData> getAllOs(); String updateOs(OsData osData, String uuid); String createOs(OsData osData, String uuid); String deleteOs(String osName, String osVersion, String uuid);  }
@Test public void testUpdateOs() { System.out.println("updateOs"); OsData osData = getOsData(); OsBO instance = new OsBO(); String expResult = "true"; boolean found = false; List<OsData> list = instance.getAllOs(); for(OsData r: list) { if( r.getName() != null && r.getName().equals(osData.getName())) { found = true; } } if(!found) { instance.createOs(osData, null); } String updatedDescription = "updated "+rnd.nextInt(99); osData.setDescription(updatedDescription); String result = instance.updateOs(osData, null); assertEquals(expResult, result); boolean isUpdated = false; List<OsData> list2 = instance.getAllOs(); for(OsData r: list2) { if(r.getName().equals(osData.getName()) && r.getDescription().equals(updatedDescription)) { isUpdated = true; } } assertTrue(isUpdated); }
@Test(expected=ASException.class) public void testUpdateNonExistentOs() { System.out.println("testUpdateNonExistentOs"); OsData osData = getOsData(); osData.setName("unknown"); osData.setDescription("udpated"); OsBO instance = new OsBO(); String result = instance.updateOs(osData, null); System.out.println("testUpdateNonExistentOs result is "+result); }