/** Test if int value are ok. */
 @Test(dataProvider = "persistentSearchChangeTypeData")
 public void checkIntValueTest(Map<Integer, String> expectedValues) throws Exception {
   for (Integer i : expectedValues.keySet()) {
     PersistentSearchChangeType val = PersistentSearchChangeType.valueOf(i);
     String expected = expectedValues.get(i);
     assertEquals(val.toString(), expected);
   }
 }
 /** Create correct values. */
 @DataProvider(name = "persistentSearchChangeTypeData")
 public Object[][] createPersistentSearchChangeTypeData() {
   Map<Integer, String> values = new HashMap<>();
   values.put(1, "add");
   values.put(2, "delete");
   values.put(4, "modify");
   values.put(8, "modDN");
   return new Object[][] {{values}};
 }
Пример #3
0
 @Test
 public void main() {
   Map m = new AHTMap();
   m.put(key, oldValue);
   Map.Entry e = (Map.Entry) m.entrySet().iterator().next();
   Object returnVal = e.setValue(newValue);
   assertTrue(returnVal.equals(oldValue));
   assertEquals(m.get(key), newValue);
 }
  /** Test If we have only the required values. */
  @Test(dataProvider = "persistentSearchChangeTypeData")
  public void checkRequiredValuesTest(Map<Integer, String> exceptedValues) throws Exception {
    // Retrieve the values
    PersistentSearchChangeType[] vals = PersistentSearchChangeType.values();

    // Check if we have the correct number
    assertEquals(vals.length, exceptedValues.size());

    // Check if we have the correct int value
    for (PersistentSearchChangeType val : vals) {
      assertTrue(exceptedValues.containsKey(val.intValue()));
    }
  }
  @BeforeMethod(groups = {"dev"})
  public static void setup() throws UnknownHostException {
    mongo = new Mongo("localhost", 27017);

    Map<String, String> ctxMap = new HashMap<String, String>();
    ctxMap.put(MongoSink.HOST, "localhost");
    ctxMap.put(MongoSink.PORT, "27017");
    ctxMap.put(MongoSink.DB_NAME, "test_events");
    ctxMap.put(MongoSink.COLLECTION, "test_log");
    ctxMap.put(MongoSink.BATCH_SIZE, "100");

    ctx.putAll(ctxMap);

    Context channelCtx = new Context();
    channelCtx.put("capacity", "1000000");
    channelCtx.put("transactionCapacity", "1000000");
    channel = new MemoryChannel();
    Configurables.configure(channel, channelCtx);
  }
  /** Test int to type. */
  @Test(dataProvider = "persistentSearchChangeTypeData")
  public void checkIntToTypeTest(Map<Integer, String> exceptedValues) throws Exception {
    Set<Integer> keys = exceptedValues.keySet();

    Set<PersistentSearchChangeType> expectedTypes = new HashSet<>(4);

    for (int i = 1; i <= 15; i++) {
      expectedTypes.clear();
      for (int key : keys) {
        if ((i & key) != 0) {
          expectedTypes.add(PersistentSearchChangeType.valueOf(key));
        }
      }
      Set<PersistentSearchChangeType> returnTypes = PersistentSearchChangeType.intToTypes(i);
      assertEquals(expectedTypes.size(), returnTypes.size());
      for (PersistentSearchChangeType type : expectedTypes) {
        assertTrue(returnTypes.contains(type));
      }
    }

    // We should have an exception
    try {
      PersistentSearchChangeType.intToTypes(0);
      fail();
    } catch (LDAPException expected) {
      assertEquals(
          expected.getMessage(),
          "The provided integer value indicated that there were no persistent search change types, which is not allowed");
    }

    // We should have an exception
    int i = 16;
    try {
      PersistentSearchChangeType.intToTypes(i);
      fail();
    } catch (LDAPException expected) {
      assertEquals(
          expected.getMessage(),
          "The provided integer value "
              + i
              + " was outside the range of acceptable values for an encoded change type set");
    }
  }
 /** Test invalid int values. */
 @Test(dataProvider = "persistentSearchChangeTypeData")
 public void checkInvalidIntTest(Map<Integer, String> exceptedValues) throws Exception {
   Set<Integer> keys = exceptedValues.keySet();
   for (int i = -10; i < 10; i++) {
     if (keys.contains(i)) {
       continue;
     }
     try {
       PersistentSearchChangeType.valueOf(i);
       fail();
     } catch (LDAPException e) {
       assertThat(e.getMessage())
           .contains(
               "The provided integer value "
                   + i
                   + " does not correspond to any persistent search change type");
     }
   }
 }