PageRenderTime 40ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/core/src/test/java/com/trackit/server/core/DefaultTrackableUnitQueryDispatcherTests.java

https://bitbucket.org/EvgenyKotkov/student-trackit-server
Java | 49 lines | 40 code | 8 blank | 1 comment | 0 complexity | c394a7c067a98851229fc0b6087273ce MD5 | raw file
  1. package com.trackit.server.core;
  2. import com.google.common.collect.ImmutableCollection;
  3. import com.google.gson.Gson;
  4. import org.junit.Assert;
  5. import org.junit.Ignore;
  6. import org.junit.Test;
  7. public class DefaultTrackableUnitQueryDispatcherTests {
  8. @Test
  9. @Ignore("Requires specific MongoDB setup to run.")
  10. public void testAddOrUpdateTrackableUnit() throws Exception {
  11. final TrackableUnitQueryDispatcher testedQueryDispatcher =
  12. new DefaultTrackableUnitQueryDispatcher();
  13. final DefaultTrackableUnit addedTrackableUnit =
  14. new DefaultTrackableUnit("trackableUnit", "imageString");
  15. testedQueryDispatcher.addOrUpdateTrackableUnit(addedTrackableUnit);
  16. final ImmutableCollection<TrackableUnit> allTrackableUnits =
  17. testedQueryDispatcher.getAllTrackableUnits();
  18. Assert.assertEquals(1, allTrackableUnits.size());
  19. Assert.assertTrue(allTrackableUnits.contains(addedTrackableUnit));
  20. // Ensure that no more entities would be added.
  21. testedQueryDispatcher.addOrUpdateTrackableUnit(addedTrackableUnit);
  22. final ImmutableCollection<TrackableUnit> allTrackableUnitsAfterSecondAddition =
  23. testedQueryDispatcher.getAllTrackableUnits();
  24. Assert.assertEquals(1, allTrackableUnitsAfterSecondAddition.size());
  25. }
  26. @Test
  27. @Ignore("Requires specific MongoDB setup to run.")
  28. public void testJsonEncodingForRetrievedTrackableUnits() throws Exception {
  29. final TrackableUnitQueryDispatcher testedQueryDispatcher =
  30. new DefaultTrackableUnitQueryDispatcher();
  31. final DefaultTrackableUnit addedTrackableUnit =
  32. new DefaultTrackableUnit("UNIQUE_MARKER", "IMAGE123");
  33. testedQueryDispatcher.addOrUpdateTrackableUnit(addedTrackableUnit);
  34. final ImmutableCollection<TrackableUnit> allTrackableUnits =
  35. testedQueryDispatcher.getAllTrackableUnits();
  36. String gson = new Gson().toJson(allTrackableUnits);
  37. Assert.assertTrue(gson.length() > 0);
  38. Assert.assertTrue(gson.contains("UNIQUE_MARKER"));
  39. Assert.assertTrue(gson.contains("IMAGE123"));
  40. }
  41. }