@Override public Resource create(DataSet content) throws FeatureException { finalizeSession(); throw new UnsupportedFeatureException(resource(),ContainerHandler.class); }
protected final void checkResponseNotNull(Object response, Class<?> feature, String violation) throws FeaturePostconditionException { if(response==null) { throw new FeaturePostconditionException(resource(),feature,violation); } }
private <T extends Resource> Adapter adapter(T resource, WriteSessionConfiguration configuration) { ResourceTemplate template=this.templateManagementService.templateOfId(resource.id().templateId()); Class<? extends ResourceHandler> handlerClass = template.handlerClass(); ResourceHandler delegate=this.templateManagementService.getHandler(handlerClass); return AdapterFactory.newAdapter(resource,delegate,this.writeSessionService,configuration); }
private Resource findResource(Name<?> name, Class<? extends ResourceHandler> handlerClass) { ResourceTemplate template = this.templateManagementService.templateOfHandler(handlerClass); ResourceId id = ResourceId.createId(name,template); return this.resourceRepository.resourceOfId(id); }
@Test public void createdAdapterFailsOnInternalQueryFailure(final @Mocked Resource resource, final @Mocked WriteSessionService service, final @Mocked WriteSessionConfiguration configuration, final @Mocked WriteSession session) throws Exception { Adapter adapter=prepareAdapter(resource, service,configuration, new MockResourceSnapshot(), new FailingHandler(),session); try { adapter.query(null); fail("Should fail if an exception is thrown on query"); } catch(FeatureException e) { verifyExpectedFeatureFailure(e, Queryable.class, session); } }
@Test public void createdAdapterFailsOnInternalUpdateFailure(final @Mocked Resource resource, final @Mocked WriteSessionService service, final @Mocked WriteSessionConfiguration configuration, final @Mocked WriteSession session) throws Exception { Adapter adapter=prepareAdapter(resource, service,configuration, new MockResourceSnapshot(), new FailingHandler(),session); try { adapter.update(null); fail("Should fail if an exception is thrown on update"); } catch(FeatureException e) { verifyExpectedFeatureFailure(e, Modifiable.class, session); } }
@Override public Void call() throws Exception { try { sut.updateResource(resource,updatedDate,getSessionConfiguration(resource)); } catch (FeatureException e) { e.printStackTrace(); fail("Should not fail update"); } return null; } }
/** * {@inheritDoc} */ @Override public void accept(ResourceVisitor visitor) { visitor.visitResource(this); }
@Override public ResourceControllerService build() { return new ResourceControllerService( service(WriteSessionService.class), service(TemplateManagementService.class)); }
protected final FeatureException featureException(Throwable cause, Class<?> feature) { return new FeatureExecutionException(resource(),feature,cause); }
protected final <S> S as(Class<? extends S> clazz) throws UnsupportedFeatureException { if(clazz.isInstance(this.delegate)) { return clazz.cast(this.delegate); } throw new UnsupportedFeatureException(resource(),clazz); }
@SuppressWarnings("unchecked") @Override public Class<? extends ContainerHandler> handlerClass() { return (Class<? extends ContainerHandler>)super.handlerClass(); }
/** * {@inheritDoc} */ @Override public void accept(ResourceVisitor visitor) { visitor.visitResource(this); }