/** * @verifies return default representation if given null * @see RestServiceImpl#getRepresentation(String) */ @Test public void getRepresentation_shouldReturnDefaultRepresentationIfGivenNull() throws Exception { assertThat(restService.getRepresentation(null), is(Representation.DEFAULT)); }
/** * @verifies return default representation if given string is empty * @see RestServiceImpl#getRepresentation(String) */ @Test public void getRepresentation_shouldReturnDefaultRepresentationIfGivenStringIsEmpty() throws Exception { assertThat(restService.getRepresentation(""), is(Representation.DEFAULT)); }
/** * @see RestService#getRepresentation(String) * @verifies get default representation when specified */ @Test public void getRepresentation_shouldGetDefaultRepresentationWhenSpecified() throws Exception { Assert.assertEquals(Representation.DEFAULT, service.getRepresentation(RestConstants.REPRESENTATION_DEFAULT)); }
/** * @see RestService#getRepresentation(String) * @verifies get full representation when specified */ @Test public void getRepresentation_shouldGetFullRepresentationWhenSpecified() throws Exception { Assert.assertEquals(Representation.FULL, service.getRepresentation(RestConstants.REPRESENTATION_FULL)); }
/** * @see RestService#getRepresentation(String) * @verifies get ref representation when specified */ @Test public void getRepresentation_shouldGetRefRepresentationWhenSpecified() throws Exception { Assert.assertEquals(Representation.REF, service.getRepresentation(RestConstants.REPRESENTATION_REF)); }
/** * @verifies return full representation if given string matches the full representation constant * @see RestServiceImpl#getRepresentation(String) */ @Test public void getRepresentation_shouldReturnFullRepresentationIfGivenStringMatchesTheFullRepresentationConstant() throws Exception { RestUtil.disableContext(); //to avoid a Context call assertThat(restService.getRepresentation("full"), is(Representation.FULL)); }
/** * @verifies return default representation if given string matches the default representation * constant * @see RestServiceImpl#getRepresentation(String) */ @Test public void getRepresentation_shouldReturnDefaultRepresentationIfGivenStringMatchesTheDefaultRepresentationConstant() throws Exception { RestUtil.disableContext(); //to avoid a Context call assertThat(restService.getRepresentation("default"), is(Representation.DEFAULT)); }
/** * @verifies return reference representation if given string matches the ref representation * constant * @see RestServiceImpl#getRepresentation(String) */ @Test public void getRepresentation_shouldReturnReferenceRepresentationIfGivenStringMatchesTheRefRepresentationConstant() throws Exception { RestUtil.disableContext(); //to avoid a Context call assertThat(restService.getRepresentation("ref"), is(Representation.REF)); }
+ " because it is the default behavior for this request"); } else { ret.setRepresentation(Context.getService(RestService.class).getRepresentation(temp));
/** * @verifies return an instance of named representation for given string if it is not empty and * does not match any other case * @see RestServiceImpl#getRepresentation(String) */ @Test public void getRepresentation_shouldReturnAnInstanceOfNamedRepresentationForGivenStringIfItIsNotEmptyAndDoesNotMatchAnyOtherCase() throws Exception { RestUtil.disableContext(); //to avoid a Context call Representation representation = restService.getRepresentation("UNKNOWNREPRESENTATION"); assertThat(representation, instanceOf(NamedRepresentation.class)); assertThat(representation.getRepresentation(), is("UNKNOWNREPRESENTATION")); }
/** * @verifies return an instance of custom representation if given string starts with the custom * representation prefix * @see RestServiceImpl#getRepresentation(String) */ @Test public void getRepresentation_shouldReturnAnInstanceOfCustomRepresentationIfGivenStringStartsWithTheCustomRepresentationPrefix() throws Exception { RestUtil.disableContext(); //to avoid a Context call Representation representation = restService.getRepresentation("custom:datatableslist"); assertThat(representation, instanceOf(CustomRepresentation.class)); assertThat(representation.getRepresentation(), is("datatableslist")); }
/** * @see RestService#getRepresentation(String) * @verifies get a named representation when specified */ @Test public void getRepresentation_shouldGetANamedRepresentationWhenSpecified() throws Exception { String namedRep = "someName"; Representation representation = service.getRepresentation(namedRep); Assert.assertTrue(representation instanceof NamedRepresentation); Assert.assertEquals(namedRep, representation.getRepresentation()); } }
/** * Tells the user their sessionId, and whether or not they are authenticated. * * @param request * @return * @should return the session id if the user is authenticated * @should return the session id if the user is not authenticated */ @RequestMapping(method = RequestMethod.GET) @ResponseBody public Object get(WebRequest request) { boolean authenticated = Context.isAuthenticated(); SimpleObject session = new SimpleObject(); session.add("sessionId", request.getSessionId()).add("authenticated", authenticated); if (authenticated) { String repParam = request.getParameter(RestConstants.REQUEST_PROPERTY_FOR_REPRESENTATION); Representation rep = (repParam != null) ? restService.getRepresentation(repParam) : Representation.DEFAULT; session.add("user", ConversionUtil.convertToRepresentation(Context.getAuthenticatedUser(), rep)); session.add("locale", Context.getLocale()); session.add("allowedLocales", Context.getAdministrationService().getAllowedLocales()); } return session; }