protected void setUp() throws Exception { super.setUp(); getContext().setDoc(new XWikiDocument()); XWiki xwiki = new XWiki(); Mock mockXWikiStore = mock( XWikiHibernateStore.class, new Class[] {XWiki.class, XWikiContext.class}, new Object[] {xwiki, getContext()}); xwiki.setStore((XWikiStoreInterface) mockXWikiStore.proxy()); Mock mockXWikiRenderingEngine = mock(XWikiRenderingEngine.class); mockXWikiRenderingEngine .stubs() .method("interpretText") .will( new CustomStub("Implements XWikiRenderingEngine.interpretText") { public Object invoke(Invocation invocation) throws Throwable { return invocation.parameterValues.get(0); } }); xwiki.setRenderingEngine((XWikiRenderingEngine) mockXWikiRenderingEngine.proxy()); getContext().setWiki(xwiki); }
@Override protected void setUp() throws Exception { super.setUp(); this.authService = new XWikiAuthServiceImpl(); this.mockXWiki = mock(XWiki.class); getContext().setWiki((XWiki) this.mockXWiki.proxy()); BaseClass userClass = new BaseClass(); userClass.setDocumentReference( new DocumentReference(getContext().getWikiId(), "XWiki", "XWikiUsers")); userClass.addPasswordField("password", "Password", 10); this.mockXWiki.stubs().method("getUserClass").will(returnValue(userClass)); }
/** * {@inheritDoc} * * @see junit.framework.TestCase#setUp() */ @Override protected void setUp() throws Exception { super.setUp(); this.databases.put(MAIN_WIKI_NAME, new HashMap<String, XWikiDocument>()); XWiki xwiki = new XWiki() { public XWikiDocument getDocument(String fullname, XWikiContext context) throws XWikiException { return XWikiServletURLFactoryTest.this.getDocument( Utils.getComponent(DocumentReferenceResolver.class, "currentmixed") .resolve(fullname)); } public XWikiDocument getDocument( DocumentReference documentReference, XWikiContext context) throws XWikiException { return XWikiServletURLFactoryTest.this.getDocument(documentReference); } public String getXWikiPreference( String prefname, String defaultValue, XWikiContext context) { return defaultValue; } protected void registerWikiMacros() {} }; xwiki.setConfig((this.config = new XWikiConfig())); xwiki.setDatabase(getContext().getDatabase()); Mock mockXWikiRequest = mock(XWikiRequest.class, new Class[] {}, new Object[] {}); mockXWikiRequest.stubs().method("getScheme").will(returnValue("http")); mockXWikiRequest .stubs() .method("isSecure") .will( new CustomStub("Implements ServletRequest.isSecure") { public Object invoke(Invocation invocation) throws Throwable { return secure; } }); mockXWikiRequest.stubs().method("getServletPath").will(returnValue("")); mockXWikiRequest.stubs().method("getContextPath").will(returnValue("/xwiki")); mockXWikiRequest .stubs() .method("getHeader") .will( new CustomStub("Implements HttpServletRequest.getHeader") { public Object invoke(Invocation invocation) throws Throwable { String headerName = (String) invocation.parameterValues.get(0); return httpHeaders.get(headerName); } }); getContext().setWiki(xwiki); getContext().setRequest((XWikiRequest) mockXWikiRequest.proxy()); // Create sub-wikis. createWiki("wiki1"); createWiki("wiki2"); getContext().setURL(new URL("http://127.0.0.1/xwiki/view/InitialSpace/InitialPage")); this.urlFactory.init(getContext()); }
@Before public void setUp() throws Exception { super.setUp(); this.serializer = getComponentManager().lookup(EntityReferenceSerializer.class, "compact"); }
/** * {@inheritDoc} * * @see com.xpn.xwiki.test.AbstractBridgedXWikiComponentTestCase#setUp() */ @Override protected void setUp() throws Exception { super.setUp(); XWikiConfig config = new XWikiConfig(); Mock mockServletContext = mock(ServletContext.class); ByteArrayInputStream bais = new ByteArrayInputStream("code=wiki:code:type:content".getBytes("UTF-8")); mockServletContext .stubs() .method("getResourceAsStream") .with(eq("/templates/macros.txt")) .will(returnValue(bais)); mockServletContext .stubs() .method("getResourceAsStream") .with(eq("/WEB-INF/oscache.properties")) .will(returnValue(new ByteArrayInputStream("".getBytes("UTF-8")))); mockServletContext .stubs() .method("getResourceAsStream") .with(eq("/WEB-INF/oscache-local.properties")) .will(returnValue(new ByteArrayInputStream("".getBytes("UTF-8")))); XWikiServletContext engineContext = new XWikiServletContext((ServletContext) mockServletContext.proxy()); xwiki = new XWiki(config, getContext(), engineContext, false) { public String getSkin(XWikiContext context) { return "skin"; } public String getXWikiPreference( String prefname, String defaultValue, XWikiContext context) { return defaultValue; } public String getSpacePreference( String prefname, String defaultValue, XWikiContext context) { return defaultValue; } protected void registerWikiMacros() {} public XWikiRightService getRightService() { return new XWikiRightServiceImpl() { public boolean hasProgrammingRights(XWikiDocument doc, XWikiContext context) { return true; } }; } }; xwiki.setVersion("1.0"); // Ensure that no Velocity Templates are going to be used when executing Velocity since // otherwise // the Velocity init would fail (since by default the macros.vm templates wouldn't be found as // we're // not providing it in our unit test resources). xwiki.getConfig().setProperty("xwiki.render.velocity.macrolist", ""); this.engine = (DefaultXWikiRenderingEngine) xwiki.getRenderingEngine(); // Make sure the wiki in the context will say that we have programming permission. getContext().setWiki(this.xwiki); }
@Override protected void setUp() throws Exception { super.setUp(); this.document = new XWikiDocument(new DocumentReference(DOCWIKI, DOCSPACE, DOCNAME)); this.document.setSyntax(Syntax.XWIKI_1_0); this.document.setLanguage("en"); this.document.setDefaultLanguage("en"); this.document.setNew(false); getContext().setDoc(this.document); this.translatedDocument = new XWikiDocument(); this.translatedDocument.setSyntax(Syntax.XWIKI_1_0); this.translatedDocument.setLanguage("fr"); this.translatedDocument.setNew(false); getContext().put("isInRenderingEngine", true); this.mockXWiki = mock(XWiki.class); this.mockXWiki.stubs().method("Param").will(returnValue(null)); this.mockXWikiRenderingEngine = mock(XWikiRenderingEngine.class); this.mockXWikiRenderingEngine .stubs() .method("interpretText") .will( new CustomStub("Implements XWikiRenderingEngine.interpretText") { @Override public Object invoke(Invocation invocation) throws Throwable { return invocation.parameterValues.get(0); } }); this.mockXWikiVersioningStore = mock(XWikiVersioningStoreInterface.class); this.mockXWikiVersioningStore.stubs().method("getXWikiDocumentArchive").will(returnValue(null)); this.mockXWikiRightService = mock(XWikiRightService.class); this.mockXWikiRightService.stubs().method("hasProgrammingRights").will(returnValue(true)); this.mockXWikiStoreInterface = mock(XWikiStoreInterface.class); this.mockXWikiStoreInterface .stubs() .method("search") .will(returnValue(new ArrayList<XWikiDocument>())); this.document.setStore((XWikiStoreInterface) this.mockXWikiStoreInterface.proxy()); this.mockXWiki .stubs() .method("getRenderingEngine") .will(returnValue(this.mockXWikiRenderingEngine.proxy())); this.mockXWiki .stubs() .method("getVersioningStore") .will(returnValue(this.mockXWikiVersioningStore.proxy())); this.mockXWiki .stubs() .method("getStore") .will(returnValue(this.mockXWikiStoreInterface.proxy())); this.mockXWiki .stubs() .method("getRightService") .will(returnValue(this.mockXWikiRightService.proxy())); this.mockXWiki.stubs().method("getDocument").will(returnValue(this.document)); this.mockXWiki.stubs().method("getLanguagePreference").will(returnValue("en")); this.mockXWiki.stubs().method("exists").will(returnValue(false)); // Called from MessageToolVelocityContextInitializer. this.mockXWiki.stubs().method("prepareResources"); // The next 3 stubs are needed to properly initialize the Velocity engine. this.mockXWiki.stubs().method("getSkin").will(returnValue("default")); this.mockXWiki.stubs().method("getSkinFile").will(returnValue(null)); this.mockXWiki .stubs() .method("Param") .with(eq("xwiki.render.velocity.macrolist")) .will(returnValue("")); getContext().setWiki((XWiki) this.mockXWiki.proxy()); this.baseClass = this.document.getxWikiClass(); this.baseClass.addTextField("string", "String", 30); this.baseClass.addTextAreaField("area", "Area", 10, 10); this.baseClass.addTextAreaField("puretextarea", "Pure text area", 10, 10); // set the text areas an non interpreted content ((TextAreaClass) this.baseClass.getField("puretextarea")).setContentType("puretext"); this.baseClass.addPasswordField("passwd", "Password", 30); this.baseClass.addBooleanField("boolean", "Boolean", "yesno"); this.baseClass.addNumberField("int", "Int", 10, "integer"); this.baseClass.addStaticListField("stringlist", "StringList", "value1, value2"); this.mockXWiki.stubs().method("getXClass").will(returnValue(this.baseClass)); this.baseObject = this.document.newObject(CLASSNAME, getContext()); this.baseObject.setStringValue("string", "string"); this.baseObject.setLargeStringValue("area", "area"); this.baseObject.setStringValue("passwd", "passwd"); this.baseObject.setIntValue("boolean", 1); this.baseObject.setIntValue("int", 42); this.baseObject.setStringListValue("stringlist", Arrays.asList("VALUE1", "VALUE2")); }