### Question:
FlowResourcesManager { public FlowResources allocateFlowResources(Flow flow) throws ResourceAllocationException { log.debug("Allocate flow resources for {}.", flow); PathId forwardPathId = generatePathId(flow.getFlowId()); PathId reversePathId = generatePathId(flow.getFlowId()); try { return allocateResources(flow, forwardPathId, reversePathId); } catch (ConstraintViolationException | ResourceNotAvailableException ex) { throw new ResourceAllocationException("Unable to allocate resources", ex); } } FlowResourcesManager(PersistenceManager persistenceManager, FlowResourcesConfig config); FlowResources allocateFlowResources(Flow flow); void deallocatePathResources(PathId pathId, long unmaskedCookie, FlowEncapsulationType encapsulationType); void deallocatePathResources(FlowResources resources); Optional<EncapsulationResources> getEncapsulationResources(PathId pathId,
                                                                      PathId oppositePathId,
                                                                      FlowEncapsulationType encapsulationType);  }### Answer:
@Test public void shouldAllocateForFlow() throws ResourceAllocationException { transactionManager.doInTransaction(() -> { Flow flow = convertFlow(firstFlow); verifyAllocation(resourcesManager.allocateFlowResources(flow)); }); }
@Test public void shouldAllocateForNoBandwidthFlow() throws ResourceAllocationException { transactionManager.doInTransaction(() -> { Flow flow = convertFlow(fourthFlow); verifyMeterLessAllocation(resourcesManager.allocateFlowResources(flow)); }); }
@Test public void shouldNotConsumeVlansForSingleSwitchFlows() throws ResourceAllocationException { transactionManager.doInTransaction(() -> { final int attemps = (flowResourcesConfig.getMaxFlowTransitVlan() - flowResourcesConfig.getMinFlowTransitVlan()) / 2 + 1; for (int i = 0; i < attemps; i++) { thirdFlow.setFlowId(format("third-flow-%d", i)); Flow flow3 = convertFlow(thirdFlow); resourcesManager.allocateFlowResources(flow3); } }); }
@Test public void shouldNotConsumeMetersForUnmeteredFlows() throws ResourceAllocationException { transactionManager.doInTransaction(() -> { final int attemps = (flowResourcesConfig.getMaxFlowMeterId() - flowResourcesConfig.getMinFlowMeterId()) / 2 + 1; for (int i = 0; i < attemps; i++) { fourthFlow.setFlowId(format("fourth-flow-%d", i)); Flow flow4 = convertFlow(fourthFlow); resourcesManager.allocateFlowResources(flow4); } }); }