private Model initModel() { if (this.model == null) { this.model = new ExtendedModelMap(); } return this.model; }
@Test public void handleModelReturnValue() throws Exception { mavContainer.addAttribute("attr1", "value1"); Model returnValue = new ExtendedModelMap(); returnValue.addAttribute("attr2", "value2"); processor.handleReturnValue(returnValue , returnParamModel, mavContainer, webRequest); assertEquals("value1", mavContainer.getModel().get("attr1")); assertEquals("value2", mavContainer.getModel().get("attr2")); }
@Test public void render() throws Exception { FreeMarkerView view = new FreeMarkerView(); view.setConfiguration(this.freeMarkerConfig); view.setUrl("test.ftl"); ModelMap model = new ExtendedModelMap(); model.addAttribute("hello", "hi FreeMarker"); view.render(model, null, this.exchange).block(Duration.ofMillis(5000)); StepVerifier.create(this.exchange.getResponse().getBody()) .consumeNextWith(buf -> assertEquals("<html><body>hi FreeMarker</body></html>", asString(buf))) .expectComplete() .verify(); }
@Before public void setUpPrincipal() { IdentityZoneHolder.clear(); marissa = new UaaPrincipal("marissa-id","marissa","marissa@test.org","origin",null, IdentityZoneHolder.get().getId()); prompts = new LinkedList<>(); prompts.add(new Prompt("username", "text", "Email")); prompts.add(new Prompt("password", "password", "Password")); prompts.add(new Prompt("passcode", "text", "Temporary Authentication Code ( Get one at "+HTTP_LOCALHOST_8080_UAA+"/passcode )")); mockIDPConfigurator = mock(SamlIdentityProviderConfigurator.class); identityProviderProvisioning = mock(IdentityProviderProvisioning.class); uaaProvider = new IdentityProvider(); when(identityProviderProvisioning.retrieveByOrigin(eq(OriginKeys.UAA), anyString())).thenReturn(uaaProvider); when(identityProviderProvisioning.retrieveByOrigin(eq(OriginKeys.LDAP), anyString())).thenReturn(new IdentityProvider()); idps = getIdps(); originalConfiguration = IdentityZoneHolder.get().getConfig(); oidcMetadataFetcher = mock(OidcMetadataFetcher.class); IdentityZoneHolder.get().setConfig(new IdentityZoneConfiguration()); configurator = new XOAuthProviderConfigurator(identityProviderProvisioning, oidcMetadataFetcher); mfaChecker = spy(new MfaChecker(mock(IdentityProviderProvisioning.class))); model = new ExtendedModelMap(); }
@Test public void testGetSystemConfiguration() { ExtendedModelMap model = new ExtendedModelMap(); controller.getOne(model); assertThat(model.containsAttribute("content"), is(true)); }
@Test public void testOpenAnnouncement() { Model model = new ExtendedModelMap(); controller.open(model); assertThat(model.containsAttribute("content"), is(true)); }
@Test public void testSaveAnnouncement() { Model model = new ExtendedModelMap(); String content = "My test."; controller.save(model, content); assertThat(model.containsAttribute("success"), is(true)); assertThat(service.getOne(), is(content)); assertThat(config.getAnnouncement(), is(content)); } }
@Test public void runScriptTest() { Model model = new ExtendedModelMap(); scriptController.run("", model); assertThat((String) model.asMap().get("result"), nullValue()); String command = "print \'hello\'"; scriptController.run(command, model); assertThat(model.containsAttribute("result"), is(true)); assertThat((String) model.asMap().get("result"), containsString("hello")); scriptController.run("var a = 1", model); scriptController.run("print a", model); assertThat((String) model.asMap().get("result"), containsString("No such property")); } }
private Model newModel() { return new ExtendedModelMap(); }
@Test public void testSaveSystemConfiguration() { String oriContent = service.getOne(); ExtendedModelMap model = new ExtendedModelMap(); String content = "test=My test."; try { controller.save(content, model); ThreadUtils.sleep(2500); //sleep a while to wait for the file monitor to update the system properties. assertThat(service.getOne(), is(content)); assertThat(config.getControllerProperties().getProperty("test", ""), is("My test.")); } finally { //reset system config controller.save(oriContent, model); } } }
@Test public void testHome() throws Exception { final Model model = new ExtendedModelMap(); assertThat(controller.home(model), is("hello")); assertThat((String) model.asMap().get("msg"), is("SUCCESS")); }
/** * Creates a {@link ModelAndView} with the configured viewName and invokes * {@link #populateModel(Model, HttpServletRequest)}. * If a contentType is configured, * {@link HttpServletResponse#setContentType(String)} is invoked. */ public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception { if (contentType != null) { response.setContentType(contentType); } ExtendedModelMap model = new ExtendedModelMap(); populateModel(model, request); ModelAndView mv = new ModelAndView(viewName, model); return mv; }
@RequestMapping(value = "/types", method = {GET}) public Model getRegistries(HttpServletRequest request) { Set<URL> registryRefs = new HashSet<URL>(); for (String registryType : registryService.getRegistryTypes()) { registryRefs.add(toUrlReference(registryType, request)); } ReferencesHolder holder = new ReferencesHolder(); holder.statusCode = 200; // because the list of registries is what the client requested (e.g. the semantics of the response align with the method invoked) holder.references = registryRefs; Model model = new ExtendedModelMap(); model.addAttribute(RegistryModelAttribute.REFS.name(), holder); return model; }
@RequestMapping(value = "/entries", method = {GET}) public Model getRegistryEntries(HttpServletRequest request, @RequestParam(REGISTRY_REQUEST_PARAM) String entryType) { Model model = new ExtendedModelMap(); Set<RegistryEntry<?>> entries = registryService.getEntriesByType(entryType); model.addAttribute(RegistryModelAttribute.ENTRY_TYPE.name(), entryType); if (entries == null) { return model; } // Populate a Set of URL references to RegistryEntry objects in the model. Set<URL> entryRefs = new HashSet<URL>(); for (RegistryEntry<?> entry : entries) { URL u = toUrlReference(entry, request); if (u != null) { entryRefs.add(u); } } ReferencesHolder holder = new ReferencesHolder(); holder.statusCode = 200; // because a list of entries is what the client requested (e.g. the semantics of the response align with the method invoked) holder.references = entryRefs; model.addAttribute(RegistryModelAttribute.REFS.name(), holder); return model; }
@RequestParam(value = REGISTRY_REQUEST_PARAM, required = false) String entryType) { Model model = new ExtendedModelMap();
private ModelAndView invokeHandlerMethod( HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { try { ServletHandlerMethodResolver methodResolver = getMethodResolver( handler); Method handlerMethod = methodResolver.resolveHandlerMethod(request); ServletHandlerMethodInvoker methodInvoker = new ServletHandlerMethodInvoker(methodResolver); ServletWebRequest webRequest = new ServletWebRequest(request, response); ExtendedModelMap implicitModel = new ExtendedModelMap(); Object result = methodInvoker.invokeHandlerMethod(handlerMethod, handler, webRequest, implicitModel); ModelAndView mav = methodInvoker.getModelAndView(handlerMethod, handler.getClass(), result, implicitModel, webRequest); methodInvoker.updateModelAttributes( handler, (mav != null ? mav.getModel() : null), implicitModel, webRequest); return mav; } catch (NoSuchRequestHandlingMethodException ex) { return handleNoSuchRequestHandlingMethod(ex, request, response); } }