@Test public void listRequest() { JdbcContentPersistenceService tested = getTested(); tested.LIST_PAGE_SIZE = 3; String sysContentType = "testtypelist"; // case - no table exists for type { ListRequest req = tested.listRequestInit(sysContentType); Assert.assertFalse(req.hasContent()); } // case - data handling test { // store in reverse order to see if listing uses correct ordering for (int i = 7; i >= 1; i--) addContent(tested, sysContentType, "aaa-" + i); ListRequest req = tested.listRequestInit(sysContentType); Assert.assertTrue(req.hasContent()); Assert.assertNotNull(req.content()); Assert.assertEquals(3, req.content().size()); Assert.assertEquals("aaa-1", req.content().get(0).getId()); // assert content is correctly loaded Assert.assertEquals( "aaa-1", req.content().get(0).getContent().get(ContentObjectFields.SYS_ID)); Assert.assertEquals( "value aaa-1", req.content().get(0).getContent().get(ContentObjectFields.SYS_DESCRIPTION)); // assert id only for others Assert.assertEquals("aaa-2", req.content().get(1).getId()); Assert.assertEquals("aaa-3", req.content().get(2).getId()); req = tested.listRequestNext(req); Assert.assertTrue(req.hasContent()); Assert.assertNotNull(req.content()); Assert.assertEquals(3, req.content().size()); Assert.assertEquals("aaa-4", req.content().get(0).getId()); Assert.assertEquals("aaa-5", req.content().get(1).getId()); Assert.assertEquals("aaa-6", req.content().get(2).getId()); req = tested.listRequestNext(req); Assert.assertTrue(req.hasContent()); Assert.assertNotNull(req.content()); Assert.assertEquals(1, req.content().size()); Assert.assertEquals("aaa-7", req.content().get(0).getId()); req = tested.listRequestNext(req); Assert.assertFalse(req.hasContent()); } }
private void assertTableContent( final JdbcContentPersistenceService tested, final String sysContentType, final String id, final Date expectedUpdated) { final String tablename = tested.getTableName(sysContentType); try (final Connection conn = this.getTested().searchiskoDs.getConnection(); final PreparedStatement statement = conn.prepareStatement( String.format( "select sys_content_type, updated from %s where id = ?", tablename))) { statement.setString(1, id); try (final ResultSet rs = statement.executeQuery()) { Assert.assertTrue(rs.next()); Assert.assertEquals(sysContentType, rs.getString(1)); Timestamp actualTimestamp = rs.getTimestamp(2); if (expectedUpdated != null) { Assert.assertEquals(new Timestamp(expectedUpdated.getTime()), actualTimestamp); } else { Assert.assertNotNull(actualTimestamp); } } } catch (SQLException e) { Assert.fail(e.getMessage()); } }
public void assertNotNull(Object p) { try { Assert.assertNotNull(p); } catch (Error e) { lastTestFailed = true; throw e; } }
@Test public void requestSignatureTest() throws Exception { String envelopeId = ""; // will retrieve // // Step 1 - login // DocuSignClient client = new DocuSignClient( TestSettings.TEST_EMAIL, TestSettings.TEST_PASSWORD, TestSettings.TEST_INTEGRATOR_KEY); boolean result = client.login(); Assert.assertTrue("login should work", result); // // STEP 2 - Send signature request from template // RequestSignatureFromTemplate request = new RequestSignatureFromTemplate(); request.setEmailSubject("From a Unit Test"); request.setEmailBlurb("Blurb from a Unit Test"); request.setTemplateId(TestSettings.TEMPLATE_ID); request.setStatus("sent"); // need to fill out who signs this TemplateRole role = new TemplateRole(); role.setName("Mike Borozdin"); role.setEmail(TestSettings.SAMPLE_EMAIL); role.setRoleName("Signer1"); List<TemplateRole> roles = new ArrayList<TemplateRole>(1); roles.add(role); request.setTemplateRoles(roles); RequestSignatureResponse response = client.requestSignatureFromTemplate(request); Assert.assertNotNull(response); envelopeId = response.getEnvelopeId(); System.out.println("envelopeId = " + envelopeId); }
/** * The following test case should ensure that * * <ul> * <li>Any modifications to an attribute of a BOI via API isn't reflected to process data which * are using the BO * <li>Any modifications to an attribute of a BOI via the process data is only reflected to the * BOI which is attached to the synthetic process instance and that it doesn't affect other * BOIs which are used in other processes * </ul> */ @Test public void checkFilteringOnBusinessObjectAttrChange() { // setup final int customerIdOffset = 100; final int customerCount = 3; for (int customerId = 1; customerId <= customerCount; customerId++) { ProcessInstance pi = sf.getWorkflowService() .startProcess(new QName(MODEL_NAME2, "DistributedOrder").toString(), null, true); List<ActivityInstance> w = getWorklist(pi); Assert.assertEquals("worklist", 1, w.size()); ActivityInstance ai = w.get(0); Assert.assertEquals("activity instance", "CreateOrder", ai.getActivity().getId()); Map<String, Object> order = CollectionUtils.newMap(); order.put("date", new Date()); order.put("customerId", customerIdOffset + customerId); order.put("items", "item " + customerId); ai = complete( ai, PredefinedConstants.DEFAULT_CONTEXT, Collections.singletonMap("Order", order)); try { ActivityInstanceStateBarrier.instance().await(ai.getOID(), ActivityInstanceState.Completed); } catch (Exception e) { } } // after DistributeCreation activity is completed we have the following state: // * 2 asynchronous subprocesses are started: one which copies the data and the // other one which doesn't // * 3 synchronous subprocesses are triggered: one with shared data, one with separate // but copied data and the last one with separate data without copying // This results into the following state: // * Each process has created four business object instances // * One which is attached to a synthetic process instance // * 3 other BOIs which are attached to a real process instance String businessObjectQualifiedId = new QName(MODEL_NAME2, "Order").toString(); BusinessObjectQuery businessObjectQuery = BusinessObjectQuery.findForBusinessObject(businessObjectQualifiedId); businessObjectQuery .getFilter() .addAndTerm() .add(DataFilter.greaterThan("Order", "customerId", customerIdOffset)); businessObjectQuery.setPolicy( new BusinessObjectQuery.Policy( BusinessObjectQuery.Option.WITH_VALUES, BusinessObjectQuery.Option.WITH_DESCRIPTION)); BusinessObjects bos = sf.getQueryService().getAllBusinessObjects(businessObjectQuery); Assert.assertEquals("Only one business object, namely Order, is expected", 1, bos.getSize()); Assert.assertEquals( "Business object instances count isn't the same as started process ergo the count of the synthetic process instances", customerCount, getTotalSize(bos)); // Wait that all ShowOrder processes are started (unfortunately we cannot use // ProcessInstanceStateBarrier here // because of the async processes. ProcessInstanceQuery piQuery = ProcessInstanceQuery.findAlive("ShowOrder"); boolean waitForPIs = true; while (waitForPIs) { long instanceCount = sf.getQueryService().getProcessInstancesCount(piQuery); waitForPIs = instanceCount != (customerCount * 5); if (waitForPIs) { try { Thread.sleep(100); } catch (InterruptedException e) { } } } BusinessObject bo = bos.get(0); BusinessObject.Value customer101 = null; for (BusinessObject.Value boValue : bo.getValues()) { Map<?, ?> boAttr = (Map<?, ?>) boValue.getValue(); Integer customerId = (Integer) boAttr.get("customerId"); if (Integer.valueOf(customerIdOffset + 1).equals(customerId)) { customer101 = boValue; } } Assert.assertNotNull("Customer " + customerIdOffset + 1 + " not found", customer101); // Update BOI via API... ((Map) customer101.getValue()).put("items", "newitems"); sf.getWorkflowService() .updateBusinessObjectInstance(businessObjectQualifiedId, customer101.getValue()); // ...and validate if no process data is modified piQuery = ProcessInstanceQuery.findActive(); FilterTerm filter = piQuery.getFilter().addAndTerm(); filter.add( DataFilter.between( "Order", "customerId", customerIdOffset, customerIdOffset + customerCount)); filter.add(DataFilter.like("Order", "items", "item%")); filter.addAndTerm().add(ProcessInstanceHierarchyFilter.ROOT_PROCESS); piQuery.setPolicy(SubsetPolicy.UNRESTRICTED); ProcessInstances rootPIs = sf.getQueryService().getAllProcessInstances(piQuery); // Root process instances are the DistributedOrder processes and the ShowOrder processes which // was started // as async processes and which had copied the data Assert.assertEquals( "Changes in BOIs must not be reflected in process instance data", customerCount * 2, rootPIs.getTotalCount()); // Update BOI for a given process via data path... long piOid = rootPIs.get(0).getOID(); ((Map) customer101.getValue()).put("items", "newitems1"); sf.getWorkflowService().setOutDataPath(piOid, "OrderDataPath", (Map) customer101.getValue()); // ...and validate if the BOI is updated... businessObjectQuery = BusinessObjectQuery.findWithPrimaryKey( businessObjectQualifiedId, ((Map) customer101.getValue()).get("customerId")); businessObjectQuery.setPolicy( new BusinessObjectQuery.Policy(BusinessObjectQuery.Option.WITH_VALUES)); bos = sf.getQueryService().getAllBusinessObjects(businessObjectQuery); Assert.assertEquals("Only one business object, namely Order, is expected", 1, bos.getSize()); List<BusinessObject.Value> boValues = bos.get(0).getValues(); Assert.assertEquals(1, boValues.size()); Assert.assertEquals("newitems1", ((Map) boValues.get(0).getValue()).get("items")); // ...but the other process instance data should be untouched piQuery = ProcessInstanceQuery.findActive(); filter = piQuery.getFilter().addAndTerm(); filter.add( DataFilter.between( "Order", "customerId", customerIdOffset, customerIdOffset + customerCount)); filter.add(DataFilter.like("Order", "items", "item%")); filter.addAndTerm().add(ProcessInstanceHierarchyFilter.ROOT_PROCESS); piQuery.setPolicy(SubsetPolicy.UNRESTRICTED); rootPIs = sf.getQueryService().getAllProcessInstances(piQuery); Assert.assertEquals( "Changes in BOIs must not be reflected in process instance data", (customerCount * 2) - 1, rootPIs.getTotalCount()); }
@Test public void store_get_delete() throws Exception { JdbcContentPersistenceService tested = getTested(); // case - get from noexisting table Assert.assertNull(tested.get("a-1", "tt")); String sysContentType = "testtype_1"; Map<String, Object> content = null; // case - store into nonexisting table, nonexisting id tested.store("aaa-1", sysContentType, content); assertRowCount(tested, sysContentType, 1); Assert.assertNull(tested.get("aaa-1", sysContentType)); // case - get nonexisting id from existing table Assert.assertNull(tested.get("a-1", sysContentType)); // case - test persistence after commit assertRowCount(tested, sysContentType, 1); Assert.assertNull(tested.get("aaa-1", sysContentType)); // case - store into existing table, nonexisting id content = new HashMap<String, Object>(); content.put("testkey", "testvalue"); tested.store("aaa-2", sysContentType, content); assertRowCount(tested, sysContentType, 2); Assert.assertNull(tested.get("aaa-1", sysContentType)); TestUtils.assertJsonContent( "{\"testkey\" : \"testvalue\"}", tested.get("aaa-2", sysContentType)); // case - store into existing table, existing id so update, sys_updated is Date instance content.put(ContentObjectFields.SYS_UPDATED, new Date(65463749865l)); tested.store("aaa-1", sysContentType, content); assertRowCount(tested, sysContentType, 2); TestUtils.assertJsonContent( "{\"testkey\" : \"testvalue\", \"sys_updated\":\"1972-01-28T16:22:29.865Z\"}", tested.get("aaa-1", sysContentType)); assertTableContent( tested, sysContentType, "aaa-1", SearchUtils.getISODateFormat().parse("1972-01-28T16:22:29.865+0000")); // case - store into existing table, existing id so update, sys_updated is ISO String instance content.put(ContentObjectFields.SYS_UPDATED, "1973-01-28T17:22:29.865+0100"); tested.store("aaa-2", sysContentType, content); assertRowCount(tested, sysContentType, 2); TestUtils.assertJsonContent( "{\"testkey\" : \"testvalue\", \"sys_updated\":\"1973-01-28T17:22:29.865+0100\"}", tested.get("aaa-2", sysContentType)); assertTableContent( tested, sysContentType, "aaa-2", SearchUtils.getISODateFormat().parse("1973-01-28T17:22:29.865+0100")); // case - store into existing table, existing id so update, sys_updated is invalid String // instance but no // exception and table is correctly filled content.put(ContentObjectFields.SYS_UPDATED, "sdfasdf"); tested.store("aaa-2", sysContentType, content); assertRowCount(tested, sysContentType, 2); TestUtils.assertJsonContent( "{\"testkey\" : \"testvalue\", \"sys_updated\":\"sdfasdf\"}", tested.get("aaa-2", sysContentType)); assertTableContent(tested, sysContentType, "aaa-2", null); // case - delete from nonexisting table tested.delete("aaa", "jj"); // case - delete from existing table, nonexisting id tested.delete("a-1", sysContentType); assertRowCount(tested, sysContentType, 2); // case - delete existing id tested.delete("aaa-1", sysContentType); assertRowCount(tested, sysContentType, 1); Assert.assertNull(tested.get("aaa-1", sysContentType)); Assert.assertNotNull(tested.get("aaa-2", sysContentType)); }