@Before public void setUp() { MockSlingExtensions.setUp(context); context.addModelsForPackage("io.wcm.wcm.parsys.controller"); context.request().setAttribute(ComponentContext.CONTEXT_ATTR_NAME, componentContext); when(componentContext.getComponent()).thenReturn(component); when(component.getPath()).thenReturn(RESOURCE_TYPE_SAMPLE); when(component.getProperties()).thenReturn(ImmutableValueMap.of()); page = context.create().page("/content/page1", "/apps/sample/templates/test1"); parsysResource = context.create().resource(page.getContentResource().getPath() + "/parsys"); par1Resource = context .create() .resource( parsysResource.getPath() + "/par1", ImmutableValueMap.of("sling:resourceType", COMPONENT_PATH_1)); par2Resource = context .create() .resource( parsysResource.getPath() + "/par2", ImmutableValueMap.of("sling:resourceType", COMPONENT_PATH_2)); context.currentResource(parsysResource); }
@Test public void testWithCurrentResource() throws Exception { context.currentResource( context.resourceResolver().getResource("/content/sample/en/jcr:content")); JSONArray result = getJsonResult(); assertEquals(2, result.length()); assertItem(result.getJSONObject(0), "/content/sample/en/page1", "title1"); assertItem(result.getJSONObject(1), "/content/sample/en/page2", "title2"); }
@Before public void setup() throws Exception { resource = context.create().resource("app/content/any/resource"); context.addModelsForPackage("com.thoughtworks.www.samples.models"); String slingId = UUID.randomUUID().toString(); when(settings.getSlingId()).thenReturn(slingId); buttonModel = context.currentResource(resource).adaptTo(ButtonModel.class); PrivateAccessor.setField(buttonModel, "settings", settings); }