Skip to content

Commit

Permalink
Added get assignment test cases for empty bucket
Browse files Browse the repository at this point in the history
  • Loading branch information
mans4singh committed Dec 1, 2016
1 parent 92bc1d4 commit 455752c
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public class Constants {
public static final String BUCKET_STATE_CLOSED = "CLOSED";
public static final String BUCKET_STATE_EMPTY = "EMPTY";

public static final String ASSIGNMENT_NO_OPEN_BUCKETS = "NO_OPEN_BUCKETS";
public static final String ASSIGNMENT_NO_PROFILE_MATCH = "NO_PROFILE_MATCH";
public static final String ASSIGNMENT_NEW_ASSIGNMENT = "NEW_ASSIGNMENT";
public static final String ASSIGNMENT_EXISTING_ASSIGNMENT = "EXISTING_ASSIGNMENT";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,47 @@ public void t_AddUserToExperimentAndEmptyBucket() {
assertEqualModelItems(assignmentForSpecialAfterReassignment, putAssignmentAfterEmpty, new DefaultNameInclusionStrategy("assignment"));
}

@Test(dependsOnGroups = {"ping"})
public void t_AddUserToExperimentAndEmptyBucketAndGetAssignment() {
experiment = ExperimentFactory.createExperiment();

DefaultNameExclusionStrategy experimentComparisonStrategy = new DefaultNameExclusionStrategy("creationTime", "modificationTime", "ruleJson");
experiment.setSerializationStrategy(experimentComparisonStrategy);

Experiment exp = postExperiment(experiment);
Assert.assertNotNull(exp.creationTime, "Experiment creation failed (No creationTime).");
Assert.assertNotNull(exp.modificationTime, "Experiment creation failed (No modificationTime).");
Assert.assertNotNull(exp.state, "Experiment creation failed (No state).");
experiment.update(exp);
buckets = BucketFactory.createBuckets(experiment, 3);
postBuckets(buckets);

// Start experiment
experiment.state = Constants.EXPERIMENT_STATE_RUNNING;
Experiment exp2 = putExperiment(experiment);
assertEqualModelItems(exp2, experiment);
experiment.update(exp);

// Assign special user to bucket 0
Assignment assignment = AssignmentFactory.createAssignment()
.setAssignment(buckets.get(0).label)
.setExperimentLabel(experiment.label)
.setOverwrite(true);
Assignment putAssignment = putAssignment(experiment, assignment, specialUser);
assertEqualModelItems(putAssignment, assignment, new DefaultNameInclusionStrategy("assignment"));
assignments.put(specialUser, putAssignment);

List<Bucket> emptyBucket = new ArrayList<>();
emptyBucket.add(buckets.get(0));
emptyBucket = putBucketsState(emptyBucket, Constants.BUCKET_STATE_EMPTY);

Assignment assignmentForSpecialAfterReassignment = getAssignment(experiment, specialUser);
Assert.assertEquals(assignmentForSpecialAfterReassignment.status,Constants.NEW_ASSIGNMENT);
Assignment assignmentForSpecialAfterReassignment2ndCall = getAssignment(experiment, specialUser);

Assert.assertEquals(assignmentForSpecialAfterReassignment2ndCall.status,
Constants.ASSIGNMENT_EXISTING_ASSIGNMENT);
Assert.assertEquals(assignmentForSpecialAfterReassignment.bucket_label,
assignmentForSpecialAfterReassignment2ndCall.bucket_label);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,45 @@ public void t_AddUserToExperimentAndEmptyBucketAndReassignToAnotherEmptyBucket()
Assignment putAssignmentAfterEmpty = putAssignment(experiment, assignmentAfterEmpty, specialUser, null, HttpStatus.SC_NOT_FOUND);

}

@Test(dependsOnGroups = {"ping"})
public void t_AddUserToExperimentAndEmptyBucketAndReassignToAnotherEmptyBucketGetAssginment() {
experiment = ExperimentFactory.createExperiment();

DefaultNameExclusionStrategy experimentComparisonStrategy = new DefaultNameExclusionStrategy("creationTime", "modificationTime", "ruleJson");
experiment.setSerializationStrategy(experimentComparisonStrategy);
Experiment exp = postExperiment(experiment);
Assert.assertNotNull(exp.creationTime, "Experiment creation failed (No creationTime).");
Assert.assertNotNull(exp.modificationTime, "Experiment creation failed (No modificationTime).");
Assert.assertNotNull(exp.state, "Experiment creation failed (No state).");
experiment.update(exp);
buckets = BucketFactory.createBuckets(experiment, 3);
postBuckets(buckets);

// Start experiment
experiment.state = Constants.EXPERIMENT_STATE_RUNNING;
Experiment exp2 = putExperiment(experiment);
assertEqualModelItems(exp2, experiment);
experiment.update(exp);

// Assign special user to bucket 0
Assignment assignment = AssignmentFactory.createAssignment()
.setAssignment(buckets.get(0).label)
.setExperimentLabel(experiment.label)
.setOverwrite(true);
Assignment putAssignment = putAssignment(experiment, assignment, specialUser);
assertEqualModelItems(putAssignment, assignment, new DefaultNameInclusionStrategy("assignment"));
assignments.put(specialUser, putAssignment);

// Empty 2 buckets
List<Bucket> emptyBucket = new ArrayList<>();
emptyBucket.add(buckets.get(0));
emptyBucket.add(buckets.get(1));
emptyBucket.add(buckets.get(2));
emptyBucket = putBucketsState(emptyBucket, Constants.BUCKET_STATE_EMPTY);

Assignment putAssignmentAfterEmpty = getAssignment(experiment, specialUser);
Assert.assertEquals(Constants.ASSIGNMENT_NO_OPEN_BUCKETS,putAssignmentAfterEmpty.status );

}
}

0 comments on commit 455752c

Please sign in to comment.