/* (non-Javadoc) * @see edu.xtec.qv.qti.QTIObject#createFromXML(org.jdom.Element) */ public void createFromXML(Element eElement) { if (eElement != null) { setAttribute(VIEW, eElement.getChildText(VIEW.getTagName())); // Add qticomment if (eElement.getChild(QTICOMMENT.getTagName(), eElement.getNamespace()) != null) { QTIComment oComment = new QTIComment(eElement.getChild(QTICOMMENT.getTagName(), eElement.getNamespace())); setAttribute(QTICOMMENT, oComment); } // Add material and flow_mat Vector vContents = new Vector(); Iterator itContents = eElement.getChildren().iterator(); while (itContents.hasNext()) { Element eContent = (Element) itContents.next(); QTIObject oContent = null; if (FLOW_MAT.equals(eContent.getName())) { oContent = new FlowMat(eContent); } else if (MATERIAL.equals(eContent.getName())) { oContent = new Material(eContent); } if (oContent != null) { vContents.addElement(oContent); } } setAttribute(CONTENT, vContents); } }
@Test public void testRenderNewXmlView() { PageParameters pageParameters = new PageParameters(); pageParameters.set(VIEW.toString(), "xml"); tester.startPage(EditProductPage.class, pageParameters); tester.assertNoErrorMessage(); tester.assertComponent("productPanel:feedback", FeedbackPanel.class); tester.assertComponent("productPanel:productForm", Form.class); tester.assertComponent("productPanel:productForm:uuid", HiddenField.class); tester.assertComponent("productPanel:productForm:control.xml:xml", TextArea.class); }
@Test public void testCreateNewXmlViewWithExistingProduct() { PageParameters pageParameters = new PageParameters(); pageParameters.set(VIEW.toString(), "xml"); tester.startPage(EditProductPage.class, pageParameters); FormTester formTester = tester.newFormTester("productPanel:productForm"); formTester.setValue("control.xml:xml", productMarshaller.marshal(shsProduct)); formTester.submitLink("submit", false); tester.assertRenderedPage(EditProductPage.class); tester.assertErrorMessages( "A product with the UUID " + shsProduct.getUuid() + " already exists"); }
@Test public void testCreateNewXmlView() { PageParameters pageParameters = new PageParameters(); pageParameters.set(VIEW.toString(), "xml"); tester.startPage(EditProductPage.class, pageParameters); FormTester formTester = tester.newFormTester("productPanel:productForm"); shsProduct.setUuid(UUID.randomUUID().toString()); formTester.setValue("control.xml:xml", productMarshaller.marshal(shsProduct)); formTester.submitLink("submit", false); tester.assertRenderedPage(ProductPage.class); tester.assertNoErrorMessage(); }
@Test public void testSubmitInvalidXml() { PageParameters pageParameters = new PageParameters(); pageParameters.set(VIEW.toString(), "xml"); pageParameters.set(EDIT_MODE.toString(), true); pageParameters.set(CURRENT_UUID.toString(), shsProduct.getUuid()); tester.startPage(EditProductPage.class, pageParameters); FormTester formTester = tester.newFormTester("productPanel:productForm"); formTester.setValue("control.xml:xml", "Not xml"); formTester.submitLink("submit", false); tester.assertRenderedPage(EditProductPage.class); tester.assertErrorMessages("The supplied product xml is invalid"); }
/** * @see * org.teiid.designer.core.extension.AbstractMetaclassNameProvider#getExtendableMetaclassRoots() */ @Override public String[] getExtendableMetaclassRoots() { final String[] allRoots = this.baseProvider.getExtendableMetaclassRoots(); final String[] rootsMinusView = new String[allRoots.length - 1]; int i = 0; // need to filter out view for (final String root : allRoots) { if (VIEW.equals(root)) { continue; } rootsMinusView[i++] = root; } return rootsMinusView; }
@Test public void testEditProductXmlView() { PageParameters pageParameters = new PageParameters(); pageParameters.set(VIEW.toString(), "xml"); pageParameters.set(EDIT_MODE.toString(), true); pageParameters.set(CURRENT_UUID.toString(), shsProduct.getUuid()); tester.startPage(EditProductPage.class, pageParameters); FormTester formTester = tester.newFormTester("productPanel:productForm"); shsProduct.setCommonName("New common name"); formTester.setValue("control.xml:xml", productMarshaller.marshal(shsProduct)); formTester.submitLink("submit", false); tester.assertRenderedPage(ProductPage.class); tester.assertNoErrorMessage(); }
/* (non-Javadoc) * @see edu.xtec.qv.qti.QTIObject#getXML() */ public Element getXML() { Element eObjectives = new Element(getQTIConstant().getTagName()); if (getAttribute(VIEW) != null) { eObjectives.setAttribute(VIEW.getTagName(), getView()); } if (getQTIComment() != null) { eObjectives.addContent(getQTIComment().getXML()); } Enumeration enumContents = getContents().elements(); while (enumContents.hasMoreElements()) { QTIObject oContent = (QTIObject) enumContents.nextElement(); eObjectives.addContent(oContent.getXML()); } return eObjectives; }
@Test public void testChangeUUIDXmlView() { PageParameters pageParameters = new PageParameters(); pageParameters.set(VIEW.toString(), "xml"); pageParameters.set(EDIT_MODE.toString(), true); pageParameters.set(CURRENT_UUID.toString(), shsProduct.getUuid()); tester.startPage(EditProductPage.class, pageParameters); FormTester formTester = tester.newFormTester("productPanel:productForm"); shsProduct.setUuid(UUID.randomUUID().toString()); formTester.setValue("control.xml:xml", productMarshaller.marshal(shsProduct)); formTester.submitLink("submit", false); tester.assertRenderedPage(EditProductPage.class); tester.assertErrorMessages( "UUID must not be updated when editing an existing product. Original uuid " + ObjectMother.DEFAULT_PRODUCT_ID); }
@Test public void testRenderEditXmlView() { PageParameters pageParameters = new PageParameters(); pageParameters.set(VIEW.toString(), "xml"); pageParameters.set(EDIT_MODE.toString(), true); pageParameters.set(CURRENT_UUID.toString(), shsProduct.getUuid()); tester.startPage(EditProductPage.class, pageParameters); tester.assertNoErrorMessage(); tester.assertComponent("productPanel:feedback", FeedbackPanel.class); tester.assertComponent("productPanel:productForm", Form.class); tester.assertComponent("productPanel:productForm:uuid", HiddenField.class); tester.assertComponent("productPanel:productForm:control.xml:xml", TextArea.class); final TextArea<String> xmlField = (TextArea<String>) tester.getComponentFromLastRenderedPage("productPanel:productForm:control.xml:xml"); assertThat(xmlField.getValue(), containsString(shsProduct.getUuid())); }