### Question:
ServiceAdminManager { public JSONObject addService(JSONObject jo) throws InvalidServiceDescriptionException, JSONException, ExistingResourceException, ConfigurationException, ParseException { new RegistrationValidator().validateInfo(jo); try { JSONObject date = new JSONObject(); date.put("$date", DateUtil.toUTCFormat(new Date())); jo.put(ServiceBasicAttributeNames.SERVICE_CREATED_ON .getAttributeName(), date); if (!jo.has(ServiceBasicAttributeNames.SERVICE_UPDATE_SINCE .getAttributeName())) { jo.put(ServiceBasicAttributeNames.SERVICE_UPDATE_SINCE .getAttributeName(), date); } if (!jo.has(ServiceBasicAttributeNames.SERVICE_EXPIRE_ON .getAttributeName())) { Integer expTime = EMIRServer.getServerProperties().getIntValue(ServerProperties.PROP_RECORD_EXPIRY_DEFAULT); if (log.isDebugEnabled()) { log.debug("The expiry attribute is missing from the registered service information. The information will be expired in "+ expTime +"day from now"); } DateUtil.setExpiryTime(jo, expTime); } serviceDB.insert(new ServiceObject(jo)); return jo; } catch (PersistentStoreFailureException e) { Log.logException("",e,log); }catch (ExistingResourceException e) { if (EMIRServer.getServerProperties().isGlobalEnabled()) { try { if (serviceDB.getServiceByEndpointID(jo.getString( ServiceBasicAttributeNames.SERVICE_ENDPOINT_ID.getAttributeName())) .getServiceOwner() == null || jo.getString( ServiceBasicAttributeNames.SERVICE_ENDPOINT_ID.getAttributeName()) .equals(EMIRServer.getServerProperties() .getValue(ServerProperties.PROP_ADDRESS))){ serviceDB.update(new ServiceObject(jo)); return jo; } else { throw new ExistingResourceException(e); } } catch (MultipleResourceException e1) { Log.logException("",e,log); } catch (NonExistingResourceException e1) { Log.logException("",e,log); } catch (PersistentStoreFailureException e1) { Log.logException("",e,log); } } else { throw new ExistingResourceException(e); } } return null; } ServiceAdminManager();  ServiceAdminManager(MongoDBServiceDatabase mongoDB); JSONObject addService(JSONObject jo); void removeService(String endpointID, String messageTime); JSONObject updateService(JSONObject jo); JSONObject findServiceByUrl(String url); JSONObject findServiceByEndpointID(String endpointID); void removeExpiredEntries(); void removeAll(); List<ServiceObject> findAll(); boolean checkOwner(String owner, String sendpointID); boolean checkMessageGenerationTime(String messageTime, String sendpointID); void removeServices(JSONObject query);  }### Answer:
@Test public void addServiceDescription() throws Exception { assertNotNull(adminMgr.addService(TestValueConstants.getJSONWithMandatoryAttributes())); System.out.println("service added"); }
@Test(expected = ExistingResourceException.class) public void failDuplicateInsertion() throws Exception { adminMgr.addService(TestValueConstants.getJSONWithMandatoryAttributes()); adminMgr.addService(TestValueConstants.getJSONWithMandatoryAttributes()); }