@Test public void testToResource() throws Exception { ViewURLResourceProvider provider = new ViewURLResourceProvider(); Set<String> propertyIds = new HashSet<String>(); propertyIds.add(ViewURLResourceProvider.URL_NAME_PROPERTY_ID); propertyIds.add(ViewURLResourceProvider.URL_SUFFIX_PROPERTY_ID); ViewURLEntity viewURLEntity = createNiceMock(ViewURLEntity.class); ViewEntity viewEntity = createNiceMock(ViewEntity.class); ViewInstanceEntity viewInstanceEntity = createNiceMock(ViewInstanceEntity.class); expect(viewURLEntity.getUrlName()).andReturn("test").once(); expect(viewURLEntity.getUrlSuffix()).andReturn("url").once(); expect(viewURLEntity.getViewInstanceEntity()).andReturn(viewInstanceEntity).once(); expect(viewInstanceEntity.getViewEntity()).andReturn(viewEntity).once(); expect(viewEntity.getCommonName()).andReturn("FILES").once(); expect(viewEntity.getVersion()).andReturn("1.0.0").once(); expect(viewInstanceEntity.getName()).andReturn("test").once(); replay(viewURLEntity, viewEntity, viewInstanceEntity); Resource resource = provider.toResource(viewURLEntity); assertEquals(resource.getPropertyValue(ViewURLResourceProvider.URL_NAME_PROPERTY_ID),"test"); assertEquals(resource.getPropertyValue(ViewURLResourceProvider.URL_SUFFIX_PROPERTY_ID),"url"); assertEquals(resource.getPropertyValue(ViewURLResourceProvider.VIEW_INSTANCE_NAME_PROPERTY_ID),"test"); assertEquals(resource.getPropertyValue(ViewURLResourceProvider.VIEW_INSTANCE_VERSION_PROPERTY_ID),"1.0.0"); assertEquals(resource.getPropertyValue(ViewURLResourceProvider.VIEW_INSTANCE_COMMON_NAME_PROPERTY_ID),"FILES"); verify(viewURLEntity,viewInstanceEntity,viewEntity); }
protected Resource toResource(ViewURLEntity viewURLEntity) { Resource resource = new ResourceImpl(Resource.Type.ViewURL); resource.setProperty(URL_NAME_PROPERTY_ID,viewURLEntity.getUrlName()); resource.setProperty(URL_SUFFIX_PROPERTY_ID,viewURLEntity.getUrlSuffix()); ViewInstanceEntity viewInstanceEntity = viewURLEntity.getViewInstanceEntity(); if(viewInstanceEntity == null) return resource; ViewEntity viewEntity = viewInstanceEntity.getViewEntity(); String viewName = viewEntity.getCommonName(); String version = viewEntity.getVersion(); String name = viewInstanceEntity.getName(); resource.setProperty(VIEW_INSTANCE_NAME_PROPERTY_ID,name); resource.setProperty(VIEW_INSTANCE_VERSION_PROPERTY_ID,version); resource.setProperty(VIEW_INSTANCE_COMMON_NAME_PROPERTY_ID,viewName); return resource; }
ViewURLResourceProvider extends AbstractAuthorizedResourceProvider { protected Resource toResource(ViewURLEntity viewURLEntity) { Resource resource = new ResourceImpl(Resource.Type.ViewURL); resource.setProperty(URL_NAME_PROPERTY_ID,viewURLEntity.getUrlName()); resource.setProperty(URL_SUFFIX_PROPERTY_ID,viewURLEntity.getUrlSuffix()); ViewInstanceEntity viewInstanceEntity = viewURLEntity.getViewInstanceEntity(); if(viewInstanceEntity == null) return resource; ViewEntity viewEntity = viewInstanceEntity.getViewEntity(); String viewName = viewEntity.getCommonName(); String version = viewEntity.getVersion(); String name = viewInstanceEntity.getName(); resource.setProperty(VIEW_INSTANCE_NAME_PROPERTY_ID,name); resource.setProperty(VIEW_INSTANCE_VERSION_PROPERTY_ID,version); resource.setProperty(VIEW_INSTANCE_COMMON_NAME_PROPERTY_ID,viewName); return resource; } }
ViewURLResourceProvider extends AbstractAuthorizedResourceProvider { protected Resource toResource(ViewURLEntity viewURLEntity) { Resource resource = new ResourceImpl(Resource.Type.ViewURL); resource.setProperty(URL_NAME_PROPERTY_ID,viewURLEntity.getUrlName()); resource.setProperty(URL_SUFFIX_PROPERTY_ID,viewURLEntity.getUrlSuffix()); ViewInstanceEntity viewInstanceEntity = viewURLEntity.getViewInstanceEntity(); if(viewInstanceEntity == null) return resource; ViewEntity viewEntity = viewInstanceEntity.getViewEntity(); String viewName = viewEntity.getCommonName(); String version = viewEntity.getVersion(); String name = viewInstanceEntity.getName(); resource.setProperty(VIEW_INSTANCE_NAME_PROPERTY_ID,name); resource.setProperty(VIEW_INSTANCE_VERSION_PROPERTY_ID,version); resource.setProperty(VIEW_INSTANCE_COMMON_NAME_PROPERTY_ID,viewName); return resource; } ViewURLResourceProvider(); }
ViewURLResourceProvider extends AbstractAuthorizedResourceProvider { protected Resource toResource(ViewURLEntity viewURLEntity) { Resource resource = new ResourceImpl(Resource.Type.ViewURL); resource.setProperty(URL_NAME_PROPERTY_ID,viewURLEntity.getUrlName()); resource.setProperty(URL_SUFFIX_PROPERTY_ID,viewURLEntity.getUrlSuffix()); ViewInstanceEntity viewInstanceEntity = viewURLEntity.getViewInstanceEntity(); if(viewInstanceEntity == null) return resource; ViewEntity viewEntity = viewInstanceEntity.getViewEntity(); String viewName = viewEntity.getCommonName(); String version = viewEntity.getVersion(); String name = viewInstanceEntity.getName(); resource.setProperty(VIEW_INSTANCE_NAME_PROPERTY_ID,name); resource.setProperty(VIEW_INSTANCE_VERSION_PROPERTY_ID,version); resource.setProperty(VIEW_INSTANCE_COMMON_NAME_PROPERTY_ID,viewName); return resource; } ViewURLResourceProvider(); @Override Set<Resource> getResources(Request request, Predicate predicate); @Override Map<Resource.Type, String> getKeyPropertyIds(); }
ViewURLResourceProvider extends AbstractAuthorizedResourceProvider { protected Resource toResource(ViewURLEntity viewURLEntity) { Resource resource = new ResourceImpl(Resource.Type.ViewURL); resource.setProperty(URL_NAME_PROPERTY_ID,viewURLEntity.getUrlName()); resource.setProperty(URL_SUFFIX_PROPERTY_ID,viewURLEntity.getUrlSuffix()); ViewInstanceEntity viewInstanceEntity = viewURLEntity.getViewInstanceEntity(); if(viewInstanceEntity == null) return resource; ViewEntity viewEntity = viewInstanceEntity.getViewEntity(); String viewName = viewEntity.getCommonName(); String version = viewEntity.getVersion(); String name = viewInstanceEntity.getName(); resource.setProperty(VIEW_INSTANCE_NAME_PROPERTY_ID,name); resource.setProperty(VIEW_INSTANCE_VERSION_PROPERTY_ID,version); resource.setProperty(VIEW_INSTANCE_COMMON_NAME_PROPERTY_ID,viewName); return resource; } ViewURLResourceProvider(); @Override Set<Resource> getResources(Request request, Predicate predicate); @Override Map<Resource.Type, String> getKeyPropertyIds(); static final String URL_NAME_PROPERTY_ID; static final String URL_SUFFIX_PROPERTY_ID; static final String VIEW_INSTANCE_VERSION_PROPERTY_ID; static final String VIEW_INSTANCE_NAME_PROPERTY_ID; static final String VIEW_INSTANCE_COMMON_NAME_PROPERTY_ID; }