PaverServiceImpl implements PaverService { @Override public void createRoad(BasicRoadModel basicModel) { Road road = new Road(); road.setName(basicModel.getName()); road.setType(RoadType.NORMAL); road.setDescription(basicModel.getDescription()); road.setTeamName(basicModel.getTeamName()); road.setContactEmail(basicModel.getContactEmail()); road.setEnabled(basicModel.isEnabled()); road.setEnabledTimeStamp(clock.instant().toEpochMilli()); road.setPartitionPath(basicModel.getPartitionPath()); road.setAuthorisation(getAuthorisation(basicModel)); road.setDeleted(false); road.setMetadata(basicModel.getMetadata()); road.setCompatibilityMode(Road.DEFAULT_COMPATIBILITY_MODE); if (autoCreateHiveDestination) { HiveDestination hive = new HiveDestination(); hive.setEnabled(true); hive.setLandingInterval(HiveDestination.DEFAULT_LANDING_INTERVAL); road.setDestinations(singletonMap("hive", hive)); } roadAdminClient.createRoad(road); roadSchemaNotificationHandler.handleRoadCreated(road); } @Autowired  PaverServiceImpl(
      RoadAdminClient roadAdminClient,
      SchemaStoreClient schemaStoreClient,
      CidrBlockValidator cidrBlockBValidator,
      List<PatchMapping> mappings,
      RoadSchemaNotificationHandler roadSchemaNotificationHandler,
      @Value("${destinations.hive.autoCreate:true}") boolean autoCreateHiveDestination,
      @Value("#{clock}") Clock clock); @Override SortedSet<String> getRoadNames(); @Override void createRoad(BasicRoadModel basicModel); @Override RoadModel getRoad(String name); @Override void applyPatch(String name, List<PatchOperation> modelOperations); @Override Map<Integer, Schema> getActiveSchemas(String name); @Override SchemaVersion getActiveSchema(String name, int version); @Override SchemaVersion getLatestActiveSchema(String name); @Override SchemaVersion addSchema(String name, Schema schema); @Override SchemaVersion addSchema(String name, Schema schema, int version); @Override void deleteSchemaVersion(String name, int version); @Override void deleteRoad(String name);  }
@Test public void createRoad() throws Exception { HiveDestination hive = new HiveDestination(); hive.setEnabled(true); hive.setLandingInterval(HiveDestination.DEFAULT_LANDING_INTERVAL); road.setDestinations(singletonMap("hive", hive)); road.getAuthorisation().getOnramp().setCidrBlocks(singletonList("0.0.0.0/0")); BasicRoadModel model = new BasicRoadModel(road.getName(), road.getDescription(), road.getTeamName(), road.getContactEmail(), road.isEnabled(), road.getPartitionPath(), road.getAuthorisation(), road.getMetadata()); underTest.createRoad(model); ArgumentCaptor<Road> captor = ArgumentCaptor.forClass(Road.class); verify(roadAdminClient).createRoad(captor.capture()); Road createdRoad = captor.getValue(); assertThat(createdRoad.getCompatibilityMode(), is(Road.DEFAULT_COMPATIBILITY_MODE)); assertThat(createdRoad, is(road)); verify(notificationHandler).handleRoadCreated(road); }
@Test public void createRoadHiveDestinationDisabled() throws Exception { BasicRoadModel model = new BasicRoadModel(road.getName(), road.getDescription(), road.getTeamName(), road.getContactEmail(), road.isEnabled(), road.getPartitionPath(), null, road.getMetadata()); underTest = new PaverServiceImpl(roadAdminClient, schemaStoreClient, cidrBlockValidator, mappings, notificationHandler, false, clock); underTest.createRoad(model); ArgumentCaptor<Road> captor = ArgumentCaptor.forClass(Road.class); verify(roadAdminClient).createRoad(captor.capture()); Road createdRoad = captor.getValue(); assertThat(createdRoad.getCompatibilityMode(), is(Road.DEFAULT_COMPATIBILITY_MODE)); assertThat(createdRoad, is(road)); RoadCreatedNotification .builder() .roadName(road.getName()) .contactEmail(road.getContactEmail()) .description(road.getDescription()) .teamName(road.getTeamName()) .build(); }