ScheduledTaskLoader implements BundleEntityLoader { @Override public void load(Bundle bundle, Element element) { final Element scheduledTask = getSingleChildElement(getSingleChildElement(element, RESOURCE), SCHEDULED_TASK); final String policyId = getSingleChildElementAttribute(scheduledTask, POLICY_REFERENCE, ATTRIBUTE_ID); final String name = getSingleChildElementTextContent(scheduledTask, NAME); final boolean isOneNode = toBoolean(getSingleChildElementTextContent(scheduledTask, ONE_NODE)); final String jobType = getSingleChildElementTextContent(scheduledTask, JOB_TYPE); final String jobStatus = getSingleChildElementTextContent(scheduledTask, JOB_STATUS); final String executionDate = getSingleChildElementTextContent(scheduledTask, EXECUTION_DATE); final String cronExpression = getSingleChildElementTextContent(scheduledTask, CRON_EXPRESSION); final boolean shouldExecuteOnCreate = toBoolean(getSingleChildElementTextContent(scheduledTask, EXECUTE_ON_CREATE)); final Map<String, Object> properties = mapPropertiesElements(getSingleChildElement(scheduledTask, PROPERTIES, true), PROPERTIES); ScheduledTask task = new ScheduledTask(); task.setId(scheduledTask.getAttribute(ATTRIBUTE_ID)); task.setPolicy(policyId); task.setName(name); task.setOneNode(isOneNode); task.setJobType(jobType); task.setJobStatus(jobStatus); task.setExecutionDate(executionDate); task.setCronExpression(cronExpression); task.setShouldExecuteOnCreate(shouldExecuteOnCreate); task.setProperties(properties); bundle.getScheduledTasks().put(name, task); }  @Override void load(Bundle bundle, Element element); @Override String getEntityType();  }
@Test void loadOneTimeScheduledTask() { Bundle bundle = new Bundle(); loader.load(bundle, createScheduledTaskXml(DocumentTools.INSTANCE.getDocumentBuilder().newDocument(), true)); final ScheduledTask entity = bundle.getScheduledTasks().get("Test"); assertNotNull(entity); assertEquals("id", entity.getId()); assertEquals("Test", entity.getName()); assertFalse(entity.getIsOneNode()); assertEquals("One time", entity.getJobType()); assertEquals("someDate", entity.getExecutionDate()); assertNull(entity.getCronExpression()); assertEquals("Scheduled", entity.getJobStatus()); assertFalse(entity.getShouldExecuteOnCreate()); assertEquals("testValue", entity.getProperties().get("testProp")); }
@Test void loadScheduledTaskNoProperties() { Document document = DocumentTools.INSTANCE.getDocumentBuilder().newDocument(); Element scheduledTaskElem = createElementWithAttributesAndChildren( document, SCHEDULED_TASK, ImmutableMap.of(ATTRIBUTE_ID, "id"), createElementWithTextContent(document, NAME, "Test"), createElementWithTextContent(document, ONE_NODE, false), createElementWithTextContent(document, JOB_TYPE, "One time"), createElementWithTextContent(document, JOB_STATUS, "Scheduled"), createElementWithTextContent(document, EXECUTE_ON_CREATE, false), createElementWithTextContent(document, EXECUTION_DATE, "someDate") ); Element sheduledTaskElement = createElementWithChildren( document, ITEM, createElementWithChildren( document, RESOURCE, scheduledTaskElem ) ); Bundle bundle = new Bundle(); loader.load(bundle, sheduledTaskElement); final ScheduledTask entity = bundle.getScheduledTasks().get("Test"); assertNotNull(entity); assertEquals("id", entity.getId()); assertEquals("Test", entity.getName()); assertFalse(entity.getIsOneNode()); assertEquals("One time", entity.getJobType()); assertEquals("someDate", entity.getExecutionDate()); assertNull(entity.getCronExpression()); assertEquals("Scheduled", entity.getJobStatus()); assertFalse(entity.getShouldExecuteOnCreate()); assertEquals(0, entity.getProperties().size()); }
@Test void loadRecurringScheduledTask() { Bundle bundle = new Bundle(); loader.load(bundle, createScheduledTaskXml(DocumentTools.INSTANCE.getDocumentBuilder().newDocument(), false)); final ScheduledTask entity = bundle.getScheduledTasks().get("Test"); assertNotNull(entity); assertEquals("id", entity.getId()); assertEquals("Test", entity.getName()); assertFalse(entity.getIsOneNode()); assertEquals("Recurring", entity.getJobType()); assertEquals("Some Expression", entity.getCronExpression()); assertNull(entity.getExecutionDate()); assertEquals("Scheduled", entity.getJobStatus()); assertFalse(entity.getShouldExecuteOnCreate()); assertEquals("testValue", entity.getProperties().get("testProp")); }