Java Code Examples for com.sun.jersey.api.view.Viewable

The following are top voted examples for showing how to use com.sun.jersey.api.view.Viewable. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: darceo   File: DeliveryService.java   View source code 6 votes vote down vote up
/**
 * Checks the given plan's execution status.
 * 
 * @param planId
 *            plan id
 * @return 200 OK forwarding the request to jsp, or 404 NOT FOUND if the matching plan could not be found
 */
@GET
@Path("request/{planId}")
public Response checkStatus(@PathParam("planId") String planId) {

    DeliveryPlan plan = deliveryPlanManager.getDeliveryPlan(planId);

    if (plan == null) {
        return Response.status(Status.NOT_FOUND).build();
    }

    if (plan.getStatus() == DeliveryPlanStatus.COMPLETED) {
        return Response.seeOther(URI.create(plan.getDelivery().getClientLocation())).build();
    }

    Map<String, Object> params = new HashMap<String, Object>();
    params.put("status", plan.getStatus());
    params.put("url", uriInfo.getAbsolutePath());
    return Response.ok(new Viewable(STATUS_PATH, params)).build();
}
 
Example 2
Project: appengine-guestbookwithguice-java   File: GuestbookResource.java   View source code 6 votes vote down vote up
@POST
@Path("/sign")
@Produces(MediaType.TEXT_HTML)
public Response sign(
		@Context HttpServletRequest request,
		@FormParam("guestbookName") @DefaultValue("default") String guestbookName,
		@FormParam("content") String content) {
	UserService userService = UserServiceFactory.getUserService();
	User user = userService.getCurrentUser();

	Key guestbookKey = KeyFactory.createKey("Guestbook", guestbookName);
	Entity greeting = new Entity("Greeting", guestbookKey);
	greeting.setProperty("user", user);
	greeting.setProperty("date", new Date());
	greeting.setProperty("content", content);

	DatastoreService datastore = DatastoreServiceFactory
			.getDatastoreService();
	datastore.put(greeting);

	Map<String, Object> model = buildModel(request, guestbookName);
	return Response.ok(new Viewable("/guestbook", model)).build();
}
 
Example 3
Project: Crosslinks   File: FusekiRestMethods.java   View source code 6 votes vote down vote up
@GET
@Path("{crawler}/status")
public Viewable statusDetail(@PathParam("crawler") String crawlerName, @Context HttpServletRequest request,
		@Context HttpServletResponse response, @QueryParam("mode") String mode, @QueryParam("status") String status) throws Exception {
	ProcessorController processorController = factory.getCrawler(crawlerName);
	if (CrosslinksServletFilter.isAdministrator(request)) {
		if ("PAUSED".equalsIgnoreCase(status)) {
			processorController.pause();
		}
		if (mode != null) {
			processorController.setMode(mode);
		}
	}
	request.setAttribute("crawler", processorController);
	if (processorController.getIterable() instanceof Affiliated) {
		request.setAttribute("affiliation", ((Affiliated)processorController.getIterable()).getAffiliation());			
	}
	return new Viewable("/jsps/statusDetail.jsp", null);
}
 
Example 4
Project: Crosslinks   File: FusekiRestMethods.java   View source code 6 votes vote down vote up
@GET
  @Path("{affiliation}/researchers")
  public Viewable getResearchers(@PathParam("affiliation") String affiliationStr, @Context HttpServletRequest request,
	@Context HttpServletResponse response, @QueryParam("clearCache") String clearCache) throws Exception {
  	Affiliation affiliation = getAffiliation(affiliationStr);
request.setAttribute("affiliation", affiliation);
if ("true".equalsIgnoreCase(clearCache)) {
	request.getSession().removeAttribute(affiliation.getName() + "reseachers");
}
@SuppressWarnings("unchecked")
List<Researcher> researchers = (List<Researcher>)request.getSession().getAttribute(affiliation.getName() + "reseachers");
if (researchers == null) {
	researchers = getResearchers(affiliation);
	request.getSession().setAttribute(affiliation.getName() + "reseachers", researchers);
}

request.setAttribute("researchers", researchers);
return new Viewable("/jsps/researchers.jsp", null);
  }
 
Example 5
Project: wms-q-facade   File: ConfigResource.java   View source code 6 votes vote down vote up
@GET
@Produces(MediaType.TEXT_HTML)
public Viewable getMappingsHtml(@Context ServletContext context) {
	Config config = null;
	try {
		// Load config.xml from WEB-INF
		config = JAXB.unmarshal(
				context.getResourceAsStream("/WEB-INF/config.xml"),
				Config.class);
	} catch (Exception e) {
		throw new WebApplicationException(Response.serverError()
				.entity("Error reading configuration file").build());
	}

	return new Viewable("/mappings", config);
}
 
Example 6
Project: pi   File: UsersController.java   View source code 6 votes vote down vote up
@PUT
@Path(SLASH_USERNAME)
public Viewable putUser(@PathParam(USERNAME) String username, @FormParam(REALNAME) String realname, @FormParam(EMAIL) String emailAddress, @FormParam(ENABLED) String enabled,
		@FormParam(EXTERNAL_REF_ID) String externalRefId, @FormParam(MAX_INSTANCES) String maxInstancesStr, @FormParam(MAX_CORES) String maxCoresStr) {
	LOG.info(String.format("Updating a new user: username %s, real name %s, email %s, enabled %s, external ref id %s, maxInstances %s, maxCores %s", username, realname, emailAddress, enabled,
			externalRefId, maxInstancesStr, maxCoresStr));
	Boolean isEnabled = null;

	if (!StringUtils.isEmpty(enabled))
		isEnabled = validateAndGetEnabledBoolean(enabled);

	Integer maxInstances = validateAndGetMaxInstances(maxInstancesStr);
	Integer maxCores = validateAndGetMaxCores(maxCoresStr);
	try {
		userManagementService.updateUser(username, realname, emailAddress, isEnabled, externalRefId, maxInstances, maxCores);
	} catch (UserNotFoundException ex) {
		throw new NotFoundException("");
	}

	return getViewable(getUser(username));
}
 
Example 7
Project: pi   File: UsersControllerTest.java   View source code 6 votes vote down vote up
@Test
public void postUserShouldCreateAUser() {
	// act
	Viewable viewable = (Viewable) usersController.postUser(USERNAME, REALNAME, EMAIL, TRUE, EXTERNAL_REF, Integer.toString(MAX_INSTANCES), Integer.toString(MAX_CORES)).getEntity();

	// assert
	assertNotNull(viewable);
	assertNotNull(viewable.getModel());
	Map model = (Map<String, Object>) viewable.getModel();
	assertEquals(readOnlyUser, model.get("user"));
	assertEquals(INSTANCE_ID, ((Set<String>) model.get("instanceIds")).iterator().next());
	assertEquals(setOfStrings, model.get("imageIds"));
	assertEquals(setOfStrings, model.get("securityGroupIds"));
	assertEquals(setOfStrings, model.get("volumeIds"));
	assertEquals(MAX_INSTANCES, model.get("maxInstances"));
	assertEquals(MAX_CORES, model.get("maxCores"));
	assertEquals("single_user", viewable.getTemplateName());
}
 
Example 8
Project: pi   File: UsersControllerTest.java   View source code 6 votes vote down vote up
@Test
public void postUserShouldCreateADisabledUser() {
	// act
	Viewable viewable = (Viewable) usersController.postUser(USERNAME, REALNAME, EMAIL, "", EXTERNAL_REF, Integer.toString(MAX_INSTANCES), Integer.toString(MAX_CORES)).getEntity();

	// assert
	assertNotNull(viewable);
	assertNotNull(viewable.getModel());
	Map model = (Map<String, Object>) viewable.getModel();
	assertEquals(readOnlyUser, model.get("user"));
	assertEquals(INSTANCE_ID, ((Set<String>) model.get("instanceIds")).iterator().next());
	assertEquals(setOfStrings, model.get("imageIds"));
	assertEquals(setOfStrings, model.get("securityGroupIds"));
	assertEquals(setOfStrings, model.get("volumeIds"));
	assertEquals(MAX_INSTANCES, model.get("maxInstances"));
	assertEquals("single_user", viewable.getTemplateName());
}
 
Example 9
Project: pi   File: UsersControllerTest.java   View source code 6 votes vote down vote up
@Test
public void postUserShouldDefaultUserDisablesWhenNoEnabledFlagSet() {
	// act
	Viewable viewable = (Viewable) usersController.postUser(USERNAME, REALNAME, EMAIL, null, EXTERNAL_REF, Integer.toString(MAX_INSTANCES), Integer.toString(MAX_CORES)).getEntity();

	// assert
	assertNotNull(viewable);
	assertNotNull(viewable.getModel());
	Map model = (Map<String, Object>) viewable.getModel();
	assertEquals(readOnlyUser, model.get("user"));
	assertEquals(INSTANCE_ID, ((Set<String>) model.get("instanceIds")).iterator().next());
	assertEquals(setOfStrings, model.get("imageIds"));
	assertEquals(setOfStrings, model.get("securityGroupIds"));
	assertEquals(setOfStrings, model.get("volumeIds"));
	assertEquals(MAX_INSTANCES, model.get("maxInstances"));
	assertEquals("single_user", viewable.getTemplateName());
}
 
Example 10
Project: pi   File: UsersControllerTest.java   View source code 6 votes vote down vote up
@Test
public void postUserShouldStillWorkWhenNoExternalRefProvided() {
	// act
	Viewable viewable = (Viewable) usersController.postUser(USERNAME, REALNAME, EMAIL, TRUE, null, Integer.toString(MAX_INSTANCES), Integer.toString(MAX_CORES)).getEntity();

	// assert
	assertNotNull(viewable);
	assertNotNull(viewable.getModel());
	Map model = (Map<String, Object>) viewable.getModel();
	assertEquals(readOnlyUser, model.get("user"));
	assertEquals(INSTANCE_ID, ((Set<String>) model.get("instanceIds")).iterator().next());
	assertEquals(setOfStrings, model.get("imageIds"));
	assertEquals(setOfStrings, model.get("securityGroupIds"));
	assertEquals(setOfStrings, model.get("volumeIds"));
	assertEquals(MAX_INSTANCES, model.get("maxInstances"));
	assertEquals("single_user", viewable.getTemplateName());
}
 
Example 11
Project: pi   File: UsersControllerTest.java   View source code 6 votes vote down vote up
@Test
public void gettingUserAsHtmlShouldReturnAViewableWithTheRightTemplateAndModelPopulated() {
	// act
	Viewable viewable = usersController.getUserHtml(USERNAME);

	// assert
	assertNotNull(viewable);
	assertNotNull(viewable.getModel());
	Map model = (Map<String, Object>) viewable.getModel();
	assertEquals(readOnlyUser, model.get("user"));
	assertEquals(INSTANCE_ID, ((Set<String>) model.get("instanceIds")).iterator().next());
	assertEquals(setOfStrings, model.get("imageIds"));
	assertEquals(setOfStrings, model.get("securityGroupIds"));
	assertEquals(setOfStrings, model.get("volumeIds"));
	assertEquals(MAX_INSTANCES, model.get("maxInstances"));
	assertEquals("single_user", viewable.getTemplateName());
}
 
Example 12
Project: pi   File: UsersControllerTest.java   View source code 6 votes vote down vote up
@Test
public void puttingAUserShouldAlterTheUser() {
	// act
	Viewable viewable = usersController.putUser(USERNAME, REALNAME, EMAIL, TRUE, EXTERNAL_REF, Integer.toString(MAX_INSTANCES), Integer.toString(MAX_CORES));

	// assert
	verify(userManagementService).updateUser(USERNAME, REALNAME, EMAIL, true, EXTERNAL_REF, MAX_INSTANCES, MAX_CORES);
	assertNotNull(viewable);
	assertNotNull(viewable.getModel());
	Map model = (Map<String, Object>) viewable.getModel();
	assertEquals(readOnlyUser, model.get("user"));
	assertEquals(INSTANCE_ID, ((Set<String>) model.get("instanceIds")).iterator().next());
	assertEquals(setOfStrings, model.get("imageIds"));
	assertEquals(setOfStrings, model.get("securityGroupIds"));
	assertEquals(setOfStrings, model.get("volumeIds"));
	assertEquals(MAX_INSTANCES, model.get("maxInstances"));
	assertEquals("single_user", viewable.getTemplateName());
}
 
Example 13
Project: pi   File: UsersControllerTest.java   View source code 6 votes vote down vote up
@Test
public void gettingUserByAccessKeyAsHtmlShouldReturnAViewableWithTheRightTemplateAndModelPopulated() {
	// act
	Viewable viewable = usersController.getUserByApiAccessKeyHtml(ACCESS_KEY);

	// assert
	assertNotNull(viewable);
	assertNotNull(viewable.getModel());
	Map model = (Map<String, Object>) viewable.getModel();
	assertEquals(readOnlyUser, model.get("user"));
	assertEquals(INSTANCE_ID, ((Set<String>) model.get("instanceIds")).iterator().next());
	assertEquals(setOfStrings, model.get("imageIds"));
	assertEquals(setOfStrings, model.get("securityGroupIds"));
	assertEquals(setOfStrings, model.get("volumeIds"));
	assertEquals(MAX_INSTANCES, model.get("maxInstances"));
	assertEquals("single_user", viewable.getTemplateName());
}
 
Example 14
Project: pi   File: UsersControllerTest.java   View source code 6 votes vote down vote up
@Test
public void shouldReturnInstanceValidationAddresss() {
	// setup
	PId pid = mock(PId.class);
	when(piIdBuilder.getPId("user:" + USERNAME)).thenReturn(pid);
	String pidString = "123456";
	when(pid.toStringFull()).thenReturn(pidString);
	String dnsName = "ops.com";
	usersController.setOpsWebsiteDnsName(dnsName);

	// act
	Viewable result = usersController.getInstanceValidationAddress(USERNAME);

	// assert
	assertNotNull(result);
	assertNotNull(result.getModel());
	Map model = (Map<String, Object>) result.getModel();
	assertEquals(USERNAME, model.get("username"));
	assertEquals(pidString, model.get("pid"));
	assertEquals(dnsName, model.get("ops_website_dns_name"));
}
 
Example 15
Project: karyon   File: AdminPageResource.java   View source code 6 votes vote down vote up
@GET()
public Viewable showIndex() {
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("ajax_base", adminContainerConfig.ajaxDataResourceContext());
    model.put("template_base", adminContainerConfig.templateResourceContext());

    if (adminPageRegistry != null) {
        final Collection<AdminPageInfo> adminPages = adminPageRegistry.getAllPages();
        model.put("adminPages", adminPages);
    }
    if (adminContainerConfig != null) {
        model.put("homeScriptResources", adminContainerConfig.homeScriptResources());
    }

    return new Viewable("/webadmin/home.ftl", model, adminContainerConfig.getClass());
}
 
Example 16
Project: karyon   File: AdminPageResource.java   View source code 6 votes vote down vote up
@GET
  @Path("/{view}")
  public Viewable showViewIndex(
          @PathParam("view") String view,
          @QueryParam("id") @DefaultValue("") String id
  ) {
      LOG.info(view);
      Map<String, Object> model = new HashMap<String, Object>();
      model.put("id", id);
      model.put("ajax_base", adminContainerConfig.ajaxDataResourceContext());
      model.put("template_base", adminContainerConfig.templateResourceContext());

if (adminPageRegistry != null && adminPageRegistry.getPageInfo(view) != null) {
       AdminPageInfo pageInfo = adminPageRegistry.getPageInfo(view);
          final Map<String, Object> pageDataModel = pageInfo.getDataModel();
          if (pageDataModel != null) {
              model.putAll(pageDataModel);
          }
          return new Viewable(pageInfo.getPageTemplate(), model, pageInfo.getClass());
      }
      throw new WebApplicationException(Response.Status.NOT_FOUND);
  }
 
Example 17
Project: EuVatBanner   File: Banner.java   View source code 5 votes vote down vote up
@GET
@Produces("application/javascript")
public Viewable view(@QueryParam("excludeCountries") String excludeCountries, @Context HttpServletRequest req) {
    Map<String, Object> it = Maps.newHashMap();
    String[] excludeCountriesArray = new String[0];
    if (excludeCountries != null) {
        excludeCountriesArray = excludeCountries.split(",");
    }
    String country = getCountryCode(req);
    it.put("country", country);
    it.put("isEu", isEU(req));
    it.put("showBanner", isEU(req) && !ArrayUtils.contains(excludeCountriesArray, country));
    return new Viewable("/banner", it);
}
 
Example 18
Project: EuVatBanner   File: Test.java   View source code 5 votes vote down vote up
@GET
@Produces("application/javascript")
public Viewable view(@QueryParam("excludeCountries") String excludeCountries, @Context HttpServletRequest req) {
    Map<String, Object> it = Maps.newHashMap();
    it.put("excludeCountries", excludeCountries);
    return new Viewable("/test", it);
}
 
Example 19
Project: appengine-guestbookwithguice-java   File: GuestbookResource.java   View source code 5 votes vote down vote up
@GET
@Produces(MediaType.TEXT_HTML)
public Response sayHello(
		@Context HttpServletRequest request,
		@QueryParam("guestbookName") @DefaultValue("default") String guestbookName) {
	Map<String, Object> model = buildModel(request, guestbookName);
	return Response.ok(new Viewable("/guestbook", model)).build();
}
 
Example 20
Project: Crosslinks   File: FusekiRestMethods.java   View source code 5 votes vote down vote up
@GET
@Path("/index")
public Viewable index(@Context HttpServletRequest request,
		@Context HttpServletResponse response) throws Exception {
	request.setAttribute("affiliations", getAffiliations());
	return new Viewable("/jsps/index.jsp", null);
}
 
Example 21
Project: Crosslinks   File: FusekiRestMethods.java   View source code 5 votes vote down vote up
@GET
@Path("/status")
public Viewable status(@Context HttpServletRequest request,
		@Context HttpServletResponse response) throws Exception {
	List<ProcessorController> processorControllers = new ArrayList<ProcessorController>();
	processorControllers.addAll(factory.getCrawlers());
	// sort them so that the active ones show up at the top
	Collections.sort(processorControllers);
	request.setAttribute("crawlers", processorControllers);
	request.setAttribute("metaHistory", Quartz.getMetaControllerHistory());
	return new Viewable("/jsps/status.jsp", null);
}
 
Example 22
Project: Crosslinks   File: FusekiRestMethods.java   View source code 5 votes vote down vote up
@GET
  @Path("{affiliation}")
  public Viewable getAffiliationDetail(@PathParam("affiliation") String affiliation, @Context HttpServletRequest request,
	@Context HttpServletResponse response) throws Exception {
request.setAttribute("affiliation", getAffiliation(affiliation));
return new Viewable("/jsps/affiliation.jsp", null);
  }
 
Example 23
Project: CleverTaxes   File: SkosifierRootResource.java   View source code 5 votes vote down vote up
@GET
@Produces(TEXT_HTML)
public Response get(@Context HttpHeaders headers) {
    ResponseBuilder res = Response.ok(new Viewable("index", this),TEXT_HTML);
    addCORSOrigin(servletContext,res, headers);
    return res.build();
}
 
Example 24
Project: pi   File: UsersController.java   View source code 5 votes vote down vote up
protected Viewable getViewable(ReadOnlyUser user, String templateName) {
	Map<String, Object> model = new HashMap<String, Object>();
	model.put("user", user);
	model.put("instanceIds", user.getInstanceIds());
	model.put("imageIds", user.getImageIds());
	model.put("securityGroupIds", user.getSecurityGroupIds());
	model.put("volumeIds", user.getVolumeIds());
	model.put(ENABLED, user.isEnabled());
	model.put(MAX_INSTANCES, user.getMaxInstances());
	model.put(MAX_CORES, user.getMaxCores());
	return new Viewable(templateName, model);
}
 
Example 25
Project: pi   File: UsersController.java   View source code 5 votes vote down vote up
@GET
@Path(CERTIFICATE_PATH)
@Produces(MediaType.TEXT_HTML)
public Viewable getUserCertificate(@PathParam(USERNAME) String username) {
	checkNotNullOrEmpty(username);

	return buildModelAndView("post_user_cert", USERNAME, username);
}
 
Example 26
Project: pi   File: UsersController.java   View source code 5 votes vote down vote up
@GET
@Path(SLASH_USERNAME + SLASH_INSTANCEVALIDATION)
public Viewable getInstanceValidationAddress(@PathParam(USERNAME) String username) {
	LOG.debug(String.format("getInstanceValidationAddress(%s)", username));

	PId pId = getPiIdBuilder().getPId(User.getUrl(username));
	Map<String, Object> model = new HashMap<String, Object>();
	model.put(USERNAME, username);
	model.put("pid", pId.toStringFull());
	model.put("ops_website_dns_name", opsWebsiteDnsName);
	return new Viewable("instance_validation_address", model);
}
 
Example 27
Project: pi   File: UsersInstanceValidationController.java   View source code 5 votes vote down vote up
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Viewable validateUserInstances(MultivaluedMap<String, String> formParams, @PathParam(USERNAME) String username, @PathParam(PID) String pid) {
	LOG.debug(String.format("validateUserInstances(%s, %s, %s)", formParams, username, pid));

	// for each form param named validate_<instanceId> re-validate instance and un pause it
	List<String> instanceIdsToValidateFromRequest = new ArrayList<String>();
	validatePid(username, pid);
	for (Entry<String, List<String>> entry : formParams.entrySet()) {
		if (entry.getKey().startsWith(VALIDATE) && Boolean.valueOf(formParams.getFirst(entry.getKey()))) {
			instanceIdsToValidateFromRequest.add(entry.getKey().substring(VALIDATE.length()));
		}
	}
	LOG.debug(instanceIdsToValidateFromRequest);

	// match request to the users instances
	List<PId> ids = new ArrayList<PId>();
	if (instanceIdsToValidateFromRequest.size() > 0) {
		Collection<ReadOnlyInstance> instances = getInstances(username);
		LOG.debug(instances);
		for (ReadOnlyInstance readOnlyInstance : instances) {
			if (instanceIdsToValidateFromRequest.contains(readOnlyInstance.getInstanceId())) {
				int globalAvailabilityZoneCode = getPiIdBuilder().getGlobalAvailabilityZoneCodeFromEc2Id(readOnlyInstance.getInstanceId());
				ids.add(getPiIdBuilder().getPId(Instance.getUrl(readOnlyInstance.getInstanceId())).forGlobalAvailablityZoneCode(globalAvailabilityZoneCode));
			}
		}
	}

	scatterWriter(ids, new InstanceActivityStateResetContinuation(this));

	return getUserWithInstancesForValidation(username, pid);
}
 
Example 28
Project: pi   File: UsersInstanceValidationController.java   View source code 5 votes vote down vote up
@SuppressWarnings("unchecked")
@GET
public Viewable getUserWithInstancesForValidation(@PathParam(USERNAME) String username, @PathParam(PID) String pid) {
	LOG.debug(String.format("getUserWithInstancesForValidation(%s, %s)", username, pid));
	validatePid(username, pid);
	Viewable result = getViewable(getUser(username), "user_instances_validation");
	Collection<ReadOnlyInstance> instances = getInstances(username);
	Map<String, Object> model = (Map<String, Object>) result.getModel();
	model.put("instances", instances);
	model.put(PID, pid);
	return result;
}
 
Example 29
Project: pi   File: UserImages.java   View source code 5 votes vote down vote up
@GET
@Produces(MediaType.TEXT_HTML)
public Viewable getAllHtml(@PathParam(USERNAME) String username) {
	Map<String, Object> model = new HashMap<String, Object>();
	model.put(IMAGES, getAllImages(username));
	model.put(USERNAME, username);

	return new Viewable(USER_IMAGES, model);
}
 
Example 30
Project: pi   File: UserImages.java   View source code 5 votes vote down vote up
@Path(SLASH_IMAGEID)
@Produces(MediaType.TEXT_HTML)
@GET
public Viewable getImageHtml(@PathParam(USERNAME) String username, @PathParam(IMAGEID) String imageid) {

	Map<String, Object> model = new HashMap<String, Object>();
	model.put(IMAGES, Arrays.asList(getImage(username, imageid)));
	model.put(USERNAME, username);

	return new Viewable(USER_IMAGES, model);
}
 
Example 31
Project: pi   File: IndexControllerTest.java   View source code 5 votes vote down vote up
@Test
public void shouldReturnEmptyModelAndIndexView() {
	// act
	Viewable res = indexController.getAllHtml();

	// assert
	assertEquals("index", res.getTemplateName());
	assertEquals(0, ((Map<?, ?>) res.getModel()).size());
}
 
Example 32
Project: pi   File: UserImagesTest.java   View source code 5 votes vote down vote up
@Test
public void gettingAllImagesAsHtmlShouldReturnAViewableWithTheRightTemplateAndModelLoaded() {
	// act
	Viewable viewable = userImages.getAllHtml(USERNAME);

	assertUserImagesViewable(viewable);
}
 
Example 33
Project: pi   File: UserImagesTest.java   View source code 5 votes vote down vote up
@Test
public void getImageAsHtmlShouldReturnAViewableWithTheTemplateAndModel() {
	// act
	Viewable viewable = userImages.getImageHtml(USERNAME, IMAGE_ID);

	// assert
	assertUserImagesViewable(viewable);
}
 
Example 34
Project: pi   File: UserImagesTest.java   View source code 5 votes vote down vote up
@SuppressWarnings("unchecked")
private void assertUserImagesViewable(Viewable viewable) {
	assertNotNull(viewable);
	assertNotNull(viewable.getModel());
	final Map<String, Object> model = (Map<String, Object>) viewable.getModel();
	assertNotNull(model.get("images"));
	assertTrue(model.get("images") instanceof List);
	assertEquals(USERNAME, model.get("username"));
	assertEquals("user_images", viewable.getTemplateName());
}
 
Example 35
Project: pi   File: UsersControllerTest.java   View source code 5 votes vote down vote up
@Test
public void gettingUsersCertificateShouldReturnThePostForm() {
	// act
	Viewable viewable = usersController.getUserCertificate(USERNAME);

	// assert
	assertEquals(USERNAME, ((Map) viewable.getModel()).get("username"));
	assertEquals("post_user_cert", viewable.getTemplateName());
}
 
Example 36
Project: pi   File: UsersControllerTest.java   View source code 5 votes vote down vote up
@Test
public void setUserEnabledFlagToFalseShouldReturnViewableWithUserDisabled() {
	// act
	Viewable viewable = usersController.disableUser(USERNAME);

	// assert
	verify(userManagementService).setUserEnabledFlag(USERNAME, false);
	assertNotNull(viewable);
	assertNotNull(viewable.getModel());
	Map model = (Map<String, Object>) viewable.getModel();
	assertEquals(readOnlyUser, model.get("user"));
	assertEquals(false, model.get("enabled"));
}
 
Example 37
Project: pi   File: UsersControllerTest.java   View source code 5 votes vote down vote up
@Test
public void setUserEnabledFlagToTrueShouldReturnViewableWithUserEnabled() {
	// act
	Viewable viewable = usersController.enableUser(USERNAME);

	// assert
	verify(userManagementService).setUserEnabledFlag(USERNAME, true);
	assertNotNull(viewable);
	assertNotNull(viewable.getModel());
	Map<String, Object> model = (Map<String, Object>) viewable.getModel();
	assertEquals(readOnlyUser, model.get("user"));
	assertEquals(true, model.get("enabled"));
}
 
Example 38
Project: karyon   File: AdminFreemarkerTemplateProvider.java   View source code 5 votes vote down vote up
@Override
protected URL getURL(String name) {
	URL viewResource = null;
	Viewable viewable = (Viewable)requestInvoker.get().getAttribute(ViewableResourceTemplateLoader.KEY_NETFLIX_ADMIN_REQUEST_VIEWABLE);
	if (viewable != null && viewable.getResolvingClass() != null) {
		viewResource = viewable.getResolvingClass().getResource(name);				
	}
	return viewResource;
}
 
Example 39
Project: karyon   File: AdminPageResource.java   View source code 5 votes vote down vote up
@POST
@Path("/{view}")
public Viewable createObject(
        @PathParam("view") String view,
        @QueryParam("id") @DefaultValue("") String id
) {
    LOG.info(view);
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("id", id);
    return new Viewable("/webadmin/" + view + "/create.ftl", model, adminContainerConfig.getClass());
}
 
Example 40
Project: karyon   File: AdminPageResource.java   View source code 5 votes vote down vote up
@GET
@Path("/jmx/mbean")
public Viewable showJMXMbean(@QueryParam("id") String id, @QueryParam("key") String key) {
    LOG.info("");
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("id", id);
    model.put("key", key);
    model.put("ajax_base", adminContainerConfig.ajaxDataResourceContext());

    return new Viewable("/webadmin/jmx/view.ftl", model, adminContainerConfig.getClass());
}