@Before public void setup() throws Exception { SlingSettingsService settings = mock(SlingSettingsService.class); slingId = UUID.randomUUID().toString(); when(settings.getSlingId()).thenReturn(slingId); hello = new HelloWorldModel(); PrivateAccessor.setField(hello, "settings", settings); hello.init(); }
@Test public void testHelloWorldModelServerSide() throws Exception { assertNotNull("Expecting HelloWorldModel to be injected by Sling test runner", hello); assertNotNull("Expecting the slingsettings to be injected by Sling test runner", settings); assertTrue( "Expecting the HelloWorldModel to return the slingId as part of the message", hello.getMessage().contains(settings.getSlingId())); }
@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); }
@Override public String getMessage() { return "This is 0.0.5 snapshot " + settings.getSlingId(); }
@PostConstruct protected void init() { message = "\tHello World!\n"; message += "\tThis is instance: " + settings.getSlingId() + "\n"; message += "\tResource type is: " + resourceType + "\n"; }