@Test public void should_delegate_provision_to_customerService_addCustomer() throws HerokuException { when(customerService.addCustomer(any())) .thenReturn( CustomerService.AddCustomerResponse.builder() .customerId(1L) .licenseKey("licenseKey") .build()); service.provision( HerokuProvisionRequest.builder() .uuid("uuid") .heroku_id("heroku_id") .plan("the-plan") .build()); verify(customerService) .addCustomer( CustomerService.AddCustomerRequest.builder() .source("heroku") .externalId("uuid") .name("heroku_id") .plan("the-plan") .build()); }
@Override @Transactional public HerokuProvisionResponse provision(HerokuProvisionRequest request) throws HerokuException { logger.debug("Handling {}", request); try { String heroku = CustomerService.Source.HEROKU; CustomerService.AddCustomerResponse response = customerService.addCustomer( CustomerService.AddCustomerRequest.builder() .source(heroku) .externalId(request.getUuid()) .name(request.getHeroku_id()) .plan(request.getPlan()) .build()); String accessToken = exchangeOAuthGrant(request, response.getLicenseKey()); fetchAppDetails(heroku, request.getUuid(), accessToken, response.getCustomerId()); Map<String, String> config = new HashMap<>(); config.put("CODEKVAST_URL", settings.getHerokuCodekvastUrl()); config.put("CODEKVAST_LICENSE_KEY", response.getLicenseKey()); HerokuProvisionResponse herokuProvisionResponse = HerokuProvisionResponse.builder().id(request.getUuid()).config(config).build(); logger.debug("Returning {}", herokuProvisionResponse); return herokuProvisionResponse; } catch (Exception e) { throw new HerokuException("Could not execute " + request, e); } }
HerokuServiceImpl implements HerokuService { @Override @Transactional public HerokuProvisionResponse provision(HerokuProvisionRequest request) throws HerokuException { logger.debug("Handling {}", request); try { String heroku = CustomerService.Source.HEROKU; CustomerService.AddCustomerResponse response = customerService.addCustomer( CustomerService.AddCustomerRequest.builder() .source(heroku) .externalId(request.getUuid()) .name(request.getHeroku_id()) .plan(request.getPlan()) .build()); String accessToken = exchangeOAuthGrant(request, response.getLicenseKey()); fetchAppDetails(heroku, request.getUuid(), accessToken, response.getCustomerId()); Map<String, String> config = new HashMap<>(); config.put("CODEKVAST_URL", settings.getHerokuCodekvastUrl()); config.put("CODEKVAST_LICENSE_KEY", response.getLicenseKey()); HerokuProvisionResponse herokuProvisionResponse = HerokuProvisionResponse.builder().id(request.getUuid()).config(config).build(); logger.debug("Returning {}", herokuProvisionResponse); return herokuProvisionResponse; } catch (Exception e) { throw new HerokuException("Could not execute " + request, e); } } }
HerokuServiceImpl implements HerokuService { @Override @Transactional public HerokuProvisionResponse provision(HerokuProvisionRequest request) throws HerokuException { logger.debug("Handling {}", request); try { String heroku = CustomerService.Source.HEROKU; CustomerService.AddCustomerResponse response = customerService.addCustomer( CustomerService.AddCustomerRequest.builder() .source(heroku) .externalId(request.getUuid()) .name(request.getHeroku_id()) .plan(request.getPlan()) .build()); String accessToken = exchangeOAuthGrant(request, response.getLicenseKey()); fetchAppDetails(heroku, request.getUuid(), accessToken, response.getCustomerId()); Map<String, String> config = new HashMap<>(); config.put("CODEKVAST_URL", settings.getHerokuCodekvastUrl()); config.put("CODEKVAST_LICENSE_KEY", response.getLicenseKey()); HerokuProvisionResponse herokuProvisionResponse = HerokuProvisionResponse.builder().id(request.getUuid()).config(config).build(); logger.debug("Returning {}", herokuProvisionResponse); return herokuProvisionResponse; } catch (Exception e) { throw new HerokuException("Could not execute " + request, e); } }  }
HerokuServiceImpl implements HerokuService { @Override @Transactional public HerokuProvisionResponse provision(HerokuProvisionRequest request) throws HerokuException { logger.debug("Handling {}", request); try { String heroku = CustomerService.Source.HEROKU; CustomerService.AddCustomerResponse response = customerService.addCustomer( CustomerService.AddCustomerRequest.builder() .source(heroku) .externalId(request.getUuid()) .name(request.getHeroku_id()) .plan(request.getPlan()) .build()); String accessToken = exchangeOAuthGrant(request, response.getLicenseKey()); fetchAppDetails(heroku, request.getUuid(), accessToken, response.getCustomerId()); Map<String, String> config = new HashMap<>(); config.put("CODEKVAST_URL", settings.getHerokuCodekvastUrl()); config.put("CODEKVAST_LICENSE_KEY", response.getLicenseKey()); HerokuProvisionResponse herokuProvisionResponse = HerokuProvisionResponse.builder().id(request.getUuid()).config(config).build(); logger.debug("Returning {}", herokuProvisionResponse); return herokuProvisionResponse; } catch (Exception e) { throw new HerokuException("Could not execute " + request, e); } }  @Override @Transactional HerokuProvisionResponse provision(HerokuProvisionRequest request); @Override void changePlan(String externalId, HerokuChangePlanRequest request); @Override void deprovision(String externalId); @Override @Transactional @Secured(Roles.ADMIN) String getAccessTokenFor(Long customerId); @Override @Secured(Roles.ADMIN) Instant getAccessTokenExpiresAtFor(Long customerId); @Override String getCallbackUrlFor(Long customerId); }
HerokuServiceImpl implements HerokuService { @Override @Transactional public HerokuProvisionResponse provision(HerokuProvisionRequest request) throws HerokuException { logger.debug("Handling {}", request); try { String heroku = CustomerService.Source.HEROKU; CustomerService.AddCustomerResponse response = customerService.addCustomer( CustomerService.AddCustomerRequest.builder() .source(heroku) .externalId(request.getUuid()) .name(request.getHeroku_id()) .plan(request.getPlan()) .build()); String accessToken = exchangeOAuthGrant(request, response.getLicenseKey()); fetchAppDetails(heroku, request.getUuid(), accessToken, response.getCustomerId()); Map<String, String> config = new HashMap<>(); config.put("CODEKVAST_URL", settings.getHerokuCodekvastUrl()); config.put("CODEKVAST_LICENSE_KEY", response.getLicenseKey()); HerokuProvisionResponse herokuProvisionResponse = HerokuProvisionResponse.builder().id(request.getUuid()).config(config).build(); logger.debug("Returning {}", herokuProvisionResponse); return herokuProvisionResponse; } catch (Exception e) { throw new HerokuException("Could not execute " + request, e); } }  @Override @Transactional HerokuProvisionResponse provision(HerokuProvisionRequest request); @Override void changePlan(String externalId, HerokuChangePlanRequest request); @Override void deprovision(String externalId); @Override @Transactional @Secured(Roles.ADMIN) String getAccessTokenFor(Long customerId); @Override @Secured(Roles.ADMIN) Instant getAccessTokenExpiresAtFor(Long customerId); @Override String getCallbackUrlFor(Long customerId);  }