### Question:
ScriptConfigurationService implements ScriptingService, ServiceListener { @Override public ScriptConfiguration create(ScriptConfiguration config, Subject subject) throws ScriptException { lock.readLock().lock(); try { failIfUuidExists(config.getId()); 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 shouldModifyMetaDataOnCreate() throws ScriptException { ScriptConfiguration sc = 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(); sc = service.create(sc, subject); assertNotNull(sc.getCreatedBy()); assertEquals(sc.getCreatedBy(), TEST_USER); assertNotNull(sc.getCreationDate()); assertNotEquals(sc.getCreationDate(), 0); assertNotNull(sc.getLastModifiedBy()); assertEquals(sc.getLastModifiedBy(), TEST_USER); assertNotNull(sc.getLastModifiedDate()); assertNotEquals(sc.getLastModifiedDate(), 0); }
@Test public void shouldFailIfNameExistsOnCreate() throws ScriptException { ScriptConfiguration sc = ScriptConfiguration.builder() .generateId() .setName("Existing Org Script") .setDescription("This is a test script configuration") .setScript("var a = 123;var b = 456;") .setLanguage(JAVASCRIPT) .setContext(POLICY_CONDITION).build(); try { service.create(sc, subject); fail("shouldFailIfNameExistsOnCreate"); } catch (ScriptException e) { assertEquals(e.getScriptErrorCode(), SCRIPT_NAME_EXISTS); } }
@Test public void shouldFailIfUuidExistsOnCreate() throws ScriptException { ScriptConfiguration sc = 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(); try { service.create(sc, subject); fail("shouldFailIfUuidExistsOnCreate"); } catch (ScriptException e) { assertEquals(e.getScriptErrorCode(), SCRIPT_UUID_EXISTS); } }