コード例 #1
0
  @Test
  public void testNoFactories() {
    assertTrue(GlobalIDFactory.setIntIDFactory(null).isChanged());
    assertTrue(GlobalIDFactory.setPersistentIntIDFactory(null).isChanged());
    assertTrue(GlobalIDFactory.setStringIDFactory(null).isChanged());
    assertTrue(GlobalIDFactory.setPersistentStringIDFactory(null).isChanged());
    assertFalse(GlobalIDFactory.hasPersistentIntIDFactory());

    try {
      GlobalIDFactory.getNewIntID();
      fail();
    } catch (final IllegalStateException ex) {
    }
    try {
      GlobalIDFactory.getNewPersistentIntID();
      fail();
    } catch (final IllegalStateException ex) {
    }
    try {
      GlobalIDFactory.getNewStringID();
      fail();
    } catch (final IllegalStateException ex) {
    }
    try {
      GlobalIDFactory.getNewPersistentStringID();
      fail();
    } catch (final IllegalStateException ex) {
    }
  }
コード例 #2
0
  @Test
  public void testGetNewID() {
    // value always > 0?
    assertTrue(GlobalIDFactory.getNewIntID() > 0);

    // 2 invocation return different results?
    assertFalse(GlobalIDFactory.getNewIntID() == GlobalIDFactory.getNewIntID());

    // 2 invocation return different results?
    assertFalse(GlobalIDFactory.getNewStringID().equals(GlobalIDFactory.getNewStringID()));

    GlobalIDFactory.getNewIntID();
    GlobalIDFactory.getNewPersistentIntID();
    GlobalIDFactory.getNewStringID();
    GlobalIDFactory.getNewPersistentStringID();
  }
コード例 #3
0
ファイル: Favorite.java プロジェクト: mathewdenis/ph-oton
 public Favorite(
     @Nonnull @Nonempty final String sUserID,
     @Nonnull @Nonempty final String sApplicationID,
     @Nonnull @Nonempty final String sMenuItemID,
     @Nonnull @Nonempty final String sDisplayName,
     @Nullable final Map<String, String> aAdditionalParams) {
   this(
       GlobalIDFactory.getNewPersistentStringID(),
       sUserID,
       sApplicationID,
       sMenuItemID,
       sDisplayName,
       aAdditionalParams);
 }
コード例 #4
0
 @AfterClass
 public static void reset() {
   assertTrue(GlobalIDFactory.setIntIDFactory(new MemoryIntIDFactory()).isChanged());
   assertTrue(GlobalIDFactory.setPersistentIntIDFactory(new MemoryIntIDFactory()).isChanged());
   assertTrue(GlobalIDFactory.setLongIDFactory(new MemoryLongIDFactory()).isChanged());
   assertTrue(GlobalIDFactory.setPersistentLongIDFactory(new MemoryLongIDFactory()).isChanged());
   assertTrue(
       GlobalIDFactory.setStringIDFactory(new StringIDFromGlobalIntIDFactory()).isChanged());
   assertTrue(
       GlobalIDFactory.setPersistentStringIDFactory(new StringIDFromGlobalPersistentIntIDFactory())
           .isChanged());
   FileOperations.deleteFile(new File("idint.dat"));
   FileOperations.deleteFile(new File("idlong.dat"));
 }
コード例 #5
0
  @BeforeClass
  public static void testSet() {
    // int factories
    assertTrue(GlobalIDFactory.setIntIDFactory(new MemoryIntIDFactory(9)).isChanged());
    assertTrue(GlobalIDFactory.setIntIDFactory(new MemoryIntIDFactory(10)).isChanged());
    assertFalse(GlobalIDFactory.setIntIDFactory(new MemoryIntIDFactory(10)).isChanged());
    assertTrue(GlobalIDFactory.setPersistentIntIDFactory(new MemoryIntIDFactory()).isChanged());
    assertTrue(GlobalIDFactory.setPersistentIntIDFactory(new MemoryIntIDFactory(10)).isChanged());
    assertFalse(GlobalIDFactory.setPersistentIntIDFactory(new MemoryIntIDFactory(10)).isChanged());
    assertTrue(GlobalIDFactory.setIntIDFactory(new MemoryStaticIntIDFactory()).isChanged());
    assertFalse(GlobalIDFactory.setIntIDFactory(new MemoryStaticIntIDFactory()).isChanged());
    assertTrue(
        GlobalIDFactory.setPersistentIntIDFactory(new FileIntIDFactory(new File("idint.dat")))
            .isChanged());
    assertTrue(GlobalIDFactory.hasPersistentIntIDFactory());

    // long factories
    assertTrue(GlobalIDFactory.setLongIDFactory(new MemoryLongIDFactory(9)).isChanged());
    assertTrue(GlobalIDFactory.setLongIDFactory(new MemoryLongIDFactory(10)).isChanged());
    assertFalse(GlobalIDFactory.setLongIDFactory(new MemoryLongIDFactory(10)).isChanged());
    assertTrue(GlobalIDFactory.setPersistentLongIDFactory(new MemoryLongIDFactory()).isChanged());
    assertTrue(GlobalIDFactory.setPersistentLongIDFactory(new MemoryLongIDFactory(10)).isChanged());
    assertFalse(
        GlobalIDFactory.setPersistentLongIDFactory(new MemoryLongIDFactory(10)).isChanged());
    assertTrue(GlobalIDFactory.setLongIDFactory(new MemoryStaticLongIDFactory()).isChanged());
    assertFalse(GlobalIDFactory.setLongIDFactory(new MemoryStaticLongIDFactory()).isChanged());
    assertTrue(
        GlobalIDFactory.setPersistentLongIDFactory(new FileLongIDFactory(new File("idlong.dat")))
            .isChanged());
    assertTrue(GlobalIDFactory.hasPersistentLongIDFactory());

    // string factories
    assertTrue(
        GlobalIDFactory.setStringIDFactory(new StringIDFromGlobalIntIDFactory("prefix1"))
            .isChanged());
    assertTrue(
        GlobalIDFactory.setStringIDFactory(new StringIDFromGlobalIntIDFactory("prefix2"))
            .isChanged());
    assertFalse(
        GlobalIDFactory.setStringIDFactory(new StringIDFromGlobalIntIDFactory("prefix2"))
            .isChanged());
    assertTrue(
        GlobalIDFactory.setPersistentStringIDFactory(
                new StringIDFromGlobalPersistentIntIDFactory("prefix1"))
            .isChanged());
    assertTrue(
        GlobalIDFactory.setPersistentStringIDFactory(
                new StringIDFromGlobalPersistentIntIDFactory("prefix2"))
            .isChanged());
    assertFalse(
        GlobalIDFactory.setPersistentStringIDFactory(
                new StringIDFromGlobalPersistentIntIDFactory("prefix2"))
            .isChanged());
    assertTrue(
        GlobalIDFactory.setStringIDFactory(new StringIDFromGlobalLongIDFactory("prefix1"))
            .isChanged());
    assertTrue(
        GlobalIDFactory.setStringIDFactory(new StringIDFromGlobalLongIDFactory("prefix2"))
            .isChanged());
    assertFalse(
        GlobalIDFactory.setStringIDFactory(new StringIDFromGlobalLongIDFactory("prefix2"))
            .isChanged());
    assertTrue(
        GlobalIDFactory.setPersistentStringIDFactory(
                new StringIDFromGlobalPersistentLongIDFactory("prefix1"))
            .isChanged());
    assertTrue(
        GlobalIDFactory.setPersistentStringIDFactory(
                new StringIDFromGlobalPersistentLongIDFactory("prefix2"))
            .isChanged());
    assertFalse(
        GlobalIDFactory.setPersistentStringIDFactory(
                new StringIDFromGlobalPersistentLongIDFactory("prefix2"))
            .isChanged());
  }
コード例 #6
0
 /**
  * This method is called to initialize the global ID factory. By default a file-based {@link
  * WebIOIntIDFactory} with the filename {@link #ID_FILENAME} is created.
  */
 @OverrideOnDemand
 protected void initGlobalIDFactory() {
   // Set persistent ID provider: file based
   GlobalIDFactory.setPersistentIntIDFactory(new WebIOIntIDFactory(ID_FILENAME));
 }