public virtual void setupJPAEntityToUpdate() { EntityManager manager = entityManagerFactory.createEntityManager(); manager.Transaction.begin(); entityToUpdate = new FieldAccessJPAEntity(); entityToUpdate.Id = 3L; manager.persist(entityToUpdate); manager.flush(); manager.Transaction.commit(); manager.close(); }
public virtual void setupQueryJPAEntity(long id) { if (entityToQuery == null) { EntityManager manager = entityManagerFactory.createEntityManager(); manager.Transaction.begin(); entityToQuery = new FieldAccessJPAEntity(); entityToQuery.Id = id; manager.persist(entityToQuery); manager.flush(); manager.Transaction.commit(); manager.close(); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Deployment public void testQueryJPAVariable() public virtual void testQueryJPAVariable() { setupQueryJPAEntity(2L); IDictionary <string, object> variables = new Dictionary <string, object>(); variables["entityToQuery"] = entityToQuery; ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("JPAVariableProcess", variables); // Query the processInstance ProcessInstance result = runtimeService.createProcessInstanceQuery().variableValueEquals("entityToQuery", entityToQuery).singleResult(); assertNotNull(result); assertEquals(result.Id, processInstance.Id); // Query with the same entity-type but with different ID should have no result FieldAccessJPAEntity unexistingEntity = new FieldAccessJPAEntity(); unexistingEntity.Id = 8888L; result = runtimeService.createProcessInstanceQuery().variableValueEquals("entityToQuery", unexistingEntity).singleResult(); assertNull(result); // All other operators are unsupported try { runtimeService.createProcessInstanceQuery().variableValueNotEquals("entityToQuery", entityToQuery).singleResult(); fail("Exception expected"); } catch (ProcessEngineException ae) { assertTextPresent("JPA entity variables can only be used in 'variableValueEquals'", ae.Message); } try { runtimeService.createProcessInstanceQuery().variableValueGreaterThan("entityToQuery", entityToQuery).singleResult(); fail("Exception expected"); } catch (ProcessEngineException ae) { assertTextPresent("JPA entity variables can only be used in 'variableValueEquals'", ae.Message); } try { runtimeService.createProcessInstanceQuery().variableValueGreaterThanOrEqual("entityToQuery", entityToQuery).singleResult(); fail("Exception expected"); } catch (ProcessEngineException ae) { assertTextPresent("JPA entity variables can only be used in 'variableValueEquals'", ae.Message); } try { runtimeService.createProcessInstanceQuery().variableValueLessThan("entityToQuery", entityToQuery).singleResult(); fail("Exception expected"); } catch (ProcessEngineException ae) { assertTextPresent("JPA entity variables can only be used in 'variableValueEquals'", ae.Message); } try { runtimeService.createProcessInstanceQuery().variableValueLessThanOrEqual("entityToQuery", entityToQuery).singleResult(); fail("Exception expected"); } catch (ProcessEngineException ae) { assertTextPresent("JPA entity variables can only be used in 'variableValueEquals'", ae.Message); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Deployment public void testIllegalEntities() public virtual void testIllegalEntities() { setupIllegalJPAEntities(); // Starting process instance with a variable that has a compound primary key, which is not supported. IDictionary <string, object> variables = new Dictionary <string, object>(); variables["compoundIdJPAEntity"] = compoundIdJPAEntity; try { runtimeService.startProcessInstanceByKey("JPAVariableProcessExceptions", variables); fail("Exception expected"); } catch (ProcessEngineException ae) { assertTextPresent("Cannot find field or method with annotation @Id on class", ae.Message); assertTextPresent("only single-valued primary keys are supported on JPA-enities", ae.Message); } // Starting process instance with a variable that has null as ID-value variables = new Dictionary <string, object>(); variables["nullValueEntity"] = new FieldAccessJPAEntity(); try { runtimeService.startProcessInstanceByKey("JPAVariableProcessExceptions", variables); fail("Exception expected"); } catch (ProcessEngineException ae) { assertTextPresent("Value of primary key for JPA-Entity is null", ae.Message); } // Starting process instance with an invalid type of ID // Under normal circumstances, JPA will throw an exception for this of the class is // present in the PU when creating EntityanagerFactory, but we test it *just in case* variables = new Dictionary <string, object>(); IllegalIdClassJPAEntity illegalIdTypeEntity = new IllegalIdClassJPAEntity(); illegalIdTypeEntity.Id = new DateTime(); variables["illegalTypeId"] = illegalIdTypeEntity; try { runtimeService.startProcessInstanceByKey("JPAVariableProcessExceptions", variables); fail("Exception expected"); } catch (ProcessEngineException ae) { assertTextPresent("Unsupported Primary key type for JPA-Entity", ae.Message); } // Start process instance with JPA-entity which has an ID but isn't persisted. When reading // the variable we should get an exception. variables = new Dictionary <string, object>(); FieldAccessJPAEntity nonPersistentEntity = new FieldAccessJPAEntity(); nonPersistentEntity.Id = 9999L; variables["nonPersistentEntity"] = nonPersistentEntity; ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("JPAVariableProcessExceptions", variables); try { runtimeService.getVariable(processInstance.Id, "nonPersistentEntity"); fail("Exception expected"); } catch (ProcessEngineException ae) { //JAVA TO C# CONVERTER WARNING: The .NET Type.FullName property will not always yield results identical to the Java Class.getName method: assertTextPresent("Entity does not exist: " + typeof(FieldAccessJPAEntity).FullName + " - 9999", ae.Message); } }
public virtual void setupJPAEntities() { EntityManager manager = entityManagerFactory.createEntityManager(); manager.Transaction.begin(); // Simple test data simpleEntityFieldAccess = new FieldAccessJPAEntity(); simpleEntityFieldAccess.Id = 1L; simpleEntityFieldAccess.Value = "value1"; manager.persist(simpleEntityFieldAccess); simpleEntityPropertyAccess = new PropertyAccessJPAEntity(); simpleEntityPropertyAccess.Id = 1L; simpleEntityPropertyAccess.Value = "value2"; manager.persist(simpleEntityPropertyAccess); subclassFieldAccess = new SubclassFieldAccessJPAEntity(); subclassFieldAccess.Id = 1L; subclassFieldAccess.Value = "value3"; manager.persist(subclassFieldAccess); subclassPropertyAccess = new SubclassPropertyAccessJPAEntity(); subclassPropertyAccess.Id = 1L; subclassPropertyAccess.Value = "value4"; manager.persist(subclassPropertyAccess); // Test entities with all possible ID types byteIdJPAEntity = new ByteIdJPAEntity(); byteIdJPAEntity.ByteId = (sbyte)1; manager.persist(byteIdJPAEntity); shortIdJPAEntity = new ShortIdJPAEntity(); shortIdJPAEntity.ShortId = (short)123; manager.persist(shortIdJPAEntity); integerIdJPAEntity = new IntegerIdJPAEntity(); integerIdJPAEntity.IntId = 123; manager.persist(integerIdJPAEntity); longIdJPAEntity = new LongIdJPAEntity(); longIdJPAEntity.LongId = 123456789L; manager.persist(longIdJPAEntity); floatIdJPAEntity = new FloatIdJPAEntity(); floatIdJPAEntity.FloatId = (float)123.45678; manager.persist(floatIdJPAEntity); doubleIdJPAEntity = new DoubleIdJPAEntity(); doubleIdJPAEntity.DoubleId = 12345678.987654; manager.persist(doubleIdJPAEntity); charIdJPAEntity = new CharIdJPAEntity(); charIdJPAEntity.CharId = 'g'; manager.persist(charIdJPAEntity); dateIdJPAEntity = new DateIdJPAEntity(); dateIdJPAEntity.DateId = DateTime.Now; manager.persist(dateIdJPAEntity); sqlDateIdJPAEntity = new SQLDateIdJPAEntity(); sqlDateIdJPAEntity.DateId = new java.sql.Date(new DateTime().Ticks); manager.persist(sqlDateIdJPAEntity); stringIdJPAEntity = new StringIdJPAEntity(); stringIdJPAEntity.StringId = "azertyuiop"; manager.persist(stringIdJPAEntity); bigDecimalIdJPAEntity = new BigDecimalIdJPAEntity(); bigDecimalIdJPAEntity.BigDecimalId = new decimal("12345678912345678900000.123456789123456789"); manager.persist(bigDecimalIdJPAEntity); bigIntegerIdJPAEntity = new BigIntegerIdJPAEntity(); bigIntegerIdJPAEntity.BigIntegerId = BigInteger.Parse("12345678912345678912345678900000"); manager.persist(bigIntegerIdJPAEntity); manager.flush(); manager.Transaction.commit(); manager.close(); }