@Test public void testGetBuckets() { Experiment.ID id = Experiment.ID.newInstance(); List firstQueryResult = mock(List.class); when(transaction.select(anyString(), eq(id), eq(DELETED.toString()))).thenReturn(firstQueryResult); when(firstQueryResult.size()).thenReturn(0); BDDCatchException.when(repository).getBuckets(id, false); BDDCatchException.then(caughtException()) .isInstanceOf(ExperimentNotFoundException.class) .hasMessageContaining("Experiment") .hasNoCause(); verify(transaction, times(1)).select(anyString(), Matchers.anyVararg()); when(firstQueryResult.size()).thenReturn(1); List secondQueryResult = new ArrayList(); Map queryMap = mock(Map.class, RETURNS_DEEP_STUBS); secondQueryResult.add(queryMap); when(queryMap.get("label")).thenReturn("label"); when(queryMap.get("allocation_percent")).thenReturn(1.0); when(queryMap.get("description")).thenReturn("description"); when(queryMap.get("is_control")).thenReturn(true); when(queryMap.get("payload")).thenReturn("payload"); when(transaction.select(anyString(), eq(id))).thenReturn(secondQueryResult); BucketList result = repository.getBuckets(id, false); assertThat(result, is(not(nullValue()))); assertThat(result.getBuckets().size(), is(1)); assertThat(result.getBuckets().get(0).getExperimentID(), is(id)); }
@Override public BucketList getBuckets(Experiment.ID experimentID, boolean checkExperiment) throws RepositoryException { final String SQL_SELECT_ID = "select id from experiment " + "where id=? and state != ?"; List experiments = newTransaction().select( SQL_SELECT_ID, experimentID, DELETED.toString()); if (experiments.size() == 0) { throw new ExperimentNotFoundException(experimentID); } final String SQL_SELECT_EXPERIMENT = "select label, allocation_percent, is_control, " + " payload, description " + "from bucket " + "where experiment_id=? order by id"; List buckets = newTransaction().select( SQL_SELECT_EXPERIMENT, experimentID); BucketList returnBuckets = new BucketList(); for (Object bucket : buckets) { Map bucketMap = (Map) bucket; Bucket.Label label = Bucket.Label.valueOf( (String) bucketMap.get("label")); Bucket returnBuck = Bucket.newInstance(experimentID, label) .withAllocationPercent((Double) bucketMap.get("allocation_percent")) .withDescription((String) bucketMap.get("description")) .withControl((Boolean) bucketMap.get("is_control")) .withPayload((String) bucketMap.get("payload")) .build(); returnBuckets.addBucket(returnBuck); } return returnBuckets; }
DatabaseExperimentRepository implements ExperimentRepository { @Override public BucketList getBuckets(Experiment.ID experimentID, boolean checkExperiment) throws RepositoryException { final String SQL_SELECT_ID = "select id from experiment " + "where id=? and state != ?"; List experiments = newTransaction().select( SQL_SELECT_ID, experimentID, DELETED.toString()); if (experiments.size() == 0) { throw new ExperimentNotFoundException(experimentID); } final String SQL_SELECT_EXPERIMENT = "select label, allocation_percent, is_control, " + " payload, description " + "from bucket " + "where experiment_id=? order by id"; List buckets = newTransaction().select( SQL_SELECT_EXPERIMENT, experimentID); BucketList returnBuckets = new BucketList(); for (Object bucket : buckets) { Map bucketMap = (Map) bucket; Bucket.Label label = Bucket.Label.valueOf( (String) bucketMap.get("label")); Bucket returnBuck = Bucket.newInstance(experimentID, label) .withAllocationPercent((Double) bucketMap.get("allocation_percent")) .withDescription((String) bucketMap.get("description")) .withControl((Boolean) bucketMap.get("is_control")) .withPayload((String) bucketMap.get("payload")) .build(); returnBuckets.addBucket(returnBuck); } return returnBuckets; } }
DatabaseExperimentRepository implements ExperimentRepository { @Override public BucketList getBuckets(Experiment.ID experimentID, boolean checkExperiment) throws RepositoryException { final String SQL_SELECT_ID = "select id from experiment " + "where id=? and state != ?"; List experiments = newTransaction().select( SQL_SELECT_ID, experimentID, DELETED.toString()); if (experiments.size() == 0) { throw new ExperimentNotFoundException(experimentID); } final String SQL_SELECT_EXPERIMENT = "select label, allocation_percent, is_control, " + " payload, description " + "from bucket " + "where experiment_id=? order by id"; List buckets = newTransaction().select( SQL_SELECT_EXPERIMENT, experimentID); BucketList returnBuckets = new BucketList(); for (Object bucket : buckets) { Map bucketMap = (Map) bucket; Bucket.Label label = Bucket.Label.valueOf( (String) bucketMap.get("label")); Bucket returnBuck = Bucket.newInstance(experimentID, label) .withAllocationPercent((Double) bucketMap.get("allocation_percent")) .withDescription((String) bucketMap.get("description")) .withControl((Boolean) bucketMap.get("is_control")) .withPayload((String) bucketMap.get("payload")) .build(); returnBuckets.addBucket(returnBuck); } return returnBuckets; } @Inject  DatabaseExperimentRepository(TransactionFactory transactionFactory, ExperimentValidator validator,
                                        Flyway flyway); }
DatabaseExperimentRepository implements ExperimentRepository { @Override public BucketList getBuckets(Experiment.ID experimentID, boolean checkExperiment) throws RepositoryException { final String SQL_SELECT_ID = "select id from experiment " + "where id=? and state != ?"; List experiments = newTransaction().select( SQL_SELECT_ID, experimentID, DELETED.toString()); if (experiments.size() == 0) { throw new ExperimentNotFoundException(experimentID); } final String SQL_SELECT_EXPERIMENT = "select label, allocation_percent, is_control, " + " payload, description " + "from bucket " + "where experiment_id=? order by id"; List buckets = newTransaction().select( SQL_SELECT_EXPERIMENT, experimentID); BucketList returnBuckets = new BucketList(); for (Object bucket : buckets) { Map bucketMap = (Map) bucket; Bucket.Label label = Bucket.Label.valueOf( (String) bucketMap.get("label")); Bucket returnBuck = Bucket.newInstance(experimentID, label) .withAllocationPercent((Double) bucketMap.get("allocation_percent")) .withDescription((String) bucketMap.get("description")) .withControl((Boolean) bucketMap.get("is_control")) .withPayload((String) bucketMap.get("payload")) .build(); returnBuckets.addBucket(returnBuck); } return returnBuckets; } @Inject  DatabaseExperimentRepository(TransactionFactory transactionFactory, ExperimentValidator validator,
                                        Flyway flyway); @Override Experiment getExperiment(Experiment.ID experimentID); @Override Map<Application.Name, List<Experiment>> getExperimentsForApps(Collection<Application.Name> appNames); @Override Experiment getExperiment(Application.Name appName,
                                    Experiment.Label experimentLabel); @Override List<Experiment.ID> getExperiments(); @Override ExperimentList getExperiments(Collection<Experiment.ID> experimentIDs); @Override Map<Experiment.ID, Experiment> getExperimentsMap(Collection<Experiment.ID> experimentIDs); @Override Table<Experiment.ID, Experiment.Label, Experiment> getExperimentList(Application.Name appName); @Override List<Application.Name> getApplicationsList(); @Override Experiment.ID createExperiment(NewExperiment newExperiment); @Override Experiment updateExperiment(Experiment experiment); @Override Experiment updateExperimentState(Experiment experiment, State state); @Override Bucket getBucket(Experiment.ID experimentID,
                            Bucket.Label bucketLabel); @Override void createBucket(Bucket newBucket); @Override Bucket updateBucket(Bucket bucket); @Override Bucket updateBucketAllocationPercentage(Bucket bucket, Double desiredAllocationPercentage); @Override Bucket updateBucketState(Bucket bucket, Bucket.State desiredState); @Override BucketList updateBucketBatch(Experiment.ID experimentID, BucketList bucketList); @Override void deleteBucket(Experiment.ID experimentID,
                             Bucket.Label bucketLabel); @Override void logBucketChanges(Experiment.ID experimentID, Bucket.Label bucketLabel,
                                 List<Bucket.BucketAuditInfo> changeList); @Override void logExperimentChanges(Experiment.ID experimentID, List<Experiment.ExperimentAuditInfo> changeList); @Override List<Experiment> getExperiments(Application.Name appName); @Override void deleteExperiment(NewExperiment newExperiment); @Override void createIndicesForNewExperiment(NewExperiment newExperiment); @Override HashMap<Experiment.ID, BucketList> getBucketList(Collection<Experiment.ID> experimentIDCollection); @Override BucketList getBucketList(Experiment.ID experimentID); @Override BucketList getBuckets(Experiment.ID experimentID, boolean checkExperiment); @Override Statement createApplication(Application.Name applicationName); @Override Map<Application.Name, Set<String>> getTagListForApplications(Collection<Application.Name> applicationNames); @Override void updateStateIndex(Experiment experiment); }
DatabaseExperimentRepository implements ExperimentRepository { @Override public BucketList getBuckets(Experiment.ID experimentID, boolean checkExperiment) throws RepositoryException { final String SQL_SELECT_ID = "select id from experiment " + "where id=? and state != ?"; List experiments = newTransaction().select( SQL_SELECT_ID, experimentID, DELETED.toString()); if (experiments.size() == 0) { throw new ExperimentNotFoundException(experimentID); } final String SQL_SELECT_EXPERIMENT = "select label, allocation_percent, is_control, " + " payload, description " + "from bucket " + "where experiment_id=? order by id"; List buckets = newTransaction().select( SQL_SELECT_EXPERIMENT, experimentID); BucketList returnBuckets = new BucketList(); for (Object bucket : buckets) { Map bucketMap = (Map) bucket; Bucket.Label label = Bucket.Label.valueOf( (String) bucketMap.get("label")); Bucket returnBuck = Bucket.newInstance(experimentID, label) .withAllocationPercent((Double) bucketMap.get("allocation_percent")) .withDescription((String) bucketMap.get("description")) .withControl((Boolean) bucketMap.get("is_control")) .withPayload((String) bucketMap.get("payload")) .build(); returnBuckets.addBucket(returnBuck); } return returnBuckets; } @Inject  DatabaseExperimentRepository(TransactionFactory transactionFactory, ExperimentValidator validator,
                                        Flyway flyway); @Override Experiment getExperiment(Experiment.ID experimentID); @Override Map<Application.Name, List<Experiment>> getExperimentsForApps(Collection<Application.Name> appNames); @Override Experiment getExperiment(Application.Name appName,
                                    Experiment.Label experimentLabel); @Override List<Experiment.ID> getExperiments(); @Override ExperimentList getExperiments(Collection<Experiment.ID> experimentIDs); @Override Map<Experiment.ID, Experiment> getExperimentsMap(Collection<Experiment.ID> experimentIDs); @Override Table<Experiment.ID, Experiment.Label, Experiment> getExperimentList(Application.Name appName); @Override List<Application.Name> getApplicationsList(); @Override Experiment.ID createExperiment(NewExperiment newExperiment); @Override Experiment updateExperiment(Experiment experiment); @Override Experiment updateExperimentState(Experiment experiment, State state); @Override Bucket getBucket(Experiment.ID experimentID,
                            Bucket.Label bucketLabel); @Override void createBucket(Bucket newBucket); @Override Bucket updateBucket(Bucket bucket); @Override Bucket updateBucketAllocationPercentage(Bucket bucket, Double desiredAllocationPercentage); @Override Bucket updateBucketState(Bucket bucket, Bucket.State desiredState); @Override BucketList updateBucketBatch(Experiment.ID experimentID, BucketList bucketList); @Override void deleteBucket(Experiment.ID experimentID,
                             Bucket.Label bucketLabel); @Override void logBucketChanges(Experiment.ID experimentID, Bucket.Label bucketLabel,
                                 List<Bucket.BucketAuditInfo> changeList); @Override void logExperimentChanges(Experiment.ID experimentID, List<Experiment.ExperimentAuditInfo> changeList); @Override List<Experiment> getExperiments(Application.Name appName); @Override void deleteExperiment(NewExperiment newExperiment); @Override void createIndicesForNewExperiment(NewExperiment newExperiment); @Override HashMap<Experiment.ID, BucketList> getBucketList(Collection<Experiment.ID> experimentIDCollection); @Override BucketList getBucketList(Experiment.ID experimentID); @Override BucketList getBuckets(Experiment.ID experimentID, boolean checkExperiment); @Override Statement createApplication(Application.Name applicationName); @Override Map<Application.Name, Set<String>> getTagListForApplications(Collection<Application.Name> applicationNames); @Override void updateStateIndex(Experiment experiment);  }