@Test public void parse() { final String titleVal = "myTitle"; final String contentVal = "myContent"; final String linkVal = "myLink"; final String summaryVal = "mySummary"; final String objectTypeVal = "this/is/note"; final String objectTypeError = "this/is/nothing"; final String expectedObjType = "NOTE"; final Element root = context.mock(Element.class); final Element objElement = context.mock(Element.class, "obj"); final Element titleChild = context.mock(Element.class, "title"); final Element contentChild = context.mock(Element.class, "content"); final Element linkChild = context.mock(Element.class, "link"); final Element summaryChild = context.mock(Element.class, "summary"); final Element objTypeChild = context.mock(Element.class, "objTypeError"); final Element objTypeErrorChild = context.mock(Element.class, "objType"); final Element unexpectedChild = context.mock(Element.class, "unexpectedChild"); final List<Element> children = new LinkedList<Element>(); children.add(titleChild); children.add(contentChild); children.add(linkChild); children.add(summaryChild); children.add(objTypeChild); children.add(objTypeErrorChild); children.add(unexpectedChild); context.checking(new Expectations() { { oneOf(root).getChild(with(any(String.class)), with(any(Namespace.class))); will(returnValue(objElement)); oneOf(objElement).getChildren(); will(returnValue(children)); allowing(titleChild).getName(); will(returnValue("title")); oneOf(titleChild).getTextTrim(); will(returnValue(titleVal)); allowing(contentChild).getName(); will(returnValue("content")); oneOf(contentChild).getTextTrim(); will(returnValue(contentVal)); allowing(linkChild).getName(); will(returnValue("link")); oneOf(linkChild).getAttributeValue("href"); will(returnValue(linkVal)); allowing(summaryChild).getName(); will(returnValue("summary")); oneOf(summaryChild).getTextTrim(); will(returnValue(summaryVal)); allowing(objTypeChild).getName(); will(returnValue("object-type")); oneOf(objTypeChild).getTextTrim(); will(returnValue(objectTypeVal)); allowing(objTypeErrorChild).getName(); will(returnValue("object-type")); oneOf(objTypeErrorChild).getTextTrim(); will(returnValue(objectTypeError)); allowing(unexpectedChild).getName(); will(returnValue("unexpected")); } }); ActivityStreamsModuleImpl module = (ActivityStreamsModuleImpl) sut.parse(root); assertEquals(titleVal, module.getAtomEntry().getTitle()); assertEquals(contentVal, ((SyndContentImpl) module.getAtomEntry().getContents().get(0)).getValue()); assertEquals(linkVal, module.getAtomEntry().getLink()); assertEquals(summaryVal, module.getAtomEntry().getDescription().getValue()); assertEquals(expectedObjType, module.getObjectType()); }
@SuppressWarnings("unchecked") public Module parse(final Element root) { Namespace myNamespace = Namespace.getNamespace(ActivityStreamsModule.URI); ActivityStreamsModule myModule = new ActivityStreamsModuleImpl(); SyndEntryImpl atomEntry = new SyndEntryImpl(); Element objElement = root.getChild("object", myNamespace); List<Element> children = (List<Element>) objElement.getChildren(); for (Element child : children) { if (child.getName().equals("title")) { atomEntry.setTitle(child.getTextTrim()); } else if (child.getName().equals("content")) { List<SyndContent> contents = new LinkedList<SyndContent>(); SyndContent content = new SyndContentImpl(); content.setValue(child.getTextTrim()); contents.add(content); atomEntry.setContents(contents); } else if (child.getName().equals("link")) { atomEntry.setLink(child.getAttributeValue("href")); } else if (child.getName().equals("summary")) { SyndContent content = new SyndContentImpl(); content.setValue(child.getTextTrim()); atomEntry.setDescription(content); } else if (child.getName().equals("object-type")) { try { String[] objArr = child.getTextTrim().split("/"); String objStr = objArr[objArr.length - 1].toUpperCase(); BaseObjectType.valueOf(objStr); myModule.setObjectType(objStr); } catch (IllegalArgumentException ex) { logger.debug("ActivityObject not valid"); myModule.setObjectType("NOTE"); } } } myModule.setAtomEntry(atomEntry); return myModule; }
ActivityStreamsModuleParser implements ModuleParser { @SuppressWarnings("unchecked") public Module parse(final Element root) { Namespace myNamespace = Namespace.getNamespace(ActivityStreamsModule.URI); ActivityStreamsModule myModule = new ActivityStreamsModuleImpl(); SyndEntryImpl atomEntry = new SyndEntryImpl(); Element objElement = root.getChild("object", myNamespace); List<Element> children = (List<Element>) objElement.getChildren(); for (Element child : children) { if (child.getName().equals("title")) { atomEntry.setTitle(child.getTextTrim()); } else if (child.getName().equals("content")) { List<SyndContent> contents = new LinkedList<SyndContent>(); SyndContent content = new SyndContentImpl(); content.setValue(child.getTextTrim()); contents.add(content); atomEntry.setContents(contents); } else if (child.getName().equals("link")) { atomEntry.setLink(child.getAttributeValue("href")); } else if (child.getName().equals("summary")) { SyndContent content = new SyndContentImpl(); content.setValue(child.getTextTrim()); atomEntry.setDescription(content); } else if (child.getName().equals("object-type")) { try { String[] objArr = child.getTextTrim().split("/"); String objStr = objArr[objArr.length - 1].toUpperCase(); BaseObjectType.valueOf(objStr); myModule.setObjectType(objStr); } catch (IllegalArgumentException ex) { logger.debug("ActivityObject not valid"); myModule.setObjectType("NOTE"); } } } myModule.setAtomEntry(atomEntry); return myModule; } }
ActivityStreamsModuleParser implements ModuleParser { @SuppressWarnings("unchecked") public Module parse(final Element root) { Namespace myNamespace = Namespace.getNamespace(ActivityStreamsModule.URI); ActivityStreamsModule myModule = new ActivityStreamsModuleImpl(); SyndEntryImpl atomEntry = new SyndEntryImpl(); Element objElement = root.getChild("object", myNamespace); List<Element> children = (List<Element>) objElement.getChildren(); for (Element child : children) { if (child.getName().equals("title")) { atomEntry.setTitle(child.getTextTrim()); } else if (child.getName().equals("content")) { List<SyndContent> contents = new LinkedList<SyndContent>(); SyndContent content = new SyndContentImpl(); content.setValue(child.getTextTrim()); contents.add(content); atomEntry.setContents(contents); } else if (child.getName().equals("link")) { atomEntry.setLink(child.getAttributeValue("href")); } else if (child.getName().equals("summary")) { SyndContent content = new SyndContentImpl(); content.setValue(child.getTextTrim()); atomEntry.setDescription(content); } else if (child.getName().equals("object-type")) { try { String[] objArr = child.getTextTrim().split("/"); String objStr = objArr[objArr.length - 1].toUpperCase(); BaseObjectType.valueOf(objStr); myModule.setObjectType(objStr); } catch (IllegalArgumentException ex) { logger.debug("ActivityObject not valid"); myModule.setObjectType("NOTE"); } } } myModule.setAtomEntry(atomEntry); return myModule; }  }
ActivityStreamsModuleParser implements ModuleParser { @SuppressWarnings("unchecked") public Module parse(final Element root) { Namespace myNamespace = Namespace.getNamespace(ActivityStreamsModule.URI); ActivityStreamsModule myModule = new ActivityStreamsModuleImpl(); SyndEntryImpl atomEntry = new SyndEntryImpl(); Element objElement = root.getChild("object", myNamespace); List<Element> children = (List<Element>) objElement.getChildren(); for (Element child : children) { if (child.getName().equals("title")) { atomEntry.setTitle(child.getTextTrim()); } else if (child.getName().equals("content")) { List<SyndContent> contents = new LinkedList<SyndContent>(); SyndContent content = new SyndContentImpl(); content.setValue(child.getTextTrim()); contents.add(content); atomEntry.setContents(contents); } else if (child.getName().equals("link")) { atomEntry.setLink(child.getAttributeValue("href")); } else if (child.getName().equals("summary")) { SyndContent content = new SyndContentImpl(); content.setValue(child.getTextTrim()); atomEntry.setDescription(content); } else if (child.getName().equals("object-type")) { try { String[] objArr = child.getTextTrim().split("/"); String objStr = objArr[objArr.length - 1].toUpperCase(); BaseObjectType.valueOf(objStr); myModule.setObjectType(objStr); } catch (IllegalArgumentException ex) { logger.debug("ActivityObject not valid"); myModule.setObjectType("NOTE"); } } } myModule.setAtomEntry(atomEntry); return myModule; }  String getNamespaceUri(); @SuppressWarnings("unchecked") Module parse(final Element root); }
ActivityStreamsModuleParser implements ModuleParser { @SuppressWarnings("unchecked") public Module parse(final Element root) { Namespace myNamespace = Namespace.getNamespace(ActivityStreamsModule.URI); ActivityStreamsModule myModule = new ActivityStreamsModuleImpl(); SyndEntryImpl atomEntry = new SyndEntryImpl(); Element objElement = root.getChild("object", myNamespace); List<Element> children = (List<Element>) objElement.getChildren(); for (Element child : children) { if (child.getName().equals("title")) { atomEntry.setTitle(child.getTextTrim()); } else if (child.getName().equals("content")) { List<SyndContent> contents = new LinkedList<SyndContent>(); SyndContent content = new SyndContentImpl(); content.setValue(child.getTextTrim()); contents.add(content); atomEntry.setContents(contents); } else if (child.getName().equals("link")) { atomEntry.setLink(child.getAttributeValue("href")); } else if (child.getName().equals("summary")) { SyndContent content = new SyndContentImpl(); content.setValue(child.getTextTrim()); atomEntry.setDescription(content); } else if (child.getName().equals("object-type")) { try { String[] objArr = child.getTextTrim().split("/"); String objStr = objArr[objArr.length - 1].toUpperCase(); BaseObjectType.valueOf(objStr); myModule.setObjectType(objStr); } catch (IllegalArgumentException ex) { logger.debug("ActivityObject not valid"); myModule.setObjectType("NOTE"); } } } myModule.setAtomEntry(atomEntry); return myModule; }  String getNamespaceUri(); @SuppressWarnings("unchecked") Module parse(final Element root);  }