/** testGetAllResourceTypeNames */ @Test public void testGetAllResourceTypeNames() { // create resource, identity and group OLATResource ores = JunitTestHelper.createRandomResource(); Identity identity = JunitTestHelper.createAndPersistIdentityAsUser("prop-3-" + UUID.randomUUID().toString()); BusinessGroup group = businessGroupService.createBusinessGroup( identity, "a buddygroup", "a desc", -1, -1, false, false, null); dbInstance.commitAndCloseSession(); // create a property Property p = pm.createPropertyInstance( identity, group, ores, "catall", "TestProperty", new Float(1.1), new Long(123456), "stringValue", "textValue"); pm.saveProperty(p); dbInstance.commitAndCloseSession(); Assert.assertNotNull(p.getResourceTypeName()); List<String> resTypeNames = pm.getAllResourceTypeNames(); assertTrue(resTypeNames.contains(ores.getResourceableTypeName())); }
/** testUserInsertFindDelete */ @Test public void testUserInsertFindDelete() { // create identity and property Identity id = JunitTestHelper.createAndPersistIdentityAsUser("user-prop-" + UUID.randomUUID().toString()); Property p = pm.createUserPropertyInstance( id, "catuser", "TestProperty", new Float(1.1), new Long(123456), "stringValue", "textValue"); pm.saveProperty(p); dbInstance.commitAndCloseSession(); p = pm.findUserProperty(id, "catuser", "TestProperty"); assertNotNull(p); assertEquals(p.getStringValue(), "stringValue"); assertEquals(p.getFloatValue(), new Float(1.1)); assertEquals(p.getTextValue(), "textValue"); pm.deleteProperty(p); p = pm.findUserProperty(id, "catuser", "TestProperty"); assertNull(p); dbInstance.commitAndCloseSession(); }
@Override public void contextInitialized(ServletContextEvent sce) { System.out.println("Context initialized..........."); PropertyManager propertyManager = new PropertyManager(); System.out.println( "Application property loaded..." + propertyManager.getProperty("TEST.MESSAGE.WELCOME")); }
/** * @param job * @param mailManager * @param currentUserEmail */ public static void sendAdminEmail(EmailManager mailManager, CustomerCareForm customerCareForm) { String fromMailAddressForHolden = PropertyManager.getProperty("mail.from.holden"); String subject = "Customer Care"; StringBuilder sb = new StringBuilder(); sb.append("<html><body>"); sb.append("<b>Topic: Customer Care</b>"); sb.append("<br><br>"); sb.append("Name : " + customerCareForm.getFirstName() + " " + customerCareForm.getLastName()); sb.append("<br><br>"); sb.append("E-Mail Address : " + customerCareForm.getEmail()); sb.append("<br><br>"); sb.append("Phone No. : " + customerCareForm.getPhone()); sb.append("<br><br>"); sb.append("Preferred Contact Time : " + customerCareForm.getPreferredContactTime()); sb.append("<br><br>"); sb.append("Message body : " + customerCareForm.getComments()); sb.append("<br><br>"); sb.append("<br>"); sb.append("</body></html>"); // get from the properties String adminEmails = PropertyManager.getProperty("mail.admin"); Set<String> alltoMails = new HashSet<String>(); String[] temp = adminEmails.split(";"); for (int cnt = 0; cnt < temp.length; cnt++) { alltoMails.add(temp[cnt]); } for (String toMail : alltoMails) { try { boolean success = mailManager.sendMail( toMail, fromMailAddressForHolden, fromMailAddressForHolden, subject, sb.toString(), "charset=UTF-8", new ArrayList<Attachment>()); System.out.println("email send success ? " + success); logger.info("email send success ? " + success); } catch (Exception e) { logger.error("email send falided ", e); throw new RuntimeException( "There is the error when sending the email, please try again later."); } } }
public static void main(String[] args) { Logger logger = org.slf4j.loggerFactory.getlogger(Runner.class); String textString = Files.getText(); PropertyManager propertyManager = new PropertyManager("components.property"); logger.info(String.valueOf(propertyManager.stringPropertyNames())); Parser parser = new Parser(); parser.configure(propertyManager); parser.parse(textString); }
/** testListProperties */ @Test public void testListProperties() { // create resource, identity and group OLATResource ores = JunitTestHelper.createRandomResource(); Identity identity = JunitTestHelper.createAndPersistIdentityAsUser("prop-4-" + UUID.randomUUID().toString()); BusinessGroup group = businessGroupService.createBusinessGroup( identity, "a buddygroup", "a desc", -1, -1, false, false, null); dbInstance.commitAndCloseSession(); Property p = pm.createPropertyInstance( identity, group, ores, "cat", "TestProperty", new Float(1.1), new Long(123456), "stringValue", "textValue"); pm.saveProperty(p); List<Property> entries = PropertyManager.getInstance() .listProperties( identity, group, ores.getResourceableTypeName(), ores.getResourceableId(), "cat", "TestProperty"); Assert.assertNotNull(entries); Assert.assertEquals(1, entries.size()); Property prop = entries.get(0); assertEquals(ores.getResourceableTypeName(), prop.getResourceTypeName()); assertEquals(ores.getResourceableId(), prop.getResourceTypeId()); int numOfEntries = PropertyManager.getInstance() .countProperties( identity, group, ores.getResourceableTypeName(), ores.getResourceableId(), "cat", "TestProperty", null, null); Assert.assertEquals(entries.size(), numOfEntries); }
public class MailUtil { private static class SMTPAuthenticator extends javax.mail.Authenticator { public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(smtpUsername, smtpPassword); } } public static final String smtpHost = PropertyManager.getString("MAIL_HOST"); public static final String smtpUsername = PropertyManager.getString("MAIL_SENDER"); public static final String smtpPassword = PropertyManager.getString("MAIL_PASS"); public static final String smtpPort = PropertyManager.getString("MAIL_PORT"); public void send(String mailto, String subject, String textMessage) throws FileNotFoundException, MessagingException { send(mailto, subject, textMessage, "text/plain; charset=euc-kr"); } public void send(String mailto, String subject, String textMessage, String contentType) throws FileNotFoundException, MessagingException { Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider()); Properties props = new Properties(); props.put("mail.smtp.user", smtpUsername); props.put("mail.smtp.host", smtpHost); props.put("mail.smtp.port", smtpPort); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtps.auth", "true"); props.put("mail.smtp.debug", "true"); props.put("mail.smtp.socketFactory.port", smtpPort); props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); props.put("mail.smtp.socketFactory.fallback", "false"); props.put("mail.smtp.ssl", "true"); Authenticator auth = new SMTPAuthenticator(); Session smtpSession = Session.getInstance(props, auth); smtpSession.setDebug(true); Message message = new MimeMessage(smtpSession); InternetAddress[] address = {new InternetAddress(mailto)}; message.setRecipients(Message.RecipientType.TO, address); message.setSubject(subject); message.setSentDate(new Date()); message.setContent(textMessage, contentType); Transport tr = smtpSession.getTransport("smtp"); tr.connect(smtpHost, smtpUsername, smtpPassword); tr.sendMessage(message, message.getAllRecipients()); tr.close(); } }
public static void main(String[] args) { PropertyManager manager = PropertyManager.newInstance(args[0]); try { Generator generator = new JspToFaceletsTLD21Generator(manager); generator.generate(GeneratorUtil.getConfigBean(args[1])); } catch (Exception e) { throw new RuntimeException(e); } } // END main
private void setUpIfNeeded() { if (checkPlayServices()) { String regId = PropertyManager.getInstance().getRegistrationId(); if (!regId.equals("")) { doRealStart(); } else { registerInBackground(); } } }
@Test public void testFindWithResourceIdList() { // create resource, identity OLATResource ores = JunitTestHelper.createRandomResource(); Identity identity = JunitTestHelper.createAndPersistIdentityAsUser("prop-2-" + UUID.randomUUID().toString()); dbInstance.commitAndCloseSession(); // create the property Property p = pm.createPropertyInstance( identity, null, ores, "catidlist", "TestProperty", new Float(1.1), new Long(123456), "stringValue", "textValue"); pm.saveProperty(p); dbInstance.commitAndCloseSession(); // check with empty list List<Property> emptyProps = pm.findProperties( ores.getResourceableTypeName(), Collections.<Long>emptyList(), "catidlist", "TestProperty"); assertNotNull(emptyProps); Assert.assertTrue(emptyProps.isEmpty()); // check with a real value and a dummy List<Long> resIds = new ArrayList<Long>(); resIds.add(ores.getResourceableId()); resIds.add(2456l); // dummy List<Property> props = pm.findProperties(ores.getResourceableTypeName(), resIds, "catidlist", "TestProperty"); assertNotNull(props); Assert.assertEquals(1, props.size()); Assert.assertEquals(p, props.get(0)); }
@Test public void testFindProperties() { // create identities, group and resource OLATResource res = JunitTestHelper.createRandomResource(); Identity id1 = JunitTestHelper.createAndPersistIdentityAsUser("prop-8-" + UUID.randomUUID().toString()); Identity id2 = JunitTestHelper.createAndPersistIdentityAsUser("prop-9-" + UUID.randomUUID().toString()); BusinessGroup group = businessGroupService.createBusinessGroup( id1, "a buddygroup", "a desc", -1, -1, false, false, null); dbInstance.commitAndCloseSession(); String category = "cat3"; String propertyName = "TestProperty3"; String textValue = "textValue3"; Property p = pm.createPropertyInstance( id1, group, res, category, propertyName, new Float(1.1), new Long(123456), "stringValue", textValue); pm.saveProperty(p); p = pm.createPropertyInstance( id2, group, res, category, propertyName, new Float(1.1), new Long(123456), "stringValue", textValue); pm.saveProperty(p); List<Property> propertyList = pm.findProperties( id1, group, res.getResourceableTypeName(), res.getResourceableId(), category, propertyName); assertEquals(1, propertyList.size()); assertEquals(propertyName, propertyList.get(0).getName()); assertEquals(textValue, propertyList.get(0).getTextValue()); int deletedCount1 = pm.deleteProperties(id1, group, res, category, propertyName); Assert.assertEquals(1, deletedCount1); int deletedCount2 = pm.deleteProperties(id2, group, res, category, propertyName); Assert.assertEquals(1, deletedCount2); }
public void reset(PropertyManager propertyManager) { init(); // Xerces properties fSymbolTable = (SymbolTable) propertyManager.getProperty( Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY); fErrorReporter = (XMLErrorReporter) propertyManager.getProperty( Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY); fEntityManager = (XMLEntityManager) propertyManager.getProperty(ENTITY_MANAGER); fEntityStore = fEntityManager.getEntityStore(); fEntityScanner = (XMLEntityScanner) fEntityManager.getEntityScanner(); // fEntityManager.reset(); // DTD preparsing defaults: fValidation = false; fNotifyCharRefs = false; }
private File getBaseOutputDirectory() { File outputDir = new File( System.getProperty("user.dir") + File.separatorChar + manager.getProperty(PropertyManager.BASE_OUTPUT_DIR)); if (!outputDir.exists()) { outputDir.mkdirs(); } return outputDir; } // END getBaseOutputDirectory
/** testGenericInsertFindDelete */ @Test public void testGenericInsertFindDelete() { // create resource, identity and group OLATResource ores = JunitTestHelper.createRandomResource(); Identity identity = JunitTestHelper.createAndPersistIdentityAsUser("prop-1-" + UUID.randomUUID().toString()); BusinessGroup group = businessGroupService.createBusinessGroup( identity, "a buddygroup", "a desc", -1, -1, false, false, null); dbInstance.commitAndCloseSession(); Property p = pm.createPropertyInstance( identity, group, ores, "catgeneric", "TestProperty", new Float(1.1), new Long(123456), "stringValue", "textValue"); pm.saveProperty(p); dbInstance.commitAndCloseSession(); p = pm.findProperty(identity, group, ores, "catgeneric", "TestProperty"); assertNotNull(p); assertEquals(p.getStringValue(), "stringValue"); assertEquals(p.getFloatValue(), new Float(1.1)); assertEquals(p.getLongValue(), new Long(123456)); assertEquals(p.getTextValue(), "textValue"); pm.deleteProperty(p); p = pm.findProperty(identity, group, ores, "catgeneric", "TestProperty"); assertNull(p); }
public static void deleteTemplate(Template template) throws SQLException { if (template.getId() != null) { for (Templateproperty property : template.getEigenschaften()) { PropertyManager.deleteTemplateProperty(property); } Connection connection = null; try { connection = MySQLHelper.getInstance().getConnection(); QueryRunner run = new QueryRunner(); String sql = "DELETE FROM vorlagen WHERE VorlagenID = " + template.getId(); run.update(connection, sql); } finally { if (connection != null) { MySQLHelper.closeConnection(connection); } } } }
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.menu_view); boolean alarm = PropertyManager.getInstance().getIsAlram(); streambtn = (Button) findViewById(R.id.streambtn); storagebtn = (Button) findViewById(R.id.storagebtn); alarmbtn = (ToggleButton) findViewById(R.id.alrambtn); streambtn.setOnClickListener( new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub Intent intent = new Intent(MenuActivity.this, WebViewActivity.class); startActivity(intent); } }); storagebtn.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Intent intent = new Intent(MenuActivity.this, LogListActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); } }); alarmbtn.setOnCheckedChangeListener( new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // �븣�엺 �꽭�똿 媛� 蹂�寃� PropertyManager.getInstance().setIsAlram(isChecked); } }); alarmbtn.setChecked(alarm); }
@Override public Template handle(ResultSet rs) throws SQLException { try { if (rs.next()) { int templateId = rs.getInt("VorlagenID"); String herkunft = rs.getString("Herkunft"); int processId = rs.getInt("ProzesseID"); Template template = new Template(); template.setId(templateId); template.setHerkunft(herkunft); template.setProcessId(processId); List<Templateproperty> properties = PropertyManager.getTemplateProperties(templateId); template.setEigenschaften(properties); return template; } } finally { if (rs != null) { rs.close(); } } return null; }
public static void sendCustomerEmail( EmailManager mailManager, CustomerCareForm customerCareForm) { String fromMailAddressForUser = PropertyManager.getProperty("mail.from.user"); String subject = "Customer Care"; StringBuilder sb = new StringBuilder(); sb.append("<html><body>"); sb.append("Hi!"); sb.append("<br><br>"); sb.append("Thanks for submitting your feedback form to us. "); sb.append("<br><br>"); sb.append("We will review your request as soon as possible and get in touch. "); sb.append("<br><br>"); sb.append("Regards,"); sb.append("<br>"); sb.append("Customer Assistance team"); sb.append("</body></html>"); try { boolean success = mailManager.sendMail( customerCareForm.getEmail(), fromMailAddressForUser, fromMailAddressForUser, subject, sb.toString(), "charset=UTF-8", new ArrayList<Attachment>()); System.out.println("CustomerEmail send success ? " + success); logger.info("CustomerEmail send success ? " + success); } catch (Exception e) { logger.error("CustomerEmail send falided ", e); throw new RuntimeException( "There is the error when sending the CustomerEmail , please try again later."); } }
public static void saveTemplate(Template template) throws SQLException { Connection connection = null; try { connection = MySQLHelper.getInstance().getConnection(); QueryRunner run = new QueryRunner(); String sql = ""; if (template.getId() == null) { sql = "INSERT INTO vorlagen ( Herkunft, ProzesseID ) VALUES ( ?, ?)"; Object[] param = { template.getHerkunft() == null ? null : template.getHerkunft(), template.getProzess().getId() }; int id = run.insert(connection, sql, MySQLHelper.resultSetToIntegerHandler, param); template.setId(id); } else { sql = "UPDATE vorlagen set Herkunft = ?, ProzesseID = ? WHERE VorlagenID =" + template.getId(); Object[] param = { template.getHerkunft() == null ? null : template.getHerkunft(), template.getProzess().getId() }; run.update(connection, sql, param); } } finally { if (connection != null) { MySQLHelper.closeConnection(connection); } } List<Templateproperty> templateProperties = template.getEigenschaften(); for (Templateproperty property : templateProperties) { property.setTemplateId(template.getId()); property = PropertyManager.saveTemplateProperty(property); } }
/** * Create a <code>ResourceConfiguration</code> based on the specification stored in the project * file (.cdtbuild). * * @param parent The <code>IConfiguration</code> the resource configuration will be added to. * @param element The XML element that contains the resource configuration settings. */ public ResourceConfiguration( IConfiguration parent, ICStorageElement element, String managedBuildRevision) { super(parent, element, true); isExtensionResourceConfig = false; setResourceData(new BuildFileData(this)); setManagedBuildRevision(managedBuildRevision); // Initialize from the XML attributes loadFromProject(element); // Load children ICStorageElement configElements[] = element.getChildren(); for (int i = 0; i < configElements.length; ++i) { ICStorageElement configElement = configElements[i]; if (configElement.getName().equals(ITool.TOOL_ELEMENT_NAME)) { Tool tool = new Tool(this, configElement, getManagedBuildRevision()); addTool(tool); } } String rebuild = PropertyManager.getInstance().getProperty(this, REBUILD_STATE); if (rebuild == null || Boolean.valueOf(rebuild).booleanValue()) setRebuildState(true); setDirty(false); }
@Test public void testRealWorldScoreFloatValues() { // delete everything from previous tests pm.deleteProperties(null, null, null, "test", "TestPropertyFloatValue1"); pm.deleteProperties(null, null, null, "test", "TestPropertyFloatValue2"); // Test setting and getting of a normal float value Property prop1 = pm.createPropertyInstance( null, null, null, "test", "TestPropertyFloatValue1", new Float(0.9), null, null, null); pm.saveProperty(prop1); Property prop2 = pm.createPropertyInstance( null, null, null, "test", "TestPropertyFloatValue2", new Float(0.1), null, null, null); pm.saveProperty(prop2); dbInstance.commitAndCloseSession(); prop1 = pm.findProperty(null, null, null, "test", "TestPropertyFloatValue1"); prop2 = pm.findProperty(null, null, null, "test", "TestPropertyFloatValue2"); // In course assessment 0.1 + 0.9 must exactly give 1 as a result assertEquals( 1, prop1.getFloatValue().floatValue() + prop2.getFloatValue().floatValue(), 0.00001); pm.deleteProperties(null, null, null, "test", "TestPropertyFloatValue1"); pm.deleteProperties(null, null, null, "test", "TestPropertyFloatValue2"); }
public void setVisible(boolean v) { visible = v; if (pm != null) pm.setPropertyVisibleCallback(this, v); }
public void setValue(T newValue) { value = newValue; if (pm != null) pm.setPropertyValueCallback(this, newValue); }
@Test public void testFindIdentities() { // create identities, group and resource OLATResource res = JunitTestHelper.createRandomResource(); Identity id1 = JunitTestHelper.createAndPersistIdentityAsUser("prop-7-" + UUID.randomUUID().toString()); Identity id2 = JunitTestHelper.createAndPersistIdentityAsUser("prop-10-" + UUID.randomUUID().toString()); Identity id3 = JunitTestHelper.createAndPersistIdentityAsUser("prop-11-" + UUID.randomUUID().toString()); Identity id4 = JunitTestHelper.createAndPersistIdentityAsUser("prop-12-" + UUID.randomUUID().toString()); BusinessGroup group = businessGroupService.createBusinessGroup( id1, "a buddygroup", "a desc", -1, -1, false, false, null); dbInstance.commitAndCloseSession(); String propName = UUID.randomUUID().toString(); Property p = pm.createPropertyInstance( id1, group, res, "cat", propName, new Float(1.1), new Long(123456), "stringValue", "textValue"); pm.saveProperty(p); p = pm.createPropertyInstance( id2, group, res, "cat", propName, new Float(1.1), new Long(123456), "stringValue", "textValue"); pm.saveProperty(p); p = pm.createPropertyInstance( id3, group, res, "cat", propName, new Float(1.1), new Long(123456), "stringValue", "textValue"); pm.saveProperty(p); p = pm.createPropertyInstance( id4, group, res, "cat", propName, new Float(1.1), new Long(123456), "stringValue", "textValue"); pm.saveProperty(p); p = pm.createPropertyInstance( id1, group, res, "cat2", propName, new Float(1.1), new Long(123456), "stringValue", "textValue"); pm.saveProperty(p); p = pm.createPropertyInstance( id2, group, res, "cat2", propName, new Float(1.1), new Long(123456), "stringValue", "textValue"); pm.saveProperty(p); dbInstance.commitAndCloseSession(); // now find identities List<Identity> ids = pm.findIdentitiesWithProperty(res, "cat", propName, false); assertEquals(4, ids.size()); ids = pm.findIdentitiesWithProperty(res, "cat", propName, true); assertEquals(4, ids.size()); ids = pm.findIdentitiesWithProperty(null, "cat", propName, false); assertEquals(4, ids.size()); ids = pm.findIdentitiesWithProperty(null, "cat", propName, true); assertEquals(0, ids.size()); ids = pm.findIdentitiesWithProperty(null, "cat2", propName, false); assertEquals(2, ids.size()); ids = pm.findIdentitiesWithProperty(null, null, propName, false); assertEquals(4, ids.size()); // not 6, must be distinct ids = pm.findIdentitiesWithProperty(null, null, propName, true); assertEquals(0, ids.size()); }
/** * testFloatValues THIS test does only success when you run it against mysql with FLOAT(65,30). * FLOAT(65,30) is mysql specific and if you let hibernate generate the tables automatic it will * result in FLOAT only and this test will fail. So this means that you have to populate the * tables yourself via the sql file. */ @Test public void testFloatValues() { // create identity, group and resource OLATResource res = JunitTestHelper.createRandomResource(); Identity identity = JunitTestHelper.createAndPersistIdentityAsUser("prop-6-" + UUID.randomUUID().toString()); BusinessGroup group = businessGroupService.createBusinessGroup( identity, "a buddygroup", "a desc", -1, -1, false, false, null); dbInstance.commitAndCloseSession(); Property original, copy; // gs:changed to FLOAT(65,30) to be compatible with hsqldb and auto generated ddl // Define my own MAX float value because the db precision changed from DECIMAL(78,36) to // DECIMAL(65,30) double floatMaxValue = 1E34; // 1E35 does failed with mysql 5.0.x original = pm.createPropertyInstance( identity, group, res, "cat", "TestProperty", new Float(1234534343424213.1324534533456), new Long(123456), "stringValue", "textValue"); pm.saveProperty(original); // DBFactory.getInstance().evict(original); dbInstance.commitAndCloseSession(); copy = pm.findProperty(identity, group, res, "cat", "TestProperty"); float f1F = original.getFloatValue().floatValue(); float copyF = copy.getFloatValue().floatValue(); assertEquals("values differ:" + f1F + ", and " + copyF, f1F, copyF, 0.0000000001f); pm.deleteProperties(identity, group, res, "cat", "TestProperty"); // note: on mysql 5.0, the standard installation is strict mode, which reports any data // truncation error as a real jdbc error. // -1e35 seems out of range for DECIMAL(65,30) so data truncation occurs??? // +-> 30 digits to the right side of decimal point // From mysql: // The declaration syntax for a DECIMAL column is DECIMAL(M,D). The ranges of values for the // arguments in MySQL 5.1 are as follows: // M is the maximum number of digits (the precision). It has a range of 1 to 65. (Older versions // of MySQL allowed a range of 1 to 254.) // D is the number of digits to the right of the decimal point (the scale). It has a range of 0 // to 30 and must be no larger than M. original = pm.createPropertyInstance( identity, group, res, "cat", "TestProperty", new Float(-floatMaxValue), new Long(123456), "stringValue", "textValue"); pm.saveProperty(original); dbInstance.commitAndCloseSession(); copy = pm.findProperty( identity, group, res, "cat", "TestProperty"); // this one failes at the moment for hsqldb with: incompatible data // type in conversion: from SQL type DECIMAL to java.lang.Double, // value: // -9999999790214767953607394487959552.000000000000000000000000000000 assertTrue(original.getFloatValue().floatValue() == copy.getFloatValue().floatValue()); pm.deleteProperties(identity, group, res, "cat", "TestProperty"); original = pm.createPropertyInstance( identity, group, res, "cat", "TestProperty", new Float(floatMaxValue), new Long(123456), "stringValue", "textValue"); pm.saveProperty(original); dbInstance.commitAndCloseSession(); copy = pm.findProperty(identity, group, res, "cat", "TestProperty"); assertTrue(original.getFloatValue().floatValue() == copy.getFloatValue().floatValue()); pm.deleteProperties(identity, group, res, "cat", "TestProperty"); original = pm.createPropertyInstance( identity, group, res, "cat", "TestProperty", new Float(Long.MAX_VALUE), new Long(123456), "stringValue", "textValue"); pm.saveProperty(original); dbInstance.commitAndCloseSession(); copy = pm.findProperty(identity, group, res, "cat", "TestProperty"); assertTrue(original.getFloatValue().floatValue() == copy.getFloatValue().floatValue()); pm.deleteProperties(identity, group, res, "cat", "TestProperty"); original = pm.createPropertyInstance( identity, group, res, "cat", "TestProperty", new Float(Long.MIN_VALUE), new Long(123456), "stringValue", "textValue"); pm.saveProperty(original); dbInstance.commitAndCloseSession(); copy = pm.findProperty(identity, group, res, "cat", "TestProperty"); assertTrue(original.getFloatValue().floatValue() == copy.getFloatValue().floatValue()); pm.deleteProperties(identity, group, res, "cat", "TestProperty"); }
/** * Performance test of 500 propertycreations per type. Rename to testPerf500Properties to include * this test in the test suit. */ @Test public void testPerf500Properties() { // create identity, group and resource OLATResource res = JunitTestHelper.createRandomResource(); Identity identity = JunitTestHelper.createAndPersistIdentityAsUser("prop-5-" + UUID.randomUUID().toString()); BusinessGroup group = businessGroupService.createBusinessGroup( identity, "a buddygroup", "a desc", -1, -1, false, false, null); dbInstance.commitAndCloseSession(); long start, stop; long count = 500; // create generic proerties log.info("----------------------------------------------------------------"); log.info("Performance test startet. Running " + count + " cycles per test."); log.info("CREATE generic property test started..."); start = System.currentTimeMillis(); for (int i = 0; i < count; i++) { Property p = pm.createPropertyInstance( identity, group, res, "perf500", "TestProperty" + i, new Float(1.1), new Long(123456), "stringValue", "textValue"); pm.saveProperty(p); if (i % 50 == 0) { dbInstance.commitAndCloseSession(); } } dbInstance.commitAndCloseSession(); stop = System.currentTimeMillis(); log.info( "CREATE generic property test: " + (stop - start) + " ms (" + (count * 1000 / (stop - start)) + "/sec)"); // some find identitites tests List<Identity> ids = pm.findIdentitiesWithProperty(null, null, "perf500", null, false); Assert.assertNotNull("Identities cannot be null", ids); Assert.assertFalse("Identities cannot be empty", ids.isEmpty()); Assert.assertTrue("Identities must contains reference identity", ids.contains(identity)); // create course and user properties log.info("Preparing user/group properties test. Creating additional properties.."); start = System.currentTimeMillis(); for (int i = 0; i < count; i++) { Property pUser = pm.createUserPropertyInstance( identity, "perf500", "TestProperty" + i, new Float(1.1), new Long(123456), "stringValue", "textValue"); pm.saveProperty(pUser); if (i % 50 == 0) { dbInstance.commitAndCloseSession(); } } dbInstance.commitAndCloseSession(); stop = System.currentTimeMillis(); log.info("Ready : " + (stop - start) + " ms (" + (2 * count * 1000 / (stop - start)) + "/sec)"); log.info("Starting find tests. DB holds " + count * 3 + " records."); // find generic property test log.info("FIND generic property test started..."); start = System.currentTimeMillis(); for (int i = 0; i < count; i++) { Property p = pm.findProperty(identity, group, res, "perf500", "TestProperty" + i); assertNotNull("Must find the p (count=" + i + ")", p); dbInstance.commitAndCloseSession(); } stop = System.currentTimeMillis(); log.info( "FIND generic property test: " + (stop - start) + " ms (" + (count * 1000 / (stop - start)) + "/sec)"); // find user property test log.info("FIND user property test started..."); start = System.currentTimeMillis(); for (int i = 0; i < count; i++) { Property p = pm.findUserProperty(identity, "perf500", "TestProperty" + i); assertNotNull("Must find the p (count=" + i + ")", p); dbInstance.commitAndCloseSession(); } stop = System.currentTimeMillis(); log.info( "FIND user property test: " + (stop - start) + " ms (" + (count * 1000 / (stop - start)) + "/sec)"); // find & delete log.info("FIND and DELETE generic property test started..."); start = System.currentTimeMillis(); for (int i = 0; i < count; i++) { Property p = pm.findUserProperty(identity, "perf500", "TestProperty" + i); pm.deleteProperty(p); } stop = System.currentTimeMillis(); log.info( "FIND and DELETE generic property test: " + (stop - start) + " ms (" + (count * 1000 / (stop - start)) + "/sec)"); log.info("----------------------------------------------------------------"); log.info("Performance test finished."); }
@Test public void testDeleteUserData() { // create some identities and properties Identity id1 = JunitTestHelper.createAndPersistIdentityAsUser( "del-user-1-" + UUID.randomUUID().toString()); Identity id2 = JunitTestHelper.createAndPersistIdentityAsUser( "del-user-2-" + UUID.randomUUID().toString()); Property p10 = pm.createPropertyInstance( id1, null, null, "prop-del-1", "TestProperty", new Float(1.1), new Long(123456), "stringValue", "textValue"); pm.saveProperty(p10); Property p11 = pm.createPropertyInstance( id1, null, null, "prop-del-2", "TestProperty", new Float(1.1), new Long(123456), "stringValue", "textValue"); pm.saveProperty(p11); Property p20 = pm.createPropertyInstance( id2, null, null, "prop-del-3", "TestProperty", new Float(1.1), new Long(123456), "stringValue", "textValue"); pm.saveProperty(p20); dbInstance.commitAndCloseSession(); // delete user 1 datas pm.deleteUserData(id1, "del-" + id1.getName(), null); dbInstance.commitAndCloseSession(); // check if really deleted Property p10x = pm.findUserProperty(id1, "prop-del-1", "TestProperty"); assertNull(p10x); Property p11x = pm.findUserProperty(id1, "prop-del-2", "TestProperty"); assertNull(p11x); // check if id2 has still its properties Property p20x = pm.findUserProperty(id2, "prop-del-3", "TestProperty"); assertNotNull(p20x); }
public void setReadOnly(boolean r) { readOnly = r; if (pm != null) pm.setPropertyReadOnlyCallback(this, r); }
@Test public void testFindWithIdentityList() { // create identities, resource and properties Identity id1 = JunitTestHelper.createAndPersistIdentityAsUser("cat-id-1-" + UUID.randomUUID().toString()); Identity id2 = JunitTestHelper.createAndPersistIdentityAsUser("cat-id-2-" + UUID.randomUUID().toString()); Identity id3 = JunitTestHelper.createAndPersistIdentityAsUser("cat-id-3-" + UUID.randomUUID().toString()); OLATResource ores = JunitTestHelper.createRandomResource(); Property p1 = pm.createPropertyInstance( id1, null, ores, "catidentlist", "TestProperty", new Float(1.1), new Long(123456), "stringValue", "textValue"); pm.saveProperty(p1); Property p2 = pm.createPropertyInstance( id2, null, ores, "catidentlist", "TestProperty", new Float(1.1), new Long(123456), "stringValue", "textValue"); pm.saveProperty(p2); Property p3 = pm.createPropertyInstance( id3, null, ores, "catidentlist", "TestProperty", new Float(1.1), new Long(123456), "stringValue", "textValue"); pm.saveProperty(p3); dbInstance.commitAndCloseSession(); // check with empty list List<Property> emptyProps = pm.findProperties(Collections.<Identity>emptyList(), ores, "catidentlist", "TestProperty"); assertNotNull(emptyProps); Assert.assertTrue(emptyProps.isEmpty()); // check with a real value and a dummy List<Identity> identities = new ArrayList<Identity>(); identities.add(id1); identities.add(id2); List<Property> props = pm.findProperties(identities, ores, "catidentlist", "TestProperty"); assertNotNull(props); Assert.assertEquals(2, props.size()); Assert.assertTrue(props.contains(p1)); Assert.assertTrue(props.contains(p2)); }
private void saveRebuildState() { PropertyManager.getInstance() .setProperty(this, REBUILD_STATE, Boolean.toString(needsRebuild())); }