@Test public void testConstrainResponse_FetchLimit() { AgEntity<Tr> entity = metadata.getAgEntity(Tr.class); SizeConstraints s1 = new SizeConstraints().fetchLimit(5); SizeConstraints s2 = new SizeConstraints().fetchLimit(0); ResourceEntity<Tr> t1 = new RootResourceEntity<>(entity, null); constraintsHandler.constrainResponse(t1, s1, null); assertEquals(5, t1.getFetchLimit()); assertEquals(5, s1.getFetchLimit()); ResourceEntity<Tr> t1_1 = new RootResourceEntity<>(entity, null); t1_1.setFetchLimit(0); constraintsHandler.constrainResponse(t1_1, s1, null); assertEquals(5, t1_1.getFetchLimit()); assertEquals(5, s1.getFetchLimit()); ResourceEntity<Tr> t1_2 = new RootResourceEntity<>(entity, null); t1_2.setFetchLimit(-1); constraintsHandler.constrainResponse(t1_2, s1, null); assertEquals(5, t1_2.getFetchLimit()); assertEquals(5, s1.getFetchLimit()); ResourceEntity<Tr> t2 = new RootResourceEntity<>(entity, null); t2.setFetchLimit(3); constraintsHandler.constrainResponse(t2, s1, null); assertEquals(3, t2.getFetchLimit()); assertEquals(5, s1.getFetchLimit()); ResourceEntity<Tr> t3 = new RootResourceEntity<>(entity, null); t3.setFetchLimit(6); constraintsHandler.constrainResponse(t3, s1, null); assertEquals(5, t3.getFetchLimit()); assertEquals(5, s1.getFetchLimit()); ResourceEntity<Tr> t4 = new RootResourceEntity<>(entity, null); t4.setFetchLimit(6); constraintsHandler.constrainResponse(t4, s2, null); assertEquals(6, t4.getFetchLimit()); assertEquals(0, s2.getFetchLimit()); }
@Override public <T> void constrainResponse(ResourceEntity<T> entity, SizeConstraints sizeConstraints, Constraint<T> c) { if (sizeConstraints != null) { applySizeConstraintsForRead(entity, sizeConstraints); } if (!treeConstraintsHandler.constrainResponse(entity, c)) { entityConstraintHandler.constrainResponse(entity); } }
ConstraintsHandler implements IConstraintsHandler { @Override public <T> void constrainResponse(ResourceEntity<T> entity, SizeConstraints sizeConstraints, Constraint<T> c) { if (sizeConstraints != null) { applySizeConstraintsForRead(entity, sizeConstraints); } if (!treeConstraintsHandler.constrainResponse(entity, c)) { entityConstraintHandler.constrainResponse(entity); } } }
ConstraintsHandler implements IConstraintsHandler { @Override public <T> void constrainResponse(ResourceEntity<T> entity, SizeConstraints sizeConstraints, Constraint<T> c) { if (sizeConstraints != null) { applySizeConstraintsForRead(entity, sizeConstraints); } if (!treeConstraintsHandler.constrainResponse(entity, c)) { entityConstraintHandler.constrainResponse(entity); } } ConstraintsHandler(
            @Inject(DEFAULT_READ_CONSTRAINTS_LIST) List<EntityConstraint> readConstraints,
            @Inject(DEFAULT_WRITE_CONSTRAINTS_LIST) List<EntityConstraint> writeConstraints
    ); }
ConstraintsHandler implements IConstraintsHandler { @Override public <T> void constrainResponse(ResourceEntity<T> entity, SizeConstraints sizeConstraints, Constraint<T> c) { if (sizeConstraints != null) { applySizeConstraintsForRead(entity, sizeConstraints); } if (!treeConstraintsHandler.constrainResponse(entity, c)) { entityConstraintHandler.constrainResponse(entity); } } ConstraintsHandler(
            @Inject(DEFAULT_READ_CONSTRAINTS_LIST) List<EntityConstraint> readConstraints,
            @Inject(DEFAULT_WRITE_CONSTRAINTS_LIST) List<EntityConstraint> writeConstraints
    ); @Override void constrainUpdate(UpdateContext<T> context, Constraint<T> c); @Override void constrainResponse(ResourceEntity<T> entity, SizeConstraints sizeConstraints, Constraint<T> c); }
ConstraintsHandler implements IConstraintsHandler { @Override public <T> void constrainResponse(ResourceEntity<T> entity, SizeConstraints sizeConstraints, Constraint<T> c) { if (sizeConstraints != null) { applySizeConstraintsForRead(entity, sizeConstraints); } if (!treeConstraintsHandler.constrainResponse(entity, c)) { entityConstraintHandler.constrainResponse(entity); } } ConstraintsHandler(
            @Inject(DEFAULT_READ_CONSTRAINTS_LIST) List<EntityConstraint> readConstraints,
            @Inject(DEFAULT_WRITE_CONSTRAINTS_LIST) List<EntityConstraint> writeConstraints
    ); @Override void constrainUpdate(UpdateContext<T> context, Constraint<T> c); @Override void constrainResponse(ResourceEntity<T> entity, SizeConstraints sizeConstraints, Constraint<T> c); static final String DEFAULT_READ_CONSTRAINTS_LIST; static final String DEFAULT_WRITE_CONSTRAINTS_LIST; }