public virtual void testConvertResponse() { JDFDoc doc = new JDFDoc(ElementName.JMF); JDFJMF jmf = doc.getJMFRoot(); JDFDoc doc2 = new JDFDoc(ElementName.JMF); JDFJMF jmf2 = doc2.getJMFRoot(); JDFSignal s = jmf.appendSignal(); JDFResponse r = jmf2.appendResponse(); JDFQuery q = jmf.appendQuery(); q.setType("KnownMessages"); r.setQuery(q); Assert.AreEqual(q.getID(), r.getrefID(), "refID"); JDFMessageService ms = r.appendMessageService(); ms.setType("KnownMessages"); s.convertResponse(r, q); Assert.AreEqual(r.getType(), s.getType(), "type"); Assert.IsTrue(ms.isEqual(s.getMessageService(0)), "ms equal"); s = jmf.appendSignal(); s.convertResponse(r, null); Assert.AreEqual(r.getType(), s.getType(), "type"); Assert.IsTrue(ms.isEqual(s.getMessageService(0)), "ms equal"); Assert.IsTrue(s.getXSIType().StartsWith("Signal")); }
/// /// <summary> * converts a response to a signal that can be sent individually /// * </summary> /// * <param name="response"> the response to convert </param> /// * <returns> true if successful </returns> /// public virtual bool convertResponse(JDFResponse response, JDFQuery q) { if (response == null) { return(false); } setAttributes(response); VElement elements = response.getChildElementVector(null, null, null, true, 0, true); for (int i = 0; i < elements.Count; i++) { JDFElement element = (JDFElement)elements[i]; copyElement(element, null); } if (q != null) { VElement v = q.getChildElementVector(null, null, null, true, 0, true); for (int i = 0; i < v.Count; i++) { KElement item = v.item(i); if (item is JDFSubscription) { continue; } copyElement(item, null); } } setType(response.getType()); // also fix xsi:type return(true); }
public virtual void testSenderIDBlank() { JDFJMF.setTheSenderID("a b"); JDFJMF jmf = JDFJMF.createJMF(EnumFamily.Response, EnumType.AbortQueueEntry); JDFResponse response = jmf.getResponse(0); Assert.IsTrue(response.getID().IndexOf(".ab.") > 0, "thge sender id was added but stripped"); }
public override void setUp() { base.setUp(); JDFDoc doc = new JDFDoc(ElementName.JMF); JDFJMF jmf = doc.getJMFRoot(); JDFResponse r = jmf.appendResponse(); jmf.setSenderID("DeviceSenderID"); r.setType(EnumType.Resource); ri = r.getCreateResourceInfo(0); }
public virtual JDFQueue copyToResponse(JDFResponse resp, JDFQueueFilter filter) { if (resp == null) { return(null); } resp.removeChildren(ElementName.QUEUE, null, null); JDFQueue newQueue = (JDFQueue)resp.copyElement(this, null); if (filter != null) { filter.match(newQueue); } return(newQueue); }
public virtual void testError() { JDFDoc doc = new JDFDoc(ElementName.JMF); JDFJMF jmf = doc.getJMFRoot(); JDFResponse r = (JDFResponse)jmf.appendMessageElement(EnumFamily.Response, null); r.setType("Status"); r.setrefID("r1"); JDFNotification n = r.setErrorText("blub"); Assert.AreEqual("blub", n.getComment(0).getText(), "get comment text"); Assert.AreEqual("Error", n.getType(), "type"); Assert.IsTrue(r.isValid(EnumValidationLevel.Complete)); jmf.setSenderID("S1"); Assert.IsTrue(jmf.isValid(EnumValidationLevel.Complete)); }
/// /// <summary> * add a queueentry to a queue based on the parameters of this you can get the new queueentry by {@link} /// * getQueueEntry(0) on the response /// * </summary> /// * <param name="theQueue"> the queue to submit to, note that the queue IS modified by this call </param> /// * <param name="responseIn"> the jmf that serves as a container for the new response /// * </param> /// * <returns> the response jmf to the submission message </returns> /// public virtual JDFResponse addEntry(JDFQueue theQueue, JDFJMF responseIn) { JDFCommand command = (JDFCommand)getParentNode_KElement(); JDFJMF jmf = command.createResponse(); JDFResponse resp = jmf.getResponse(0); if (responseIn != null) { resp = (JDFResponse)responseIn.copyElement(resp, null); } if (theQueue == null) { resp.setErrorText("No Queue specified"); resp.setReturnCode(2); return(resp); } if (!theQueue.canAccept()) { resp.setReturnCode(112); resp.copyElement(theQueue, null); return(resp); } JDFQueueEntry qe = theQueue.createQueueEntry(getHold()); string[] copyAtts = new string[] { AttributeName.GANGNAME, AttributeName.GANGPOLICY }; for (int i = 0; i < copyAtts.Length; i++) { if (hasAttribute(copyAtts[i])) { qe.copyAttribute(copyAtts[i], this, null, null, null); } } // TODO more attributes e.g prev. next... if (hasAttribute(AttributeName.PRIORITY)) { qe.setPriority(getPriority()); // calls the automated function, } // therfore not in the list above resp.copyElement(theQueue, null); resp.copyElement(qe, null); return(resp); }
public virtual void testConvertResponses() { JDFDoc doc = new JDFDoc(ElementName.JMF); JDFJMF jmf = doc.getJMFRoot(); JDFDoc doc2 = new JDFDoc(ElementName.JMF); JDFJMF jmf2 = doc2.getJMFRoot(); JDFResponse r = jmf2.appendResponse(); JDFQuery q = jmf.appendQuery(); q.setType("KnownMessages"); r.setQuery(q); Assert.AreEqual(q.getID(), r.getrefID(), "refID"); jmf2.convertResponses(q); Assert.IsNull(jmf2.getResponse(0)); Assert.AreEqual(q.getID(), jmf2.getSignal(0).getrefID()); }
public virtual void testCreateResponse() { JDFDoc doc = new JDFDoc(ElementName.JMF); JDFJMF jmf = doc.getJMFRoot(); JDFCommand command = (JDFCommand)jmf.appendMessageElement(EnumFamily.Command,EnumType.UpdateJDF); Assert.AreEqual("CommandUpdateJDF",command.getXSIType()); command.setType("foo:bar"); Assert.IsNull(command.getXSIType()); Assert.AreEqual("foo:bar",command.getType()); JDFJMF resp = command.createResponse(); JDFResponse response = resp.getResponse(0); Assert.AreEqual(resp.getMessageElement(null,null,0),response); Assert.AreEqual("foo:bar",response.getType()); Assert.AreEqual(command.getID(),response.getrefID()); }
/// /// <summary> * convert all responses that match the query q to signals /// * </summary> /// * <returns> the newly created JMF with multiple responses </returns> /// public virtual void convertResponses(JDFQuery q) { EnumType t = q == null ? null : q.getEnumType(); VElement v = getMessageVector(EnumFamily.Response, t); string qID = q == null ? null : q.getID(); for (int i = 0; i < v.Count; i++) { JDFResponse r = (JDFResponse)v[i]; if (qID == null || qID.Equals(r.getrefID())) { JDFSignal s = appendSignal(); moveElement(s, r); // retain ordering s.convertResponse(r, q); r.deleteNode(); } } }
public virtual void testIsValidMessageElement() { JDFDoc doc = new JDFDoc(ElementName.JMF); JDFJMF jmf = doc.getJMFRoot(); JDFSignal sig = (JDFSignal)jmf.appendMessageElement(EnumFamily.Signal, EnumType.UpdateJDF); Assert.IsTrue(sig.isValidMessageElement(ElementName.UPDATEJDFCMDPARAMS, 0)); Assert.IsFalse(sig.isValidMessageElement(ElementName.MODIFYNODECMDPARAMS, 0)); JDFResponse resp = (JDFResponse)jmf.appendMessageElement(EnumFamily.Response, EnumType.RepeatMessages); Assert.IsTrue(resp.isValidMessageElement(ElementName.SIGNAL,3)); Assert.IsTrue(resp.isValidMessageElement(ElementName.REGISTRATION,3)); Assert.IsFalse(resp.isValidMessageElement(ElementName.QUEUE,0)); JDFRegistration reg = (JDFRegistration)jmf.appendMessageElement(EnumFamily.Registration,EnumType.RepeatMessages); Assert.IsFalse(reg.isValidMessageElement(ElementName.SIGNAL,3)); }
public virtual void testCopyToResponse() { JDFResponse r = JDFJMF.createJMF(JDFMessage.EnumFamily.Response, EnumType.AbortQueueEntry).getResponse(0); JDFQueueFilter qf = (JDFQueueFilter) new JDFDoc(ElementName.QUEUEFILTER).getRoot(); qf.setMaxEntries(3); JDFQueue q2 = q.copyToResponse(r, qf); Assert.AreEqual(r.getQueue(0), q2); Assert.AreEqual(3, q2.numEntries(null)); Assert.AreNotEqual(q, q2); Assert.IsTrue(q.numEntries(null) > 3); q2 = q.copyToResponse(r, qf); Assert.AreEqual(r.getQueue(0), q2); Assert.IsNull(r.getElement("Queue", null, 1)); Assert.AreEqual(3, q2.numEntries(null)); Assert.AreNotEqual(q, q2); Assert.IsTrue(q.numEntries(null) > 3); }
public virtual void testAddEntry() { JDFResponse resp = qsp.addEntry(theQueue, null); Assert.AreEqual(0, resp.getReturnCode()); theQueue = resp.getQueue(0); Assert.AreEqual(theQueue.getQueueEntry(0).getQueueEntryStatus(), resp.getQueueEntry(0).getQueueEntryStatus()); Assert.AreEqual(theQueue.getQueueEntry(0).getQueueEntryID(), resp.getQueueEntry(0).getQueueEntryID()); Assert.AreNotEqual("", theQueue.getQueueEntry(0).getQueueEntryID()); Assert.AreEqual(1, theQueue.numEntries(null)); Assert.AreEqual(1, theQueue.numEntries(EnumQueueEntryStatus.Waiting)); qsp.setHold(true); JDFJMF jmfNew = new JDFDoc("JMF").getJMFRoot(); resp = qsp.addEntry(theQueue, jmfNew); Assert.AreEqual(jmfNew.getResponse(0), resp); Assert.AreEqual(2, theQueue.numEntries(null)); Assert.AreEqual(1, theQueue.numEntries(EnumQueueEntryStatus.Waiting)); Assert.AreEqual(1, theQueue.numEntries(EnumQueueEntryStatus.Held)); Assert.AreNotEqual(theQueue.getQueueEntry(0).getQueueEntryID(), theQueue.getQueueEntry(1).getQueueEntryID()); }
public virtual void testCreateResponse() { JDFJMF queries = JDFJMF.createJMF(EnumFamily.Query, EnumType.Status); queries.appendCommand(EnumType.Resource); queries.appendCommand(EnumType.Resource); queries.appendRegistration(EnumType.Resource); JDFJMF responses = queries.createResponse(); VElement messageVector = queries.getMessageVector(null, null); VElement responseVector = responses.getMessageVector(null, null); Assert.AreEqual(responseVector.Count, 4); for (int i = 0; i < responseVector.Count; i++) { JDFResponse r = (JDFResponse)responseVector[i]; JDFMessage m = (JDFMessage)messageVector[i]; Assert.AreEqual(r.getrefID(), m.getID()); Assert.AreEqual(r.getType(), m.getType()); } }
public virtual void testMediaCatalog() { JDFDoc doc = new JDFDoc(ElementName.JMF); JDFJMF jmf = doc.getJMFRoot(); jmf.setSenderID("DeviceSenderID"); JDFQuery q = jmf.appendQuery(EnumType.Resource); q.setXMLComment("This is the query for a catalog"); JDFResourceQuParams rqp = q.appendResourceQuParams(); rqp.setExact(true); rqp.setXMLComment("Scope=Allowed is a new attribute to describe that we want a complet list of all known resources"); rqp.setResourceName(ElementName.MEDIA); // rqp.setAttribute("Scope", "Allowed"); JDFResponse r = q.createResponse().getResponse(0); r = (JDFResponse)jmf.moveElement(r, null); r.setXMLComment("This is the response to the query - generally it will be in it's own jmf...\nThe list of ResourceInfo + the ResourceQuParams could also be specified in a Signal."); for (int i = 1; i < 5; i++) { JDFResourceInfo ri = r.appendResourceInfo(); ri.setResourceName("Media"); JDFMedia m = (JDFMedia)ri.appendResource("Media"); m.setDescriptiveName("Description of Media #" + i); m.setDimensionCM(new JDFXYPair(i * 10, 13 + i % 2 * 20)); m.setBrand("Brand #" + i); m.setProductID("ProductID_" + i); m.setMediaType(EnumMediaType.Paper); m.setResStatus((i < 2 ? EnumResStatus.Available : EnumResStatus.Unavailable), false); ri.setXMLComment("More attributes can be added as needed; Available = loaded"); } doc.write2File(sm_dirTestDataTemp + "MediaCatalog.jmf", 2, false); Assert.IsTrue(jmf.isValid(EnumValidationLevel.Complete)); }
/// /// <summary> * create a new response for all messages of this if the message is any message except response correctly fills /// * refId, type etc. /// * </summary> /// * <returns> the newly created JMF with multiple responses </returns> /// public virtual JDFJMF createResponse() { VElement v = getMessageVector(null, null); JDFJMF jmf = new JDFDoc("JMF").getJMFRoot(); for (int i = 0; i < v.Count; i++) { JDFMessage m = (JDFMessage)v[i]; EnumFamily family = m.getFamily(); if (family != null && EnumFamily.Response != family && EnumFamily.Acknowledge != family) { if (!m.hasAttribute(AttributeName.ID)) // in case someone sends // crappy requests... { m.appendAnchor(null); } JDFResponse r = jmf.appendResponse(); r.setQuery(m); } } return(jmf); }
public virtual void testJMFDevCaps() { JDFDoc doc = new JDFDoc(ElementName.JMF); JDFJMF jmfDC = doc.getJMFRoot(); JDFResponse r = jmfDC.appendResponse(EnumType.KnownMessages); jmfDC.setSenderID("DeviceSenderID"); JDFMessageService ms = r.appendMessageService(); ms.setJMFRole(EnumJMFRole.Sender); ms.setQuery(true); ms.setType("KnownDevices"); JDFDevCaps dcs = ms.appendDevCaps(); dcs.setName("DeviceList"); JDFDevCap dc = dcs.appendDevCapInPool(); JDFDevCap dcDI = dc.appendDevCap(); dcDI.setName(ElementName.DEVICEINFO); dcDI.setMinOccurs(1); dcDI.setMaxOccurs(1); JDFStringState state = dcDI.appendStringState(AttributeName.DEVICEID); state.setRequired(true); state = dcDI.appendStringState(AttributeName.DEVICESTATUS); state.setRequired(true); state.appendValueAllowedValue("Running"); ms = r.appendMessageService(); ms.setJMFRole(EnumJMFRole.Sender); ms.setQuery(true); ms.setType("KnownMessages"); dcs = ms.appendDevCaps(); dcs.setName("MessageService"); dc = dcs.appendDevCapInPool(); state = dc.appendStringState(AttributeName.TYPE); state.setRequired(true); state = dc.appendStringState("Foo"); state.setRequired(false); JDFActionPool ap = ms.appendActionPool(); JDFAction a = ap.appendActionTest(EnumTerm.IsPresentEvaluation, true); JDFTest t = a.getTest(); // JDFTerm term= t.getTerm(); // TODO JDFDoc docJMF = new JDFDoc("JMF"); JDFJMF jmf = docJMF.getJMFRoot(); for (int i = 0; i < 3; i++) { JDFResponse resp = jmf.appendResponse(EnumType.KnownDevices); JDFDeviceList dl = resp.appendDeviceList(); JDFDeviceInfo di = dl.appendDeviceInfo(); di.setDeviceID("d123"); di.setDeviceStatus(EnumDeviceStatus.Running); XMLDoc report = JDFDeviceCap.getJMFInfo(jmf, r, EnumFitsValue.Allowed, EnumValidationLevel.Complete, true); Assert.AreEqual("true", report.getRoot().getAttribute("IsValid")); } { JDFResponse resp = jmf.appendResponse(EnumType.KnownMessages); JDFMessageService mi = resp.appendMessageService(); mi.setType("FooBar"); doc.write2File(sm_dirTestDataTemp + "JMFDevCap.xml", 2, false); docJMF.write2File(sm_dirTestDataTemp + "JMFDevCapTest.jmf", 2, false); } XMLDoc report_1 = JDFDeviceCap.getJMFInfo(jmf, r, EnumFitsValue.Allowed, EnumValidationLevel.Complete, true); Assert.AreEqual("true", report_1.getRoot().getAttribute("IsValid")); doc.write2File(sm_dirTestDataTemp + "JMFDevCap.xml", 2, false); docJMF.write2File(sm_dirTestDataTemp + "JMFDevCapTest.jmf", 2, false); { jmf.appendResponse(EnumType.AbortQueueEntry); } report_1 = JDFDeviceCap.getJMFInfo(jmf, r, EnumFitsValue.Allowed, EnumValidationLevel.Complete, true); Assert.AreEqual("false", report_1.getRoot().getAttribute("IsValid")); }
public virtual void testAddNull() { JDFResponse resp = qsp.addEntry(null, null); Assert.AreEqual(2, resp.getReturnCode()); }
public virtual bool convertResponse(JDFResponse response) { return(convertResponse(response, null)); }