### Question:
ScriptConfigurationService implements ScriptingService, ServiceListener { @Override public ScriptConfiguration update(ScriptConfiguration config, Subject subject) throws ScriptException { lock.readLock().lock(); try { final ScriptConfiguration oldConfig = get(config.getId()); if (!oldConfig.getName().equals(config.getName())) { failIfNameExists(config.getName()); } final ScriptConfiguration updatedConfig = setMetaData(config, subject); save(updatedConfig); return updatedConfig; } finally { lock.readLock().unlock(); } } @Inject  ScriptConfigurationService(Logger logger, String realm, CoreWrapper coreWrapper, ServiceConfigManager scm); @Override ScriptConfiguration create(ScriptConfiguration config, Subject subject); @Override ScriptConfiguration update(ScriptConfiguration config, Subject subject); @Override void delete(String uuid); @Override Set<ScriptConfiguration> getAll(); @Override ScriptConfiguration get(String uuid); @Override Set<ScriptConfiguration> get(QueryFilter<String> queryFilter); @Override void schemaChanged(String serviceName, String version); @Override void globalConfigChanged(String serviceName, String version, String groupName, String serviceComponent,
            int type); @Override void organizationConfigChanged(String serviceName, String version, String orgName, String groupName,
            String serviceComponent, int type);  }### Answer:
@Test public void shouldModifyMetaDataOnUpdate() throws ScriptException { ScriptConfiguration scNew = ScriptConfiguration.builder() .setId("ExistingOrgScript") .setName("MyJavaScript") .setDescription("This is a test script configuration") .setScript("var a = 123;var b = 456;") .setLanguage(JAVASCRIPT) .setContext(POLICY_CONDITION).build(); scNew = service.update(scNew, subject); assertNotNull(scNew.getCreatedBy()); assertEquals(scNew.getCreatedBy(), TEST_USER); assertNotNull(scNew.getCreationDate()); assertNotEquals(scNew.getCreationDate(), 0); assertNotNull(scNew.getLastModifiedBy()); assertEquals(scNew.getLastModifiedBy(), TEST_USER); assertNotNull(scNew.getLastModifiedDate()); assertNotEquals(scNew.getLastModifiedDate(), 0); }
@Test public void shouldFailIfUuidDoesNotExistOnUpdate() throws ScriptException { ScriptConfiguration scNew = ScriptConfiguration.builder() .generateId() .setName("MyJavaScript") .setDescription("This is a test script configuration") .setScript("var a = 123;var b = 456;") .setLanguage(JAVASCRIPT) .setContext(POLICY_CONDITION).build(); try { service.update(scNew, subject); fail("shouldFailIfUuidDoesNotExistOnUpdate"); } catch (ScriptException e) { assertEquals(e.getScriptErrorCode(), SCRIPT_UUID_NOT_FOUND); } }
@Test public void shouldFailIfNameExistOnUpdate() throws ScriptException { ScriptConfiguration scNew = ScriptConfiguration.builder() .setId("ExistingOrgScript") .setName("Existing Global Script") .setDescription("This is a test script configuration") .setScript("var a = 123;var b = 456;") .setLanguage(JAVASCRIPT) .setContext(POLICY_CONDITION).build(); try { service.update(scNew, subject); fail("shouldFailIfNameExistOnUpdate"); } catch (ScriptException e) { assertEquals(e.getScriptErrorCode(), SCRIPT_NAME_EXISTS); } }