@Test public void testGetExtractor() { ParamsExtractor extractor = new ResourceWebScriptGet(); Map<String, String> templateVars = new HashMap<String, String>(); WebScriptRequest request = mock(WebScriptRequest.class); when(request.getServiceMatch()).thenReturn(new Match(null, templateVars, null)); Params params = extractor.extractParams(mockEntity(), request); assertNull("For getting a Collection there should be no entity params.", params.getEntityId()); assertNull("For getting a Collection there should be no passed params.", params.getPassedIn()); assertNull( "For getting a Collection there should be no relationshipId params.", params.getRelationshipId()); assertEquals(Paging.DEFAULT_SKIP_COUNT, params.getPaging().getSkipCount()); assertEquals(Paging.DEFAULT_MAX_ITEMS, params.getPaging().getMaxItems()); assertNotNull(params.getFilter()); assertTrue( "Default filter is BeanPropertiesFilter.AllProperties", BeanPropertiesFilter.AllProperties.class.equals(params.getFilter().getClass())); templateVars.put(ResourceLocator.ENTITY_ID, "1234"); params = extractor.extractParams(mockEntity(), request); assertNotNull(params); assertNotNull(params.getRelationsFilter()); templateVars.put(ResourceLocator.RELATIONSHIP_ID, "45678"); params = extractor.extractParams(mockRelationship(), request); assertNotNull(params); assertEquals("1234", params.getEntityId()); assertEquals("45678", params.getRelationshipId()); testExtractAddressedParams(templateVars, request, extractor); }
@Test public void testDeleteExtractor() throws IOException { ParamsExtractor extractor = new ResourceWebScriptDelete(); Map<String, String> templateVars = new HashMap<String, String>(); WebScriptRequest request = mock(WebScriptRequest.class); when(request.getServiceMatch()).thenReturn(new Match(null, templateVars, null)); Params params = null; try { params = extractor.extractParams(mockEntity(), request); fail("Should not get here. DELETE is executed against the instance URL"); } catch (UnsupportedResourceOperationException uoe) { assertNotNull(uoe); // Must throw this exception } templateVars.put(ResourceLocator.ENTITY_ID, "1234"); try { params = extractor.extractParams(mockRelationship(), request); fail("Should not get here. DELETE is executed against the instance URL"); } catch (UnsupportedResourceOperationException uoe) { assertNotNull(uoe); // Must throw this exception } templateVars.put(ResourceLocator.RELATIONSHIP_ID, "45678"); params = extractor.extractParams(mockRelationship(), request); assertNotNull(params); assertEquals("1234", params.getEntityId()); assertEquals("45678", params.getRelationshipId()); assertNotNull(params.getFilter()); assertTrue( "Default filter is BeanPropertiesFilter.AllProperties", BeanPropertiesFilter.AllProperties.class.equals(params.getFilter().getClass())); testExtractAddressedParams(templateVars, request, extractor); }
private Params testExtractAddressedParams( Map<String, String> templateVars, WebScriptRequest request, ParamsExtractor extractor) { templateVars.clear(); templateVars.put(ResourceLocator.ENTITY_ID, "1234"); templateVars.put(ResourceLocator.RELATIONSHIP_RESOURCE, "codfish"); Params params = extractor.extractParams(mockProperty(), request); assertNotNull(params); assertTrue(params.hasBinaryProperty("codfish")); assertFalse(params.hasBinaryProperty("something")); assertEquals("codfish", params.getBinaryProperty()); return params; }